Registering tool commands
This commit is contained in:
parent
dbbcbe6e67
commit
fa7ad2c51e
@ -8,6 +8,7 @@
|
||||
ohif:polyfill
|
||||
ohif:design
|
||||
ohif:core
|
||||
ohif:commands
|
||||
ohif:hotkeys
|
||||
ohif:header
|
||||
ohif:cornerstone
|
||||
|
||||
@ -72,6 +72,7 @@ mongo-id@1.0.6
|
||||
natestrauser:select2@4.0.3
|
||||
npm-mongo@2.2.11_2
|
||||
observe-sequence@1.0.14
|
||||
ohif:commands@0.0.1
|
||||
ohif:core@0.0.1
|
||||
ohif:cornerstone@0.0.1
|
||||
ohif:design@0.0.1
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { ReactiveDict } from 'meteor/reactive-dict';
|
||||
import { Tracker } from 'meteor/tracker';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
export class CommandsManager {
|
||||
@ -16,22 +16,28 @@ export class CommandsManager {
|
||||
getContext(contextName) {
|
||||
const context = this.contexts[contextName];
|
||||
if (!context) {
|
||||
OHIF.log.warn(`No context found with name "${contextName}"`);
|
||||
return OHIF.log.warn(`No context found with name "${contextName}"`);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
getCurrentContext(contextName) {
|
||||
return this.getContext(OHIF.context.get());
|
||||
getCurrentContext() {
|
||||
const contextName = OHIF.context.get();
|
||||
if (!contextName) {
|
||||
return OHIF.log.warn('There is no selected context');
|
||||
}
|
||||
|
||||
return this.getContext(contextName);
|
||||
}
|
||||
|
||||
createContext(contextName) {
|
||||
if (!contextName) return;
|
||||
if (this.contexts[contextName]) {
|
||||
return this.unsetCommands(contextName);
|
||||
}
|
||||
|
||||
this.contexts[contextName] = new ReactiveDict();
|
||||
this.contexts[contextName] = {};
|
||||
}
|
||||
|
||||
setCommands(contextName, definitions) {
|
||||
@ -40,21 +46,36 @@ export class CommandsManager {
|
||||
if (!context) return;
|
||||
|
||||
this.unsetCommands(contextName);
|
||||
Object.keys(definitions).forEach(key => context.set(key, definitions[key]));
|
||||
Object.keys(definitions).forEach(command => (context[command] = definitions[command]));
|
||||
}
|
||||
|
||||
registerCommand(contextName, key, definition) {
|
||||
registerCommand(contextName, command, definition) {
|
||||
if (typeof definition !== 'object') return;
|
||||
const context = this.getContext(contextName);
|
||||
if (!context) return;
|
||||
|
||||
context.set(key, definition);
|
||||
context[command] = definition;
|
||||
}
|
||||
|
||||
unsetCommands(contextName) {
|
||||
const context = this.getContext(contextName);
|
||||
if (!context) return;
|
||||
if (!contextName) return;
|
||||
this.contexts[contextName] = {};
|
||||
}
|
||||
|
||||
context.clear();
|
||||
run(command) {
|
||||
const context = this.getCurrentContext();
|
||||
if (!context) return;
|
||||
const definition = context[command];
|
||||
if (!definition) {
|
||||
return OHIF.log.warn(`Command "${command}" not found in current context`);
|
||||
}
|
||||
|
||||
const { action, disabled, params } = definition;
|
||||
if ((_.isFunction(disabled) && disabled()) || (!_.isUndefined(disabled) && disabled)) return;
|
||||
if (typeof action !== 'function') {
|
||||
return OHIF.log.warn(`No action was defined for command "${command}"`);
|
||||
} else {
|
||||
return action(params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,11 +5,14 @@ import { CommandsManager } from 'meteor/ohif:commands/client/classes/CommandsMan
|
||||
// Create context namespace using a ReactiveVar
|
||||
const context = new ReactiveVar(null);
|
||||
|
||||
// Create commands namespace using a CommandsManager class instance
|
||||
const commands = new CommandsManager(context);
|
||||
|
||||
// Append context namespace to OHIF namespace
|
||||
OHIF.context = context;
|
||||
|
||||
// Create commands namespace using a CommandsManager class instance
|
||||
const commands = new CommandsManager(context);
|
||||
|
||||
// Append commands namespace to OHIF namespace
|
||||
OHIF.commands = commands;
|
||||
|
||||
// Export relevant objects
|
||||
export { context, commands };
|
||||
|
||||
@ -10,12 +10,12 @@ Package.onUse(function(api) {
|
||||
// Meteor packages
|
||||
api.use([
|
||||
'ecmascript',
|
||||
'reactive-var',
|
||||
'reactive-dict'
|
||||
'reactive-var'
|
||||
]);
|
||||
|
||||
// OHIF dependencies
|
||||
api.use('ohif:core');
|
||||
api.use('ohif:log');
|
||||
|
||||
// Main module definition
|
||||
api.mainModule('main.js', 'client');
|
||||
|
||||
@ -17,6 +17,7 @@ Package.onUse(function(api) {
|
||||
|
||||
// OHIF dependencies
|
||||
api.use('ohif:core');
|
||||
api.use('ohif:commands');
|
||||
|
||||
// Main module definition
|
||||
api.mainModule('main.js', 'client');
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { $ } from 'meteor/jquery';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { toolManager } from './toolManager';
|
||||
import { switchToImageRelative } from './switchToImageRelative';
|
||||
@ -50,6 +51,33 @@ Meteor.startup(function() {
|
||||
// For now
|
||||
OHIF.viewer.hotkeys = OHIF.viewer.defaultHotkeys;
|
||||
|
||||
const contextName = 'viewer';
|
||||
OHIF.commands.createContext(contextName);
|
||||
const registerToolCommand = (commandName, toolId) => {
|
||||
OHIF.commands.registerCommand(contextName, toolId, {
|
||||
name: commandName,
|
||||
action: toolManager.setActiveTool,
|
||||
params: toolId
|
||||
});
|
||||
};
|
||||
|
||||
const registerToolCommands = map => _.each(map, registerToolCommand);
|
||||
|
||||
registerToolCommands({
|
||||
wwwc: 'Levels',
|
||||
zoom: 'Zoom',
|
||||
angle: 'Angle',
|
||||
dragProbe: 'Probe',
|
||||
ellipticalRoi: 'Ellipse',
|
||||
magnify: 'Magnify',
|
||||
annotate: 'Annotate',
|
||||
stackScroll: 'Stack Scroll',
|
||||
pan: 'Pan',
|
||||
length: 'Length',
|
||||
spine: 'Spine',
|
||||
wwwcRegion: 'ROI Window'
|
||||
});
|
||||
|
||||
OHIF.viewer.hotkeyFunctions = {
|
||||
wwwc: () => toolManager.setActiveTool('wwwc'),
|
||||
zoom: () => toolManager.setActiveTool('zoom'),
|
||||
@ -256,6 +284,7 @@ function enableHotkeys(hotkeys) {
|
||||
|
||||
OHIF.hotkeys.setContext('viewer', definitions);
|
||||
OHIF.hotkeys.switchToContext('viewer');
|
||||
OHIF.context.set('viewer');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user