WIP hotkeys code
This commit is contained in:
parent
d9e45261f3
commit
fabe981855
@ -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));
|
||||
// },
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
38
src/hotkeys/index.js
Normal file
38
src/hotkeys/index.js
Normal 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,
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user