Adding inputs to define hotkeys
This commit is contained in:
1 parent
bbb1cf0789
commit
20f274962b
8 files changed
+160
-74
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Template } from 'meteor/templating';
|
||||
import { $ } from 'meteor/jquery';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
Template.hotkeysForm.onCreated(() => {
|
||||
const instance = Template.instance();
|
||||
@@ -38,6 +40,19 @@ Template.hotkeysForm.onCreated(() => {
|
||||
|
||||
return keysPressedArray;
|
||||
};
|
||||
|
||||
instance.disallowedCombinations = {
|
||||
'': [],
|
||||
ALT: ['SPACE'],
|
||||
SHIFT: [],
|
||||
CTRL: ['F4', 'F5', 'F11', 'W', 'R', 'T', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'PAGEDOWN', 'PAGEUP'],
|
||||
'CTRL+SHIFT': ['Q', 'W', 'R', 'T', 'P', 'A', 'H', 'V', 'B', 'N']
|
||||
};
|
||||
});
|
||||
|
||||
// >>>> REMOVE ME
|
||||
Meteor.startup(() => {
|
||||
OHIF.ui.showDialog('hotkeysDialog', { contextName: 'viewer' });
|
||||
});
|
||||
|
||||
Template.hotkeysForm.events({
|
||||
@@ -52,7 +67,47 @@ Template.hotkeysForm.events({
|
||||
event.preventDefault();
|
||||
},
|
||||
|
||||
'blur .hotkey'(event, instance) {
|
||||
const $target = $(event.currentTarget);
|
||||
const combination = $target.val();
|
||||
const keys = combination.split('+');
|
||||
const lastKey = keys.pop();
|
||||
const modifierCombination = keys.join('+');
|
||||
const isModifier = ['CTRL', 'ALT', 'SHIFT'].indexOf(lastKey) > -1;
|
||||
// Clean the input if left with only a modifier key or browser specific command
|
||||
if (isModifier) {
|
||||
$target.val('');
|
||||
} else if (instance.disallowedCombinations[modifierCombination].indexOf(lastKey) > -1) {
|
||||
$target.val('');
|
||||
// TODO: show warning
|
||||
$target.focus();
|
||||
}
|
||||
},
|
||||
|
||||
'keyup .hotkey'(event, instance) {
|
||||
instance.updateInputText(event);
|
||||
}
|
||||
});
|
||||
|
||||
Template.hotkeysForm.helpers({
|
||||
getHotkeyInputInformationList() {
|
||||
OHIF.context.dep.depend();
|
||||
const instance = Template.instance();
|
||||
const { contextName } = instance.data;
|
||||
const hotkeysInputInformation = [];
|
||||
const hotkeysContext = OHIF.hotkeys.getContext(contextName);
|
||||
const commandsContext = OHIF.commands.getContext(contextName);
|
||||
if (!hotkeysContext || !commandsContext) return hotkeysInputInformation;
|
||||
const hotkeyDefinitions = hotkeysContext.definitions;
|
||||
_.each(hotkeyDefinitions, (keyCombination, commandName) => {
|
||||
const commandDefinitions = commandsContext[commandName];
|
||||
if (!commandDefinitions) return;
|
||||
hotkeysInputInformation.push({
|
||||
key: commandName,
|
||||
label: commandDefinitions.name,
|
||||
value: keyCombination
|
||||
});
|
||||
});
|
||||
return hotkeysInputInformation;
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user