feat: let users disable shortcuts

This commit is contained in:
Louis Pontoise authored and lwouis committed 2020-04-07 18:06:26 +09:00
1 parent 7f27cb950b
commit 5b0341539c
4 files changed
+29 -23

No files matched your search

+1 -1
View File
@@ -20,7 +20,7 @@ EXTERNAL SOURCES:
CHECKOUT OPTIONS: CHECKOUT OPTIONS:
ShortcutRecorder: ShortcutRecorder:
:commit: 4aebe01e1ec9eebb520ef50e42bc321be473c580 :commit: f718220854575bad86fa89dd2bb3decd0b14b2b0
:git: https://github.com/Kentzo/ShortcutRecorder.git :git: https://github.com/Kentzo/ShortcutRecorder.git
SPEC CHECKSUMS: SPEC CHECKSUMS:
-2
View File
@@ -113,7 +113,6 @@
D04BA26C75F76C277653C932 /* FeedbackWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedbackWindow.swift; sourceTree = "<group>"; }; D04BA26C75F76C277653C932 /* FeedbackWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedbackWindow.swift; sourceTree = "<group>"; };
D04BA27C87B86C4484A5B15B /* TabViewItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabViewItem.swift; sourceTree = "<group>"; }; D04BA27C87B86C4484A5B15B /* TabViewItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabViewItem.swift; sourceTree = "<group>"; };
D04BA282BB16C1554595A968 /* Applications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Applications.swift; sourceTree = "<group>"; }; D04BA282BB16C1554595A968 /* Applications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Applications.swift; sourceTree = "<group>"; };
D04BA2A4F257F4DCE1421758 /* Podfile.lock */ = {isa = PBXFileReference; lastKnownFileType = file.lock; path = Podfile.lock; sourceTree = "<group>"; };
D04BA2C7B51F68651B3C60E2 /* 6 windows - 1 line.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "6 windows - 1 line.jpg"; sourceTree = "<group>"; }; D04BA2C7B51F68651B3C60E2 /* 6 windows - 1 line.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "6 windows - 1 line.jpg"; sourceTree = "<group>"; };
D04BA2E723062A1DAC58618F /* setup_ci_pr.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = setup_ci_pr.sh; sourceTree = "<group>"; }; D04BA2E723062A1DAC58618F /* setup_ci_pr.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = setup_ci_pr.sh; sourceTree = "<group>"; };
D04BA2E8D5D5CC23456BC8F7 /* tr */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = tr; path = Localizable.strings; sourceTree = "<group>"; }; D04BA2E8D5D5CC23456BC8F7 /* tr */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = tr; path = Localizable.strings; sourceTree = "<group>"; };
@@ -294,7 +293,6 @@
D04BA2C9EF33A646D0977195 /* .github */, D04BA2C9EF33A646D0977195 /* .github */,
4807A6C423A9CD190052A53E /* Frameworks */, 4807A6C423A9CD190052A53E /* Frameworks */,
4A443501F57D4759B190C07E /* Pods */, 4A443501F57D4759B190C07E /* Pods */,
D04BA2A4F257F4DCE1421758 /* Podfile.lock */,
D04BA0E071D2EDFDB9A20523 /* Podfile */, D04BA0E071D2EDFDB9A20523 /* Podfile */,
D04BAAF760E3A8A22BDA84D6 /* appcast.xml */, D04BAAF760E3A8A22BDA84D6 /* appcast.xml */,
D04BA6251F309645757C6000 /* src */, D04BA6251F309645757C6000 /* src */,
@@ -1,29 +1,30 @@
import Cocoa import Cocoa
import ShortcutRecorder import ShortcutRecorder
class UnclearableRecorderControl: RecorderControl { class UnclearableRecorderControl: RecorderControl, RecorderControlDelegate {
convenience init(_ shortcutString: String, _ modifierFlagsOnly: Bool) { convenience init(_ shortcutString: String, _ modifierFlagsOnly: Bool) {
self.init(frame: .zero) self.init(frame: .zero)
allowsDeleteToClearShortcutAndEndRecording = false delegate = self
set(allowedModifierFlags: CocoaModifierFlagsMask, requiredModifierFlags: [], allowsEmptyModifierFlags: false) allowsEscapeToCancelRecording = false
set(allowedModifierFlags: CocoaModifierFlagsMask, requiredModifierFlags: [], allowsEmptyModifierFlags: true)
if modifierFlagsOnly { if modifierFlagsOnly {
allowsModifierFlagsOnlyShortcut = true allowsModifierFlagsOnlyShortcut = true
} }
objectValue = Shortcut(keyEquivalent: shortcutString) objectValue = Shortcut(keyEquivalent: shortcutString)
// TODO: doesn't seem to work; handle width of the control better widthAnchor.constraint(equalToConstant: 100).isActive = true
allowsExpansionToolTips = true
widthAnchor.constraint(equalToConstant: 80).isActive = true
} }
override func drawClearButton(_ aDirtyRect: NSRect) { override func drawClearButton(_ aDirtyRect: NSRect) {
// don't draw the clear button if !allowsModifierFlagsOnlyShortcut {
super.drawClearButton(aDirtyRect)
}
} }
override func areModifierFlagsValid(_ aModifierFlags: NSEvent.ModifierFlags, for aKeyCode: KeyCode) -> Bool { func recorderControl(_ aControl: RecorderControl, canRecord aShortcut: Shortcut) -> Bool {
// only allow modifiers: ⌥ -> valid, e -> invalid, ⌥e -> invalid // only allow modifiers: ⌥ -> valid, e -> invalid, ⌥e -> invalid
if allowsModifierFlagsOnlyShortcut && aKeyCode != .none { if allowsModifierFlagsOnlyShortcut && aShortcut.keyCode != .none {
return false return false
} }
return super.areModifierFlagsValid(aModifierFlags, for: aKeyCode) return true
} }
} }
+17 -10
View File
@@ -71,16 +71,23 @@ class GeneralTab {
@objc static func shortcutChangedCallback(_ sender: NSControl) { @objc static func shortcutChangedCallback(_ sender: NSControl) {
let controlId = sender.identifier!.rawValue let controlId = sender.identifier!.rawValue
// remove the holdShortcut character in case they also use it in the other shortcuts if controlId == "holdShortcut" {
let newValue = (sender as! RecorderControl).stringValue.replacingOccurrences(of: Preferences.holdShortcut, with: "") addShortcut({ App.app.focusTarget() }, .up, Shortcut(keyEquivalent: Preferences.holdShortcut)!, controlId)
switch controlId { shortcutsDependentOnHoldShortcut.forEach { $0.sendAction($0.action, to: $0.target) }
case "holdShortcut": } else {
addShortcut({ App.app.focusTarget() }, .up, Shortcut(keyEquivalent: Preferences.holdShortcut)!, controlId) // remove the holdShortcut character in case they also use it in the other shortcuts
shortcutsDependentOnHoldShortcut.forEach { $0.sendAction($0.action, to: $0.target) } let newValue = Preferences.holdShortcut.reduce((sender as! RecorderControl).stringValue, { $0.replacingOccurrences(of: String($1), with: "") })
case "nextWindowShortcut": addShortcut({ App.app.showUiOrCycleSelection(1) }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId) if newValue.isEmpty {
case "previousWindowShortcut": addShortcut({ App.app.showUiOrCycleSelection(-1) }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId) removeShortcutIfExists(controlId, .down)
case "cancelShortcut": addShortcut({ App.app.hideUi() }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId) return
default: return }
if controlId == "nextWindowShortcut" {
addShortcut({ App.app.showUiOrCycleSelection(1) }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId)
} else if controlId == "previousWindowShortcut" {
addShortcut({ App.app.showUiOrCycleSelection(-1) }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId)
} else if controlId == "cancelShortcut" {
addShortcut({ App.app.hideUi() }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId)
}
} }
} }