feat: let users disable shortcuts
This commit is contained in:
1 parent
7f27cb950b
commit
5b0341539c
4 files changed
+29
-23
No files matched your search
+1
-1
@@ -20,7 +20,7 @@ EXTERNAL SOURCES:
|
||||
|
||||
CHECKOUT OPTIONS:
|
||||
ShortcutRecorder:
|
||||
:commit: 4aebe01e1ec9eebb520ef50e42bc321be473c580
|
||||
:commit: f718220854575bad86fa89dd2bb3decd0b14b2b0
|
||||
:git: https://github.com/Kentzo/ShortcutRecorder.git
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
|
||||
@@ -113,7 +113,6 @@
|
||||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
@@ -294,7 +293,6 @@
|
||||
D04BA2C9EF33A646D0977195 /* .github */,
|
||||
4807A6C423A9CD190052A53E /* Frameworks */,
|
||||
4A443501F57D4759B190C07E /* Pods */,
|
||||
D04BA2A4F257F4DCE1421758 /* Podfile.lock */,
|
||||
D04BA0E071D2EDFDB9A20523 /* Podfile */,
|
||||
D04BAAF760E3A8A22BDA84D6 /* appcast.xml */,
|
||||
D04BA6251F309645757C6000 /* src */,
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
import Cocoa
|
||||
import ShortcutRecorder
|
||||
|
||||
class UnclearableRecorderControl: RecorderControl {
|
||||
class UnclearableRecorderControl: RecorderControl, RecorderControlDelegate {
|
||||
convenience init(_ shortcutString: String, _ modifierFlagsOnly: Bool) {
|
||||
self.init(frame: .zero)
|
||||
allowsDeleteToClearShortcutAndEndRecording = false
|
||||
set(allowedModifierFlags: CocoaModifierFlagsMask, requiredModifierFlags: [], allowsEmptyModifierFlags: false)
|
||||
delegate = self
|
||||
allowsEscapeToCancelRecording = false
|
||||
set(allowedModifierFlags: CocoaModifierFlagsMask, requiredModifierFlags: [], allowsEmptyModifierFlags: true)
|
||||
if modifierFlagsOnly {
|
||||
allowsModifierFlagsOnlyShortcut = true
|
||||
}
|
||||
objectValue = Shortcut(keyEquivalent: shortcutString)
|
||||
// TODO: doesn't seem to work; handle width of the control better
|
||||
allowsExpansionToolTips = true
|
||||
widthAnchor.constraint(equalToConstant: 80).isActive = true
|
||||
widthAnchor.constraint(equalToConstant: 100).isActive = true
|
||||
}
|
||||
|
||||
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
|
||||
if allowsModifierFlagsOnlyShortcut && aKeyCode != .none {
|
||||
if allowsModifierFlagsOnlyShortcut && aShortcut.keyCode != .none {
|
||||
return false
|
||||
}
|
||||
return super.areModifierFlagsValid(aModifierFlags, for: aKeyCode)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -71,16 +71,23 @@ class GeneralTab {
|
||||
|
||||
@objc static func shortcutChangedCallback(_ sender: NSControl) {
|
||||
let controlId = sender.identifier!.rawValue
|
||||
// remove the holdShortcut character in case they also use it in the other shortcuts
|
||||
let newValue = (sender as! RecorderControl).stringValue.replacingOccurrences(of: Preferences.holdShortcut, with: "")
|
||||
switch controlId {
|
||||
case "holdShortcut":
|
||||
addShortcut({ App.app.focusTarget() }, .up, Shortcut(keyEquivalent: Preferences.holdShortcut)!, controlId)
|
||||
shortcutsDependentOnHoldShortcut.forEach { $0.sendAction($0.action, to: $0.target) }
|
||||
case "nextWindowShortcut": addShortcut({ App.app.showUiOrCycleSelection(1) }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId)
|
||||
case "previousWindowShortcut": addShortcut({ App.app.showUiOrCycleSelection(-1) }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId)
|
||||
case "cancelShortcut": addShortcut({ App.app.hideUi() }, .down, Shortcut(keyEquivalent: Preferences.holdShortcut + newValue)!, controlId)
|
||||
default: return
|
||||
if controlId == "holdShortcut" {
|
||||
addShortcut({ App.app.focusTarget() }, .up, Shortcut(keyEquivalent: Preferences.holdShortcut)!, controlId)
|
||||
shortcutsDependentOnHoldShortcut.forEach { $0.sendAction($0.action, to: $0.target) }
|
||||
} else {
|
||||
// remove the holdShortcut character in case they also use it in the other shortcuts
|
||||
let newValue = Preferences.holdShortcut.reduce((sender as! RecorderControl).stringValue, { $0.replacingOccurrences(of: String($1), with: "") })
|
||||
if newValue.isEmpty {
|
||||
removeShortcutIfExists(controlId, .down)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user