2016-06-04 00:43:39 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
2016-06-03 23:13:59 +03:00
|
|
|
|
|
|
|
import Cocoa
|
2016-07-19 20:34:05 +03:00
|
|
|
import RxSwift
|
2016-07-04 23:06:39 +03:00
|
|
|
import PureLayout
|
2016-06-03 23:13:59 +03:00
|
|
|
|
|
|
|
@NSApplicationMain
|
2016-07-10 19:47:24 +03:00
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
2016-06-03 23:13:59 +03:00
|
|
|
|
2016-07-26 23:51:05 +03:00
|
|
|
private let disposeBag = DisposeBag()
|
|
|
|
|
|
|
|
private let changeSubject = PublishSubject<Any>()
|
|
|
|
private let changeSink: Observable<Any>
|
2016-07-27 00:40:20 +03:00
|
|
|
|
|
|
|
private let actionSubject = PublishSubject<Any>()
|
2016-07-26 23:51:05 +03:00
|
|
|
private let actionSink: Observable<Any>
|
|
|
|
|
|
|
|
private let prefStore: PrefStore
|
2016-07-24 21:32:07 +03:00
|
|
|
|
|
|
|
private let mainWindowManager: MainWindowManager
|
2016-07-26 23:51:05 +03:00
|
|
|
private let prefWindowComponent: PrefWindowComponent
|
2016-07-26 22:42:30 +03:00
|
|
|
|
|
|
|
override init() {
|
2016-07-27 00:40:20 +03:00
|
|
|
self.actionSink = self.actionSubject.asObservable()
|
2016-07-26 23:51:05 +03:00
|
|
|
self.changeSink = self.changeSubject.asObservable()
|
|
|
|
|
|
|
|
self.prefStore = PrefStore(source: self.actionSink)
|
|
|
|
|
2016-07-27 00:40:20 +03:00
|
|
|
self.prefWindowComponent = PrefWindowComponent(source: self.changeSink, initialData: self.prefStore.data)
|
|
|
|
self.mainWindowManager = MainWindowManager(source: self.changeSink, initialData: self.prefStore.data)
|
|
|
|
|
2016-07-26 22:42:30 +03:00
|
|
|
super.init()
|
2016-07-26 23:51:05 +03:00
|
|
|
|
|
|
|
[ self.prefStore ]
|
|
|
|
.map { $0.sink }
|
2016-07-27 19:22:25 +03:00
|
|
|
.toMergedObservables()
|
2016-07-26 23:51:05 +03:00
|
|
|
.subscribe(self.changeSubject)
|
|
|
|
.addDisposableTo(self.disposeBag)
|
2016-07-27 00:40:20 +03:00
|
|
|
|
|
|
|
[ self.prefWindowComponent ]
|
|
|
|
.map { $0.sink }
|
2016-07-27 19:22:25 +03:00
|
|
|
.toMergedObservables()
|
2016-07-27 00:40:20 +03:00
|
|
|
.subscribe(self.actionSubject)
|
|
|
|
.addDisposableTo(self.disposeBag)
|
2016-07-26 22:42:30 +03:00
|
|
|
}
|
2016-07-24 21:32:07 +03:00
|
|
|
|
2016-06-08 19:17:12 +03:00
|
|
|
@IBAction func debugSomething(sender: AnyObject!) {
|
2016-07-10 19:47:24 +03:00
|
|
|
NSLog("debug sth...")
|
2016-06-08 19:17:12 +03:00
|
|
|
}
|
2016-07-10 19:47:24 +03:00
|
|
|
|
|
|
|
@IBAction func newDocument(sender: AnyObject!) {
|
|
|
|
self.mainWindowManager.newMainWindow()
|
|
|
|
}
|
2016-07-24 21:32:07 +03:00
|
|
|
|
2016-07-24 23:31:19 +03:00
|
|
|
@IBAction func showPrefWindow(sender: AnyObject!) {
|
|
|
|
self.prefWindowComponent.show()
|
|
|
|
}
|
|
|
|
|
2016-07-12 00:24:40 +03:00
|
|
|
func applicationDidFinishLaunching(aNotification: NSNotification) {
|
2016-06-24 22:08:34 +03:00
|
|
|
// let testView = InputTestView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
|
|
|
|
// self.window.contentView?.addSubview(testView)
|
|
|
|
// self.window.makeFirstResponder(testView)
|
2016-07-12 00:24:40 +03:00
|
|
|
|
2016-07-24 23:31:19 +03:00
|
|
|
self.newDocument(self)
|
2016-07-12 00:24:40 +03:00
|
|
|
}
|
2016-07-18 23:44:23 +03:00
|
|
|
|
|
|
|
func applicationShouldTerminate(sender: NSApplication) -> NSApplicationTerminateReply {
|
|
|
|
if self.mainWindowManager.hasDirtyWindows() {
|
|
|
|
let alert = NSAlert()
|
|
|
|
alert.addButtonWithTitle("Cancel")
|
|
|
|
alert.addButtonWithTitle("Discard and Quit")
|
|
|
|
alert.messageText = "There are windows with unsaved buffers!"
|
|
|
|
alert.alertStyle = .WarningAlertStyle
|
|
|
|
|
|
|
|
if alert.runModal() == NSAlertSecondButtonReturn {
|
|
|
|
return .TerminateNow
|
|
|
|
}
|
|
|
|
|
|
|
|
return .TerminateCancel
|
|
|
|
}
|
|
|
|
|
|
|
|
return .TerminateNow
|
|
|
|
}
|
2016-06-03 23:13:59 +03:00
|
|
|
}
|