Modernize to latest Swift
This commit is contained in:
parent
a559f9bf6e
commit
61ef712df4
|
@ -9,10 +9,10 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
extension ACEView {
|
extension ACEView {
|
||||||
class func themeIdByName(themeName: String) -> UInt? {
|
class func themeIdByName(themeName: String) -> ACETheme? {
|
||||||
for (themeIdx, theme) in enumerate(ACEThemeNames.themeNames() as! [String]) {
|
for (themeIdx, theme) in enumerate(ACEThemeNames.themeNames() as! [String]) {
|
||||||
if themeName == theme {
|
if themeName == theme {
|
||||||
return UInt(themeIdx)
|
return ACETheme(rawValue: UInt(themeIdx))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -39,11 +39,11 @@ enum ASFileType : String {
|
||||||
var aceMode : ACEMode {
|
var aceMode : ACEMode {
|
||||||
switch self {
|
switch self {
|
||||||
case .Header,.CFile,.CppFile,.Arduino:
|
case .Header,.CFile,.CppFile,.Arduino:
|
||||||
return ACEModeCPP
|
return .CPP
|
||||||
case .Markdown:
|
case .Markdown:
|
||||||
return ACEModeMarkdown
|
return .Markdown
|
||||||
default:
|
default:
|
||||||
return ACEModeText
|
return .Text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,12 @@ private let kNodeTypeGroup = "Group"
|
||||||
private let kNodeTypeFile = "File"
|
private let kNodeTypeFile = "File"
|
||||||
private let kNameKey = "Name"
|
private let kNameKey = "Name"
|
||||||
|
|
||||||
class ASFileNode {
|
//
|
||||||
|
// <rdar://problem/19787270> At the moment, Swift crashes at link time with an assertion
|
||||||
|
// if anything other than a value type or an @objc class is put into a container
|
||||||
|
// exposed to ObjC APIs. As a workaround, we declare this hierarchy @objc
|
||||||
|
//
|
||||||
|
@objc class ASFileNode {
|
||||||
func nodeName() -> String {
|
func nodeName() -> String {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
typealias ASPropertyEntry = [String: String]
|
typealias ASPropertyEntry = [String: String]
|
||||||
typealias ASProperties = [String: ASPropertyEntry]
|
typealias ASProperties = [String: ASPropertyEntry]
|
||||||
|
|
||||||
extension NSMenu {
|
extension NSMenu {
|
||||||
|
|
|
@ -62,7 +62,7 @@ class ASPreferences: NSWindowController, NSOpenSavePanelDelegate {
|
||||||
return NSSet(objects: "toolchainPref")
|
return NSSet(objects: "toolchainPref")
|
||||||
}
|
}
|
||||||
|
|
||||||
override convenience init() {
|
convenience init() {
|
||||||
self.init(windowNibName:"ASPreferences")
|
self.init(windowNibName:"ASPreferences")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,11 +32,12 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
|
||||||
@IBOutlet weak var boardTool: NSPopUpButton!
|
@IBOutlet weak var boardTool: NSPopUpButton!
|
||||||
@IBOutlet weak var progTool : NSPopUpButton!
|
@IBOutlet weak var progTool : NSPopUpButton!
|
||||||
@IBOutlet weak var portTool : NSPopUpButton!
|
@IBOutlet weak var portTool : NSPopUpButton!
|
||||||
|
@IBOutlet weak var printView: ACEView!
|
||||||
|
|
||||||
let files = ASFileTree()
|
let files = ASFileTree()
|
||||||
let builder = ASBuilder()
|
let builder = ASBuilder()
|
||||||
var mainEditor : ASFileNode?
|
var mainEditor : ASFileNode?
|
||||||
var currentTheme : UInt = 0
|
var currentTheme : ACETheme = .Xcode
|
||||||
var fontSize : UInt = 12
|
var fontSize : UInt = 12
|
||||||
var themeObserver : AnyObject!
|
var themeObserver : AnyObject!
|
||||||
var serialObserver : AnyObject!
|
var serialObserver : AnyObject!
|
||||||
|
@ -245,12 +246,12 @@ 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) as? String ?? "")
|
editor.setString(NSString(contentsOfURL:file.url, usedEncoding:&enc, error:nil) as? String ?? "")
|
||||||
editor.setMode(UInt(file.type.aceMode))
|
editor.setMode(file.type.aceMode)
|
||||||
editor.alphaValue = 1.0
|
editor.alphaValue = 1.0
|
||||||
mainEditor = selection
|
mainEditor = selection
|
||||||
} else if let log = (selection as? ASLogNode) {
|
} else if let log = (selection as? ASLogNode) {
|
||||||
editor.setString("")
|
editor.setString("")
|
||||||
editor.setMode(UInt(ACEModeText))
|
editor.setMode(.Text)
|
||||||
editor.alphaValue = 0.8
|
editor.alphaValue = 0.8
|
||||||
logModified = NSDate.distantPast() as! NSDate
|
logModified = NSDate.distantPast() as! NSDate
|
||||||
logSize = -1
|
logSize = -1
|
||||||
|
@ -274,6 +275,12 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
|
||||||
return selection
|
return selection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Printing
|
||||||
|
|
||||||
|
override func printDocument(sender: AnyObject?) {
|
||||||
|
editor.print(sender)
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Outline View Delegate
|
// MARK: Outline View Delegate
|
||||||
|
|
||||||
func outlineViewSelectionDidChange(notification: NSNotification) {
|
func outlineViewSelectionDidChange(notification: NSNotification) {
|
||||||
|
@ -449,7 +456,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
|
||||||
// MARK: Editor configuration
|
// MARK: Editor configuration
|
||||||
|
|
||||||
@IBAction func changeTheme(item: NSMenuItem) {
|
@IBAction func changeTheme(item: NSMenuItem) {
|
||||||
currentTheme = UInt(item.tag)
|
currentTheme = ACETheme(rawValue: UInt(item.tag)) ?? .Xcode
|
||||||
editor.setTheme(currentTheme)
|
editor.setTheme(currentTheme)
|
||||||
NSUserDefaults.standardUserDefaults().setObject(
|
NSUserDefaults.standardUserDefaults().setObject(
|
||||||
ACEThemeNames.humanNameForTheme(currentTheme), forKey: kThemeKey)
|
ACEThemeNames.humanNameForTheme(currentTheme), forKey: kThemeKey)
|
||||||
|
@ -465,7 +472,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
|
||||||
override func validateUserInterfaceItem(anItem: NSValidatedUserInterfaceItem) -> Bool {
|
override func validateUserInterfaceItem(anItem: NSValidatedUserInterfaceItem) -> Bool {
|
||||||
if let menuItem = anItem as? NSMenuItem {
|
if let menuItem = anItem as? NSMenuItem {
|
||||||
if menuItem.action == "changeTheme:" {
|
if menuItem.action == "changeTheme:" {
|
||||||
menuItem.state = (menuItem.tag == Int(currentTheme) ? NSOnState : NSOffState)
|
menuItem.state = (UInt(menuItem.tag) == currentTheme.rawValue ? NSOnState : NSOffState)
|
||||||
return true
|
return true
|
||||||
} else if menuItem.action == "changeKeyboardHandler:" {
|
} else if menuItem.action == "changeKeyboardHandler:" {
|
||||||
menuItem.state = (menuItem.tag == Int(keyboardHandler.rawValue) ? NSOnState : NSOffState)
|
menuItem.state = (menuItem.tag == Int(keyboardHandler.rawValue) ? NSOnState : NSOffState)
|
||||||
|
|
|
@ -39,7 +39,7 @@ class ASSerialWin: NSWindowController {
|
||||||
var serialObserver : AnyObject!
|
var serialObserver : AnyObject!
|
||||||
var termination : AnyObject!
|
var termination : AnyObject!
|
||||||
dynamic var portHandle : NSFileHandle?
|
dynamic var portHandle : NSFileHandle?
|
||||||
var currentTheme : UInt = 0
|
var currentTheme : ACETheme = .Xcode
|
||||||
var fontSize : UInt = 12
|
var fontSize : UInt = 12
|
||||||
var portDefaults = [String: AnyObject]()
|
var portDefaults = [String: AnyObject]()
|
||||||
var shouldReconnect = false
|
var shouldReconnect = false
|
||||||
|
@ -147,7 +147,7 @@ class ASSerialWin: NSWindowController {
|
||||||
logView.setTheme(currentTheme)
|
logView.setTheme(currentTheme)
|
||||||
logView.setKeyboardHandler(keyboardHandler)
|
logView.setKeyboardHandler(keyboardHandler)
|
||||||
logView.setFontSize(fontSize)
|
logView.setFontSize(fontSize)
|
||||||
logView.setMode(UInt(ACEModeText))
|
logView.setMode(.Text)
|
||||||
logView.alphaValue = 0.8
|
logView.alphaValue = 0.8
|
||||||
window?.title = port
|
window?.title = port
|
||||||
if task == nil {
|
if task == nil {
|
||||||
|
@ -235,7 +235,7 @@ class ASSerialWin: NSWindowController {
|
||||||
|
|
||||||
@IBAction func changeTheme(item: NSMenuItem) {
|
@IBAction func changeTheme(item: NSMenuItem) {
|
||||||
let userDefaults = NSUserDefaults.standardUserDefaults()
|
let userDefaults = NSUserDefaults.standardUserDefaults()
|
||||||
currentTheme = UInt(item.tag)
|
currentTheme = ACETheme(rawValue: UInt(item.tag)) ?? .Xcode
|
||||||
logView.setTheme(currentTheme)
|
logView.setTheme(currentTheme)
|
||||||
let themeName = ACEThemeNames.humanNameForTheme(currentTheme)
|
let themeName = ACEThemeNames.humanNameForTheme(currentTheme)
|
||||||
userDefaults.setObject(themeName, forKey: "SerialTheme")
|
userDefaults.setObject(themeName, forKey: "SerialTheme")
|
||||||
|
@ -252,7 +252,7 @@ class ASSerialWin: NSWindowController {
|
||||||
func validateUserInterfaceItem(anItem: NSValidatedUserInterfaceItem) -> Bool {
|
func validateUserInterfaceItem(anItem: NSValidatedUserInterfaceItem) -> Bool {
|
||||||
if let menuItem = anItem as? NSMenuItem {
|
if let menuItem = anItem as? NSMenuItem {
|
||||||
if menuItem.action == "changeTheme:" {
|
if menuItem.action == "changeTheme:" {
|
||||||
menuItem.state = (menuItem.tag == Int(currentTheme) ? NSOnState : NSOffState)
|
menuItem.state = (UInt(menuItem.tag) == currentTheme.rawValue ? NSOnState : NSOffState)
|
||||||
return true
|
return true
|
||||||
} else if menuItem.action == "changeKeyboardHandler:" {
|
} else if menuItem.action == "changeKeyboardHandler:" {
|
||||||
menuItem.state = (menuItem.tag == Int(keyboardHandler.rawValue) ? NSOnState : NSOffState)
|
menuItem.state = (menuItem.tag == Int(keyboardHandler.rawValue) ? NSOnState : NSOffState)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user