Skip to content

Commit

Permalink
Improve ToolManagerAPI (#367)
Browse files Browse the repository at this point in the history
- Add `defaultToolsEnabled` flag to `ToolManager` which is true if currently only the default tools are enabled i.e. no tools have been enabled explicitly
- Avoid (re)activation of default tools if the are already enabled
- Remove unused GRID_STYLE property


Co-authored-by: Martin Fleck <[email protected]>
  • Loading branch information
tortmayr and martin-fleck-at authored Jun 25, 2024
1 parent da06174 commit 7e20238
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [di] Improve `ContainerConfiguration` API and add additional checks to ensure that all ids of `FeatureModules` are unique [#355](https://github.com/eclipse-glsp/glsp-client/pull/355)
- [diagram] Update to sprotty 1.2.0. Non-breaking as all potential API breaks have been mitigated via the glsp-sprotty rexport layer [#357](https://github.com/eclipse-glsp/glsp-client/pull/357)
- [diagram] Fix a bug with the `AutocompleteWidget` that prevented proper application of valid suggestions [#362](https://github.com/eclipse-glsp/glsp-client/pull/362)
- [api] Improved behavior of default `ToolManager` to avoid unnecessary deactivation and reactivation of default tools [#367](https://github.com/eclipse-glsp/glsp-client/pull/367)

### Potentially breaking changes

Expand Down
20 changes: 17 additions & 3 deletions packages/client/src/base/tool-manager/tool-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
MaybePromise,
TYPES,
distinctAdd,
matchesKeystroke
matchesKeystroke,
pluck
} from '@eclipse-glsp/sprotty';
import { inject, injectable } from 'inversify';
import { EditorContextService, IEditModeListener } from '../editor-context-service';
Expand All @@ -49,6 +50,9 @@ export interface IToolManager {
/** The currently active tools, which are either specifically enabled tools, or the default tools. */
readonly activeTools: Tool[];

/** Flag to indicate that the default tools are enabled and no other tool was explicitly enabled. */
readonly defaultToolsEnabled: boolean;

/**
* Enables the tools with the specified `toolIds`.
* Therefore, this manager first disables currently active tools and then enable the
Expand All @@ -62,7 +66,7 @@ export interface IToolManager {
enable(toolIds: string[]): void;

/**
* Enables all default tools.
* Enables all default tools. If the default tools are already enabled, this is a no-op.
*/
enableDefaultTools(): void;

Expand Down Expand Up @@ -90,6 +94,11 @@ export class ToolManager implements IToolManager, IDiagramStartup, IEditModeList
readonly tools: Tool[] = [];
readonly defaultTools: Tool[] = [];

protected _defaultToolsEnabled = false;
get defaultToolsEnabled(): boolean {
return this._defaultToolsEnabled;
}

preLoadDiagram(): MaybePromise<void> {
const tools: Tool[] = this.lazyInjector.getAll(TYPES.ITool);
const defaultTools: Tool[] = this.lazyInjector.getAll(TYPES.IDefaultTool);
Expand Down Expand Up @@ -119,12 +128,17 @@ export class ToolManager implements IToolManager, IDiagramStartup, IEditModeList
}

disableActiveTools(): void {
this._defaultToolsEnabled = false;
this.actives.forEach(tool => tool.disable());
this.actives.splice(0, this.actives.length);
}

enableDefaultTools(): void {
this.enable(this.defaultTools.map(tool => tool.id));
if (this.defaultToolsEnabled) {
return;
}
this.enable(pluck(this.defaultTools, 'id'));
this._defaultToolsEnabled = true;
}

enable(toolIds: string[]): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2019-2023 EclipseSource and others.
* Copyright (c) 2019-2024 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -83,7 +83,7 @@ export class GLSPContextMenuMouseListener extends MouseListener {
return FocusStateChangedAction.create(false);
}

// Clear selection the context menu target is not selectable
// Clear selection if the context menu target is not selectable
// Otherwise either maintain current selection if target is already selected or single select the current target.
protected async handleContextElementSelection(target: GModelElement, event: MouseEvent): Promise<void> {
const selectableTarget = findParentByFeature(target, isSelectable);
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/features/grid/grid-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ export namespace GridProperty {
export const GRID_BACKGROUND_WIDTH = '--grid-background-width';
export const GRID_BACKGROUND_HEIGHT = '--grid-background-height';
export const GRID_BACKGROUND_ZOOM = '--grid-background-zoom';
export const GRID_BACKGROUND_IMAGE = '--grid-background-image';
export const GRID_COLOR = '--grid-color';
}

0 comments on commit 7e20238

Please sign in to comment.