Skip to content

Commit

Permalink
Allow overriding system-reserved shortcuts (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
tofumatt authored Nov 15, 2023
1 parent ac302e2 commit de40257
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "لا يمكن استخدام اختصار لوحة المفاتيح هذا لأنه مستخدم بواسطة عنصر القائمة “%@”.";
"keyboard_shortcut_used_by_system" = "لا يمكن استخدام اختصار لوحة المفاتيح هذا لأنه مستخدم مسبقاً على مستوى النظام.";
"keyboard_shortcuts_can_be_changed" = "يمكن تغيير معظم اختصارات لوحة المفاتيح على مستوى النظام في “تفضيلات النظام > لوحة المفاتيح > الاختصارات ”.";
"ok" = "موافق";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "Tuto zkratku nelze použít, protože je již využívána položkou „%@“";
"keyboard_shortcut_used_by_system" = "Tuto zkratku nelze použít, protože už ji používá systém.";
"keyboard_shortcuts_can_be_changed" = "Většinu systémových zkratek můžete změnit v „Nastavení systému › Klávesnice › Klávesové zkratky“.";
"ok" = "OK";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "Dieses Tastaturkürzel kann nicht verwendet werden, da es bereits durch den Menüpunkt „%@” belegt ist.";
"keyboard_shortcut_used_by_system" = "Dieses Tastaturkürzel kann nicht verwendet werden, da es bereits systemweit verwendet wird.";
"keyboard_shortcuts_can_be_changed" = "Die meisten systemweiten Tastaturkürzel können unter „Systemeinstellungen › Tastatur › Kurzbefehle“ geändert werden.";
"ok" = "OK";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
"keyboard_shortcut_used_by_menu_item" = "This keyboard shortcut cannot be used as it’s already used by the “%@” menu item.";
"keyboard_shortcut_used_by_system" = "This keyboard shortcut cannot be used as it’s 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";
"ok" = "OK";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "Este atajo de teclado no se puede utilizar ya que está siendo utilizado por el elemento de menú “%@”.";
"keyboard_shortcut_used_by_system" = "Este atajo de teclado no se puede utilizar ya que está siendo utilizado por un atajo del sistema operativo.";
"keyboard_shortcuts_can_be_changed" = "La mayoría de los atajos de teclado del sistema operativo pueden ser modificados en “Configuración del sistema › Teclado › Atajos de teclado“.";
"ok" = "Aceptar";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "Ce raccourci ne peut pas être utilisé, car il est déjà utilisé par le menu “%@”.";
"keyboard_shortcut_used_by_system" = "Ce raccourci ne peut pas être utilisé car il s'agit d'un raccourci déjà présent dans le système.";
"keyboard_shortcuts_can_be_changed" = "La plupart des raccourcis clavier de l'ensemble du système peuvent être modifiés en “Réglages du système… › Clavier › Raccourcis clavier…”.";
"ok" = "OK";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "Ez a billentyűparancs nem használható mert már a “%@” menü elem használja.";
"keyboard_shortcut_used_by_system" = "Ez a billentyűparancs nem használható mert már egy rendszerszintü billentyűparancs.";
"keyboard_shortcuts_can_be_changed" = "A legtöbb rendszerszintü billentyűparancsot a “Rendszerbeállítások › Billentyűzet › Billentyűparancsok“ menüben meg lehet változtatni";
"ok" = "OK";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "このショートカットは既に“%@”で使われており使えません。";
"keyboard_shortcut_used_by_system" = "このショートカットキーは既にシステムで使われており使えません。";
"keyboard_shortcuts_can_be_changed" = "システムで設定されているショートカットキーは“システム設定 › キーボード › キーボードショートカット”で変更できます。";
"ok" = "OK";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "이 키보드 단축키는 이미 “%@” 메뉴 항목에 사용되고 있으므로 등록할 수 없습니다.";
"keyboard_shortcut_used_by_system" = "이 키보드 단축키는 이미 시스템상에서 사용되고 있으므로 등록할 수 없습니다.";
"keyboard_shortcuts_can_be_changed" = "대부분의 시스템 키보드 단축키는 “시스템 설정 › 키보드 › 키보드 단축키”에서 변경 가능합니다.";
"ok" = "확인";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "Deze toetscombinatie kan niet worden gebruikt omdat hij al wordt gebruikt door het menu item “%@”.";
"keyboard_shortcut_used_by_system" = "Deze toetscombinatie kan niet worden gebruikt omdat hij al door het systeem gebruikt wordt.";
"keyboard_shortcuts_can_be_changed" = "De meeste systeem toetscombinaties kunnen onder “Systeeminstellingen… > Toetsenbord > Toetscombinaties…” veranderd worden.";
"ok" = "OK";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "Este atalho não pode ser usado porque ele já é usado pelo item de menu “%@”.";
"keyboard_shortcut_used_by_system" = "Este atalho não pode ser usado porque ele já é usado por um atalho do sistema.";
"keyboard_shortcuts_can_be_changed" = "A maioria dos atalhos do sistema podem ser alterados em “Ajustes do Sistema › Teclado › Atalhos de Teclado”.";
"ok" = "OK";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "Это сочетание клавиш нельзя использовать, так как оно уже используется в пункте меню «%@».";
"keyboard_shortcut_used_by_system" = "Это сочетание клавиш нельзя использовать, поскольку оно является системным.";
"keyboard_shortcuts_can_be_changed" = "Большинство системных сочетаний клавиш можно изменить в «Системные настройки › Клавиатура › Сочетания клавиш».";
"ok" = "OK";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "当前快捷键无法使用,因为它已被用作菜单项 “%@” 的快捷键。";
"keyboard_shortcut_used_by_system" = "当前快捷键无法使用,因为它已被用作系统快捷键。";
"keyboard_shortcuts_can_be_changed" = "可以在 “系统设置 › 键盘 › 键盘快捷键” 中更改大多数系统快捷键。";
"ok" = "好";
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
"keyboard_shortcut_used_by_menu_item" = "此快速鍵無法使用,因為它已被選單項目「%@」使用。";
"keyboard_shortcut_used_by_system" = "此快速鍵無法使用,因為它已被系統使用。";
"keyboard_shortcuts_can_be_changed" = "可以在「系統設定 › 鍵盤 › 鍵盤快速鍵」中更改大多數的系統快速鍵。";
"ok" = "好";
15 changes: 11 additions & 4 deletions Sources/KeyboardShortcuts/RecorderCocoa.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,26 @@ 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: [
"ok".localized,
"force_use_shortcut".localized
]
)

self.focus()

return nil
// If the user has selected "Use Anyway" in the dialog (the second option), we'll continue setting the keyboard shorcut even though it's reserved by the system.
guard modalResponse == .alertSecondButtonReturn else {
return nil
}
}

self.stringValue = "\(shortcut)"
Expand Down
13 changes: 10 additions & 3 deletions Sources/KeyboardShortcuts/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,27 +201,34 @@ 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)
}

convenience init(
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
}
Expand Down

0 comments on commit de40257

Please sign in to comment.