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