Fix incompatibilities with Swift 1.2

This commit is contained in:
Matthias Neeracher 2015-02-14 17:43:20 +01:00 committed by Matthias Neeracher
parent 6e7135d298
commit 0d25f9a5a6
9 changed files with 107 additions and 106 deletions

View File

@ -10,7 +10,7 @@ import Foundation
extension ACEView { extension ACEView {
class func themeIdByName(themeName: String) -> UInt? { class func themeIdByName(themeName: String) -> UInt? {
for (themeIdx, theme) in enumerate(ACEThemeNames.themeNames() as [NSString]) { for (themeIdx, theme) in enumerate(ACEThemeNames.themeNames() as! [String]) {
if themeName == theme { if themeName == theme {
return UInt(themeIdx) return UInt(themeIdx)
} }
@ -19,7 +19,7 @@ extension ACEView {
} }
class func handlerIdByName(handlerName: String) -> ACEKeyboardHandler? { class func handlerIdByName(handlerName: String) -> ACEKeyboardHandler? {
for (handlerIdx, handler) in enumerate(ACEKeyboardHandlerNames.humanKeyboardHandlerNames() as [NSString]) { for (handlerIdx, handler) in enumerate(ACEKeyboardHandlerNames.humanKeyboardHandlerNames() as! [String]) {
if handlerName == handler { if handlerName == handler {
return ACEKeyboardHandler(rawValue: UInt(handlerIdx))! return ACEKeyboardHandler(rawValue: UInt(handlerIdx))!
} }

View File

@ -32,7 +32,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
let workSpace = NSWorkspace.sharedWorkspace() let workSpace = NSWorkspace.sharedWorkspace()
let userDefaults = NSUserDefaults.standardUserDefaults() let userDefaults = NSUserDefaults.standardUserDefaults()
let appDefaultsURL = NSBundle.mainBundle().URLForResource("Defaults", withExtension: "plist")! let appDefaultsURL = NSBundle.mainBundle().URLForResource("Defaults", withExtension: "plist")!
let appDefaults = NSMutableDictionary(contentsOfURL: appDefaultsURL)! var appDefaults = NSDictionary(contentsOfURL: appDefaultsURL) as! [String: AnyObject]
// //
// Add dynamic app defaults // Add dynamic app defaults
// //
@ -55,12 +55,12 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
} }
func applicationDidFinishLaunching(aNotification: NSNotification) { func applicationDidFinishLaunching(aNotification: NSNotification) {
themeMenu.removeAllItems() themeMenu.removeAllItems()
for (index, theme) in enumerate(ACEThemeNames.humanThemeNames() as [NSString]) { for (index, theme) in enumerate(ACEThemeNames.humanThemeNames() as! [String]) {
let menuItem = themeMenu.addItemWithTitle(theme, action: "changeTheme:", keyEquivalent: "") let menuItem = themeMenu.addItemWithTitle(theme, action: "changeTheme:", keyEquivalent: "")
menuItem!.tag = index menuItem!.tag = index
} }
keyboardMenu.removeAllItems() keyboardMenu.removeAllItems()
for (index, theme) in enumerate(ACEKeyboardHandlerNames.humanKeyboardHandlerNames() as [NSString]) { for (index, theme) in enumerate(ACEKeyboardHandlerNames.humanKeyboardHandlerNames() as! [String]) {
let menuItem = keyboardMenu.addItemWithTitle(theme, action: "changeKeyboardHandler:", keyEquivalent: "") let menuItem = keyboardMenu.addItemWithTitle(theme, action: "changeKeyboardHandler:", keyEquivalent: "")
menuItem!.tag = index menuItem!.tag = index
} }
@ -76,7 +76,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
case "Sketchbook": case "Sketchbook":
menu.removeAllItems() menu.removeAllItems()
sketches = [String]() sketches = [String]()
for sketchBook in NSUserDefaults.standardUserDefaults().objectForKey("Sketchbooks") as [NSString] { for sketchBook in NSUserDefaults.standardUserDefaults().objectForKey("Sketchbooks") as! [String] {
if NSFileManager.defaultManager().fileExistsAtPath(sketchBook) { if NSFileManager.defaultManager().fileExistsAtPath(sketchBook) {
ASSketchBook.addSketches(menu, target: self, action: "openSketch:", path: sketchBook, sketches: &sketches) ASSketchBook.addSketches(menu, target: self, action: "openSketch:", path: sketchBook, sketches: &sketches)
} }
@ -93,7 +93,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
while menu.numberOfItems > 2 { while menu.numberOfItems > 2 {
menu.removeItemAtIndex(2) menu.removeItemAtIndex(2)
} }
for port in ASSerial.ports() as [String] { for port in ASSerial.ports() as! [String] {
menu.addItemWithTitle(port, action:"serialConnectMenu:", keyEquivalent:"") menu.addItemWithTitle(port, action:"serialConnectMenu:", keyEquivalent:"")
} }
default: default:
@ -132,7 +132,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
let sketch = ASSketchBook.findSketch(saveTo.path!) let sketch = ASSketchBook.findSketch(saveTo.path!)
switch sketch { switch sketch {
case .Sketch(_, let path): case .Sketch(_, let path):
let doc = NSDocumentController.sharedDocumentController() as NSDocumentController let doc = NSDocumentController.sharedDocumentController() as! NSDocumentController
doc.openDocumentWithContentsOfURL(NSURL(fileURLWithPath: path)!, display: true) { (doc, alreadyOpen, error) -> Void in doc.openDocumentWithContentsOfURL(NSURL(fileURLWithPath: path)!, display: true) { (doc, alreadyOpen, error) -> Void in
} }
default: default:
@ -143,7 +143,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
@IBAction func openSketch(item: NSMenuItem) { @IBAction func openSketch(item: NSMenuItem) {
let url = NSURL(fileURLWithPath: sketches[item.tag])! let url = NSURL(fileURLWithPath: sketches[item.tag])!
let doc = NSDocumentController.sharedDocumentController() as NSDocumentController let doc = NSDocumentController.sharedDocumentController() as! NSDocumentController
doc.openDocumentWithContentsOfURL(url, display: true) { (doc, alreadyOpen, error) -> Void in doc.openDocumentWithContentsOfURL(url, display: true) { (doc, alreadyOpen, error) -> Void in
} }
} }
@ -160,7 +160,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
let fileManager = NSFileManager.defaultManager() let fileManager = NSFileManager.defaultManager()
fileManager.createDirectoryAtURL(saveTo, withIntermediateDirectories:false, attributes:nil, error:nil) fileManager.createDirectoryAtURL(saveTo, withIntermediateDirectories:false, attributes:nil, error:nil)
let proj = saveTo.URLByAppendingPathComponent(saveTo.lastPathComponent!+".avrsackproj") let proj = saveTo.URLByAppendingPathComponent(saveTo.lastPathComponent!+".avrsackproj")
let docController = NSDocumentController.sharedDocumentController() as NSDocumentController let docController = NSDocumentController.sharedDocumentController() as! NSDocumentController
if let doc = docController.openUntitledDocumentAndDisplay(true, error:nil) as? ASProjDoc { if let doc = docController.openUntitledDocumentAndDisplay(true, error:nil) as? ASProjDoc {
doc.fileURL = proj doc.fileURL = proj
doc.updateProjectURL() doc.updateProjectURL()

View File

@ -48,18 +48,18 @@ class ASBuilder {
} }
func buildProject(board: String, files: ASFileTree) { func buildProject(board: String, files: ASFileTree) {
let toolChain = (NSApplication.sharedApplication().delegate as ASApplication).preferences.toolchainPath let toolChain = (NSApplication.sharedApplication().delegate as! ASApplication).preferences.toolchainPath
task = NSTask() task = NSTask()
task!.currentDirectoryPath = dir.path! task!.currentDirectoryPath = dir.path!
task!.launchPath = NSBundle.mainBundle().pathForResource("BuildProject", ofType: "")! task!.launchPath = NSBundle.mainBundle().pathForResource("BuildProject", ofType: "")!
let fileManager = NSFileManager.defaultManager() let fileManager = NSFileManager.defaultManager()
let libPath = (ASLibraries.instance().directories as NSArray).componentsJoinedByString(":") let libPath = (ASLibraries.instance().directories as NSArray).componentsJoinedByString(":")
var args = [NSString]() var args = [String]()
let boardProp = ASHardware.instance().boards[board]! let boardProp = ASHardware.instance().boards[board]!
let library = boardProp["library"]! let library = boardProp["library"]!
var corePath = library+"/cores/"+boardProp["build.core"]! var corePath = library+"/cores/"+boardProp["build.core"]!
var variantPath : NSString? var variantPath : String?
if fileManager.fileExistsAtPath(corePath) { if fileManager.fileExistsAtPath(corePath) {
if let variantName = boardProp["build.variant"] { if let variantName = boardProp["build.variant"] {
variantPath = library+"/variants/"+variantName variantPath = library+"/variants/"+variantName
@ -103,7 +103,7 @@ class ASBuilder {
let useProgrammer = mode != .Upload let useProgrammer = mode != .Upload
let interactive = mode == .Interactive let interactive = mode == .Interactive
let portPath = ASSerial.fileNameForPort(port) let portPath = ASSerial.fileNameForPort(port)
let toolChain = (NSApplication.sharedApplication().delegate as ASApplication).preferences.toolchainPath let toolChain = (NSApplication.sharedApplication().delegate as! ASApplication).preferences.toolchainPath
task = NSTask() task = NSTask()
task!.currentDirectoryPath = dir.path! task!.currentDirectoryPath = dir.path!
task!.launchPath = toolChain+"/bin/avrdude" task!.launchPath = toolChain+"/bin/avrdude"
@ -231,7 +231,7 @@ class ASBuilder {
} }
func disassembleProject(board: String) { func disassembleProject(board: String) {
let toolChain = (NSApplication.sharedApplication().delegate as ASApplication).preferences.toolchainPath let toolChain = (NSApplication.sharedApplication().delegate as! ASApplication).preferences.toolchainPath
task = NSTask() task = NSTask()
task!.currentDirectoryPath = dir.path! task!.currentDirectoryPath = dir.path!
task!.launchPath = toolChain+"/bin/avr-objdump" task!.launchPath = toolChain+"/bin/avr-objdump"

View File

@ -61,11 +61,11 @@ class ASFileNode {
func apply(closure:(ASFileNode)->()) { func apply(closure:(ASFileNode)->()) {
closure(self) closure(self)
} }
func propertyList(rootPath: NSString) -> AnyObject { func propertyList(rootPath: String) -> AnyObject {
return "" return ""
} }
class func readPropertyList(prop: NSDictionary, rootURL: NSURL) -> ASFileNode { class func readPropertyList(prop: NSDictionary, rootURL: NSURL) -> ASFileNode {
switch prop[kTypeKey] as String { switch prop[kTypeKey] as! String {
case kNodeTypeProject: case kNodeTypeProject:
return ASProject(prop, withRootURL:rootURL) return ASProject(prop, withRootURL:rootURL)
case kNodeTypeGroup: case kNodeTypeGroup:
@ -76,8 +76,8 @@ class ASFileNode {
assertionFailure("Undefined item type in file hierarchy") assertionFailure("Undefined item type in file hierarchy")
} }
} }
func paths(rootPath: NSString) -> [NSString] { func paths(rootPath: String) -> [String] {
return [NSString]() return [String]()
} }
func exists() -> Bool { func exists() -> Bool {
return true return true
@ -112,11 +112,11 @@ class ASFileGroup : ASFileNode {
self.expanded = true self.expanded = true
} }
init(_ prop: NSDictionary, withRootURL rootURL: NSURL) { init(_ prop: NSDictionary, withRootURL rootURL: NSURL) {
name = prop[kNameKey] as String name = prop[kNameKey] as! String
expanded = prop[kExpandedKey] as Bool expanded = prop[kExpandedKey] as! Bool
children = [] children = []
for child in (prop[kChildrenKey] as NSArray) { for child in (prop[kChildrenKey] as! [NSDictionary]) {
children.append(ASFileNode.readPropertyList(child as NSDictionary, rootURL: rootURL)) children.append(ASFileNode.readPropertyList(child, rootURL: rootURL))
} }
} }
override func nodeName() -> String { override func nodeName() -> String {
@ -128,15 +128,15 @@ class ASFileGroup : ASFileNode {
child.apply(closure) child.apply(closure)
} }
} }
func childrenPropertyList(rootPath: NSString) -> [AnyObject] { func childrenPropertyList(rootPath: String) -> [AnyObject] {
return children.map() { (node) in node.propertyList(rootPath) } return children.map() { (node) in node.propertyList(rootPath) }
} }
override func propertyList(rootPath: NSString) -> AnyObject { override func propertyList(rootPath: String) -> AnyObject {
return [kTypeKey: kNodeType, kNameKey: name, kExpandedKey: expanded, return [kTypeKey: kNodeType, kNameKey: name, kExpandedKey: expanded,
kChildrenKey: childrenPropertyList(rootPath)] kChildrenKey: childrenPropertyList(rootPath)]
} }
override func paths(rootPath: NSString) -> [NSString] { override func paths(rootPath: String) -> [String] {
var allPaths = [NSString]() var allPaths = [String]()
for child in children { for child in children {
allPaths += child.paths(rootPath) allPaths += child.paths(rootPath)
} }
@ -164,11 +164,11 @@ class ASFileItem : ASFileNode {
self.type = type self.type = type
} }
init(_ prop: NSDictionary, withRootURL rootURL: NSURL) { init(_ prop: NSDictionary, withRootURL rootURL: NSURL) {
type = ASFileType(rawValue: prop[kKindKey] as String)! type = ASFileType(rawValue: prop[kKindKey] as! String)!
if let relativeURL = NSURL(string: prop[kPathKey] as NSString, relativeToURL: rootURL) { if let relativeURL = NSURL(string: prop[kPathKey] as! String, relativeToURL: rootURL) {
url = relativeURL.standardizedURL! url = relativeURL.standardizedURL!
} else { } else {
url = NSURL(fileURLWithPath: prop[kPathKey] as NSString)!.standardizedURL! url = NSURL(fileURLWithPath:(prop[kPathKey] as! String))!.standardizedURL!
} }
} }
override func nodeName() -> String { override func nodeName() -> String {
@ -197,10 +197,10 @@ class ASFileItem : ASFileNode {
let resComp = Array(count: relCount-matchComp, repeatedValue: "..")+pathComp[matchComp..<pathCount] let resComp = Array(count: relCount-matchComp, repeatedValue: "..")+pathComp[matchComp..<pathCount]
return "/".join(resComp) return "/".join(resComp)
} }
override func propertyList(rootPath: NSString) -> AnyObject { override func propertyList(rootPath: String) -> AnyObject {
return [kTypeKey: kNodeTypeFile, kKindKey: type.rawValue, kPathKey: relativePath(rootPath)] return [kTypeKey: kNodeTypeFile, kKindKey: type.rawValue, kPathKey: relativePath(rootPath)]
} }
override func paths(rootPath: NSString) -> [NSString] { override func paths(rootPath: String) -> [String] {
return [relativePath(rootPath)] return [relativePath(rootPath)]
} }
override func exists() -> Bool { override func exists() -> Bool {
@ -232,9 +232,9 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
return root.propertyList(dir.path!) return root.propertyList(dir.path!)
} }
func readPropertyList(prop: NSDictionary) { func readPropertyList(prop: NSDictionary) {
root = ASFileNode.readPropertyList(prop, rootURL:dir) as ASProject root = ASFileNode.readPropertyList(prop, rootURL:dir) as! ASProject
} }
var paths : [NSString] { var paths : [String] {
return root.paths(dir.path!) return root.paths(dir.path!)
} }
@ -243,7 +243,7 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
if item == nil { if item == nil {
return 4 return 4
} else { } else {
return (item as ASFileGroup).children.count return (item as! ASFileGroup).children.count
} }
} }
func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject { func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject {
@ -259,7 +259,7 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
return root return root
} }
} else { } else {
let group = item as ASFileGroup let group = item as! ASFileGroup
return group.children[index] return group.children[index]
} }
} }
@ -267,6 +267,6 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
return item is ASFileGroup return item is ASFileGroup
} }
func outlineView(outlineView: NSOutlineView, objectValueForTableColumn tableColumn: NSTableColumn?, byItem item: AnyObject?) -> AnyObject? { func outlineView(outlineView: NSOutlineView, objectValueForTableColumn tableColumn: NSTableColumn?, byItem item: AnyObject?) -> AnyObject? {
return (item as ASFileNode).nodeName() return (item as! ASFileNode).nodeName()
} }
} }

View File

@ -20,12 +20,12 @@ extension NSMenu {
} }
} }
private func subdirectories(path: NSString) -> [NSString] { private func subdirectories(path: String) -> [String] {
let fileManager = NSFileManager.defaultManager() let fileManager = NSFileManager.defaultManager()
var subDirs = [NSString]() var subDirs = [String]()
var isDir : ObjCBool = false var isDir : ObjCBool = false
if fileManager.fileExistsAtPath(path, isDirectory: &isDir) && isDir { if fileManager.fileExistsAtPath(path, isDirectory: &isDir) && isDir {
for item in fileManager.contentsOfDirectoryAtPath(path, error: nil) as [NSString] { for item in fileManager.contentsOfDirectoryAtPath(path, error: nil) as! [String] {
let subPath = path+"/"+item let subPath = path+"/"+item
if fileManager.fileExistsAtPath(subPath, isDirectory: &isDir) && isDir { if fileManager.fileExistsAtPath(subPath, isDirectory: &isDir) && isDir {
subDirs.append(subPath) subDirs.append(subPath)
@ -38,9 +38,9 @@ private func subdirectories(path: NSString) -> [NSString] {
private let hardwareInstance = ASHardware() private let hardwareInstance = ASHardware()
class ASHardware { class ASHardware {
class func instance() -> ASHardware { return hardwareInstance } class func instance() -> ASHardware { return hardwareInstance }
let directories = [NSString]() var directories = [String]()
let programmers = ASProperties() var programmers = ASProperties()
let boards = ASProperties() var boards = ASProperties()
init() { init() {
// //
// Gather hardware directories // Gather hardware directories
@ -51,11 +51,11 @@ class ASHardware {
let arduinoHardwarePath = arduinoPath + "/Contents/Resources/Java/hardware" let arduinoHardwarePath = arduinoPath + "/Contents/Resources/Java/hardware"
directories += subdirectories(arduinoHardwarePath) directories += subdirectories(arduinoHardwarePath)
} }
for sketchDir in userDefaults.objectForKey("Sketchbooks") as [NSString] { for sketchDir in userDefaults.objectForKey("Sketchbooks") as! [String] {
let hardwarePath = sketchDir + "/hardware" let hardwarePath = sketchDir + "/hardware"
directories += subdirectories(hardwarePath) directories += subdirectories(hardwarePath)
} }
let property = NSRegularExpression(pattern: "\\s*(\\w+)\\.(\\S+?)\\s*=\\s*(\\S.*\\S)\\s*", options: nil, error: nil) let property = NSRegularExpression(pattern: "\\s*(\\w+)\\.(\\S+?)\\s*=\\s*(\\S.*\\S)\\s*", options: nil, error: nil)!
// //
// Gather board declarations // Gather board declarations
// //
@ -64,11 +64,11 @@ class ASHardware {
let provenience = dir.lastPathComponent let provenience = dir.lastPathComponent
if let boardsFile = NSString(contentsOfFile: boardsPath, usedEncoding: nil, error: nil) { if let boardsFile = NSString(contentsOfFile: boardsPath, usedEncoding: nil, error: nil) {
var seen = [String: Bool]() var seen = [String: Bool]()
for line in boardsFile.componentsSeparatedByString("\n") as [NSString] { for line in boardsFile.componentsSeparatedByString("\n") as! [NSString] {
if let match = property?.firstMatchInString(line, options: .Anchored, range: NSMakeRange(0, line.length)) { if let match = property.firstMatchInString(line as String, options: .Anchored, range: NSMakeRange(0, line.length)) {
let board = line.substringWithRange(match.rangeAtIndex(1)) let board = line.substringWithRange(match.rangeAtIndex(1)) as String
let property = line.substringWithRange(match.rangeAtIndex(2)) let property = line.substringWithRange(match.rangeAtIndex(2)) as String
let value = line.substringWithRange(match.rangeAtIndex(3)) let value = line.substringWithRange(match.rangeAtIndex(3)) as String
if seen.updateValue(true, forKey: board) == nil { if seen.updateValue(true, forKey: board) == nil {
boards[board] = ASPropertyEntry() boards[board] = ASPropertyEntry()
boards[board]!["provenience"] = provenience boards[board]!["provenience"] = provenience
@ -88,8 +88,8 @@ class ASHardware {
let provenience = dir.lastPathComponent let provenience = dir.lastPathComponent
if let programmersFile = NSString(contentsOfFile: programmersPath, usedEncoding: nil, error: nil) { if let programmersFile = NSString(contentsOfFile: programmersPath, usedEncoding: nil, error: nil) {
var seen = [String: Bool]() var seen = [String: Bool]()
for line in programmersFile.componentsSeparatedByString("\n") as [NSString] { for line in programmersFile.componentsSeparatedByString("\n") as! [NSString] {
if let match = property?.firstMatchInString(line, options: .Anchored, range: NSMakeRange(0, line.length)) { if let match = property.firstMatchInString(line as String, options: .Anchored, range: NSMakeRange(0, line.length)) {
let programmer = line.substringWithRange(match.rangeAtIndex(1)) let programmer = line.substringWithRange(match.rangeAtIndex(1))
let property = line.substringWithRange(match.rangeAtIndex(2)) let property = line.substringWithRange(match.rangeAtIndex(2))
let value = line.substringWithRange(match.rangeAtIndex(3)) let value = line.substringWithRange(match.rangeAtIndex(3))
@ -145,8 +145,8 @@ class ASHardware {
private let librariesInstance = ASLibraries() private let librariesInstance = ASLibraries()
class ASLibraries { class ASLibraries {
class func instance() -> ASLibraries { return librariesInstance } class func instance() -> ASLibraries { return librariesInstance }
let directories = [NSString]() var directories = [String]()
let libraries = [NSString]() var libraries = [String]()
init() { init() {
// //
// Gather hardware directories // Gather hardware directories
@ -161,7 +161,7 @@ class ASLibraries {
libraries += dirs libraries += dirs
} }
} }
for sketchDir in userDefaults.objectForKey("Sketchbooks") as [NSString] { for sketchDir in userDefaults.objectForKey("Sketchbooks") as! [String] {
let librariesPath = sketchDir + "/libraries" let librariesPath = sketchDir + "/libraries"
let dirs = subdirectories(librariesPath) let dirs = subdirectories(librariesPath)
if dirs.count > 0 { if dirs.count > 0 {

View File

@ -15,7 +15,7 @@ private let kASToolchainOther = 2
class ASPreferences: NSWindowController, NSOpenSavePanelDelegate { class ASPreferences: NSWindowController, NSOpenSavePanelDelegate {
var toolchainPref : String { var toolchainPref : String {
get { get {
return NSUserDefaults.standardUserDefaults().objectForKey("Toolchain") as String return NSUserDefaults.standardUserDefaults().objectForKey("Toolchain") as! String
} }
set(newToolchain) { set(newToolchain) {
NSUserDefaults.standardUserDefaults().setObject(newToolchain, forKey: "Toolchain") NSUserDefaults.standardUserDefaults().setObject(newToolchain, forKey: "Toolchain")
@ -50,7 +50,7 @@ class ASPreferences: NSWindowController, NSOpenSavePanelDelegate {
var toolchainPath : String { var toolchainPath : String {
get { get {
if toolchainPref != "" { if toolchainPref != ("" as String) {
return toolchainPref return toolchainPref
} else { } else {
return NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier("cc.arduino.Arduino")!.path! + return NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier("cc.arduino.Arduino")!.path! +

View File

@ -45,7 +45,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
dynamic var port : String = "" dynamic var port : String = ""
var recentBoards = [String]() var recentBoards = [String]()
var recentProgrammers = [String]() var recentProgrammers = [String]()
var logModified = NSDate.distantPast() as NSDate var logModified = NSDate.distantPast() as! NSDate
var logSize = 0 var logSize = 0
var updateLogTimer : NSTimer? var updateLogTimer : NSTimer?
@ -81,8 +81,8 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
board = userDefaults.stringForKey(kBoardKey)! board = userDefaults.stringForKey(kBoardKey)!
programmer = userDefaults.stringForKey(kProgrammerKey)! programmer = userDefaults.stringForKey(kProgrammerKey)!
port = userDefaults.stringForKey(kPortKey)! port = userDefaults.stringForKey(kPortKey)!
recentBoards = userDefaults.objectForKey(kRecentBoardsKey) as [String] recentBoards = userDefaults.objectForKey(kRecentBoardsKey) as! [String]
recentProgrammers = userDefaults.objectForKey(kRecentProgrammersKey) as [String] recentProgrammers = userDefaults.objectForKey(kRecentProgrammersKey) as! [String]
var nc = NSNotificationCenter.defaultCenter() var nc = NSNotificationCenter.defaultCenter()
themeObserver = nc.addObserverForName(kBindingsKey, object: nil, queue: nil, usingBlock: { (NSNotification) in themeObserver = nc.addObserverForName(kBindingsKey, object: nil, queue: nil, usingBlock: { (NSNotification) in
@ -164,10 +164,10 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
} }
let filesInProject = let filesInProject =
NSFileManager.defaultManager().contentsOfDirectoryAtURL(url, includingPropertiesForKeys: nil, NSFileManager.defaultManager().contentsOfDirectoryAtURL(url, includingPropertiesForKeys: nil,
options: .SkipsHiddenFiles, error: nil)! options: .SkipsHiddenFiles, error: nil) as! [NSURL]
updateProjectURL() updateProjectURL()
for file in filesInProject { for file in filesInProject {
files.addFileURL(file as NSURL) files.addFileURL(file)
} }
return true return true
} }
@ -187,14 +187,14 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
return success return success
} }
override func readFromData(data: NSData, ofType typeName: String, error outError: NSErrorPointer) -> Bool { override func readFromData(data: NSData, ofType typeName: String, error outError: NSErrorPointer) -> Bool {
if typeName != "Project" { if typeName != ("Project" as String) {
return false return false
} }
updateProjectURL() updateProjectURL()
let projectData : NSDictionary = NSPropertyListSerialization.propertyListFromData(data, mutabilityOption: .Immutable, format: nil, errorDescription: nil) as NSDictionary let projectData : NSDictionary = NSPropertyListSerialization.propertyListFromData(data, mutabilityOption: .Immutable, format: nil, errorDescription: nil) as! NSDictionary
let projectVersion = projectData[kVersionKey] as Double let projectVersion = projectData[kVersionKey] as! Double
assert(projectVersion <= floor(kCurVersion+1.0), "Project version too new for this app") assert(projectVersion <= floor(kCurVersion+1.0), "Project version too new for this app")
if let themeName = projectData[kThemeKey] as? NSString { if let themeName = projectData[kThemeKey] as? String {
if let themeId = ACEView.themeIdByName(themeName) { if let themeId = ACEView.themeIdByName(themeName) {
currentTheme = themeId currentTheme = themeId
} }
@ -202,7 +202,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
if let fontSz = projectData[kFontSizeKey] as? Int { if let fontSz = projectData[kFontSizeKey] as? Int {
fontSize = UInt(fontSz) fontSize = UInt(fontSz)
} }
files.readPropertyList(projectData[kFilesKey] as NSDictionary) files.readPropertyList(projectData[kFilesKey] as! NSDictionary)
board = (projectData[kBoardKey] as? String) ?? board board = (projectData[kBoardKey] as? String) ?? board
programmer = (projectData[kProgrammerKey] as? String) ?? programmer programmer = (projectData[kProgrammerKey] as? String) ?? programmer
port = (projectData[kPortKey] as? String) ?? port port = (projectData[kPortKey] as? String) ?? port
@ -228,13 +228,13 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
return return
} }
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) let newText = NSString(contentsOfURL:url!, usedEncoding:&enc, error:nil) as! String
editor.setString(newText) editor.setString(newText)
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
} }
} }
} }
@ -244,7 +244,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
} }
if let file = (selection as? ASFileItem) { if let file = (selection as? ASFileItem) {
var enc : UInt = 0 var enc : UInt = 0
editor.setString(NSString(contentsOfURL:file.url, usedEncoding:&enc, error:nil)) editor.setString(NSString(contentsOfURL:file.url, usedEncoding:&enc, error:nil) as! String)
editor.setMode(UInt(file.type.aceMode)) editor.setMode(UInt(file.type.aceMode))
editor.alphaValue = 1.0 editor.alphaValue = 1.0
mainEditor = selection mainEditor = selection
@ -252,7 +252,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
editor.setString("") editor.setString("")
editor.setMode(UInt(ACEModeText)) editor.setMode(UInt(ACEModeText))
editor.alphaValue = 0.8 editor.alphaValue = 0.8
logModified = NSDate.distantPast() as NSDate logModified = NSDate.distantPast() as! NSDate
logSize = -1 logSize = -1
mainEditor = selection mainEditor = selection
updateLog(nil) updateLog(nil)
@ -279,17 +279,17 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
func outlineViewSelectionDidChange(notification: NSNotification) { func outlineViewSelectionDidChange(notification: NSNotification) {
willChangeValueForKey("hasSelection") willChangeValueForKey("hasSelection")
if outline.numberOfSelectedRows < 2 { if outline.numberOfSelectedRows < 2 {
selectNode(outline.itemAtRow(outline.selectedRow) as ASFileNode?) selectNode(outline.itemAtRow(outline.selectedRow) as! ASFileNode?)
} }
didChangeValueForKey("hasSelection") didChangeValueForKey("hasSelection")
} }
func outlineViewItemDidExpand(notification: NSNotification) { func outlineViewItemDidExpand(notification: NSNotification) {
let group = notification.userInfo!["NSObject"] as ASFileGroup let group = notification.userInfo!["NSObject"] as! ASFileGroup
group.expanded = true group.expanded = true
updateChangeCount(.ChangeDone) updateChangeCount(.ChangeDone)
} }
func outlineViewItemDidCollapse(notification: NSNotification) { func outlineViewItemDidCollapse(notification: NSNotification) {
let group = notification.userInfo!["NSObject"] as ASFileGroup let group = notification.userInfo!["NSObject"] as! ASFileGroup
group.expanded = false group.expanded = false
updateChangeCount(.ChangeDone) updateChangeCount(.ChangeDone)
} }
@ -300,7 +300,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
textCell.font = NSFont.boldSystemFontOfSize(13.0) textCell.font = NSFont.boldSystemFontOfSize(13.0)
} else { } else {
textCell.font = NSFont.systemFontOfSize(13.0) textCell.font = NSFont.systemFontOfSize(13.0)
if !(item as ASFileNode).exists() { if !(item as! ASFileNode).exists() {
textCell.textColor = NSColor.redColor() textCell.textColor = NSColor.redColor()
} }
} }
@ -326,8 +326,8 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
alert.addButtonWithTitle("Move to Trash") alert.addButtonWithTitle("Move to Trash")
alert.addButtonWithTitle(selection.count == 1 ? "Remove Reference" : "Remove References") alert.addButtonWithTitle(selection.count == 1 ? "Remove Reference" : "Remove References")
alert.addButtonWithTitle("Cancel") alert.addButtonWithTitle("Cancel")
(alert.buttons[0] as NSButton).keyEquivalent = "" (alert.buttons[0] as! NSButton).keyEquivalent = ""
(alert.buttons[1] as NSButton).keyEquivalent = "\r" (alert.buttons[1] as! NSButton).keyEquivalent = "\r"
alert.beginSheetModalForWindow(outline.window!) { (response) in alert.beginSheetModalForWindow(outline.window!) { (response) in
if response != NSAlertThirdButtonReturn { if response != NSAlertThirdButtonReturn {
if response == NSAlertFirstButtonReturn { if response == NSAlertFirstButtonReturn {
@ -361,7 +361,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
panel.delegate = self panel.delegate = self
panel.beginSheetModalForWindow(outline.window!, completionHandler: { (returnCode: Int) -> Void in panel.beginSheetModalForWindow(outline.window!, completionHandler: { (returnCode: Int) -> Void in
if returnCode == NSFileHandlingPanelOKButton { if returnCode == NSFileHandlingPanelOKButton {
for url in panel.URLs as [NSURL] { for url in panel.URLs as! [NSURL] {
self.files.addFileURL(url) self.files.addFileURL(url)
} }
self.outline.deselectAll(self) self.outline.deselectAll(self)
@ -372,7 +372,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
} }
func panel(panel:NSSavePanel, shouldEnableURL url:NSURL) -> Bool { func panel(panel:AnyObject, shouldEnableURL url:NSURL) -> Bool {
var shouldEnable = true var shouldEnable = true
var resourceID : AnyObject? var resourceID : AnyObject?
url.getResourceValue(&resourceID, forKey:NSURLFileResourceIdentifierKey, error:nil) url.getResourceValue(&resourceID, forKey:NSURLFileResourceIdentifierKey, error:nil)
@ -414,7 +414,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
break break
} }
var header = "" var header = ""
if prefix != "" { if prefix != ("" as String) {
if firstPfx == "" { if firstPfx == "" {
firstPfx = prefix firstPfx = prefix
} }
@ -541,7 +541,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
pushToFront(&recentBoards, board) pushToFront(&recentBoards, board)
let userDefaults = NSUserDefaults.standardUserDefaults() let userDefaults = NSUserDefaults.standardUserDefaults()
var globalBoards = userDefaults.objectForKey(kRecentBoardsKey) as [String] var globalBoards = userDefaults.objectForKey(kRecentBoardsKey) as! [String]
pushToFront(&globalBoards, board) pushToFront(&globalBoards, board)
userDefaults.setObject(globalBoards, forKey: kRecentBoardsKey) userDefaults.setObject(globalBoards, forKey: kRecentBoardsKey)
@ -555,7 +555,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
} }
@IBAction func selectBoard(item: AnyObject) { @IBAction func selectBoard(item: AnyObject) {
selectedBoard = (item as NSMenuItem).title selectedBoard = (item as! NSMenuItem).title
} }
var selectedProgrammer : String { var selectedProgrammer : String {
@ -571,7 +571,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
pushToFront(&recentProgrammers, programmer) pushToFront(&recentProgrammers, programmer)
let userDefaults = NSUserDefaults.standardUserDefaults() let userDefaults = NSUserDefaults.standardUserDefaults()
var globalProgs = userDefaults.objectForKey(kRecentProgrammersKey) as [String] var globalProgs = userDefaults.objectForKey(kRecentProgrammersKey) as! [String]
pushToFront(&globalProgs, programmer) pushToFront(&globalProgs, programmer)
userDefaults.setObject(globalProgs, forKey: kRecentProgrammersKey) userDefaults.setObject(globalProgs, forKey: kRecentProgrammersKey)
@ -586,18 +586,18 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
} }
@IBAction func selectProgrammer(item: AnyObject) { @IBAction func selectProgrammer(item: AnyObject) {
selectedProgrammer = (item as NSMenuItem).title selectedProgrammer = (item as! NSMenuItem).title
} }
@IBAction func selectPort(item: AnyObject) { @IBAction func selectPort(item: AnyObject) {
port = (item as NSPopUpButton).titleOfSelectedItem! port = (item as! NSPopUpButton).titleOfSelectedItem!
portTool.setTitle(port) portTool.setTitle(port)
} }
var hasUploadProtocol : Bool { var hasUploadProtocol : Bool {
get { get {
if let proto = ASHardware.instance().boards[board]?["upload.protocol"] { if let proto = ASHardware.instance().boards[board]?["upload.protocol"] {
return proto != "" return proto != ("" as String)
} else { } else {
return false return false
} }
@ -609,7 +609,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
var hasValidPort : Bool { var hasValidPort : Bool {
get { get {
return (ASSerial.ports() as NSArray).containsObject(port) return contains(ASSerial.ports() as! [String], port)
} }
} }
class func keyPathsForValuesAffectingHasValidPort() -> NSSet { class func keyPathsForValuesAffectingHasValidPort() -> NSSet {
@ -618,7 +618,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
var canUpload : Bool { var canUpload : Bool {
get { get {
return hasValidPort && (hasUploadProtocol || programmer != "") return hasValidPort && (hasUploadProtocol || programmer != ("" as String))
} }
} }
class func keyPathsForValuesAffectingCanUpload() -> NSSet { class func keyPathsForValuesAffectingCanUpload() -> NSSet {

View File

@ -80,7 +80,7 @@ class ASSerialWin: NSWindowController {
let userDefaults = NSUserDefaults.standardUserDefaults() let userDefaults = NSUserDefaults.standardUserDefaults()
if let portDef = (userDefaults.objectForKey("SerialDefaults") as NSDictionary).objectForKey(port) as? [String: AnyObject] { if let portDef = (userDefaults.objectForKey("SerialDefaults") as! NSDictionary).objectForKey(port) as? [String: AnyObject] {
portDefaults = portDef portDefaults = portDef
} else { } else {
portDefaults["Theme"] = userDefaults.stringForKey("SerialTheme") portDefaults["Theme"] = userDefaults.stringForKey("SerialTheme")
@ -89,13 +89,13 @@ class ASSerialWin: NSWindowController {
portDefaults["SendLF"] = sendLF portDefaults["SendLF"] = sendLF
portDefaults["BaudRate"] = 19200 portDefaults["BaudRate"] = 19200
} }
if let themeId = ACEView.themeIdByName(portDefaults["Theme"] as String) { if let themeId = ACEView.themeIdByName(portDefaults["Theme"] as! String) {
currentTheme = themeId currentTheme = themeId
} }
fontSize = portDefaults["FontSize"] as UInt fontSize = portDefaults["FontSize"] as! UInt
sendCR = portDefaults["SendCR"] as Bool sendCR = portDefaults["SendCR"] as! Bool
sendLF = portDefaults["SendLF"] as Bool sendLF = portDefaults["SendLF"] as! Bool
baudRate = portDefaults["BaudRate"] as Int baudRate = portDefaults["BaudRate"] as! Int
if let handlerName = userDefaults.stringForKey("Bindings") { if let handlerName = userDefaults.stringForKey("Bindings") {
if let handlerId = ACEView.handlerIdByName(handlerName) { if let handlerId = ACEView.handlerIdByName(handlerName) {
@ -162,7 +162,7 @@ class ASSerialWin: NSWindowController {
logView.setString(serialData) logView.setString(serialData)
readHandle.readabilityHandler = {(handle) in readHandle.readabilityHandler = {(handle) in
let newData = handle.availableDataIgnoringExceptions() let newData = handle.availableDataIgnoringExceptions()
let newString = NSString(data: newData, encoding: NSASCIIStringEncoding)! let newString = NSString(data: newData, encoding: NSASCIIStringEncoding) as! String
self.serialData += newString self.serialData += newString
dispatch_async(dispatch_get_main_queue(), { () -> Void in dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.logView.setString(self.serialData) self.logView.setString(self.serialData)
@ -186,7 +186,7 @@ class ASSerialWin: NSWindowController {
} }
baudRate = speed baudRate = speed
self.task = task self.task = task
portHandle = (task.standardInput as NSPipe).fileHandleForWriting portHandle = (task.standardInput as! NSPipe).fileHandleForWriting
showWindow(self) showWindow(self)
installReader((task.standardOutput as? NSPipe)?.fileHandleForReading) installReader((task.standardOutput as? NSPipe)?.fileHandleForReading)
} }
@ -227,7 +227,7 @@ class ASSerialWin: NSWindowController {
} }
var hasValidPort : Bool { var hasValidPort : Bool {
get { get {
return (ASSerial.ports() as NSArray).containsObject(port) return contains(ASSerial.ports() as! [String], port)
} }
} }
@ -278,8 +278,9 @@ class ASSerialWin: NSWindowController {
} }
func updatePortDefaults() { func updatePortDefaults() {
let userDefaults = NSUserDefaults.standardUserDefaults() let userDefaults = NSUserDefaults.standardUserDefaults()
let serialDefaults = NSMutableDictionary(dictionary:userDefaults.objectForKey("SerialDefaults") as NSDictionary) let sd = userDefaults.objectForKey("SerialDefaults") as! [String: AnyObject]
let serialDefaults = NSMutableDictionary(dictionary: sd)
serialDefaults.setValue(NSDictionary(dictionary:portDefaults), forKey:port) serialDefaults.setValue(NSDictionary(dictionary:portDefaults), forKey:port)
userDefaults.setObject(serialDefaults, forKey:"SerialDefaults") userDefaults.setObject(serialDefaults, forKey:"SerialDefaults")
} }

View File

@ -15,10 +15,10 @@ class ASSketchBook {
case SketchDir(String, [SketchBookItem]) case SketchDir(String, [SketchBookItem])
} }
class func findSketch(path: NSString) -> SketchBookItem { class func findSketch(path: String) -> SketchBookItem {
let fileManager = NSFileManager.defaultManager() let fileManager = NSFileManager.defaultManager()
var inoSketch = SketchBookItem.Nothing var inoSketch = SketchBookItem.Nothing
let contents = fileManager.contentsOfDirectoryAtPath(path, error: nil) as [String] let contents = fileManager.contentsOfDirectoryAtPath(path, error: nil) as! [String]
for item in contents { for item in contents {
switch item.pathExtension { switch item.pathExtension {
case "avrsackproj": case "avrsackproj":
@ -32,9 +32,9 @@ class ASSketchBook {
return inoSketch return inoSketch
} }
private class func enumerateSketches(path: NSString) -> SketchBookItem { private class func enumerateSketches(path: String) -> SketchBookItem {
let fileManager = NSFileManager.defaultManager() let fileManager = NSFileManager.defaultManager()
let contents = fileManager.contentsOfDirectoryAtPath(path, error: nil) as [String] let contents = fileManager.contentsOfDirectoryAtPath(path, error: nil) as! [String]
let sketch = findSketch(path) let sketch = findSketch(path)
switch sketch { switch sketch {
case .Sketch: case .Sketch:
@ -98,7 +98,7 @@ class ASSketchBook {
} }
} }
class func addSketches(menu: NSMenu, target: AnyObject, action: Selector, path: NSString, inout sketches: [String]) { class func addSketches(menu: NSMenu, target: AnyObject, action: Selector, path: String, inout sketches: [String]) {
switch enumerateSketches(path) { switch enumerateSketches(path) {
case .SketchDir(let item, let sketchList): case .SketchDir(let item, let sketchList):
appendSketchesToMenu(menu, target: target, action: action, sketchList: sketchList, sketches: &sketches) appendSketchesToMenu(menu, target: target, action: action, sketchList: sketchList, sketches: &sketches)