2016-07-21 20:28:58 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
2016-08-03 22:41:43 +03:00
|
|
|
import Cocoa
|
2016-07-21 20:28:58 +03:00
|
|
|
import RxSwift
|
|
|
|
|
2016-10-02 15:07:12 +03:00
|
|
|
protocol Flow: class {
|
2016-08-30 23:25:34 +03:00
|
|
|
|
2016-07-21 20:28:58 +03:00
|
|
|
var sink: Observable<Any> { get }
|
|
|
|
}
|
|
|
|
|
2016-09-27 19:02:05 +03:00
|
|
|
class PublishingFlow: Flow {
|
|
|
|
|
|
|
|
var sink: Observable<Any> {
|
|
|
|
return self.subject.asObservable()
|
|
|
|
}
|
|
|
|
|
|
|
|
let subject = PublishSubject<Any>()
|
|
|
|
|
|
|
|
init() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
|
|
|
self.subject.onCompleted()
|
|
|
|
}
|
|
|
|
|
|
|
|
func publish(event: Any) {
|
|
|
|
self.subject.onNext(event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class StandardFlow: PublishingFlow {
|
|
|
|
|
|
|
|
let source: Observable<Any>
|
|
|
|
let disposeBag = DisposeBag()
|
|
|
|
|
|
|
|
init(source: Observable<Any>) {
|
|
|
|
self.source = source
|
|
|
|
super.init()
|
|
|
|
|
|
|
|
self.subscription(source: source).addDisposableTo(self.disposeBag)
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
|
|
|
self.subject.onCompleted()
|
|
|
|
}
|
|
|
|
|
|
|
|
func subscription(source: Observable<Any>) -> Disposable {
|
|
|
|
preconditionFailure("Please override")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-03 10:45:38 +03:00
|
|
|
class StandardComponent: NSObject, Flow {
|
2016-08-30 23:25:34 +03:00
|
|
|
|
|
|
|
var sink: Observable<Any> {
|
|
|
|
return self.subject.asObservable()
|
|
|
|
}
|
|
|
|
|
|
|
|
let subject = PublishSubject<Any>()
|
|
|
|
let source: Observable<Any>
|
|
|
|
let disposeBag = DisposeBag()
|
|
|
|
|
|
|
|
init(source: Observable<Any>) {
|
|
|
|
self.source = source
|
2016-09-27 19:02:05 +03:00
|
|
|
super.init()
|
|
|
|
|
|
|
|
self.addViews()
|
2016-08-30 23:25:34 +03:00
|
|
|
self.subscription(source: source).addDisposableTo(self.disposeBag)
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
|
|
|
self.subject.onCompleted()
|
|
|
|
}
|
|
|
|
|
2016-09-27 19:02:05 +03:00
|
|
|
func addViews() {
|
|
|
|
preconditionFailure("Please override")
|
|
|
|
}
|
|
|
|
|
2016-09-25 18:50:33 +03:00
|
|
|
func subscription(source: Observable<Any>) -> Disposable {
|
2016-08-30 23:25:34 +03:00
|
|
|
preconditionFailure("Please override")
|
|
|
|
}
|
|
|
|
|
2016-09-25 18:50:33 +03:00
|
|
|
func publish(event: Any) {
|
2016-08-30 23:25:34 +03:00
|
|
|
self.subject.onNext(event)
|
|
|
|
}
|
2016-07-21 20:28:58 +03:00
|
|
|
}
|
2016-08-30 23:25:34 +03:00
|
|
|
|
2016-10-03 10:45:38 +03:00
|
|
|
class ViewComponent: NSView, Flow {
|
2016-09-27 19:02:05 +03:00
|
|
|
|
|
|
|
var view: NSView {
|
|
|
|
preconditionFailure("Please override")
|
|
|
|
}
|
2016-08-30 23:25:34 +03:00
|
|
|
|
|
|
|
var sink: Observable<Any> {
|
|
|
|
return self.subject.asObservable()
|
|
|
|
}
|
|
|
|
|
|
|
|
let subject = PublishSubject<Any>()
|
|
|
|
let source: Observable<Any>
|
|
|
|
let disposeBag = DisposeBag()
|
|
|
|
|
|
|
|
init(source: Observable<Any>) {
|
|
|
|
self.source = source
|
2016-09-27 19:02:05 +03:00
|
|
|
|
|
|
|
super.init(frame: CGRect.zero)
|
|
|
|
self.translatesAutoresizingMaskIntoConstraints = false
|
2016-08-30 23:25:34 +03:00
|
|
|
|
|
|
|
self.addViews()
|
|
|
|
self.subscription(source: source).addDisposableTo(self.disposeBag)
|
|
|
|
}
|
2016-09-27 19:02:05 +03:00
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
2016-08-30 23:25:34 +03:00
|
|
|
|
|
|
|
deinit {
|
|
|
|
self.subject.onCompleted()
|
|
|
|
}
|
|
|
|
|
|
|
|
func addViews() {
|
|
|
|
preconditionFailure("Please override")
|
|
|
|
}
|
|
|
|
|
2016-09-25 18:50:33 +03:00
|
|
|
func subscription(source: Observable<Any>) -> Disposable {
|
2016-08-30 23:25:34 +03:00
|
|
|
preconditionFailure("Please override")
|
|
|
|
}
|
|
|
|
|
2016-09-25 18:50:33 +03:00
|
|
|
func publish(event: Any) {
|
2016-08-30 23:25:34 +03:00
|
|
|
self.subject.onNext(event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-03 10:45:38 +03:00
|
|
|
class WorkspaceToolComponent: WorkspaceTool, Flow {
|
|
|
|
|
|
|
|
let viewComponent: ViewComponent
|
|
|
|
var sink: Observable<Any> {
|
|
|
|
return self.viewComponent.sink
|
|
|
|
}
|
|
|
|
|
|
|
|
init(title: String, viewComponent: ViewComponent, minimumDimension: CGFloat = 50) {
|
|
|
|
self.viewComponent = viewComponent
|
|
|
|
super.init(title: title, view: viewComponent, minimumDimension: minimumDimension)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-30 23:25:34 +03:00
|
|
|
class WindowComponent: StandardComponent {
|
|
|
|
|
|
|
|
let windowController: NSWindowController
|
|
|
|
var window: NSWindow {
|
|
|
|
return self.windowController.window!
|
|
|
|
}
|
|
|
|
|
|
|
|
init(source: Observable<Any>, nibName: String) {
|
|
|
|
self.windowController = NSWindowController(windowNibName: nibName)
|
|
|
|
super.init(source: source)
|
|
|
|
}
|
|
|
|
|
|
|
|
func show() {
|
|
|
|
self.windowController.showWindow(self)
|
|
|
|
}
|
2016-09-01 21:09:00 +03:00
|
|
|
}
|