fix: custom shortcuts can use arrow keys (closes #1376)
This commit is contained in:
1 parent
254f238f82
commit
bb1de75128
3 files changed
+16
-7
No files matched your search
@@ -38,7 +38,7 @@ They helped [localize the app](https://poeditor.com/join/project/8AOEZ0eAZE):
|
|||||||
* Albert Abdilim
|
* Albert Abdilim
|
||||||
* Ali Gokmen
|
* Ali Gokmen
|
||||||
* Allen Guan
|
* Allen Guan
|
||||||
* Anurag
|
* Anurag Roy
|
||||||
* anushree b
|
* anushree b
|
||||||
* Arthur
|
* Arthur
|
||||||
* Ash
|
* Ash
|
||||||
|
|||||||
@@ -49,11 +49,12 @@ class CustomRecorderControl: RecorderControl, RecorderControlDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func alertIfSameShortcutAlreadyAssigned(_ shortcut: Shortcut, _ shortcutAlreadyAssigned: ATShortcut) {
|
func alertIfSameShortcutAlreadyAssigned(_ shortcut: Shortcut, _ shortcutAlreadyAssigned: ATShortcut) {
|
||||||
let existing = ControlsTab.shortcutControls[shortcutAlreadyAssigned.id]!
|
let isArrowKeys = ["←", "→", "↑", "↓"].contains(shortcutAlreadyAssigned.id)
|
||||||
|
let existing = ControlsTab.shortcutControls[shortcutAlreadyAssigned.id]
|
||||||
let alert = NSAlert()
|
let alert = NSAlert()
|
||||||
alert.alertStyle = .critical
|
alert.alertStyle = .critical
|
||||||
alert.messageText = NSLocalizedString("Conflicting shortcut", comment: "")
|
alert.messageText = NSLocalizedString("Conflicting shortcut", comment: "")
|
||||||
alert.informativeText = String(format: NSLocalizedString("Shortcut already assigned to another action: %@", comment: ""), existing.1.replacingOccurrences(of: " ", with: "\u{00A0}"))
|
alert.informativeText = String(format: NSLocalizedString("Shortcut already assigned to another action: %@", comment: ""), (isArrowKeys ? "Arrow keys" : existing!.1).replacingOccurrences(of: " ", with: "\u{00A0}"))
|
||||||
if !id.starts(with: "holdShortcut") {
|
if !id.starts(with: "holdShortcut") {
|
||||||
alert.addButton(withTitle: NSLocalizedString("Unassign existing shortcut and continue", comment: "")).setAccessibilityFocused(true)
|
alert.addButton(withTitle: NSLocalizedString("Unassign existing shortcut and continue", comment: "")).setAccessibilityFocused(true)
|
||||||
}
|
}
|
||||||
@@ -64,9 +65,15 @@ class CustomRecorderControl: RecorderControl, RecorderControlDelegate {
|
|||||||
}
|
}
|
||||||
let userChoice = alert.runModal()
|
let userChoice = alert.runModal()
|
||||||
if !id.starts(with: "holdShortcut") && userChoice == .alertFirstButtonReturn {
|
if !id.starts(with: "holdShortcut") && userChoice == .alertFirstButtonReturn {
|
||||||
existing.0.objectValue = nil
|
if isArrowKeys {
|
||||||
ControlsTab.shortcutChangedCallback(existing.0)
|
ControlsTab.arrowKeysCheckbox.state = .off
|
||||||
LabelAndControl.controlWasChanged(existing.0, shortcutAlreadyAssigned.id)
|
ControlsTab.arrowKeysEnabledCallback(ControlsTab.arrowKeysCheckbox)
|
||||||
|
LabelAndControl.controlWasChanged(ControlsTab.arrowKeysCheckbox, nil)
|
||||||
|
} else {
|
||||||
|
existing!.0.objectValue = nil
|
||||||
|
ControlsTab.shortcutChangedCallback(existing!.0)
|
||||||
|
LabelAndControl.controlWasChanged(existing!.0, shortcutAlreadyAssigned.id)
|
||||||
|
}
|
||||||
ControlsTab.shortcutControls[id]!.0.objectValue = shortcut
|
ControlsTab.shortcutControls[id]!.0.objectValue = shortcut
|
||||||
ControlsTab.shortcutChangedCallback(self)
|
ControlsTab.shortcutChangedCallback(self)
|
||||||
LabelAndControl.controlWasChanged(self, id)
|
LabelAndControl.controlWasChanged(self, id)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class ControlsTab {
|
|||||||
"quitAppShortcut": { App.app.quitSelectedApp() },
|
"quitAppShortcut": { App.app.quitSelectedApp() },
|
||||||
"hideShowAppShortcut": { App.app.hideShowSelectedApp() },
|
"hideShowAppShortcut": { App.app.hideShowSelectedApp() },
|
||||||
]
|
]
|
||||||
|
static var arrowKeysCheckbox: NSButton!
|
||||||
|
|
||||||
static func initTab() -> NSView {
|
static func initTab() -> NSView {
|
||||||
let focusWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Focus selected window", comment: ""), "focusWindowShortcut", Preferences.focusWindowShortcut, labelPosition: .right)
|
let focusWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Focus selected window", comment: ""), "focusWindowShortcut", Preferences.focusWindowShortcut, labelPosition: .right)
|
||||||
@@ -31,6 +32,7 @@ class ControlsTab {
|
|||||||
let quitAppShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Quit app", comment: ""), "quitAppShortcut", Preferences.quitAppShortcut, labelPosition: .right)
|
let quitAppShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Quit app", comment: ""), "quitAppShortcut", Preferences.quitAppShortcut, labelPosition: .right)
|
||||||
let hideShowAppShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Hide/Show app", comment: ""), "hideShowAppShortcut", Preferences.hideShowAppShortcut, labelPosition: .right)
|
let hideShowAppShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Hide/Show app", comment: ""), "hideShowAppShortcut", Preferences.hideShowAppShortcut, labelPosition: .right)
|
||||||
let enableArrows = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Arrow keys", comment: ""), "arrowKeysEnabled", extraAction: ControlsTab.arrowKeysEnabledCallback, labelPosition: .right)
|
let enableArrows = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Arrow keys", comment: ""), "arrowKeysEnabled", extraAction: ControlsTab.arrowKeysEnabledCallback, labelPosition: .right)
|
||||||
|
arrowKeysCheckbox = enableArrows[0] as! NSButton
|
||||||
let enableMouse = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Mouse hover", comment: ""), "mouseHoverEnabled", labelPosition: .right)
|
let enableMouse = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Mouse hover", comment: ""), "mouseHoverEnabled", labelPosition: .right)
|
||||||
let enableCursorFollowFocus = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Cursor follows focus", comment: ""), "cursorFollowFocusEnabled", labelPosition: .right)
|
let enableCursorFollowFocus = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Cursor follows focus", comment: ""), "cursorFollowFocusEnabled", labelPosition: .right)
|
||||||
let selectWindowcheckboxesExplanations = LabelAndControl.makeLabel(NSLocalizedString("Also select windows using:", comment: ""))
|
let selectWindowcheckboxesExplanations = LabelAndControl.makeLabel(NSLocalizedString("Also select windows using:", comment: ""))
|
||||||
@@ -43,7 +45,7 @@ class ControlsTab {
|
|||||||
let (holdShortcut2, nextWindowShortcut2, tab2View) = toShowSection("2")
|
let (holdShortcut2, nextWindowShortcut2, tab2View) = toShowSection("2")
|
||||||
let tabView = TabView([(NSLocalizedString("Shortcut 1", comment: ""), tab1View), (NSLocalizedString("Shortcut 2", comment: ""), tab2View)])
|
let tabView = TabView([(NSLocalizedString("Shortcut 1", comment: ""), tab1View), (NSLocalizedString("Shortcut 2", comment: ""), tab2View)])
|
||||||
|
|
||||||
ControlsTab.arrowKeysEnabledCallback(enableArrows[0] as! NSControl)
|
ControlsTab.arrowKeysEnabledCallback(arrowKeysCheckbox)
|
||||||
// trigger shortcutChanged for these shortcuts to trigger .restrictModifiers
|
// trigger shortcutChanged for these shortcuts to trigger .restrictModifiers
|
||||||
[holdShortcut, holdShortcut2].forEach { ControlsTab.shortcutChangedCallback($0[1] as! NSControl) }
|
[holdShortcut, holdShortcut2].forEach { ControlsTab.shortcutChangedCallback($0[1] as! NSControl) }
|
||||||
[nextWindowShortcut, nextWindowShortcut2].forEach { ControlsTab.shortcutChangedCallback($0[0] as! NSControl) }
|
[nextWindowShortcut, nextWindowShortcut2].forEach { ControlsTab.shortcutChangedCallback($0[0] as! NSControl) }
|
||||||
|
|||||||
Reference in new issue
Block a user