Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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';
Expand All @@ -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 = {
Expand All @@ -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];
}
}
4 changes: 3 additions & 1 deletion packages/server/src/common/di/diagram-module.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand All @@ -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[];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Action[]> {
this.modelState.editMode = action.editMode;
return [];
}
}
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down