Skip to content

Commit 86e01cc

Browse files
committed
GLSP-1586: Adjust to new MenuItem API
Adjust Theia GLSP context menu service for new MenuItem API. Ensure that isEnabled,isVisible and isToggled are properly forwarded to the Theia Menu item Part of eclipse-glsp/glsp#1586 Requires: eclipse-glsp/glsp-client#450 Requires: eclipse-glsp/glsp-server-node#116
1 parent 331f73e commit 86e01cc

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

packages/theia-integration/src/browser/theia-glsp-context-menu-service.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
1515
********************************************************************************/
1616
// based on: https://github.com/eclipse-sprotty/sprotty-theia/blob/v0.12.0/src/sprotty/theia-sprotty-context-menu-service.ts
17-
import { Anchor, FocusStateChangedAction, IActionDispatcher, IContextMenuService, MenuItem } from '@eclipse-glsp/client';
17+
import { Anchor, ClientMenuItem, FocusStateChangedAction, IActionDispatcher, IContextMenuService } from '@eclipse-glsp/client';
1818
import { Command, CommandHandler, CommandRegistry, Disposable, MenuAction, MenuModelRegistry, MenuPath } from '@theia/core';
1919
import { ApplicationShell, ContextMenuRenderer } from '@theia/core/lib/browser';
2020
import { inject, injectable } from 'inversify';
@@ -51,7 +51,7 @@ export class TheiaContextMenuService implements IContextMenuService {
5151
return getDiagramWidget(this.shell);
5252
}
5353

54-
show(items: MenuItem[], anchor: Anchor, onHide?: () => void): void {
54+
show(items: ClientMenuItem[], anchor: Anchor, onHide?: () => void): void {
5555
const context = this.diagramWidget?.node;
5656
if (!context) {
5757
console.warn('No context available for context menu');
@@ -75,7 +75,7 @@ export class TheiaContextMenuService implements IContextMenuService {
7575
this.contextMenuRenderer.render(renderOptions);
7676
}
7777

78-
protected register(menuPath: string[], items: MenuItem[]): DisposableItem[] {
78+
protected register(menuPath: string[], items: ClientMenuItem[]): DisposableItem[] {
7979
const disposables: DisposableItem[] = [];
8080
for (const item of items) {
8181
if (item.children && item.children.length > 0) {
@@ -90,18 +90,19 @@ export class TheiaContextMenuService implements IContextMenuService {
9090
return disposables;
9191
}
9292

93-
protected registerSubmenu(menuPath: string[], item: MenuItem): DisposableItem {
93+
protected registerSubmenu(menuPath: string[], item: ClientMenuItem): DisposableItem {
9494
return this.menuProvider.registerSubmenu([...menuPath, item.id], item.label, { icon: item.icon });
9595
}
9696

97-
protected registerCommand(menuPath: string[], item: MenuItem): DisposableItem {
97+
protected registerCommand(menuPath: string[], item: ClientMenuItem): DisposableItem {
9898
const command: Command = { id: commandId(menuPath, item), label: item.label, iconClass: item.icon };
9999
const disposable = this.commandRegistry.registerCommand(command, new GLSPCommandHandler(item, this.actionDispatcher));
100100
return new DisposableCommand(command, disposable);
101101
}
102102

103-
protected registerMenuAction(menuPath: string[], item: MenuItem): DisposableItem {
104-
const menuAction = { label: item.label, order: item.sortString, commandId: commandId(menuPath, item) };
103+
protected registerMenuAction(menuPath: string[], item: ClientMenuItem): DisposableItem {
104+
const { label, sortString: order, isEnabled, isToggled, isVisible } = item;
105+
const menuAction = { label, order, isEnabled, isToggled, isVisible, commandId: commandId(menuPath, item) };
105106
const menuPathOfItem = item.group ? [...menuPath, item.group] : menuPath;
106107
const disposable = this.menuProvider.registerMenuAction(menuPathOfItem, menuAction);
107108
return new DisposableMenuAction(menuAction, disposable);
@@ -134,7 +135,7 @@ export class TheiaContextMenuService implements IContextMenuService {
134135

135136
class GLSPCommandHandler implements CommandHandler {
136137
constructor(
137-
readonly menuItem: MenuItem,
138+
readonly menuItem: ClientMenuItem,
138139
readonly actionDispatcher?: IActionDispatcher
139140
) {}
140141

0 commit comments

Comments
 (0)