Integrating hotkeys with commands

This commit is contained in:
Bruno Alves de Faria authored and Erik Ziegler committed 2017-06-14 09:19:49 +02:00
1 parent 199115a9d3
commit 1a0729336b
7 files changed
+102 -89

No files matched your search

@@ -1,4 +1,6 @@
import { ReactiveVar } from 'meteor/reactive-var';
import { Tracker } from 'meteor/tracker';
import { OHIF } from 'meteor/ohif:core';
import { HotkeysContext } from 'meteor/ohif:hotkeys/client/classes/HotkeysContext';
export class HotkeysManager {
@@ -6,6 +8,11 @@ export class HotkeysManager {
this.contexts = {};
this.currentContextName = null;
this.enabled = new ReactiveVar(true);
Tracker.autorun(() => {
const contextName = OHIF.context.get();
this.switchToContext(contextName);
});
}
disable() {
@@ -24,7 +31,7 @@ export class HotkeysManager {
return this.getContext(this.currentContextName);
}
setContext(contextName, contextDefinitions) {
set(contextName, contextDefinitions, extend=false) {
const enabled = this.enabled;
const context = new HotkeysContext(contextName, contextDefinitions, enabled);
const currentContext = this.getCurrentContext();
@@ -36,6 +43,16 @@ export class HotkeysManager {
this.contexts[contextName] = context;
}
register(contextName, command, hotkey) {
if (!command || !hotkey) return;
const context = this.getContext(contextName);
if (!context) {
this.set(contextName, {});
}
context.register(command, hotkey);
}
unsetContext(contextName) {
if (contextName === this.currentContextName) {
this.getCurrentContext().destroy();