Merge pull request #1827 from OHIF/feat/ohif-127-196
OHIF-127-196-191: Hotkeys config and defaults
This commit is contained in:
18 files changed
+260
-77
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import objectHash from 'object-hash';
|
||||
import hotkeys from './../utils/hotkeys';
|
||||
import log from './../log.js';
|
||||
|
||||
@@ -6,6 +7,7 @@ import log from './../log.js';
|
||||
*
|
||||
* @typedef {Object} HotkeyDefinition
|
||||
* @property {String} commandName - Command to call
|
||||
* @property {Object} commandOptions - Command options
|
||||
* @property {String} label - Display name for hotkey
|
||||
* @property {String[]} keys - Keys to bind; Follows Mousetrap.js binding syntax
|
||||
*/
|
||||
@@ -18,7 +20,7 @@ export class HotkeysManager {
|
||||
|
||||
if (!commandsManager) {
|
||||
log.warn(
|
||||
'HotkeysManager instantiated without a commandsManager. Hotkeys will be unable to find and run commands.'
|
||||
'[hotkeys] HotkeysManager instantiated without a commandsManager. Hotkeys will be unable to find and run commands.'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -141,28 +143,30 @@ export class HotkeysManager {
|
||||
* When a hotkey combination is triggered, the command name and active contexts
|
||||
* are used to locate the correct command to call.
|
||||
*
|
||||
* @param {HotkeyDefinition} commandName
|
||||
* @param {HotkeyDefinition} command
|
||||
* @param {String} extension
|
||||
* @returns {undefined}
|
||||
*/
|
||||
registerHotkeys({ commandName, keys, label } = {}, extension) {
|
||||
registerHotkeys({ commandName, commandOptions = {}, keys, label } = {}, extension) {
|
||||
if (!commandName) {
|
||||
log.warn(`No command was defined for hotkey "${keys}"`);
|
||||
log.warn(`[hotkeys] No command was defined for hotkey "${keys}"`);
|
||||
return;
|
||||
}
|
||||
|
||||
const previouslyRegisteredDefinition = this.hotkeyDefinitions[commandName];
|
||||
const commandHash = objectHash({ commandName, commandOptions });
|
||||
const options = Object.keys(commandOptions).length ? JSON.stringify(commandOptions) : 'no';
|
||||
const previouslyRegisteredDefinition = this.hotkeyDefinitions[commandHash];
|
||||
|
||||
if (previouslyRegisteredDefinition) {
|
||||
const previouslyRegisteredKeys = previouslyRegisteredDefinition.keys;
|
||||
this._unbindHotkeys(commandName, previouslyRegisteredKeys);
|
||||
log.info(`Unbinding ${commandName} from ${previouslyRegisteredKeys}`);
|
||||
log.info(`[hotkeys] Unbinding ${commandName} with ${options} options from ${previouslyRegisteredKeys}`);
|
||||
}
|
||||
|
||||
// Set definition & bind
|
||||
this.hotkeyDefinitions[commandName] = { keys, label };
|
||||
this._bindHotkeys(commandName, keys);
|
||||
log.info(`Binding ${commandName} to ${keys}`);
|
||||
this.hotkeyDefinitions[commandHash] = { keys, label };
|
||||
this._bindHotkeys(commandName, commandOptions, keys);
|
||||
log.info(`[hotkeys] Binding ${commandName} with ${options} options to ${keys}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +195,7 @@ export class HotkeysManager {
|
||||
* @param {string[]} keys - One or more key combinations that should trigger command
|
||||
* @returns {undefined}
|
||||
*/
|
||||
_bindHotkeys(commandName, keys) {
|
||||
_bindHotkeys(commandName, commandOptions = {}, keys) {
|
||||
const isKeyDefined = keys === '' || keys === undefined;
|
||||
if (isKeyDefined) {
|
||||
return;
|
||||
@@ -203,7 +207,7 @@ export class HotkeysManager {
|
||||
hotkeys.bind(combinedKeys, evt => {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
this._commandsManager.runCommand(commandName, { evt });
|
||||
this._commandsManager.runCommand(commandName, { evt, ...commandOptions });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import windowLevelPresets from "./windowLevelPresets";
|
||||
|
||||
/*
|
||||
* Supported Keys: https://craig.is/killing/mice
|
||||
*/
|
||||
export default [
|
||||
/** Global */
|
||||
{
|
||||
commandName: 'incrementActiveViewport',
|
||||
label: 'Next Viewport',
|
||||
keys: ['right'],
|
||||
},
|
||||
{
|
||||
commandName: 'decrementActiveViewport',
|
||||
label: 'Previous Viewport',
|
||||
keys: ['left'],
|
||||
},
|
||||
/** Viewport */
|
||||
{ commandName: 'rotateViewportCW', label: 'Rotate Right', keys: ['r'] },
|
||||
{ commandName: 'rotateViewportCCW', label: 'Rotate Left', keys: ['l'] },
|
||||
{ commandName: 'invertViewport', label: 'Invert', keys: ['i'] },
|
||||
{
|
||||
commandName: 'flipViewportVertical',
|
||||
label: 'Flip Horizontally',
|
||||
keys: ['h'],
|
||||
},
|
||||
{
|
||||
commandName: 'flipViewportHorizontal',
|
||||
label: 'Flip Vertically',
|
||||
keys: ['v'],
|
||||
},
|
||||
{ commandName: 'scaleUpViewport', label: 'Zoom In', keys: ['+'] },
|
||||
{ commandName: 'scaleDownViewport', label: 'Zoom Out', keys: ['-'] },
|
||||
{ commandName: 'fitViewportToWindow', label: 'Zoom to Fit', keys: ['='] },
|
||||
{ commandName: 'resetViewport', label: 'Reset', keys: ['space'] },
|
||||
{ commandName: 'nextImage', label: 'Next Image', keys: ['down'] },
|
||||
{ commandName: 'previousImage', label: 'Previous Image', keys: ['up'] },
|
||||
{
|
||||
commandName: 'previousViewportDisplaySet',
|
||||
label: 'Previous Series',
|
||||
keys: ['pagedown'],
|
||||
},
|
||||
{
|
||||
commandName: 'nextViewportDisplaySet',
|
||||
label: 'Next Series',
|
||||
keys: ['pageup'],
|
||||
},
|
||||
/** Window level presets */
|
||||
{
|
||||
commandName: 'setWindowLevel',
|
||||
commandOptions: windowLevelPresets[1],
|
||||
label: 'W/L Preset 1',
|
||||
keys: ['1'],
|
||||
},
|
||||
{
|
||||
commandName: 'setWindowLevel',
|
||||
commandOptions: windowLevelPresets[2],
|
||||
label: 'W/L Preset 2',
|
||||
keys: ['2'],
|
||||
},
|
||||
{
|
||||
commandName: 'setWindowLevel',
|
||||
commandOptions: windowLevelPresets[3],
|
||||
label: 'W/L Preset 3',
|
||||
keys: ['3'],
|
||||
},
|
||||
{
|
||||
commandName: 'setWindowLevel',
|
||||
commandOptions: windowLevelPresets[4],
|
||||
label: 'W/L Preset 4',
|
||||
keys: ['4'],
|
||||
},
|
||||
{
|
||||
commandName: 'setWindowLevel',
|
||||
commandOptions: windowLevelPresets[5],
|
||||
label: 'W/L Preset 5',
|
||||
keys: ['5'],
|
||||
},
|
||||
{
|
||||
commandName: 'setWindowLevel',
|
||||
commandOptions: windowLevelPresets[6],
|
||||
label: 'W/L Preset 6',
|
||||
keys: ['6'],
|
||||
},
|
||||
{
|
||||
commandName: 'setWindowLevel',
|
||||
commandOptions: windowLevelPresets[7],
|
||||
label: 'W/L Preset 7',
|
||||
keys: ['7'],
|
||||
},
|
||||
{
|
||||
commandName: 'setWindowLevel',
|
||||
commandOptions: windowLevelPresets[8],
|
||||
label: 'W/L Preset 8',
|
||||
keys: ['8'],
|
||||
},
|
||||
{
|
||||
commandName: 'setWindowLevel',
|
||||
commandOptions: windowLevelPresets[9],
|
||||
label: 'W/L Preset 9',
|
||||
keys: ['9'],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,4 @@
|
||||
import hotkeyBindings from './hotkeyBindings';
|
||||
import windowLevelPresets from './windowLevelPresets';
|
||||
export { hotkeyBindings, windowLevelPresets };
|
||||
export default { hotkeyBindings, windowLevelPresets };
|
||||
@@ -0,0 +1,12 @@
|
||||
export default {
|
||||
1: { description: 'Soft tissue', window: '400', level: '40' },
|
||||
2: { description: 'Lung', window: '1500', level: '-600' },
|
||||
3: { description: 'Liver', window: '150', level: '90' },
|
||||
4: { description: 'Bone', window: '2500', level: '480' },
|
||||
5: { description: 'Brain', window: '80', level: '40' },
|
||||
6: { description: 'Trest', window: '1', level: '1' },
|
||||
7: { description: '', window: '', level: '' },
|
||||
8: { description: '', window: '', level: '' },
|
||||
9: { description: '', window: '', level: '' },
|
||||
10: { description: '', window: '', level: '' },
|
||||
};
|
||||
@@ -20,7 +20,8 @@ import studies from './studies/';
|
||||
import ui from './ui';
|
||||
import user from './user.js';
|
||||
import { ViewModelProvider, useViewModel } from './ViewModelContext';
|
||||
import utils, { hotkeys } from './utils/';
|
||||
import utils from './utils/';
|
||||
import defaults from './defaults';
|
||||
|
||||
import {
|
||||
UIDialogService,
|
||||
@@ -37,6 +38,11 @@ import {
|
||||
|
||||
import IWebApiDataSource from './DataSources/IWebApiDataSource';
|
||||
|
||||
const hotkeys = {
|
||||
...utils.hotkeys,
|
||||
defaults: { hotkeyBindings: defaults.hotkeyBindings }
|
||||
};
|
||||
|
||||
const OHIF = {
|
||||
MODULE_TYPES,
|
||||
//
|
||||
@@ -45,6 +51,7 @@ const OHIF = {
|
||||
HotkeysManager,
|
||||
ServicesManager,
|
||||
//
|
||||
defaults,
|
||||
utils,
|
||||
hotkeys,
|
||||
studies,
|
||||
@@ -88,6 +95,7 @@ export {
|
||||
HotkeysManager,
|
||||
ServicesManager,
|
||||
//
|
||||
defaults,
|
||||
utils,
|
||||
hotkeys,
|
||||
studies,
|
||||
|
||||
@@ -15,6 +15,7 @@ describe('Top level exports', () => {
|
||||
'UIDialogService',
|
||||
'MeasurementService',
|
||||
//
|
||||
'defaults',
|
||||
'utils',
|
||||
'hotkeys',
|
||||
'studies',
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
import { windowLevelPresets } from '../../defaults';
|
||||
|
||||
const defaultState = {
|
||||
windowLevelData: {
|
||||
1: { description: 'Soft tissue', window: '550', level: '40' },
|
||||
2: { description: 'Lung', window: '150', level: '-600' },
|
||||
3: { description: 'Liver', window: '150', level: '90' },
|
||||
4: { description: 'Bone', window: '2500', level: '480' },
|
||||
5: { description: 'Brain', window: '80', level: '40' },
|
||||
6: { description: 'Trest', window: '1', level: '1' },
|
||||
7: { description: '', window: '', level: '' },
|
||||
8: { description: '', window: '', level: '' },
|
||||
9: { description: '', window: '', level: '' },
|
||||
10: { description: '', window: '', level: '' },
|
||||
},
|
||||
windowLevelData: windowLevelPresets,
|
||||
generalPreferences: {
|
||||
// language: 'en-US'
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user