WIP hotkeys code

This commit is contained in:
dannyrb 2019-05-31 22:09:05 -04:00
parent d9e45261f3
commit fabe981855
3 changed files with 68 additions and 24 deletions

View File

@ -1,12 +1,12 @@
import { connect } from 'react-redux';
import ViewerMain from './ViewerMain';
import OHIF from 'ohif-core'; import OHIF from 'ohif-core';
import ViewerMain from './ViewerMain';
import { connect } from 'react-redux';
const { const {
setViewportSpecificData, setViewportSpecificData,
clearViewportSpecificData, clearViewportSpecificData,
setToolActive, // setToolActive,
setActiveViewportSpecificData, // setActiveViewportSpecificData,
} = OHIF.redux.actions; } = OHIF.redux.actions;
const mapStateToProps = state => { const mapStateToProps = state => {
@ -16,6 +16,7 @@ const mapStateToProps = state => {
activeViewportIndex, activeViewportIndex,
layout, layout,
viewportSpecificData, viewportSpecificData,
viewports: state.viewports,
}; };
}; };
@ -27,12 +28,12 @@ const mapDispatchToProps = dispatch => {
clearViewportSpecificData: () => { clearViewportSpecificData: () => {
dispatch(clearViewportSpecificData()); dispatch(clearViewportSpecificData());
}, },
setToolActive: tool => { // setToolActive: tool => {
dispatch(setToolActive(tool)); // dispatch(setToolActive(tool));
}, // },
setActiveViewportSpecificData: viewport => { // setActiveViewportSpecificData: viewport => {
dispatch(setActiveViewportSpecificData(viewport)); // dispatch(setActiveViewportSpecificData(viewport));
}, // },
}; };
}; };

View File

@ -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 './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 { class ViewerMain extends Component {
static propTypes = { static propTypes = {
studies: PropTypes.array.isRequired, activeViewportIndex: PropTypes.number.isRequired,
layout: PropTypes.object,
viewportSpecificData: PropTypes.object,
setViewportSpecificData: PropTypes.func.isRequired, setViewportSpecificData: PropTypes.func.isRequired,
clearViewportSpecificData: PropTypes.func.isRequired, clearViewportSpecificData: PropTypes.func.isRequired,
setToolActive: PropTypes.func.isRequired,
setActiveViewportSpecificData: PropTypes.func.isRequired,
}; };
constructor(props) { constructor(props) {
super(props); super(props);
// Initialize hotkeys // Initialize hotkeys
new OHIF.HotkeysUtil('viewer', { // new OHIF.HotkeysUtil('viewer', {
setViewportSpecificData: props.setViewportSpecificData, // setViewportSpecificData: props.setViewportSpecificData,
clearViewportSpecificData: props.clearViewportSpecificData, // clearViewportSpecificData: props.clearViewportSpecificData,
setToolActive: props.setToolActive, // setToolActive: props.setToolActive,
setActiveViewportSpecificData: props.setActiveViewportSpecificData, // setActiveViewportSpecificData: props.setActiveViewportSpecificData,
}); // });
hotkeys.init();
this.state = { this.state = {
displaySets: [], displaySets: [],
@ -147,6 +150,8 @@ class ViewerMain extends Component {
this.props.clearViewportSpecificData(viewportIndex); this.props.clearViewportSpecificData(viewportIndex);
}); });
hotkeys.clear();
// Remove beforeUnload event handler... // Remove beforeUnload event handler...
//window.removeEventListener('beforeunload', unloadHandlers.beforeUnload); //window.removeEventListener('beforeunload', unloadHandlers.beforeUnload);
// Destroy the synchronizer used to update reference lines // Destroy the synchronizer used to update reference lines

38
src/hotkeys/index.js Normal file
View File

@ -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,
};