Skip to content

Commit

Permalink
Support bindings when setting tool passive and keeping it passive if …
Browse files Browse the repository at this point in the history
…all bindings are for primary button
  • Loading branch information
Adithyan-Dinesh-Trenser committed Aug 19, 2024
1 parent 642bbba commit 9d6a52d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 21 additions & 5 deletions packages/tools/src/store/ToolGroupManager/ToolGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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];

Expand All @@ -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,
{
Expand All @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/tools/src/types/IToolGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand Down

0 comments on commit 9d6a52d

Please sign in to comment.