diff --git a/application/utils.inc.php b/application/utils.inc.php index 21226de12..bf5af6085 100644 --- a/application/utils.inc.php +++ b/application/utils.inc.php @@ -2684,15 +2684,13 @@ HTML; } /** - * Return keyboard shortcuts config as an array - * - * @return array + * @return array All keyboard shortcuts config as an array * @throws \CoreException * @throws \CoreUnexpectedValue * @throws \MySQLException * @since 3.0.0 */ - public static function GetKeyboardShortcutPref(): array + public static function GetAllKeyboardShortcutsPrefs(): array { $aResultPref = []; $aShortcutPrefs = appUserPreferences::GetPref('keyboard_shortcuts', []); @@ -2703,13 +2701,48 @@ HTML; $sTriggeredElement = $cShortcutPlugin::GetShortcutTriggeredElementSelector(); foreach ($cShortcutPlugin::GetShortcutKeys() as $aShortcutKey) { $sKey = isset($aShortcutPrefs[$aShortcutKey['id']]) ? $aShortcutPrefs[$aShortcutKey['id']] : $aShortcutKey['key']; - $aResultPref[$aShortcutKey['id']] = ['key' => $sKey, 'label' => $aShortcutKey['label'], 'event' => $aShortcutKey['event'], 'triggered_element_selector' => $sTriggeredElement]; + + // Format key for display + $aKeyParts = explode('+', $sKey); + $aFormattedKeyParts = []; + foreach ($aKeyParts as $sKeyPart) { + $aFormattedKeyParts[] = ucfirst(trim($sKeyPart)); + } + $sFormattedKey = implode(' + ', $aFormattedKeyParts); + + $aResultPref[$aShortcutKey['id']] = [ + 'key' => $sKey, + 'key_for_display' => $sFormattedKey, + 'label' => $aShortcutKey['label'], + 'event' => $aShortcutKey['event'], + 'triggered_element_selector' => $sTriggeredElement, + ]; } } return $aResultPref; } + /** + * @param string $sShortcutId + * + * @return array The properties of the $sShortcutId shorcut + * @throws \Exception + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \MySQLException + * @since 3.0.0 + */ + public static function GetKeyboardShortcutPref(string $sShortcutId): array + { + $aPrefs = static::GetAllKeyboardShortcutsPrefs(); + if (false === array_key_exists($sShortcutId, $aPrefs)) { + throw new Exception('No shortcut identified as "'.$sShortcutId.'" is currently handled by the application.'); + } + + return $aPrefs[$sShortcutId]; + } + //---------------------------------------------- // Environment helpers //---------------------------------------------- diff --git a/pages/preferences.php b/pages/preferences.php index 4560046c2..1ac22d749 100644 --- a/pages/preferences.php +++ b/pages/preferences.php @@ -338,14 +338,14 @@ JS JS ); // For each existing shortcut keyboard existing in iTop - $aKeyboardShortcuts = utils::GetKeyboardShortcutPref(); + $aKeyboardShortcuts = utils::GetAllKeyboardShortcutsPrefs(); $sKeyboardShortcutsInputHint = Dict::S('UI:Preferences:PersonalizeKeyboardShortcuts:Input:Hint'); $sKeyboardShortcutsButtonTooltip = Dict::S('UI:Preferences:PersonalizeKeyboardShortcuts:Button:Tooltip'); - foreach($aKeyboardShortcuts as $sKeyboardShortcutId => $aKeyboardShortcut){ - // Recording button - $oButton = ButtonUIBlockFactory::MakeForAlternativeSecondaryAction(''); - $oButton->SetIconClass('fas fa-pen')->SetTooltip($sKeyboardShortcutsButtonTooltip)->SetOnClickJsCode( - << $aKeyboardShortcut) { + // Recording button + $oButton = ButtonUIBlockFactory::MakeForAlternativeSecondaryAction(''); + $oButton->SetIconClass('fas fa-pen')->SetTooltip($sKeyboardShortcutsButtonTooltip)->SetOnClickJsCode( + <<add_script("aKeyboardShortcuts = $sShortcuts;"); }