2016-08-14 00:01:08 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
import RxSwift
|
|
|
|
|
2016-08-30 23:25:34 +03:00
|
|
|
class PrefPane: NSView, Component {
|
2016-09-11 15:28:56 +03:00
|
|
|
|
|
|
|
let disposeBag = DisposeBag()
|
2016-08-14 00:01:08 +03:00
|
|
|
|
|
|
|
private let source: Observable<Any>
|
|
|
|
|
|
|
|
private let subject = PublishSubject<Any>()
|
|
|
|
var sink: Observable<Any> {
|
|
|
|
return self.subject.asObservable()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true to place this to the upper left corner when the scroll view is bigger than this view.
|
|
|
|
override var flipped: Bool {
|
|
|
|
return true
|
|
|
|
}
|
2016-09-24 17:35:27 +03:00
|
|
|
|
|
|
|
var displayName: String {
|
|
|
|
preconditionFailure("Please override")
|
|
|
|
}
|
2016-08-25 10:27:59 +03:00
|
|
|
|
|
|
|
var pinToContainer: Bool {
|
|
|
|
return false
|
|
|
|
}
|
2016-08-14 00:01:08 +03:00
|
|
|
|
|
|
|
init(source: Observable<Any>) {
|
|
|
|
self.source = source
|
|
|
|
|
|
|
|
super.init(frame: CGRect.zero)
|
|
|
|
self.translatesAutoresizingMaskIntoConstraints = false
|
2016-08-25 10:27:59 +03:00
|
|
|
|
2016-08-14 00:01:08 +03:00
|
|
|
self.addViews()
|
|
|
|
self.subscription(source: self.source).addDisposableTo(self.disposeBag)
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
|
|
|
self.subject.onCompleted()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func addViews() {
|
|
|
|
preconditionFailure("Please override")
|
|
|
|
}
|
|
|
|
|
|
|
|
func subscription(source source: Observable<Any>) -> Disposable {
|
|
|
|
preconditionFailure("Please override")
|
|
|
|
}
|
|
|
|
|
|
|
|
func publish(event event: Any) {
|
|
|
|
self.subject.onNext(event)
|
|
|
|
}
|
2016-09-13 09:32:58 +03:00
|
|
|
|
|
|
|
func windowWillClose() {
|
|
|
|
|
|
|
|
}
|
2016-08-14 00:01:08 +03:00
|
|
|
}
|
2016-08-14 16:01:28 +03:00
|
|
|
|
|
|
|
// MARK: - Control Utils
|
|
|
|
extension PrefPane {
|
|
|
|
|
|
|
|
func paneTitleTextField(title title: String) -> NSTextField {
|
|
|
|
let field = defaultTitleTextField()
|
|
|
|
field.font = NSFont.boldSystemFontOfSize(16)
|
|
|
|
field.alignment = .Left;
|
|
|
|
field.stringValue = title
|
|
|
|
return field
|
|
|
|
}
|
|
|
|
|
|
|
|
func titleTextField(title title: String) -> NSTextField {
|
|
|
|
let field = defaultTitleTextField()
|
|
|
|
field.alignment = .Right;
|
|
|
|
field.stringValue = title
|
|
|
|
return field
|
|
|
|
}
|
|
|
|
|
2016-09-10 22:46:43 +03:00
|
|
|
func infoTextField(text text: String) -> NSTextField {
|
|
|
|
let field = NSTextField(forAutoLayout: ())
|
|
|
|
field.font = NSFont.systemFontOfSize(NSFont.smallSystemFontSize())
|
|
|
|
field.textColor = NSColor.grayColor()
|
|
|
|
field.backgroundColor = NSColor.clearColor()
|
|
|
|
field.editable = false
|
|
|
|
field.bordered = false
|
|
|
|
|
|
|
|
// both are needed, otherwise hyperlink won't accept mousedown
|
|
|
|
field.selectable = true
|
|
|
|
field.allowsEditingTextAttributes = true
|
|
|
|
|
|
|
|
field.stringValue = text
|
|
|
|
|
|
|
|
return field
|
|
|
|
}
|
|
|
|
|
2016-08-14 16:38:41 +03:00
|
|
|
func configureCheckbox(button button: NSButton, title: String, action: Selector) {
|
2016-08-14 16:01:28 +03:00
|
|
|
button.title = title
|
|
|
|
button.setButtonType(.SwitchButton)
|
|
|
|
button.bezelStyle = .ThickSquareBezelStyle
|
|
|
|
button.target = self
|
|
|
|
button.action = action
|
|
|
|
}
|
|
|
|
|
|
|
|
private func defaultTitleTextField() -> NSTextField {
|
|
|
|
let field = NSTextField(forAutoLayout: ())
|
|
|
|
field.backgroundColor = NSColor.clearColor();
|
|
|
|
field.editable = false;
|
|
|
|
field.bordered = false;
|
|
|
|
return field
|
|
|
|
}
|
|
|
|
}
|