1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-28 08:13:17 +03:00

GH-543 Add Keys preferences pane

This commit is contained in:
Tae Won Ha 2018-04-05 21:15:54 +02:00
parent a600707b23
commit 423406adb5
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
3 changed files with 117 additions and 0 deletions

View File

@ -66,6 +66,7 @@
1929BD2F41D93ADFF43C1C98 /* NetUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929B02440BC99C42F9EBD45 /* NetUtils.m */; };
1929BD3878A3A47B8D685CD2 /* AppDelegateReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B7A68B7109CEFAF105E8 /* AppDelegateReducer.swift */; };
1929BD3F9E609BFADB27584B /* Scorer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B9D510177918080BE39B /* Scorer.swift */; };
1929BD9AEB34F95438D97FE7 /* KeysPref.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B461EB3DE08C58DD9ED9 /* KeysPref.swift */; };
1929BDFDBDA7180D02ACB37E /* RxSwiftCommonsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B6C215ACCBE12672A8D7 /* RxSwiftCommonsTest.swift */; };
1929BE0DAEE9664C5BCFA211 /* States.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BB6608B4F0E037CA0F4C /* States.swift */; };
1929BE0F64A6CE5BCE2A5092 /* MainWindow+Delegates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B714EB137AE448CE8ABD /* MainWindow+Delegates.swift */; };
@ -228,6 +229,7 @@
1929B364460D86F17E80943C /* PrefService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrefService.swift; sourceTree = "<group>"; };
1929B365A6434354B568B04F /* FileMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileMonitor.swift; sourceTree = "<group>"; };
1929B457B9D0FA4D21F3751E /* UiRootReducer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UiRootReducer.swift; sourceTree = "<group>"; };
1929B461EB3DE08C58DD9ED9 /* KeysPref.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeysPref.swift; sourceTree = "<group>"; };
1929B49E6924847AD085C8C9 /* PrefWindowReducer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrefWindowReducer.swift; sourceTree = "<group>"; };
1929B5046239709E33516F5C /* Pref128ToCurrentConverter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Pref128ToCurrentConverter.swift; sourceTree = "<group>"; };
1929B56C8ED31834BA9D8543 /* FileItemUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileItemUtils.swift; sourceTree = "<group>"; };
@ -386,6 +388,7 @@
1929BCE3E156C06EDF1F2806 /* FileOutlineView.swift */,
1929BA5C7099CDEB04B76BA4 /* FileBrowser.swift */,
1929BD2CA8DD198A6BCDBCB7 /* ThemedTableSubviews.swift */,
1929B461EB3DE08C58DD9ED9 /* KeysPref.swift */,
);
name = "File Browser";
sourceTree = "<group>";
@ -913,6 +916,7 @@
1929B8DDACEB28E6672AEC42 /* MainWindow.swift in Sources */,
1929B5257DB27F03C6663482 /* MainWindow+Actions.swift in Sources */,
1929BE0F64A6CE5BCE2A5092 /* MainWindow+Delegates.swift in Sources */,
1929BD9AEB34F95438D97FE7 /* KeysPref.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

112
VimR/VimR/KeysPref.swift Normal file
View File

@ -0,0 +1,112 @@
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Cocoa
import PureLayout
import RxSwift
class KeysPref: PrefPane, UiComponent, NSTextFieldDelegate {
typealias StateType = AppState
enum Action {
case isLeftOptionMeta(Bool)
case isRightOptionMeta(Bool)
}
override var displayName: String {
return "Keys"
}
override var pinToContainer: Bool {
return true
}
required init(source: Observable<StateType>, emitter: ActionEmitter, state: StateType) {
self.emit = emitter.typedEmit()
self.isLeftOptionMeta = state.mainWindowTemplate.isLeftOptionMeta
self.isRightOptionMeta = state.mainWindowTemplate.isRightOptionMeta
super.init(frame: .zero)
self.addViews()
self.updateViews()
source
.observeOn(MainScheduler.instance)
.subscribe(onNext: { state in
if self.isLeftOptionMeta != state.mainWindowTemplate.isLeftOptionMeta
|| self.isRightOptionMeta != state.mainWindowTemplate.isRightOptionMeta
{
self.isLeftOptionMeta = state.mainWindowTemplate.isLeftOptionMeta
self.isRightOptionMeta = state.mainWindowTemplate.isRightOptionMeta
self.updateViews()
}
})
.disposed(by: self.disposeBag)
}
private let emit: (Action) -> Void
private let disposeBag = DisposeBag()
private var isLeftOptionMeta: Bool
private var isRightOptionMeta: Bool
private let isLeftOptionMetaCheckbox = NSButton(forAutoLayout: ())
private let isRightOptionMetaCheckbox = NSButton(forAutoLayout: ())
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func updateViews() {
self.isLeftOptionMetaCheckbox.boolState = self.isLeftOptionMeta
self.isRightOptionMetaCheckbox.boolState = self.isRightOptionMeta
}
private func addViews() {
let paneTitle = self.paneTitleTextField(title: "Keys")
let isLeftOptionMeta = self.isLeftOptionMetaCheckbox
self.configureCheckbox(button: isLeftOptionMeta,
title: "Use Left Option as Meta",
action: #selector(KeysPref.isLeftOptionMetaAction(_:)))
let isRightOptionMeta = self.isRightOptionMetaCheckbox
self.configureCheckbox(button: isRightOptionMeta,
title: "Use Right Option as Meta",
action: #selector(KeysPref.isRightOptionMetaAction(_:)))
self.addSubview(paneTitle)
self.addSubview(isLeftOptionMeta)
self.addSubview(isRightOptionMeta)
paneTitle.autoPinEdge(toSuperviewEdge: .top, withInset: 18)
paneTitle.autoPinEdge(toSuperviewEdge: .left, withInset: 18)
paneTitle.autoPinEdge(toSuperviewEdge: .right, withInset: 18, relation: .greaterThanOrEqual)
isLeftOptionMeta.autoPinEdge(.top, to: .bottom, of: paneTitle, withOffset: 18)
isLeftOptionMeta.autoPinEdge(toSuperviewEdge: .left, withInset: 18)
isRightOptionMeta.autoPinEdge(.top, to: .bottom, of: isLeftOptionMeta, withOffset: 5)
isRightOptionMeta.autoPinEdge(toSuperviewEdge: .left, withInset: 18)
}
}
// MARK: - Actions
extension KeysPref {
@objc func isLeftOptionMetaAction(_ sender: NSButton) {
self.emit(.isLeftOptionMeta(sender.boolState))
}
@objc func isRightOptionMetaAction(_ sender: NSButton) {
self.emit(.isRightOptionMeta(sender.boolState))
}
}

View File

@ -30,6 +30,7 @@ class PrefWindow: NSObject,
ToolsPref(source: source, emitter: emitter, state: state),
AppearancePref(source: source, emitter: emitter, state: state),
AdvancedPref(source: source, emitter: emitter, state: state),
KeysPref(source: source, emitter: emitter, state: state)
]
super.init()