Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set tool passive bindings support #1430

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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