feat(toolbar/hokeys): add pub sub events to hotkeys manager class, subscribe toolbar to hotkeys pressed event (#5157)
This commit is contained in:
parent
b1ad3787e4
commit
57f07ad9f2
@ -3,6 +3,7 @@ import { calculateSUVScalingFactors } from '@cornerstonejs/calculate-suv';
|
||||
|
||||
import getPTImageIdInstanceMetadata from './getPTImageIdInstanceMetadata';
|
||||
import { registerHangingProtocolAttributes } from './hangingprotocols';
|
||||
import { HotkeysManager } from '@ohif/core'
|
||||
|
||||
const metadataProvider = classes.MetadataProvider;
|
||||
|
||||
@ -11,13 +12,17 @@ const metadataProvider = classes.MetadataProvider;
|
||||
* @param {Object} servicesManager
|
||||
* @param {Object} configuration
|
||||
*/
|
||||
export default function init({ servicesManager, commandsManager }: withAppTypes): void {
|
||||
export default function init({ servicesManager, commandsManager, hotkeysManager }: withAppTypes): void {
|
||||
const { toolbarService, cineService, viewportGridService } = servicesManager.services;
|
||||
|
||||
toolbarService.registerEventForToolbarUpdate(cineService, [
|
||||
cineService.EVENTS.CINE_STATE_CHANGED,
|
||||
]);
|
||||
|
||||
toolbarService.registerEventForToolbarUpdate(hotkeysManager, [
|
||||
HotkeysManager.EVENTS.HOTKEY_PRESSED,
|
||||
]);
|
||||
|
||||
// Add
|
||||
DicomMetadataStore.subscribe(DicomMetadataStore.EVENTS.INSTANCES_ADDED, handleScalingModules);
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ import objectHash from 'object-hash';
|
||||
import { hotkeys as mouseTrapAPI } from '../utils';
|
||||
import Hotkey from './Hotkey';
|
||||
import migrateOldHotkeyDefinitions from '../utils/hotkeys/migrateHotkeys';
|
||||
import pubSubServiceInterface from '../services/_shared/pubSubServiceInterface';
|
||||
|
||||
/**
|
||||
*
|
||||
@ -19,6 +20,16 @@ export class HotkeysManager {
|
||||
public hotkeyDefinitions: Record<string, any> = {};
|
||||
public hotkeyDefaults: any[] = [];
|
||||
|
||||
public static EVENTS: Record<string, string> = {
|
||||
HOTKEY_PRESSED: 'event::hotkeysManager:hotkeyPressed',
|
||||
};
|
||||
public EVENTS: Record<string, string>;
|
||||
public listeners: Record<string, Array<{ id: string; callback: (data: unknown) => void }> | undefined> = {};
|
||||
public subscribe: (eventName: string, callback: (data: unknown) => void) => { unsubscribe: () => void };
|
||||
public _broadcastEvent: (eventName: string, callbackProps: unknown) => void;
|
||||
public _unsubscribe: (eventName: string, listenerId: string) => void;
|
||||
public _isValidEvent: (eventName: string) => boolean;
|
||||
|
||||
constructor(
|
||||
commandsManager: AppTypes.CommandsManager,
|
||||
servicesManager: AppTypes.ServicesManager
|
||||
@ -26,6 +37,12 @@ export class HotkeysManager {
|
||||
this._servicesManager = servicesManager;
|
||||
this._commandsManager = commandsManager;
|
||||
|
||||
this.EVENTS = HotkeysManager.EVENTS;
|
||||
this.subscribe = pubSubServiceInterface.subscribe.bind(this);
|
||||
this._broadcastEvent = pubSubServiceInterface._broadcastEvent.bind(this);
|
||||
this._unsubscribe = pubSubServiceInterface._unsubscribe.bind(this);
|
||||
this._isValidEvent = pubSubServiceInterface._isValidEvent.bind(this);
|
||||
|
||||
// Check for old hotkey definitions format and migrate if needed
|
||||
migrateOldHotkeyDefinitions({
|
||||
generateHash: this.generateHash,
|
||||
@ -264,6 +281,13 @@ export class HotkeysManager {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
this._commandsManager.runCommand(commandName, { evt, ...commandOptions }, context);
|
||||
this._broadcastEvent(HotkeysManager.EVENTS.HOTKEY_PRESSED, {
|
||||
commandName,
|
||||
commandOptions,
|
||||
keys: combinedKeys,
|
||||
context,
|
||||
evt,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user