From c6a267bdcb70c1d1ec6bb68dab718fe7a518171c Mon Sep 17 00:00:00 2001 From: Adithyan Dinesh Date: Mon, 19 Aug 2024 17:41:41 +0530 Subject: [PATCH 1/2] Support bindings when setting tool passive and keeping it passive if all bindings are for primary button --- common/reviews/api/tools.api.md | 1 + .../src/store/ToolGroupManager/ToolGroup.ts | 26 +++++++++++++++---- packages/tools/src/types/IToolGroup.ts | 5 +++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/common/reviews/api/tools.api.md b/common/reviews/api/tools.api.md index fb22d86bd3..4e16551a93 100644 --- a/common/reviews/api/tools.api.md +++ b/common/reviews/api/tools.api.md @@ -5832,6 +5832,7 @@ class ToolGroup implements ToolGroup { // (undocumented) setToolPassive(toolName: string, options?: { removeAllBindings?: boolean | IToolBinding[]; + bindings?: IToolBinding[] }): void; // (undocumented) setViewportsCursorByToolName(toolName: string, strategyName?: string): void; diff --git a/packages/tools/src/store/ToolGroupManager/ToolGroup.ts b/packages/tools/src/store/ToolGroupManager/ToolGroup.ts index c17cff4321..64c5809fdd 100644 --- a/packages/tools/src/store/ToolGroupManager/ToolGroup.ts +++ b/packages/tools/src/store/ToolGroupManager/ToolGroup.ts @@ -324,7 +324,10 @@ export default class ToolGroup implements IToolGroup { } if (mode === ToolModes.Passive) { - this.setToolPassive(toolName); + this.setToolPassive( + toolName, + options || this.restoreToolOptions[toolName] + ); return; } @@ -462,10 +465,14 @@ export default class ToolGroup implements IToolGroup { * @param options - Options used when setting the tool as passive * - removeAllBindings: only the primary button bindings are removed but * if this parameter is set to true all bindings are removed. + * - bindings: Set additional bindings. */ public setToolPassive( toolName: string, - options?: { removeAllBindings?: boolean | IToolBinding[] } + options?: { + removeAllBindings?: boolean | IToolBinding[]; + bindings?: IToolBinding[]; + } ): void { const toolInstance = this._toolInstances[toolName]; @@ -482,7 +489,7 @@ export default class ToolGroup implements IToolGroup { const prevToolOptions = this.getToolOptions(toolName); const toolOptions = Object.assign( { - bindings: prevToolOptions ? prevToolOptions.bindings : [], + bindings: options?.bindings || prevToolOptions?.bindings || [], }, prevToolOptions, { @@ -503,9 +510,18 @@ export default class ToolGroup implements IToolGroup { ) //(binding.mouseButton !== defaultMousePrimary || binding.modifierKey) ); - // If there are other bindings, set the tool to be active + // If there are other bindings, set the tool to be active. + // But if all bindings are for primary button, keep the binding passive. This + // can be used to keep extra primary mouse button + key combinations for a tool + // to each exhibit different behaviour of the same tool. let mode = Passive; - if (toolOptions.bindings.length !== 0) { + const primaryButton = this.getDefaultMousePrimary(); + if ( + toolOptions.bindings.length !== 0 && + toolOptions.bindings.some( + (binding) => binding.mouseButton !== primaryButton + ) + ) { mode = Active; toolOptions.mode = mode; } diff --git a/packages/tools/src/types/IToolGroup.ts b/packages/tools/src/types/IToolGroup.ts index 4fe9250092..1531d0d7a0 100644 --- a/packages/tools/src/types/IToolGroup.ts +++ b/packages/tools/src/types/IToolGroup.ts @@ -52,7 +52,10 @@ export default interface IToolGroup { setToolPassive: { ( toolName: string, - options?: { removeAllBindings?: boolean | IToolBinding[] } + options?: { + removeAllBindings?: boolean | IToolBinding[]; + bindings?: IToolBinding[]; + } ): void; }; /** Setting the tool to be Enabled by its name*/ From 19a699152941f457553e28de71af15757a6319aa Mon Sep 17 00:00:00 2001 From: Adithyan Dinesh Date: Tue, 20 Aug 2024 20:39:32 +0530 Subject: [PATCH 2/2] Modified the API report file --- common/reviews/api/tools.api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/reviews/api/tools.api.md b/common/reviews/api/tools.api.md index 4e16551a93..a9596dc934 100644 --- a/common/reviews/api/tools.api.md +++ b/common/reviews/api/tools.api.md @@ -5832,7 +5832,7 @@ class ToolGroup implements ToolGroup { // (undocumented) setToolPassive(toolName: string, options?: { removeAllBindings?: boolean | IToolBinding[]; - bindings?: IToolBinding[] + bindings?: IToolBinding[]; }): void; // (undocumented) setViewportsCursorByToolName(toolName: string, strategyName?: string): void;