Playing with a hotkeys + commands setup and config

This commit is contained in:
dannyrb 2019-06-02 15:44:27 -04:00
parent d29f996e61
commit b0706e5544
2 changed files with 43 additions and 32 deletions

View File

@ -23,8 +23,19 @@ import WhiteLabellingContext from './WhiteLabellingContext';
import setupTools from './setupTools'; import setupTools from './setupTools';
import store from './store'; import store from './store';
// Register all of our commands and hotkeys
import commands from './commands';
const { ExtensionManager } = OHIF.extensions; const { ExtensionManager } = OHIF.extensions;
commands.init();
// window.config.userPreferences
Object.keys(window.config.hotkeys).forEach(commandName => {
const keys = window.config.hotkeys[commandName];
// OHIF.HotkeysManager.set();
OHIF.HotkeysManager.registerHotkeys(commandName, keys);
});
setupTools(store); setupTools(store);
const children = { const children = {

View File

@ -1,38 +1,38 @@
import { HotkeysManager } from 'ohif-core'; // import { HotkeysManager } from 'ohif-core';
import store from './store'; // import store from './store';
function initialize() { // function initialize() {
// binding, method, // // binding, method,
const numHotkeys = hotkeyConfig.length; // const numHotkeys = hotkeyConfig.length;
for (let i = 0; i < numHotkeys; i++) { // for (let i = 0; i < numHotkeys; i++) {
const { keys, actionName, actionContexts, options } = hotkeyConfig[i]; // const { keys, actionName, actionContexts, options } = hotkeyConfig[i];
const action = actions[actionName]; // const action = actions[actionName];
Mousetrap.bind(keys, () => { // Mousetrap.bind(keys, () => {
let actionParams = options; // let actionParams = options;
actionContexts.forEach(context => { // actionContexts.forEach(context => {
actionParams[context] = store.getState()[context]; // actionParams[context] = store.getState()[context];
}); // });
action(actionParams); // action(actionParams);
}); // });
} // }
const hotkeysPreferences = store.getState().preferences; // const hotkeysPreferences = store.getState().preferences;
const hotkeysViewerContext = hotkeysPreferences.viewer; // const hotkeysViewerContext = hotkeysPreferences.viewer;
const hotkeysData = hotkeysViewerContext.hotkeysData; // const hotkeysData = hotkeysViewerContext.hotkeysData;
Object.keys(hotkeysData).forEach(hotkeyName => { // Object.keys(hotkeysData).forEach(hotkeyName => {
// context, // // context,
const hotkeyCommandName = hotkeysData[hotkeyName]; // const hotkeyCommandName = hotkeysData[hotkeyName];
HotkeysManager.register(); // HotkeysManager.register();
}); // });
} // }
function clear() { // function clear() {
HotkeysManager.clear(); // HotkeysManager.clear();
} // }
export default { // export default {
clear, // clear,
initialize, // initialize,
}; // };