Fix IBAction signatures

This commit is contained in:
Matthias Neeracher 2016-11-14 01:58:22 +01:00 committed by Matthias Neeracher
parent a806f24a1a
commit 780d132e27
4 changed files with 34 additions and 34 deletions

View File

@ -75,7 +75,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
sketches = [String]() sketches = [String]()
for sketchBook in UserDefaults.standard.object(forKey:"Sketchbooks") as! [String] { for sketchBook in UserDefaults.standard.object(forKey:"Sketchbooks") as! [String] {
if FileManager.default.fileExists(atPath: sketchBook) { if FileManager.default.fileExists(atPath: sketchBook) {
ASSketchBook.addSketches(menu: menu, target: self, action: Selector(("openSketch:")), path: sketchBook, sketches: &sketches) ASSketchBook.addSketches(menu: menu, target: self, action: #selector(ASApplication.openSketch(_:)), path: sketchBook, sketches: &sketches)
} }
} }
case "Examples": case "Examples":
@ -83,7 +83,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
examples = [String]() examples = [String]()
if let arduinoURL = NSWorkspace.shared().urlForApplication(withBundleIdentifier: "cc.arduino.Arduino") { if let arduinoURL = NSWorkspace.shared().urlForApplication(withBundleIdentifier: "cc.arduino.Arduino") {
let examplePath = arduinoURL.appendingPathComponent("Contents/Resources/Java/examples", isDirectory:true).path let examplePath = arduinoURL.appendingPathComponent("Contents/Resources/Java/examples", isDirectory:true).path
ASSketchBook.addSketches(menu: menu, target: self, action: #selector(ASApplication.openExample(item:)), path: examplePath, sketches: &examples) ASSketchBook.addSketches(menu: menu, target: self, action: #selector(ASApplication.openExample(_:)), path: examplePath, sketches: &examples)
} }
case "Import Standard Library": case "Import Standard Library":
menu.removeAllItems() menu.removeAllItems()
@ -97,14 +97,14 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
menu.removeItem(at: 2) menu.removeItem(at: 2)
} }
for port in ASSerial.ports() { for port in ASSerial.ports() {
menu.addItem(withTitle: port, action:Selector(("serialConnectMenu:")), keyEquivalent:"") menu.addItem(withTitle: port, action:#selector(ASApplication.serialConnectMenu(_:)), keyEquivalent:"")
} }
default: default:
break break
} }
} }
@IBAction func serialConnectMenu(port: NSMenuItem) { @IBAction func serialConnectMenu(_ port: NSMenuItem) {
ASSerialWin.showWindowWithPort(port: port.title) ASSerialWin.showWindowWithPort(port: port.title)
} }
@ -148,14 +148,14 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
} }
} }
@IBAction func openSketch(item: NSMenuItem) { @IBAction func openSketch(_ item: NSMenuItem) {
let url = URL(fileURLWithPath: sketches[item.tag]) let url = URL(fileURLWithPath: sketches[item.tag])
let doc = NSDocumentController.shared() let doc = NSDocumentController.shared()
doc.openDocument(withContentsOf: url, display: true) { (doc, alreadyOpen, error) -> Void in doc.openDocument(withContentsOf: url, display: true) { (doc, alreadyOpen, error) -> Void in
} }
} }
@IBAction func openExample(item: NSMenuItem) { @IBAction func openExample(_ item: NSMenuItem) {
let url = NSURL(fileURLWithPath: examples[item.tag]) let url = NSURL(fileURLWithPath: examples[item.tag])
openTemplate(template: url.deletingLastPathComponent!, fromReadOnly:true) openTemplate(template: url.deletingLastPathComponent!, fromReadOnly:true)
} }
@ -199,7 +199,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
} }
} }
@IBAction func goToHelpPage(sender: AnyObject) { @IBAction func goToHelpPage(_ sender: AnyObject) {
let helpString: String let helpString: String
switch sender.tag { switch sender.tag {
case 0: case 0:
@ -211,7 +211,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
AHGotoPage(locBookName, helpString, nil) AHGotoPage(locBookName, helpString, nil)
} }
@IBAction func goToHelpURL(sender: AnyObject) { @IBAction func goToHelpURL(_ sender: AnyObject) {
let helpString: String let helpString: String
switch sender.tag { switch sender.tag {
case 0: case 0:

View File

@ -177,24 +177,24 @@ class ASLibraries : NSObject {
} }
func addStandardLibrariesToMenu(menu: NSMenu) { func addStandardLibrariesToMenu(menu: NSMenu) {
for (index,lib) in standardLib.enumerated() { for (index,lib) in standardLib.enumerated() {
let menuItem = menu.addItem(withTitle: (lib as NSString).lastPathComponent, action: #selector(ASLibraries.importStandardLibrary(menuItem:)), keyEquivalent: "") let menuItem = menu.addItem(withTitle: (lib as NSString).lastPathComponent, action: #selector(ASLibraries.importStandardLibrary(_:)), keyEquivalent: "")
menuItem.target = self menuItem.target = self
menuItem.tag = index menuItem.tag = index
} }
} }
func addContribLibrariesToMenu(menu: NSMenu) { func addContribLibrariesToMenu(menu: NSMenu) {
for (index,lib) in contribLib.enumerated() { for (index,lib) in contribLib.enumerated() {
let menuItem = menu.addItem(withTitle: (lib as NSString).lastPathComponent, action: #selector(ASLibraries.importContribLibrary(menuItem:)), keyEquivalent: "") let menuItem = menu.addItem(withTitle: (lib as NSString).lastPathComponent, action: #selector(ASLibraries.importContribLibrary(_:)), keyEquivalent: "")
menuItem.target = self menuItem.target = self
menuItem.tag = index menuItem.tag = index
} }
} }
@IBAction func importStandardLibrary(menuItem: AnyObject) { @IBAction func importStandardLibrary(_ menuItem: AnyObject) {
if let tag = (menuItem as? NSMenuItem)?.tag { if let tag = (menuItem as? NSMenuItem)?.tag {
NSApplication.shared().sendAction(#selector(ASProjDoc.importLibrary(_:)), to: nil, from: standardLib[tag]) NSApplication.shared().sendAction(#selector(ASProjDoc.importLibrary(_:)), to: nil, from: standardLib[tag])
} }
} }
@IBAction func importContribLibrary(menuItem: AnyObject) { @IBAction func importContribLibrary(_ menuItem: AnyObject) {
if let tag = (menuItem as? NSMenuItem)?.tag { if let tag = (menuItem as? NSMenuItem)?.tag {
NSApplication.shared().sendAction(#selector(ASProjDoc.importLibrary(_:)), to: nil, from: contribLib[tag]) NSApplication.shared().sendAction(#selector(ASProjDoc.importLibrary(_:)), to: nil, from: contribLib[tag])
} }

View File

@ -667,14 +667,14 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
// MARK: Editor configuration // MARK: Editor configuration
@IBAction func changeTheme(item: NSMenuItem) { @IBAction func changeTheme(_ item: NSMenuItem) {
currentTheme = ACETheme(rawValue: UInt(item.tag)) ?? .xcode currentTheme = ACETheme(rawValue: UInt(item.tag)) ?? .xcode
editor.setTheme(currentTheme) editor.setTheme(currentTheme)
UserDefaults.standard.set( UserDefaults.standard.set(
ACEThemeNames.humanName(for: currentTheme), forKey: kThemeKey) ACEThemeNames.humanName(for: currentTheme), forKey: kThemeKey)
updateChangeCount(.changeDone) updateChangeCount(.changeDone)
} }
@IBAction func changeKeyboardHandler(item: NSMenuItem) { @IBAction func changeKeyboardHandler(_ item: NSMenuItem) {
keyboardHandler = ACEKeyboardHandler(rawValue: UInt(item.tag))! keyboardHandler = ACEKeyboardHandler(rawValue: UInt(item.tag))!
UserDefaults.standard.set( UserDefaults.standard.set(
ACEKeyboardHandlerNames.humanName(for: keyboardHandler), forKey: kBindingsKey) ACEKeyboardHandlerNames.humanName(for: keyboardHandler), forKey: kBindingsKey)
@ -683,18 +683,18 @@ 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 == #selector(ASProjDoc.changeTheme(item:)) { if menuItem.action == #selector(ASProjDoc.changeTheme(_:)) {
menuItem.state = (UInt(menuItem.tag) == currentTheme.rawValue ? NSOnState : NSOffState) menuItem.state = (UInt(menuItem.tag) == currentTheme.rawValue ? NSOnState : NSOffState)
return true return true
} else if menuItem.action == #selector(ASProjDoc.changeKeyboardHandler(item:)) { } else if menuItem.action == #selector(ASProjDoc.changeKeyboardHandler(_:)) {
menuItem.state = (menuItem.tag == Int(keyboardHandler.rawValue) ? NSOnState : NSOffState) menuItem.state = (menuItem.tag == Int(keyboardHandler.rawValue) ? NSOnState : NSOffState)
return true return true
} else if menuItem.action == #selector(ASProjDoc.serialConnect(sender:)) { } else if menuItem.action == #selector(ASProjDoc.serialConnect(_:)) {
menuItem.title = port menuItem.title = port
return true return true
} else if menuItem.action == #selector(ASLibraries.importStandardLibrary(menuItem:)) || } else if menuItem.action == #selector(ASLibraries.importStandardLibrary(_:)) ||
menuItem.action == #selector(ASLibraries.importContribLibrary(menuItem:)) menuItem.action == #selector(ASLibraries.importContribLibrary(_:))
{ {
return mainEditor is ASFileItem return mainEditor is ASFileItem
} }
@ -716,7 +716,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
} }
// MARK: Issues // MARK: Issues
@IBAction func jumpToIssue(sender: AnyObject) { @IBAction func jumpToIssue(_ sender: AnyObject) {
let direction : Int = (sender as! NSMenuItem).tag let direction : Int = (sender as! NSMenuItem).tag
if editors.views(in: .bottom).count == 0 { if editors.views(in: .bottom).count == 0 {
editors.addView(auxEdit, in: .bottom) editors.addView(auxEdit, in: .bottom)
@ -801,11 +801,11 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
switch menu.title { switch menu.title {
case "Boards": case "Boards":
ASHardware.instance().buildBoardsMenu(menu: menu, recentBoards: recentBoards, ASHardware.instance().buildBoardsMenu(menu: menu, recentBoards: recentBoards,
target: self, selector: #selector(ASProjDoc.selectBoard(item:))) target: self, selector: #selector(ASProjDoc.selectBoard(_:)))
boardTool.setTitle(selectedBoard) boardTool.setTitle(selectedBoard)
case "Programmers": case "Programmers":
ASHardware.instance().buildProgrammersMenu(menu: menu, recentProgrammers: recentProgrammers, ASHardware.instance().buildProgrammersMenu(menu: menu, recentProgrammers: recentProgrammers,
target: self, selector: #selector(ASProjDoc.selectProgrammer(item:))) target: self, selector: #selector(ASProjDoc.selectProgrammer(_:)))
progTool.setTitle(selectedProgrammer) progTool.setTitle(selectedProgrammer)
default: default:
break break
@ -838,7 +838,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
} }
@ -869,11 +869,11 @@ 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)
} }
@ -909,7 +909,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
return NSSet(objects: "hasValidPort", "hasUploadProtocol", "programmer") return NSSet(objects: "hasValidPort", "hasUploadProtocol", "programmer")
} }
@IBAction func uploadProject(sender: AnyObject) { @IBAction func uploadProject(_ sender: AnyObject) {
builder.continuation = { builder.continuation = {
self.selectNodeInOutline(selection: self.files.uploadLog) self.selectNodeInOutline(selection: self.files.uploadLog)
DispatchQueue.main.async(execute: { DispatchQueue.main.async(execute: {
@ -919,16 +919,16 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
buildProject(sender) buildProject(sender)
} }
@IBAction func uploadTerminal(sender: AnyObject) { @IBAction func uploadTerminal(_: AnyObject) {
builder.uploadProject(board: board, programmer:programmer, port:port, mode:.Interactive) builder.uploadProject(board: board, programmer:programmer, port:port, mode:.Interactive)
} }
@IBAction func burnBootloader(sender: AnyObject) { @IBAction func burnBootloader(_: AnyObject) {
self.selectNodeInOutline(selection: self.files.uploadLog) self.selectNodeInOutline(selection: self.files.uploadLog)
builder.uploadProject(board: board, programmer:programmer, port:port, mode:.BurnBootloader) builder.uploadProject(board: board, programmer:programmer, port:port, mode:.BurnBootloader)
} }
@IBAction func disassembleProject(sender: AnyObject) { @IBAction func disassembleProject(_ sender: AnyObject) {
builder.continuation = { builder.continuation = {
self.selectNodeInOutline(selection: self.files.disassembly) self.selectNodeInOutline(selection: self.files.disassembly)
self.builder.disassembleProject(board: self.board) self.builder.disassembleProject(board: self.board)
@ -936,7 +936,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
buildProject(sender) buildProject(sender)
} }
@IBAction func serialConnect(sender: AnyObject) { @IBAction func serialConnect(_: AnyObject) {
ASSerialWin.showWindowWithPort(port: port) ASSerialWin.showWindowWithPort(port: port)
} }
} }

View File

@ -235,7 +235,7 @@ class ASSerialWin: NSWindowController {
// MARK: Editor configuration // MARK: Editor configuration
@IBAction func changeTheme(item: NSMenuItem) { @IBAction func changeTheme(_ item: NSMenuItem) {
let userDefaults = UserDefaults.standard let userDefaults = UserDefaults.standard
currentTheme = ACETheme(rawValue: UInt(item.tag)) ?? .xcode currentTheme = ACETheme(rawValue: UInt(item.tag)) ?? .xcode
logView.setTheme(currentTheme) logView.setTheme(currentTheme)
@ -244,7 +244,7 @@ class ASSerialWin: NSWindowController {
portDefaults["Theme"] = themeName portDefaults["Theme"] = themeName
updatePortDefaults() updatePortDefaults()
} }
@IBAction func changeKeyboardHandler(item: NSMenuItem) { @IBAction func changeKeyboardHandler(_ item: NSMenuItem) {
keyboardHandler = ACEKeyboardHandler(rawValue: UInt(item.tag))! keyboardHandler = ACEKeyboardHandler(rawValue: UInt(item.tag))!
UserDefaults.standard.set( UserDefaults.standard.set(
ACEKeyboardHandlerNames.humanName(for: keyboardHandler), forKey: "Bindings") ACEKeyboardHandlerNames.humanName(for: keyboardHandler), forKey: "Bindings")
@ -253,10 +253,10 @@ 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 == Selector(("changeTheme:")) { if menuItem.action == #selector(ASSerialWin.changeTheme(_:)) {
menuItem.state = (UInt(menuItem.tag) == currentTheme.rawValue ? NSOnState : NSOffState) menuItem.state = (UInt(menuItem.tag) == currentTheme.rawValue ? NSOnState : NSOffState)
return true return true
} else if menuItem.action == Selector(("changeKeyboardHandler:")) { } else if menuItem.action == #selector(ASSerialWin.changeKeyboardHandler(_:)) {
menuItem.state = (menuItem.tag == Int(keyboardHandler.rawValue) ? NSOnState : NSOffState) menuItem.state = (menuItem.tag == Int(keyboardHandler.rawValue) ? NSOnState : NSOffState)
return true return true
} }