This commit is contained in:
sohocoke 2023-05-04 23:27:05 +02:00 committed by GitHub
commit 1acbadc2a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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_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”.";
"force_use_shortcut" = "Use Anyway";

View File

@ -249,19 +249,27 @@ extension KeyboardShortcuts {
return nil
}
guard !shortcut.isTakenBySystem else {
if shortcut.isTakenBySystem {
self.blur()
NSAlert.showModal(
let modalResponse = NSAlert.showModal(
for: self.window,
title: "keyboard_shortcut_used_by_system".localized,
// 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()
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)"

View File

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