Skip to content

Commit

Permalink
Switched to using 'cornerstoneViewportClickCommands' and consistency …
Browse files Browse the repository at this point in the history
…with the context menu clicks.
  • Loading branch information
jbocce committed Mar 29, 2023
1 parent f98eb20 commit 2c0fac0
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions extensions/cornerstone/src/initDoubleClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,29 @@ import { findNearbyToolData } from './utils/findNearbyToolData';

const cs3DToolsEvents = Enums.Events;

const DEFAULT_DOUBLE_CLICK_COMMAND: Types.Command = {
commandName: 'toggleOneUp',
commandOptions: {},
const DEFAULT_DOUBLE_CLICK = {
doubleClick: {
commandName: 'toggleOneUp',
commandOptions: {},
},
};

/**
* Generates a double click event name, consisting of:
* * alt when the alt key is down
* * ctrl when the cctrl key is down
* * shift when the shift key is down
* * 'doubleClick'
*/
function getDoubleClickEventName(evt: CustomEvent) {
const nameArr = [];
if (evt.detail.event.altKey) nameArr.push('alt');
if (evt.detail.event.ctrlKey) nameArr.push('ctrl');
if (evt.detail.event.shiftKey) nameArr.push('shift');
nameArr.push('doubleClick');
return nameArr.join('');
}

export type initDoubleClickArgs = {
customizationService: CustomizationService;
commandsManager: CommandsManager;
Expand All @@ -26,13 +44,20 @@ function initDoubleClick({
return;
}

const eventName = getDoubleClickEventName(evt);

// Allows for the customization of the double click on a viewport.
const customizations: Types.Command | Types.CommandCustomization =
(customizationService.get(
'cornerstoneViewportDoubleClickCommands'
) as Types.CommandCustomization) || DEFAULT_DOUBLE_CLICK_COMMAND;
const customizations =
customizationService.get('cornerstoneViewportClickCommands') ||
DEFAULT_DOUBLE_CLICK;

const toRun = customizations[eventName];

if (!toRun) {
return;
}

commandsManager.run(customizations);
commandsManager.run(toRun);
};

function elementEnabledHandler(evt: CustomEvent) {
Expand Down

0 comments on commit 2c0fac0

Please sign in to comment.