From fabe9818559cb7f8c1ef90c7cea266c8a9453e70 Mon Sep 17 00:00:00 2001 From: dannyrb Date: Fri, 31 May 2019 22:09:05 -0400 Subject: [PATCH] WIP hotkeys code --- .../ConnectedViewerMain.js | 21 +++++----- src/connectedComponents/ViewerMain.js | 33 +++++++++------- src/hotkeys/index.js | 38 +++++++++++++++++++ 3 files changed, 68 insertions(+), 24 deletions(-) create mode 100644 src/hotkeys/index.js diff --git a/src/connectedComponents/ConnectedViewerMain.js b/src/connectedComponents/ConnectedViewerMain.js index 69dc37260..c51e307f9 100644 --- a/src/connectedComponents/ConnectedViewerMain.js +++ b/src/connectedComponents/ConnectedViewerMain.js @@ -1,12 +1,12 @@ -import { connect } from 'react-redux'; -import ViewerMain from './ViewerMain'; import OHIF from 'ohif-core'; +import ViewerMain from './ViewerMain'; +import { connect } from 'react-redux'; const { setViewportSpecificData, clearViewportSpecificData, - setToolActive, - setActiveViewportSpecificData, + // setToolActive, + // setActiveViewportSpecificData, } = OHIF.redux.actions; const mapStateToProps = state => { @@ -16,6 +16,7 @@ const mapStateToProps = state => { activeViewportIndex, layout, viewportSpecificData, + viewports: state.viewports, }; }; @@ -27,12 +28,12 @@ const mapDispatchToProps = dispatch => { clearViewportSpecificData: () => { dispatch(clearViewportSpecificData()); }, - setToolActive: tool => { - dispatch(setToolActive(tool)); - }, - setActiveViewportSpecificData: viewport => { - dispatch(setActiveViewportSpecificData(viewport)); - }, + // setToolActive: tool => { + // dispatch(setToolActive(tool)); + // }, + // setActiveViewportSpecificData: viewport => { + // dispatch(setActiveViewportSpecificData(viewport)); + // }, }; }; diff --git a/src/connectedComponents/ViewerMain.js b/src/connectedComponents/ViewerMain.js index 01ebb9b91..7a76493b4 100644 --- a/src/connectedComponents/ViewerMain.js +++ b/src/connectedComponents/ViewerMain.js @@ -1,29 +1,32 @@ -import { Component } from 'react'; -import React from 'react'; -import PropTypes from 'prop-types'; -import { OHIF } from 'ohif-core'; -import ConnectedLayoutManager from './ConnectedLayoutManager.js'; import './ViewerMain.css'; +import { Component } from 'react'; +import ConnectedLayoutManager from './ConnectedLayoutManager.js'; +import { OHIF } from 'ohif-core'; +import PropTypes from 'prop-types'; +import React from 'react'; +import hotkeys from './../hotkeys.js'; + class ViewerMain extends Component { static propTypes = { - studies: PropTypes.array.isRequired, + activeViewportIndex: PropTypes.number.isRequired, + layout: PropTypes.object, + viewportSpecificData: PropTypes.object, setViewportSpecificData: PropTypes.func.isRequired, clearViewportSpecificData: PropTypes.func.isRequired, - setToolActive: PropTypes.func.isRequired, - setActiveViewportSpecificData: PropTypes.func.isRequired, }; constructor(props) { super(props); // Initialize hotkeys - new OHIF.HotkeysUtil('viewer', { - setViewportSpecificData: props.setViewportSpecificData, - clearViewportSpecificData: props.clearViewportSpecificData, - setToolActive: props.setToolActive, - setActiveViewportSpecificData: props.setActiveViewportSpecificData, - }); + // new OHIF.HotkeysUtil('viewer', { + // setViewportSpecificData: props.setViewportSpecificData, + // clearViewportSpecificData: props.clearViewportSpecificData, + // setToolActive: props.setToolActive, + // setActiveViewportSpecificData: props.setActiveViewportSpecificData, + // }); + hotkeys.init(); this.state = { displaySets: [], @@ -147,6 +150,8 @@ class ViewerMain extends Component { this.props.clearViewportSpecificData(viewportIndex); }); + hotkeys.clear(); + // Remove beforeUnload event handler... //window.removeEventListener('beforeunload', unloadHandlers.beforeUnload); // Destroy the synchronizer used to update reference lines diff --git a/src/hotkeys/index.js b/src/hotkeys/index.js new file mode 100644 index 000000000..31add2027 --- /dev/null +++ b/src/hotkeys/index.js @@ -0,0 +1,38 @@ +import { HotkeysManager } from 'ohif-core'; +import store from './store'; + +function initialize() { + // binding, method, + const numHotkeys = hotkeyConfig.length; + for (let i = 0; i < numHotkeys; i++) { + const { keys, actionName, actionContexts, options } = hotkeyConfig[i]; + const action = actions[actionName]; + + Mousetrap.bind(keys, () => { + let actionParams = options; + actionContexts.forEach(context => { + actionParams[context] = store.getState()[context]; + }); + action(actionParams); + }); + } + + const hotkeysPreferences = store.getState().preferences; + const hotkeysViewerContext = hotkeysPreferences.viewer; + const hotkeysData = hotkeysViewerContext.hotkeysData; + + Object.keys(hotkeysData).forEach(hotkeyName => { + // context, + const hotkeyCommandName = hotkeysData[hotkeyName]; + HotkeysManager.register(); + }); +} + +function clear() { + HotkeysManager.clear(); +} + +export default { + clear, + initialize, +};