From 01c29d8b15a1941ba916f4ace4de4653920866e8 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Mon, 24 Nov 2014 02:00:04 +0100 Subject: [PATCH] Register user defaults at application startup --- AVRsack.xcodeproj/project.pbxproj | 4 ++++ AVRsack/ASApplication.swift | 24 ++++++++++++++++++++++++ AVRsack/ASProjDoc.swift | 1 - AVRsack/Defaults.plist | 12 ++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 AVRsack/Defaults.plist diff --git a/AVRsack.xcodeproj/project.pbxproj b/AVRsack.xcodeproj/project.pbxproj index 9752e26..ccb755e 100644 --- a/AVRsack.xcodeproj/project.pbxproj +++ b/AVRsack.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 9501D8091A17025C0034C530 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9501D8081A17025C0034C530 /* Images.xcassets */; }; 9501D80C1A17025C0034C530 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9501D80A1A17025C0034C530 /* MainMenu.xib */; }; 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 */; }; 95EA32621A17B90600F66EB0 /* ACEView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95EA325B1A17B8DA00F66EB0 /* ACEView.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; }; 9501D8161A17025C0034C530 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 9501D8171A17025C0034C530 /* AVRsackTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AVRsackTests.swift; sourceTree = ""; }; + 95468DE21A228E1300668EE2 /* Defaults.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Defaults.plist; sourceTree = ""; }; 958D76811A17DA1C00917D96 /* AVRsack-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AVRsack-Bridging-Header.h"; sourceTree = ""; }; 95BF80EA1A185C9E0004A693 /* ASFileTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ASFileTree.swift; sourceTree = ""; }; 95EA32541A17B8DA00F66EB0 /* ACEView.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ACEView.xcodeproj; path = ../ACEView/ACEView.xcodeproj; sourceTree = ""; }; @@ -158,6 +160,7 @@ 9501D8081A17025C0034C530 /* Images.xcassets */, 9501D80A1A17025C0034C530 /* MainMenu.xib */, 9501D8051A17025C0034C530 /* ASProjDoc.xib */, + 95468DE21A228E1300668EE2 /* Defaults.plist */, ); name = Resources; sourceTree = ""; @@ -292,6 +295,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 95468DE31A228E1300668EE2 /* Defaults.plist in Resources */, 9501D8071A17025C0034C530 /* ASProjDoc.xib in Resources */, 9501D8091A17025C0034C530 /* Images.xcassets in Resources */, 9501D80C1A17025C0034C530 /* MainMenu.xib in Resources */, diff --git a/AVRsack/ASApplication.swift b/AVRsack/ASApplication.swift index 5e7db02..dd37b45 100644 --- a/AVRsack/ASApplication.swift +++ b/AVRsack/ASApplication.swift @@ -13,6 +13,30 @@ class ASApplication: NSObject, NSApplicationDelegate { @IBOutlet weak var themeMenu : 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) { themeMenu.removeAllItems() for (index, theme) in enumerate(ACEThemeNames.humanThemeNames() as [NSString]) { diff --git a/AVRsack/ASProjDoc.swift b/AVRsack/ASProjDoc.swift index 9838868..95a029f 100644 --- a/AVRsack/ASProjDoc.swift +++ b/AVRsack/ASProjDoc.swift @@ -31,7 +31,6 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate { override init() { super.init() let userDefaults = NSUserDefaults.standardUserDefaults() - userDefaults.registerDefaults([kThemeKey: "xcode", kFontSizeKey: 12, kBindingsKey: "Ace"]) if let themeName = userDefaults.stringForKey(kThemeKey) { for (themeIdx, theme) in enumerate(ACEThemeNames.themeNames() as [NSString]) { if themeName == theme { diff --git a/AVRsack/Defaults.plist b/AVRsack/Defaults.plist new file mode 100644 index 0000000..2accf20 --- /dev/null +++ b/AVRsack/Defaults.plist @@ -0,0 +1,12 @@ + + + + + Bindings + Ace + FontSize + 12 + Theme + xcode + +