Support renaming of projects
This commit is contained in:
parent
b7586f1318
commit
0a829db165
|
@ -163,6 +163,13 @@ class ASFileGroup : ASFileNode {
|
||||||
class ASProject : ASFileGroup {
|
class ASProject : ASFileGroup {
|
||||||
override private var kNodeType : String { return kNodeTypeProject }
|
override private var kNodeType : String { return kNodeTypeProject }
|
||||||
|
|
||||||
|
override init(name: String = "") {
|
||||||
|
super.init(name: name)
|
||||||
|
}
|
||||||
|
override init(_ prop: NSDictionary, withRootURL rootURL: NSURL) {
|
||||||
|
super.init(prop, withRootURL:rootURL)
|
||||||
|
name = rootURL.lastPathComponent!
|
||||||
|
}
|
||||||
override func nodeName() -> String {
|
override func nodeName() -> String {
|
||||||
return "📘 "+name
|
return "📘 "+name
|
||||||
}
|
}
|
||||||
|
@ -187,6 +194,18 @@ class ASFileItem : ASFileNode {
|
||||||
} else {
|
} else {
|
||||||
url = NSURL(fileURLWithPath:(prop[kPathKey] as! String))!.URLByStandardizingPath!
|
url = NSURL(fileURLWithPath:(prop[kPathKey] as! String))!.URLByStandardizingPath!
|
||||||
}
|
}
|
||||||
|
if !url.checkResourceIsReachableAndReturnError(nil) {
|
||||||
|
//
|
||||||
|
// When projects get moved, .ino files get renamed but that fact is not
|
||||||
|
// yet reflected in the project file.
|
||||||
|
//
|
||||||
|
let urlDir = url.URLByDeletingLastPathComponent
|
||||||
|
let newName = rootURL.lastPathComponent!.stringByAppendingPathExtension(url.pathExtension!)!
|
||||||
|
let altURL = urlDir?.URLByAppendingPathComponent(newName)
|
||||||
|
if altURL != nil && altURL!.checkResourceIsReachableAndReturnError(nil) {
|
||||||
|
url = altURL!
|
||||||
|
}
|
||||||
|
}
|
||||||
super.init(name:url.lastPathComponent!)
|
super.init(name:url.lastPathComponent!)
|
||||||
}
|
}
|
||||||
override func nodeName() -> String {
|
override func nodeName() -> String {
|
||||||
|
|
|
@ -189,6 +189,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
|
||||||
success = writeToURL(projectURL, ofType: "Project", forSaveOperation: .SaveAsOperation, originalContentsURL: nil, error: outError)
|
success = writeToURL(projectURL, ofType: "Project", forSaveOperation: .SaveAsOperation, originalContentsURL: nil, error: outError)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
fileURL = url
|
||||||
success = super.readFromURL(url, ofType: typeName, error: outError)
|
success = super.readFromURL(url, ofType: typeName, error: outError)
|
||||||
}
|
}
|
||||||
return success
|
return success
|
||||||
|
@ -221,6 +222,11 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func duplicateDocument(sender: AnyObject?) {
|
||||||
|
let app = NSApplication.sharedApplication().delegate as! ASApplication
|
||||||
|
app.openTemplate(fileURL!.URLByDeletingLastPathComponent!)
|
||||||
|
}
|
||||||
|
|
||||||
func updateLog(AnyObject?) {
|
func updateLog(AnyObject?) {
|
||||||
if let logNode = mainEditor as? ASLogNode {
|
if let logNode = mainEditor as? ASLogNode {
|
||||||
let url = fileURL?.URLByDeletingLastPathComponent?.URLByAppendingPathComponent(logNode.path)
|
let url = fileURL?.URLByDeletingLastPathComponent?.URLByAppendingPathComponent(logNode.path)
|
||||||
|
@ -238,8 +244,8 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
|
||||||
|
|
||||||
if (modified as! NSDate).compare(logModified) == .OrderedDescending || (size as! Int) != logSize {
|
if (modified as! NSDate).compare(logModified) == .OrderedDescending || (size as! Int) != logSize {
|
||||||
var enc : UInt = 0
|
var enc : UInt = 0
|
||||||
let newText = NSString(contentsOfURL:url!, usedEncoding:&enc, error:nil) as! String
|
let newText = NSString(contentsOfURL:url!, usedEncoding:&enc, error:nil)
|
||||||
editor.setString(newText)
|
editor.setString((newText as? String) ?? "")
|
||||||
editor.gotoLine(1000000000, column: 0, animated: true)
|
editor.gotoLine(1000000000, column: 0, animated: true)
|
||||||
logModified = modified as! NSDate
|
logModified = modified as! NSDate
|
||||||
logSize = size as! Int
|
logSize = size as! Int
|
||||||
|
|
Loading…
Reference in New Issue
Block a user