1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-22 05:01:50 +03:00
vimr/VimR/AdvancedPrefPane.swift

135 lines
4.6 KiB
Swift
Raw Normal View History

2016-09-24 17:31:14 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Cocoa
import PureLayout
import RxSwift
struct AdvancedPrefData: Equatable {
2016-10-14 22:51:30 +03:00
let useSnapshotUpdateChannel: Bool
2016-09-24 17:31:14 +03:00
let useInteractiveZsh: Bool
}
func == (left: AdvancedPrefData, right: AdvancedPrefData) -> Bool {
2016-10-14 22:51:30 +03:00
return left.useSnapshotUpdateChannel == right.useSnapshotUpdateChannel &&
left.useInteractiveZsh == right.useInteractiveZsh
2016-09-24 17:31:14 +03:00
}
class AdvancedPrefPane: PrefPane {
2016-09-24 17:35:27 +03:00
override var displayName: String {
return "Advanced"
}
2016-09-24 17:31:14 +03:00
override var pinToContainer: Bool {
return true
}
2016-09-25 18:50:33 +03:00
fileprivate var data: AdvancedPrefData
2016-09-24 17:31:14 +03:00
2016-09-25 18:50:33 +03:00
fileprivate let useInteractiveZshCheckbox = NSButton(forAutoLayout: ())
2016-10-14 22:51:30 +03:00
fileprivate let useSnapshotUpdateCheckbox = NSButton(forAutoLayout: ())
2016-09-24 17:31:14 +03:00
init(source: Observable<Any>, initialData: AdvancedPrefData) {
self.data = initialData
super.init(source: source)
self.updateViews(newData: initialData)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func addViews() {
let paneTitle = self.paneTitleTextField(title: "Advanced")
2016-10-14 22:51:30 +03:00
let useInteractiveZsh = self.useInteractiveZshCheckbox
self.configureCheckbox(button: useInteractiveZsh,
2016-09-24 17:31:14 +03:00
title: "Use interactive mode for zsh",
action: #selector(AdvancedPrefPane.useInteractiveZshAction(_:)))
let useInteractiveZshInfo = self.infoTextField(
text: "If your login shell is zsh, when checked, the '-i' option will be used to launch zsh.\n"
+ "Checking this option may break VimR if your .zshrc contains complex stuff.\n"
+ "It may be a good idea to put the PATH-settings in .zshenv and let this unchecked.\n"
+ "Use with caution."
)
2016-10-14 22:51:30 +03:00
let useSnapshotUpdate = self.useSnapshotUpdateCheckbox
self.configureCheckbox(button: self.useSnapshotUpdateCheckbox,
title: "Use Snapshot Update Channel",
action: #selector(AdvancedPrefPane.useSnapshotUpdateChannelAction(_:)))
let useSnapshotUpdateInfo = self.infoTextField(
2016-10-15 11:55:56 +03:00
text: "If you are adventurous, check this.\n"
2016-10-14 22:51:30 +03:00
+ "You'll be test driving the newest snapshot builds of VimR in no time!"
)
2016-09-24 17:31:14 +03:00
self.addSubview(paneTitle)
2016-10-14 22:51:30 +03:00
self.addSubview(useSnapshotUpdate)
self.addSubview(useSnapshotUpdateInfo)
2016-09-24 17:31:14 +03:00
self.addSubview(useInteractiveZsh)
self.addSubview(useInteractiveZshInfo)
2016-09-25 18:50:33 +03:00
paneTitle.autoPinEdge(toSuperviewEdge: .top, withInset: 18)
paneTitle.autoPinEdge(toSuperviewEdge: .left, withInset: 18)
paneTitle.autoPinEdge(toSuperviewEdge: .right, withInset: 18, relation: .greaterThanOrEqual)
2016-09-24 17:31:14 +03:00
2016-10-14 22:51:30 +03:00
useSnapshotUpdate.autoPinEdge(.top, to: .bottom, of: paneTitle, withOffset: 18)
useSnapshotUpdate.autoPinEdge(toSuperviewEdge: .left, withInset: 18)
useSnapshotUpdateInfo.autoPinEdge(.top, to: .bottom, of: useSnapshotUpdate, withOffset: 5)
useSnapshotUpdateInfo.autoPinEdge(toSuperviewEdge: .left, withInset: 18)
useInteractiveZsh.autoPinEdge(.top, to: .bottom, of: useSnapshotUpdateInfo, withOffset: 18)
2016-09-25 18:50:33 +03:00
useInteractiveZsh.autoPinEdge(toSuperviewEdge: .left, withInset: 18)
2016-09-24 17:31:14 +03:00
2016-09-25 18:50:33 +03:00
useInteractiveZshInfo.autoPinEdge(.top, to: .bottom, of: useInteractiveZsh, withOffset: 5)
useInteractiveZshInfo.autoPinEdge(toSuperviewEdge: .left, withInset: 18)
2016-09-24 17:31:14 +03:00
2016-10-14 22:51:30 +03:00
useSnapshotUpdate.boolState = self.data.useSnapshotUpdateChannel
2016-09-24 17:31:14 +03:00
useInteractiveZsh.boolState = self.data.useInteractiveZsh
}
2016-09-25 18:50:33 +03:00
override func subscription(source: Observable<Any>) -> Disposable {
2016-09-24 17:31:14 +03:00
return source
.filter { $0 is PrefData }
.map { ($0 as! PrefData).advanced }
.filter { [unowned self] data in data != self.data }
2016-09-25 19:10:07 +03:00
.subscribe(onNext: { [unowned self] data in
2016-09-24 17:31:14 +03:00
self.updateViews(newData: data)
self.data = data
2016-09-25 19:10:07 +03:00
})
2016-09-24 17:31:14 +03:00
}
2016-09-25 18:50:33 +03:00
fileprivate func set(data: AdvancedPrefData) {
2016-09-24 17:31:14 +03:00
self.data = data
self.publish(event: data)
}
2016-09-25 18:50:33 +03:00
fileprivate func updateViews(newData: AdvancedPrefData) {
2016-10-14 22:51:30 +03:00
self.useSnapshotUpdateCheckbox.boolState = newData.useSnapshotUpdateChannel
2016-09-24 17:31:14 +03:00
self.useInteractiveZshCheckbox.boolState = newData.useInteractiveZsh
}
}
// MARK: - Actions
extension AdvancedPrefPane {
2016-09-25 18:50:33 +03:00
func useInteractiveZshAction(_ sender: NSButton) {
2016-10-14 22:51:30 +03:00
self.set(data: AdvancedPrefData(useSnapshotUpdateChannel:self.useSnapshotUpdateCheckbox.boolState,
useInteractiveZsh: self.useInteractiveZshCheckbox.boolState))
}
func useSnapshotUpdateChannelAction(_ sender: NSButton) {
self.set(data: AdvancedPrefData(useSnapshotUpdateChannel:self.useSnapshotUpdateCheckbox.boolState,
useInteractiveZsh: self.useInteractiveZshCheckbox.boolState))
2016-09-24 17:31:14 +03:00
}
}