Register user defaults at application startup

This commit is contained in:
Matthias Neeracher 2014-11-24 02:00:04 +01:00 committed by Matthias Neeracher
parent 263a7c5051
commit 01c29d8b15
4 changed files with 40 additions and 1 deletions

View File

@ -13,6 +13,7 @@
9501D8091A17025C0034C530 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9501D8081A17025C0034C530 /* Images.xcassets */; }; 9501D8091A17025C0034C530 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9501D8081A17025C0034C530 /* Images.xcassets */; };
9501D80C1A17025C0034C530 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9501D80A1A17025C0034C530 /* MainMenu.xib */; }; 9501D80C1A17025C0034C530 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9501D80A1A17025C0034C530 /* MainMenu.xib */; };
9501D8181A17025C0034C530 /* AVRsackTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9501D8171A17025C0034C530 /* AVRsackTests.swift */; }; 9501D8181A17025C0034C530 /* AVRsackTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9501D8171A17025C0034C530 /* AVRsackTests.swift */; };
95468DE31A228E1300668EE2 /* Defaults.plist in Resources */ = {isa = PBXBuildFile; fileRef = 95468DE21A228E1300668EE2 /* Defaults.plist */; };
95BF80EB1A185C9E0004A693 /* ASFileTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BF80EA1A185C9E0004A693 /* ASFileTree.swift */; }; 95BF80EB1A185C9E0004A693 /* ASFileTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BF80EA1A185C9E0004A693 /* ASFileTree.swift */; };
95EA32621A17B90600F66EB0 /* ACEView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95EA325B1A17B8DA00F66EB0 /* ACEView.framework */; }; 95EA32621A17B90600F66EB0 /* ACEView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95EA325B1A17B8DA00F66EB0 /* ACEView.framework */; };
95EA32651A17BA8C00F66EB0 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95EA32631A17BA8C00F66EB0 /* Cocoa.framework */; }; 95EA32651A17BA8C00F66EB0 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95EA32631A17BA8C00F66EB0 /* Cocoa.framework */; };
@ -67,6 +68,7 @@
9501D8111A17025C0034C530 /* AVRsackTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AVRsackTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 9501D8111A17025C0034C530 /* AVRsackTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AVRsackTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
9501D8161A17025C0034C530 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 9501D8161A17025C0034C530 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9501D8171A17025C0034C530 /* AVRsackTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AVRsackTests.swift; sourceTree = "<group>"; }; 9501D8171A17025C0034C530 /* AVRsackTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AVRsackTests.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>"; }; 958D76811A17DA1C00917D96 /* AVRsack-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AVRsack-Bridging-Header.h"; sourceTree = "<group>"; };
95BF80EA1A185C9E0004A693 /* ASFileTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ASFileTree.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>"; }; 95EA32541A17B8DA00F66EB0 /* ACEView.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ACEView.xcodeproj; path = ../ACEView/ACEView.xcodeproj; sourceTree = "<group>"; };
@ -158,6 +160,7 @@
9501D8081A17025C0034C530 /* Images.xcassets */, 9501D8081A17025C0034C530 /* Images.xcassets */,
9501D80A1A17025C0034C530 /* MainMenu.xib */, 9501D80A1A17025C0034C530 /* MainMenu.xib */,
9501D8051A17025C0034C530 /* ASProjDoc.xib */, 9501D8051A17025C0034C530 /* ASProjDoc.xib */,
95468DE21A228E1300668EE2 /* Defaults.plist */,
); );
name = Resources; name = Resources;
sourceTree = "<group>"; sourceTree = "<group>";
@ -292,6 +295,7 @@
isa = PBXResourcesBuildPhase; isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
95468DE31A228E1300668EE2 /* Defaults.plist in Resources */,
9501D8071A17025C0034C530 /* ASProjDoc.xib in Resources */, 9501D8071A17025C0034C530 /* ASProjDoc.xib in Resources */,
9501D8091A17025C0034C530 /* Images.xcassets in Resources */, 9501D8091A17025C0034C530 /* Images.xcassets in Resources */,
9501D80C1A17025C0034C530 /* MainMenu.xib in Resources */, 9501D80C1A17025C0034C530 /* MainMenu.xib in Resources */,

View File

@ -13,6 +13,30 @@ class ASApplication: NSObject, NSApplicationDelegate {
@IBOutlet weak var themeMenu : NSMenu! @IBOutlet weak var themeMenu : NSMenu!
@IBOutlet weak var keyboardMenu : NSMenu! @IBOutlet weak var keyboardMenu : NSMenu!
func applicationWillFinishLaunching(notification: NSNotification) {
//
// Retrieve static app defaults
//
let fileManager = NSFileManager.defaultManager()
let workSpace = NSWorkspace.sharedWorkspace()
let userDefaults = NSUserDefaults.standardUserDefaults()
let appDefaultsURL = NSBundle.mainBundle().URLForResource("Defaults", withExtension: "plist")!
let appDefaults = NSMutableDictionary(contentsOfURL: appDefaultsURL)!
//
// Add dynamic app defaults
//
if let arduinoPath = workSpace.URLForApplicationWithBundleIdentifier("cc.arduino.Arduino")?.path {
appDefaults["Arduino"] = arduinoPath
}
var sketchbooks = [NSString]()
for doc in fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) {
sketchbooks.append(doc.URLByAppendingPathComponent("Arduino").path!)
sketchbooks.append(doc.URLByAppendingPathComponent("AVRSack").path!)
}
appDefaults["Sketchbooks"] = sketchbooks
userDefaults.registerDefaults(appDefaults)
}
func applicationDidFinishLaunching(aNotification: NSNotification) { func applicationDidFinishLaunching(aNotification: NSNotification) {
themeMenu.removeAllItems() themeMenu.removeAllItems()
for (index, theme) in enumerate(ACEThemeNames.humanThemeNames() as [NSString]) { for (index, theme) in enumerate(ACEThemeNames.humanThemeNames() as [NSString]) {

View File

@ -31,7 +31,6 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate {
override init() { override init() {
super.init() super.init()
let userDefaults = NSUserDefaults.standardUserDefaults() let userDefaults = NSUserDefaults.standardUserDefaults()
userDefaults.registerDefaults([kThemeKey: "xcode", kFontSizeKey: 12, kBindingsKey: "Ace"])
if let themeName = userDefaults.stringForKey(kThemeKey) { if let themeName = userDefaults.stringForKey(kThemeKey) {
for (themeIdx, theme) in enumerate(ACEThemeNames.themeNames() as [NSString]) { for (themeIdx, theme) in enumerate(ACEThemeNames.themeNames() as [NSString]) {
if themeName == theme { if themeName == theme {

12
AVRsack/Defaults.plist Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Bindings</key>
<string>Ace</string>
<key>FontSize</key>
<integer>12</integer>
<key>Theme</key>
<string>xcode</string>
</dict>
</plist>