fix: Store hotkeys to specified name (#3280)
* fix: Store hotkeys to specified name * fix: Move hotkey name into a new hotkey object
This commit is contained in:
parent
b2128976a3
commit
2f33e42004
@ -81,7 +81,6 @@ function modeFactory() {
|
|||||||
initToolGroups(extensionManager, toolGroupService, commandsManager);
|
initToolGroups(extensionManager, toolGroupService, commandsManager);
|
||||||
|
|
||||||
// init customizations
|
// init customizations
|
||||||
console.log('* Adding mode customizations');
|
|
||||||
customizationService.addModeCustomizations([
|
customizationService.addModeCustomizations([
|
||||||
'@ohif/extension-test.customizationModule.custom-context-menu',
|
'@ohif/extension-test.customizationModule.custom-context-menu',
|
||||||
]);
|
]);
|
||||||
@ -211,7 +210,12 @@ function modeFactory() {
|
|||||||
dicompdf.sopClassHandler,
|
dicompdf.sopClassHandler,
|
||||||
dicomsr.sopClassHandler,
|
dicomsr.sopClassHandler,
|
||||||
],
|
],
|
||||||
hotkeys: [...hotkeys.defaults.hotkeyBindings],
|
hotkeys: {
|
||||||
|
// Don't store the hotkeys for basic-test-mode under the same key
|
||||||
|
// because they get customized by tests
|
||||||
|
name: 'basic-test-hotkeys',
|
||||||
|
hotkeys: [...hotkeys.defaults.hotkeyBindings],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -64,19 +64,17 @@ export class HotkeysManager {
|
|||||||
*
|
*
|
||||||
* @param {HotkeyDefinition[] | Object} [hotkeyDefinitions=[]] Contains hotkeys definitions
|
* @param {HotkeyDefinition[] | Object} [hotkeyDefinitions=[]] Contains hotkeys definitions
|
||||||
*/
|
*/
|
||||||
setHotkeys(hotkeyDefinitions = [], key = 'hotkey-definitions') {
|
setHotkeys(hotkeyDefinitions = [], name = 'hotkey-definitions') {
|
||||||
try {
|
try {
|
||||||
const definitions = this.getValidDefinitions(hotkeyDefinitions);
|
const definitions = this.getValidDefinitions(hotkeyDefinitions);
|
||||||
if (isequal(definitions, this.hotkeyDefaults)) {
|
if (isequal(definitions, this.hotkeyDefaults)) {
|
||||||
console.log('hotkeys REMOVING unused definition', key);
|
localStorage.removeItem(name);
|
||||||
localStorage.removeItem(key);
|
|
||||||
} else {
|
} else {
|
||||||
console.log('hotkeys setting local storage', key);
|
localStorage.setItem(name, JSON.stringify(definitions));
|
||||||
localStorage.setItem(key, JSON.stringify(definitions));
|
|
||||||
}
|
}
|
||||||
definitions.forEach(definition => this.registerHotkeys(definition));
|
definitions.forEach(definition => this.registerHotkeys(definition));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const { uiNotificationService, } = this._servicesManager.services;
|
const { uiNotificationService } = this._servicesManager.services;
|
||||||
uiNotificationService.show({
|
uiNotificationService.show({
|
||||||
title: 'Hotkeys Manager',
|
title: 'Hotkeys Manager',
|
||||||
message: 'Error while setting hotkeys',
|
message: 'Error while setting hotkeys',
|
||||||
|
|||||||
@ -315,7 +315,9 @@ handles creation of the displaySets.
|
|||||||
### Hotkeys
|
### Hotkeys
|
||||||
|
|
||||||
`hotkeys` is another property in the configuration of a mode that can be defined
|
`hotkeys` is another property in the configuration of a mode that can be defined
|
||||||
to add the specific hotkeys to the viewer at all routes.
|
to add the specific hotkeys to the viewer on the mode route. Additionally, the
|
||||||
|
name under which the hotkeys are stored can be configured as `hotkeyName`.
|
||||||
|
This allows user customization of the mode specific hotkeys.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// default hotkeys
|
// default hotkeys
|
||||||
@ -347,7 +349,13 @@ function modeFactory() {
|
|||||||
/*
|
/*
|
||||||
...
|
...
|
||||||
*/
|
*/
|
||||||
hotkeys: [..hotkeys.defaults.hotkeyBindings, ...myHotkeys],
|
hotkeys: {
|
||||||
|
// The name in preferences to use for this set of hotkeys
|
||||||
|
// Allows defining different sets for different modes
|
||||||
|
name: 'custom-hotkey-name',
|
||||||
|
// And the actual custom values here.
|
||||||
|
hotkeys:[..hotkeys.defaults.hotkeyBindings, ...myHotkeys]
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -114,7 +114,15 @@ export default function ModeRoute({
|
|||||||
hangingProtocolService,
|
hangingProtocolService,
|
||||||
} = (servicesManager as ServicesManager).services;
|
} = (servicesManager as ServicesManager).services;
|
||||||
|
|
||||||
const { extensions, sopClassHandlers, hotkeys, hangingProtocol } = mode;
|
const {
|
||||||
|
extensions,
|
||||||
|
sopClassHandlers,
|
||||||
|
hotkeys: hotkeyObj,
|
||||||
|
hangingProtocol,
|
||||||
|
} = mode;
|
||||||
|
// Preserve the old array interface for hotkeys
|
||||||
|
const hotkeys = Array.isArray(hotkeyObj) ? hotkeyObj : hotkeyObj?.hotkeys;
|
||||||
|
const hotkeyName = hotkeyObj?.name || 'hotkey-definitions-v2';
|
||||||
|
|
||||||
if (dataSourceName === undefined) {
|
if (dataSourceName === undefined) {
|
||||||
dataSourceName = extensionManager.defaultDataSourceName;
|
dataSourceName = extensionManager.defaultDataSourceName;
|
||||||
@ -204,14 +212,12 @@ export default function ModeRoute({
|
|||||||
|
|
||||||
hotkeysManager.setDefaultHotKeys(hotkeys);
|
hotkeysManager.setDefaultHotKeys(hotkeys);
|
||||||
|
|
||||||
const userPreferredHotkeys = JSON.parse(
|
const userPreferredHotkeys = JSON.parse(localStorage.getItem(hotkeyName));
|
||||||
localStorage.getItem('hotkey-definitions')
|
|
||||||
);
|
|
||||||
|
|
||||||
if (userPreferredHotkeys?.length) {
|
if (userPreferredHotkeys?.length) {
|
||||||
hotkeysManager.setHotkeys(userPreferredHotkeys);
|
hotkeysManager.setHotkeys(userPreferredHotkeys, hotkeyName);
|
||||||
} else {
|
} else {
|
||||||
hotkeysManager.setHotkeys(hotkeys);
|
hotkeysManager.setHotkeys(hotkeys, hotkeyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user