when shortcut taken by system, allow user to use anyway

This commit is contained in:
Andy Park 2023-03-11 15:07:07 +09:00
parent d168f629ed
commit 671b73a7ab
3 changed files with 23 additions and 7 deletions

View File

@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "This keyboard shortcut cannot be used as its already used by the “%@” menu item."; "keyboard_shortcut_used_by_menu_item" = "This keyboard shortcut cannot be used as its already used by the “%@” menu item.";
"keyboard_shortcut_used_by_system" = "This keyboard shortcut cannot be used as its already a system-wide keyboard shortcut."; "keyboard_shortcut_used_by_system" = "This keyboard shortcut cannot be used as its already a system-wide keyboard shortcut.";
"keyboard_shortcuts_can_be_changed" = "Most system-wide keyboard shortcuts can be changed in “System Settings Keyboard Keyboard Shortcuts”."; "keyboard_shortcuts_can_be_changed" = "Most system-wide keyboard shortcuts can be changed in “System Settings Keyboard Keyboard Shortcuts”.";
"force_use_shortcut" = "Use Anyway";

View File

@ -248,19 +248,27 @@ extension KeyboardShortcuts {
return nil return nil
} }
guard !shortcut.isTakenBySystem else { if shortcut.isTakenBySystem {
self.blur() self.blur()
NSAlert.showModal( let modalResponse = NSAlert.showModal(
for: self.window, for: self.window,
title: "keyboard_shortcut_used_by_system".localized, title: "keyboard_shortcut_used_by_system".localized,
// TODO: Add button to offer to open the relevant system settings pane for the user. // TODO: Add button to offer to open the relevant system settings pane for the user.
message: "keyboard_shortcuts_can_be_changed".localized message: "keyboard_shortcuts_can_be_changed".localized,
buttonTitles: [
"force_use_shortcut".localized,
"Cancel"
]
) )
self.focus() self.focus()
return nil // first button returned from alert means user wants to continue setting this
// shortcut despite it being used by system.
guard modalResponse == .alertFirstButtonReturn else {
return nil
}
} }
self.stringValue = "\(shortcut)" self.stringValue = "\(shortcut)"

View File

@ -138,13 +138,15 @@ extension NSAlert {
title: String, title: String,
message: String? = nil, message: String? = nil,
style: Style = .warning, style: Style = .warning,
icon: NSImage? = nil icon: NSImage? = nil,
buttonTitles: [String] = []
) -> NSApplication.ModalResponse { ) -> NSApplication.ModalResponse {
NSAlert( NSAlert(
title: title, title: title,
message: message, message: message,
style: style, style: style,
icon: icon icon: icon,
buttonTitles: buttonTitles
).runModal(for: window) ).runModal(for: window)
} }
@ -152,12 +154,17 @@ extension NSAlert {
title: String, title: String,
message: String? = nil, message: String? = nil,
style: Style = .warning, style: Style = .warning,
icon: NSImage? = nil icon: NSImage? = nil,
buttonTitles: [String] = []
) { ) {
self.init() self.init()
self.messageText = title self.messageText = title
self.alertStyle = style self.alertStyle = style
self.icon = icon self.icon = icon
for buttonTitle in buttonTitles {
self.addButton(withTitle: buttonTitle)
}
if let message { if let message {
self.informativeText = message self.informativeText = message