2014-11-15 03:39:10 +00:00
|
|
|
//
|
|
|
|
// AppDelegate.swift
|
|
|
|
// AVRsack
|
|
|
|
//
|
|
|
|
// Created by Matthias Neeracher on 11/15/14.
|
|
|
|
// Copyright (c) 2014 Aere Perennius. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
|
|
@NSApplicationMain
|
2014-11-15 22:47:46 +00:00
|
|
|
class ASApplication: NSObject, NSApplicationDelegate {
|
2014-11-17 04:39:39 +00:00
|
|
|
@IBOutlet weak var themeMenu : NSMenu!
|
|
|
|
@IBOutlet weak var keyboardMenu : NSMenu!
|
|
|
|
|
2014-11-24 01:00:04 +00:00
|
|
|
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)
|
|
|
|
}
|
2014-11-15 03:39:10 +00:00
|
|
|
func applicationDidFinishLaunching(aNotification: NSNotification) {
|
2014-11-17 04:39:39 +00:00
|
|
|
themeMenu.removeAllItems()
|
|
|
|
for (index, theme) in enumerate(ACEThemeNames.humanThemeNames() as [NSString]) {
|
2014-11-17 04:53:33 +00:00
|
|
|
let menuItem = themeMenu.addItemWithTitle(theme, action: "changeTheme:", keyEquivalent: "")
|
2014-11-17 04:39:39 +00:00
|
|
|
menuItem!.tag = index
|
|
|
|
}
|
|
|
|
keyboardMenu.removeAllItems()
|
|
|
|
for (index, theme) in enumerate(ACEKeyboardHandlerNames.humanKeyboardHandlerNames() as [NSString]) {
|
|
|
|
let menuItem = keyboardMenu.addItemWithTitle(theme, action: "changeKeyboardHandler:", keyEquivalent: "")
|
|
|
|
menuItem!.tag = index
|
|
|
|
}
|
2014-11-15 03:39:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func applicationWillTerminate(aNotification: NSNotification) {
|
|
|
|
// Insert code here to tear down your application
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|