Added preferences window, manipulate toolchain path

This commit is contained in:
Matthias Neeracher 2014-12-14 10:28:10 +01:00 committed by Matthias Neeracher
parent e3520d91ee
commit f26cddf8aa
6 changed files with 235 additions and 2 deletions

View File

@ -19,6 +19,8 @@
951CD1771A2615000066C1A1 /* BuildProject in Resources */ = {isa = PBXBuildFile; fileRef = 951CD1761A2615000066C1A1 /* BuildProject */; };
95468DDF1A228BE600668EE2 /* ASHardware.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95468DDE1A228BE600668EE2 /* ASHardware.swift */; };
95468DE31A228E1300668EE2 /* Defaults.plist in Resources */ = {isa = PBXBuildFile; fileRef = 95468DE21A228E1300668EE2 /* Defaults.plist */; };
95A7C6401A38914300EF1963 /* ASPreferences.xib in Resources */ = {isa = PBXBuildFile; fileRef = 95A7C63E1A38914300EF1963 /* ASPreferences.xib */; };
95A7C6461A3894C900EF1963 /* ASPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A7C6451A3894C900EF1963 /* ASPreferences.swift */; };
95BF80EB1A185C9E0004A693 /* ASFileTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BF80EA1A185C9E0004A693 /* ASFileTree.swift */; };
95EA32621A17B90600F66EB0 /* ACEView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95EA325B1A17B8DA00F66EB0 /* ACEView.framework */; };
95EA32651A17BA8C00F66EB0 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95EA32631A17BA8C00F66EB0 /* Cocoa.framework */; };
@ -80,6 +82,8 @@
95468DDE1A228BE600668EE2 /* ASHardware.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ASHardware.swift; sourceTree = "<group>"; };
95468DE21A228E1300668EE2 /* Defaults.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Defaults.plist; sourceTree = "<group>"; };
958D76811A17DA1C00917D96 /* AVRsack-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AVRsack-Bridging-Header.h"; sourceTree = "<group>"; };
95A7C63F1A38914300EF1963 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/ASPreferences.xib; sourceTree = "<group>"; };
95A7C6451A3894C900EF1963 /* ASPreferences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ASPreferences.swift; sourceTree = "<group>"; };
95BF80EA1A185C9E0004A693 /* ASFileTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ASFileTree.swift; sourceTree = "<group>"; };
95EA32541A17B8DA00F66EB0 /* ACEView.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ACEView.xcodeproj; path = ../ACEView/ACEView.xcodeproj; sourceTree = "<group>"; };
95EA32631A17BA8C00F66EB0 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
@ -171,6 +175,7 @@
95468DDE1A228BE600668EE2 /* ASHardware.swift */,
950AB9281A2D4F9B0033A9DA /* ASSerial.swift */,
951CD1731A23C9FC0066C1A1 /* ASBuilder.swift */,
95A7C6451A3894C900EF1963 /* ASPreferences.swift */,
951CD1761A2615000066C1A1 /* BuildProject */,
);
name = Source;
@ -183,6 +188,7 @@
950AB9261A296A160033A9DA /* ProjIcon.icns */,
9501D80A1A17025C0034C530 /* MainMenu.xib */,
9501D8051A17025C0034C530 /* ASProjDoc.xib */,
95A7C63E1A38914300EF1963 /* ASPreferences.xib */,
95468DE21A228E1300668EE2 /* Defaults.plist */,
);
name = Resources;
@ -318,6 +324,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
95A7C6401A38914300EF1963 /* ASPreferences.xib in Resources */,
95468DE31A228E1300668EE2 /* Defaults.plist in Resources */,
9501D8071A17025C0034C530 /* ASProjDoc.xib in Resources */,
950AB9271A296A160033A9DA /* ProjIcon.icns in Resources */,
@ -347,6 +354,7 @@
950AB9291A2D4F9B0033A9DA /* ASSerial.swift in Sources */,
9501D8021A17025C0034C530 /* ASApplication.swift in Sources */,
95BF80EB1A185C9E0004A693 /* ASFileTree.swift in Sources */,
95A7C6461A3894C900EF1963 /* ASPreferences.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -390,6 +398,14 @@
name = MainMenu.xib;
sourceTree = "<group>";
};
95A7C63E1A38914300EF1963 /* ASPreferences.xib */ = {
isa = PBXVariantGroup;
children = (
95A7C63F1A38914300EF1963 /* Base */,
);
name = ASPreferences.xib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */

View File

@ -34,6 +34,11 @@ class ASApplication: NSObject, NSApplicationDelegate {
sketchbooks.append(doc.URLByAppendingPathComponent("AVRSack").path!)
}
appDefaults["Sketchbooks"] = sketchbooks
if fileManager.fileExistsAtPath("/usr/local/CrossPack-AVR") {
appDefaults["Toolchain"] = "/usr/local/CrossPack-AVR"
} else {
appDefaults["Toolchain"] = ""
}
userDefaults.registerDefaults(appDefaults)
}

View File

@ -0,0 +1,95 @@
//
// ASPreferences.swift
// AVRsack
//
// Created by Matthias Neeracher on 12/10/14.
// Copyright © 2014 Aere Perennius. All rights reserved.
//
import Cocoa
private let kASToolchainCrosspack = 0
private let kASToolchainArduino = 1
private let kASToolchainOther = 2
class ASPreferences: NSWindowController, NSOpenSavePanelDelegate {
dynamic var toolchainPref : String = "" {
didSet(oldPref) {
NSUserDefaults.standardUserDefaults().setObject(toolchainPref, forKey: "Toolchain")
}
}
var toolchainType : Int {
get {
switch toolchainPref {
case "/usr/local/CrossPack-AVR":
return kASToolchainCrosspack
case "":
return kASToolchainArduino
default:
return kASToolchainOther
}
}
set (toolchain) {
switch toolchain {
case kASToolchainCrosspack:
toolchainPref = "/usr/local/CrossPack-AVR"
case kASToolchainArduino:
toolchainPref = ""
default:
otherToolchainDialog()
}
}
}
class func keyPathsForValuesAffectingToolchainType() -> NSSet {
return NSSet(objects: "toolchainPref")
}
var toolchainPath : String {
get {
if toolchainPref != "" {
return toolchainPref
} else {
return NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier("cc.arduino.Arduino")!.path! +
"/Contents/Resources/Java/hardware/tools/avr"
}
}
}
class func keyPathsForValuesAffectingToolchainPath() -> NSSet {
return NSSet(objects: "toolchainPref")
}
override convenience init() {
self.init(windowNibName:"ASPreferences")
}
override func awakeFromNib() {
super.awakeFromNib()
toolchainPref = NSUserDefaults.standardUserDefaults().objectForKey("Toolchain") as String
}
var hasCrossPackAVR : Bool {
get {
return NSFileManager.defaultManager().fileExistsAtPath("/usr/local/CrossPack-AVR/bin")
}
}
func otherToolchainDialog() {
let openPanel = NSOpenPanel()
openPanel.delegate = self
openPanel.canChooseFiles = false
openPanel.canChooseDirectories = true
openPanel.allowsMultipleSelection = false
openPanel.resolvesAliases = true
openPanel.beginSheetModalForWindow(window!, completionHandler: { (returnCode: Int) -> Void in
if returnCode == NSFileHandlingPanelOKButton {
self.toolchainPref = openPanel.URL!.path!
}
})
}
func panel(sender: AnyObject, shouldEnableURL url: NSURL) -> Bool {
let gccPath = url.URLByAppendingPathComponent("bin/avr-gcc")
return NSFileManager.defaultManager().fileExistsAtPath(gccPath.path!)
}
}

View File

@ -0,0 +1,108 @@
<?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">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7096"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="ASPreferences" customModule="AVRsack" customModuleProvider="target">
<connections>
<outlet property="window" destination="QvC-M9-y7g" id="UPg-mQ-lKM"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="473" height="230"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<view key="contentView" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="-6" width="473" height="230"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<box autoresizesSubviews="NO" fixedFrame="YES" title="Toolchain" borderType="bezel" translatesAutoresizingMaskIntoConstraints="NO" id="lUB-N9-MQk">
<rect key="frame" x="17" y="85" width="446" height="136"/>
<view key="contentView">
<rect key="frame" x="3" y="3" width="440" height="118"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9aO-EG-pZd">
<rect key="frame" x="14" y="17" width="412" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="lLl-0E-bfa">
<font key="font" metaFont="fixedUser" size="11"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<binding destination="-2" name="value" keyPath="toolchainPath" id="1bg-4u-IfN"/>
</connections>
</textField>
<matrix verticalHuggingPriority="750" fixedFrame="YES" allowsEmptySelection="NO" autosizesCells="NO" translatesAutoresizingMaskIntoConstraints="NO" id="I7Q-7e-0fF">
<rect key="frame" x="17" y="47" width="407" height="62"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
<size key="cellSize" width="407" height="18"/>
<size key="intercellSpacing" width="0.0" height="4"/>
<buttonCell key="prototype" type="radio" title="CrossPack-AVR" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="YdD-bN-1zl">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<cells>
<column>
<buttonCell type="radio" title="CrossPack-AVR" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="Tup-pR-nsY">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
<connections>
<binding destination="-2" name="enabled" keyPath="hasCrossPackAVR" id="0UQ-FH-CMa"/>
</connections>
</buttonCell>
<buttonCell type="radio" title="Arduino" bezelStyle="regularSquare" imagePosition="left" alignment="left" tag="1" inset="2" id="zIW-6Z-Ogk">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<buttonCell type="radio" title="Other…" bezelStyle="regularSquare" imagePosition="left" alignment="left" tag="2" inset="2" id="fk8-pr-Yac">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</column>
</cells>
<connections>
<binding destination="-2" name="selectedTag" keyPath="toolchainType" id="l8Q-Gq-AtL"/>
</connections>
</matrix>
</subviews>
</view>
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
<color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</box>
<slider verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Uao-vY-7Of">
<rect key="frame" x="141" y="41" width="314" height="25"/>
<sliderCell key="cell" state="on" alignment="left" maxValue="4" doubleValue="2" tickMarkPosition="below" numberOfTickMarks="5" allowsTickMarkValuesOnly="YES" sliderType="linear" id="7Y7-kq-HKp"/>
<connections>
<binding destination="U9x-0v-Fkq" name="value" keyPath="values.UploadVerbosity" id="D6L-gh-25Z"/>
</connections>
</slider>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="KJa-Bw-fAb">
<rect key="frame" x="20" y="45" width="117" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Upload Verbosity" id="bb7-nI-YMg">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="8aR-WB-BsV">
<rect key="frame" x="20" y="18" width="247" height="18"/>
<buttonCell key="cell" type="check" title="Show Source Code in Disassembly" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="n3w-Da-CaD">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<binding destination="U9x-0v-Fkq" name="value" keyPath="values.ShowSourceInDisassembly" id="Nnr-C2-5B5"/>
</connections>
</button>
</subviews>
</view>
<point key="canvasLocation" x="338.5" y="245"/>
</window>
<userDefaultsController representsSharedInstance="YES" id="U9x-0v-Fkq"/>
</objects>
</document>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7096" systemVersion="14B25" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7096" systemVersion="14C82" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7096"/>
</dependencies>
@ -18,6 +18,7 @@
</connections>
</customObject>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="sor-iB-NZD" customClass="ASPreferences" customModule="AVRsack" customModuleProvider="target"/>
<menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
<items>
<menuItem title="AVRsack" id="1Xt-HY-uBw">
@ -31,7 +32,11 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW">
<connections>
<action selector="showWindow:" target="sor-iB-NZD" id="zLp-gD-hKn"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
<menuItem title="Services" id="NMo-om-nkz">
<modifierMask key="keyEquivalentModifierMask"/>

View File

@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ShowSourceInDisassembly</key>
<string></string>
<key>UploadVerbosity</key>
<integer>2</integer>
<key>RecentProgrammers</key>
<array>
<string>usbasp</string>