feat(toolbar/hokeys): add pub sub events to hotkeys manager class, subscribe toolbar to hotkeys pressed event (#5157)

This commit is contained in:
Ibrahim 2025-06-25 10:43:27 -04:00 committed by GitHub
parent b1ad3787e4
commit 57f07ad9f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 1 deletions

View File

@ -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);

View File

@ -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,
});
});
}