// // AppDelegate.swift // TagTunes // // Created by Kim Wittenburg on 28.08.15. // Copyright © 2015 Kim Wittenburg. All rights reserved. // import Cocoa @NSApplicationMain internal class AppDelegate: NSObject, NSApplicationDelegate { /// The app's unsorted tracks window. This should be initalized when the app /// launches. var unsortedTracksWindowController: NSWindowController! /// The app's unsorted tracks controller. weak var unsortedTracksController: UnsortedTracksController! internal func applicationDidFinishLaunching(aNotification: NSNotification) { Preferences.sharedPreferences.initializeDefaultValues() let storyboard = NSStoryboard(name: "Main", bundle: nil) unsortedTracksWindowController = storyboard.instantiateControllerWithIdentifier("unsortedTracksWindowController") as? NSWindowController unsortedTracksController.visible = true } internal func applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication) -> Bool { return true } @IBAction func toggleUnsortedTracks(sender: AnyObject?) { unsortedTracksController.visible = !unsortedTracksController.visible } } extension NSApplication { /// The app`s unsorted tracks controller. When a `UnsortedTracksController` /// is initialized it should this property to itself. /// /// The value of this property is not retained. var unsortedTracksController: UnsortedTracksController! { set { (delegate as? AppDelegate)?.unsortedTracksController = newValue } get { return (delegate as? AppDelegate)?.unsortedTracksController } } }