Keyboard shortcuts: Add method to retrieve info about a particular shortcut

This commit is contained in:
Molkobain
2021-04-13 11:25:40 +02:00
parent 0816d27456
commit 923a4048d3
3 changed files with 45 additions and 12 deletions

View File

@@ -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
//----------------------------------------------