diff --git a/examples/workflow-server/src/common/provider/workflow-context-menu-item-provider.ts b/examples/workflow-server/src/common/provider/workflow-context-menu-item-provider.ts index 6d038c2..8d90dd8 100644 --- a/examples/workflow-server/src/common/provider/workflow-context-menu-item-provider.ts +++ b/examples/workflow-server/src/common/provider/workflow-context-menu-item-provider.ts @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2022-2023 STMicroelectronics and others. + * Copyright (c) 2022-2025 STMicroelectronics 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 @@ -13,7 +13,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { Args, ContextMenuItemProvider, CreateNodeOperation, MenuItem, ModelState, Point } from '@eclipse-glsp/server'; +import { Args, ContextMenuItemProvider, CreateNodeOperation, MenuItem, ModelState, Point, SetEditModeAction } from '@eclipse-glsp/server'; import { inject, injectable } from 'inversify'; import { GridSnapper } from '../handler/grid-snapper'; import { ModelTypes } from '../util/model-types'; @@ -24,8 +24,15 @@ export class WorkflowContextMenuItemProvider extends ContextMenuItemProvider { protected modelState: ModelState; getItems(selectedElementIds: string[], position: Point, args?: Args): MenuItem[] { + const editModeMenu: MenuItem = { + id: 'editMode', + label: 'Readonly Mode', + isToggled: this.modelState.isReadonly, + actions: [this.modelState.isReadonly ? SetEditModeAction.create('editable') : SetEditModeAction.create('readonly')] + }; + if (this.modelState.isReadonly || selectedElementIds.length !== 0) { - return []; + return [editModeMenu]; } const snappedPosition = GridSnapper.snap(position); const newAutTask: MenuItem = { @@ -38,14 +45,22 @@ export class WorkflowContextMenuItemProvider extends ContextMenuItemProvider { label: 'Manual Task', actions: [CreateNodeOperation.create(ModelTypes.MANUAL_TASK, { location: snappedPosition })] }; + + const hiddenItem: MenuItem = { + id: 'hiddenItem', + label: 'Should be hidden', + actions: [], + isVisible: false + }; const newChildMenu: MenuItem = { id: 'new', label: 'New', actions: [], - children: [newAutTask, newManTask], + children: [newAutTask, newManTask, hiddenItem], icon: 'add', group: '0_new' }; - return [newChildMenu]; + + return [newChildMenu, editModeMenu]; } } diff --git a/packages/server/src/common/di/diagram-module.ts b/packages/server/src/common/di/diagram-module.ts index 6f2937e..f1bb515 100644 --- a/packages/server/src/common/di/diagram-module.ts +++ b/packages/server/src/common/di/diagram-module.ts @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2022-2023 STMicroelectronics and others. + * Copyright (c) 2022-2025 STMicroelectronics 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 @@ -44,6 +44,7 @@ import { ModelState } from '../features/model/model-state'; import { ModelSubmissionHandler } from '../features/model/model-submission-handler'; import { RequestModelActionHandler } from '../features/model/request-model-action-handler'; import { SaveModelActionHandler } from '../features/model/save-model-action-handler'; +import { SetEditModeActionHandler } from '../features/model/set-edit-mode-action-handler'; import { SourceModelStorage } from '../features/model/source-model-storage'; import { NavigationTargetProvider } from '../features/navigation/navigation-target-provider'; import { @@ -214,6 +215,7 @@ export abstract class DiagramModule extends GLSPModule { binding.add(RequestNavigationTargetsActionHandler); binding.add(ResolveNavigationTargetsActionHandler); binding.add(SaveModelActionHandler); + binding.add(SetEditModeActionHandler); binding.add(UndoRedoActionHandler); binding.add(ComputedBoundsActionHandler); } diff --git a/packages/server/src/common/features/contextactions/command-palette-action-provider.ts b/packages/server/src/common/features/contextactions/command-palette-action-provider.ts index 66520c1..5cd387d 100644 --- a/packages/server/src/common/features/contextactions/command-palette-action-provider.ts +++ b/packages/server/src/common/features/contextactions/command-palette-action-provider.ts @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2022-2023 STMicroelectronics and others. + * Copyright (c) 2022-2025 STMicroelectronics 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 @@ -64,11 +64,6 @@ export abstract class CommandPaletteActionProvider implements ContextActionsProv * @returns A list of {@link LabeledAction}s for a given {@link EditorContext}. */ getActions(editorContext: EditorContext): LabeledAction[] { - const actions: LabeledAction[] = []; - if (this.modelState.isReadonly) { - return actions; - } - const selectedIds = editorContext.selectedElementIds; const position = editorContext.lastMousePosition ? editorContext.lastMousePosition : { x: 0, y: 0 }; const selectedElements = this.modelState.index.getAll(selectedIds); diff --git a/packages/server/src/common/features/contextactions/context-menu-item-provider.ts b/packages/server/src/common/features/contextactions/context-menu-item-provider.ts index a814bc6..c9d6e90 100644 --- a/packages/server/src/common/features/contextactions/context-menu-item-provider.ts +++ b/packages/server/src/common/features/contextactions/context-menu-item-provider.ts @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2022-2023 STMicroelectronics and others. + * Copyright (c) 2022-2025 STMicroelectronics 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 @@ -18,7 +18,7 @@ import { injectable } from 'inversify'; import { ContextActionsProvider } from './context-actions-provider'; /** - * A {@link ContextActionsProvider} for {@link MenuItem}s. + * A {@link ContextActionsProvider} for {@link ServerMenuItem}s. */ @injectable() export abstract class ContextMenuItemProvider implements ContextActionsProvider { @@ -30,13 +30,14 @@ export abstract class ContextMenuItemProvider implements ContextActionsProvider } /** - * Returns a list of {@link MenuItem}s for a given list of selected elements at a certain mouse position. + * Returns a list of {@link ServerMenuItem}s for a given list of selected elements at a certain mouse position. * * @param selectedElementIds The list of currently selected elementIds. * @param position The current mouse position. * @param args Additional arguments. - * @returns A list of {@link MenuItem}s for a given list of selected elements at a certain mouse position. + * @returns A list of {@link ServerMenuItem}s for a given list of selected elements at a certain mouse position. */ + abstract getItems(selectedElementIds: string[], position: Point, args?: Args): MenuItem[]; /** diff --git a/packages/server/src/common/features/model/set-edit-mode-action-handler.ts b/packages/server/src/common/features/model/set-edit-mode-action-handler.ts new file mode 100644 index 0000000..3ebbe96 --- /dev/null +++ b/packages/server/src/common/features/model/set-edit-mode-action-handler.ts @@ -0,0 +1,33 @@ +/******************************************************************************** + * Copyright (c) 2025 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 + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { Action, SetEditModeAction } from '@eclipse-glsp/protocol'; +import { inject, injectable } from 'inversify'; +import { ActionHandler } from '../../actions/action-handler'; +import { ModelState } from './model-state'; + +@injectable() +export class SetEditModeActionHandler implements ActionHandler { + actionKinds = [SetEditModeAction.KIND]; + + @inject(ModelState) + protected modelState: ModelState; + + async execute(action: SetEditModeAction): Promise { + this.modelState.editMode = action.editMode; + return []; + } +} diff --git a/yarn.lock b/yarn.lock index 264859f..a74cc0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -301,9 +301,9 @@ prettier-plugin-packagejson "~2.4.6" "@eclipse-glsp/protocol@next": - version "2.6.0-next.1" - resolved "https://registry.yarnpkg.com/@eclipse-glsp/protocol/-/protocol-2.6.0-next.1.tgz#adc43f3f7a3cc0c17d12970b473521df5dbb6d66" - integrity sha512-pRcQAJl8JIXaC8O4UKlgAsJDsHhRWLP6Sn0phjI+34uEuYtWz/Ps6deHKbPPsbaeLd9ljZv7DB4KuXnL3nYWjQ== + version "2.6.0-next.6" + resolved "https://registry.yarnpkg.com/@eclipse-glsp/protocol/-/protocol-2.6.0-next.6.tgz#7437694ed1e4f5ca716ba657b98af46c90abbc9a" + integrity sha512-uswJrgPNb7wwRCiqyoNOkTCqdM2S+3avXuh4/vDKxyo7w05yLkblp1foEInfYIbRmqTod05K4fAtUWEkxJcg5Q== dependencies: sprotty-protocol "1.4.0" uuid "~10.0.0"