Add serial menu
This commit is contained in:
parent
7f55d7bd0f
commit
c1ea478c46
|
@ -10,12 +10,20 @@ import Cocoa
|
||||||
|
|
||||||
@NSApplicationMain
|
@NSApplicationMain
|
||||||
class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
||||||
@IBOutlet weak var themeMenu : NSMenu!
|
@IBOutlet var themeMenu : NSMenu!
|
||||||
@IBOutlet weak var keyboardMenu : NSMenu!
|
@IBOutlet var keyboardMenu : NSMenu!
|
||||||
@IBOutlet weak var preferences : ASPreferences!
|
@IBOutlet var preferences : ASPreferences!
|
||||||
var sketches = [String]()
|
var sketches = [String]()
|
||||||
var examples = [String]()
|
var examples = [String]()
|
||||||
|
|
||||||
|
func hasDocument() -> Bool {
|
||||||
|
if let doc = NSDocumentController.sharedDocumentController().currentDocument as? NSDocument {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func applicationWillFinishLaunching(notification: NSNotification) {
|
func applicationWillFinishLaunching(notification: NSNotification) {
|
||||||
//
|
//
|
||||||
// Retrieve static app defaults
|
// Retrieve static app defaults
|
||||||
|
@ -80,12 +88,23 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
||||||
let examplePath = arduinoPath.stringByAppendingPathComponent("Contents/Resources/Java/examples")
|
let examplePath = arduinoPath.stringByAppendingPathComponent("Contents/Resources/Java/examples")
|
||||||
ASSketchBook.addSketches(menu, target: self, action: "openExample:", path: examplePath, sketches: &examples)
|
ASSketchBook.addSketches(menu, target: self, action: "openExample:", path: examplePath, sketches: &examples)
|
||||||
}
|
}
|
||||||
|
case "Serial Monitor":
|
||||||
|
menu.itemAtIndex(0)?.hidden = !hasDocument()
|
||||||
|
while menu.numberOfItems > 2 {
|
||||||
|
menu.removeItemAtIndex(2)
|
||||||
|
}
|
||||||
|
for port in ASSerial.ports() as [String] {
|
||||||
|
menu.addItemWithTitle(port, action:"serialConnectMenu:", keyEquivalent:"")
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IBAction func serialConnectMenu(port: NSMenuItem) {
|
||||||
|
ASSerialWin.showWindowWithPort(port.title)
|
||||||
|
}
|
||||||
|
|
||||||
func openTemplate(template: NSURL) {
|
func openTemplate(template: NSURL) {
|
||||||
ASApplication.newProjectLocation(nil,
|
ASApplication.newProjectLocation(nil,
|
||||||
message: "Save editable copy of project \(template.lastPathComponent)")
|
message: "Save editable copy of project \(template.lastPathComponent)")
|
||||||
|
|
|
@ -309,6 +309,10 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate {
|
||||||
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)
|
||||||
|
return true
|
||||||
|
} else if menuItem.action == "serialConnect:" {
|
||||||
|
menuItem.title = port
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ NSString * kASSerialPortsChanged = @"PortsChanged";
|
||||||
if ([[port substringToIndex:2] isEqualToString:@"cu"])
|
if ([[port substringToIndex:2] isEqualToString:@"cu"])
|
||||||
[cuPorts addObject:[port substringFromIndex:3]];
|
[cuPorts addObject:[port substringFromIndex:3]];
|
||||||
}
|
}
|
||||||
return cuPorts;
|
return [cuPorts sortedArrayUsingSelector:@selector(compare:)];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSString *) fileNameForPort:(NSString *)port
|
+ (NSString *) fileNameForPort:(NSString *)port
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7096" systemVersion="14C82" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="14C79" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7096"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<objects>
|
<objects>
|
||||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
</customObject>
|
</customObject>
|
||||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||||
<customObject id="Voe-Tx-rLC" customClass="ASApplication" customModule="AVRsack">
|
<customObject id="Voe-Tx-rLC" userLabel="AppDelegate" customClass="ASApplication" customModule="AVRsack">
|
||||||
<connections>
|
<connections>
|
||||||
<outlet property="keyboardMenu" destination="WWD-TD-lpw" id="Tr8-cg-fXf"/>
|
<outlet property="keyboardMenu" destination="WWD-TD-lpw" id="Tr8-cg-fXf"/>
|
||||||
<outlet property="preferences" destination="sor-iB-NZD" id="zad-hM-0R0"/>
|
<outlet property="preferences" destination="sor-iB-NZD" id="zad-hM-0R0"/>
|
||||||
|
@ -384,17 +384,51 @@
|
||||||
<action selector="buildProject:" target="-1" id="d3i-8e-6sp"/>
|
<action selector="buildProject:" target="-1" id="d3i-8e-6sp"/>
|
||||||
</connections>
|
</connections>
|
||||||
</menuItem>
|
</menuItem>
|
||||||
|
<menuItem title="Disassemble" keyEquivalent="d" id="QfC-vq-ugs">
|
||||||
|
<connections>
|
||||||
|
<action selector="disassembleProject:" target="-1" id="sLA-dm-Dzo"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem isSeparatorItem="YES" id="ebE-qS-CZ6"/>
|
||||||
<menuItem title="Upload" keyEquivalent="u" id="rRD-Cm-5An">
|
<menuItem title="Upload" keyEquivalent="u" id="rRD-Cm-5An">
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="uploadProject:" target="-1" id="Un4-q1-nWg"/>
|
<action selector="uploadProject:" target="-1" id="Un4-q1-nWg"/>
|
||||||
</connections>
|
</connections>
|
||||||
</menuItem>
|
</menuItem>
|
||||||
|
<menuItem title="Serial Monitor" id="GxC-cS-qvx">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<menu key="submenu" title="Serial Monitor" id="i2j-Ds-oRH">
|
||||||
|
<items>
|
||||||
|
<menuItem title="Current Port" keyEquivalent="M" id="KeI-AS-2tX">
|
||||||
|
<connections>
|
||||||
|
<action selector="serialConnect:" target="-1" id="l7A-MU-U4h"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem isSeparatorItem="YES" id="V8r-XG-DbV">
|
||||||
|
<connections>
|
||||||
|
<binding destination="Voe-Tx-rLC" name="hidden" keyPath="hasDocument" id="iL4-Mk-XXX">
|
||||||
|
<dictionary key="options">
|
||||||
|
<string key="NSValueTransformerName">NSNegateBoolean</string>
|
||||||
|
</dictionary>
|
||||||
|
</binding>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
</items>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="Voe-Tx-rLC" id="4mJ-AQ-EY3"/>
|
||||||
|
</connections>
|
||||||
|
</menu>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem isSeparatorItem="YES" id="l8E-4R-wRl"/>
|
||||||
<menuItem title="Clean" keyEquivalent="K" id="bin-2x-Ysd">
|
<menuItem title="Clean" keyEquivalent="K" id="bin-2x-Ysd">
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="cleanProject:" target="-1" id="4hi-zQ-Zoi"/>
|
<action selector="cleanProject:" target="-1" id="4hi-zQ-Zoi"/>
|
||||||
</connections>
|
</connections>
|
||||||
</menuItem>
|
</menuItem>
|
||||||
</items>
|
</items>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="Voe-Tx-rLC" id="hr7-QB-jdo"/>
|
||||||
|
</connections>
|
||||||
</menu>
|
</menu>
|
||||||
</menuItem>
|
</menuItem>
|
||||||
<menuItem title="Window" id="aUF-d1-5bR">
|
<menuItem title="Window" id="aUF-d1-5bR">
|
||||||
|
@ -436,5 +470,6 @@
|
||||||
</menuItem>
|
</menuItem>
|
||||||
</items>
|
</items>
|
||||||
</menu>
|
</menu>
|
||||||
|
<userDefaultsController representsSharedInstance="YES" id="Jox-o7-4sb"/>
|
||||||
</objects>
|
</objects>
|
||||||
</document>
|
</document>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user