@theia/core 1.62.0-next.3 → 1.62.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/i18n/nls.cs.json +158 -13
- package/i18n/nls.de.json +158 -13
- package/i18n/nls.es.json +158 -13
- package/i18n/nls.fr.json +158 -13
- package/i18n/nls.hu.json +158 -13
- package/i18n/nls.it.json +158 -13
- package/i18n/nls.ja.json +158 -13
- package/i18n/nls.json +159 -14
- package/i18n/nls.ko.json +158 -13
- package/i18n/nls.pl.json +158 -13
- package/i18n/nls.pt-br.json +158 -13
- package/i18n/nls.ru.json +158 -13
- package/i18n/nls.tr.json +158 -13
- package/i18n/nls.zh-cn.json +158 -13
- package/i18n/nls.zh-tw.json +158 -13
- package/lib/browser/catalog.json +206 -33
- package/lib/browser/common-frontend-contribution.d.ts +1 -1
- package/lib/browser/common-frontend-contribution.d.ts.map +1 -1
- package/lib/browser/common-frontend-contribution.js +13 -11
- package/lib/browser/common-frontend-contribution.js.map +1 -1
- package/lib/browser/context-menu-renderer.d.ts +14 -3
- package/lib/browser/context-menu-renderer.d.ts.map +1 -1
- package/lib/browser/context-menu-renderer.js +23 -1
- package/lib/browser/context-menu-renderer.js.map +1 -1
- package/lib/browser/frontend-application-module.d.ts.map +1 -1
- package/lib/browser/frontend-application-module.js +1 -3
- package/lib/browser/frontend-application-module.js.map +1 -1
- package/lib/browser/hover-service.d.ts.map +1 -1
- package/lib/browser/hover-service.js +7 -0
- package/lib/browser/hover-service.js.map +1 -1
- package/lib/browser/menu/action-menu-node.d.ts +36 -0
- package/lib/browser/menu/action-menu-node.d.ts.map +1 -0
- package/lib/browser/menu/action-menu-node.js +113 -0
- package/lib/browser/menu/action-menu-node.js.map +1 -0
- package/lib/browser/menu/browser-context-menu-renderer.d.ts +12 -4
- package/lib/browser/menu/browser-context-menu-renderer.d.ts.map +1 -1
- package/lib/browser/menu/browser-context-menu-renderer.js +12 -13
- package/lib/browser/menu/browser-context-menu-renderer.js.map +1 -1
- package/lib/browser/menu/browser-menu-module.d.ts.map +1 -1
- package/lib/browser/menu/browser-menu-module.js +4 -0
- package/lib/browser/menu/browser-menu-module.js.map +1 -1
- package/lib/browser/menu/browser-menu-node-factory.d.ts +13 -0
- package/lib/browser/menu/browser-menu-node-factory.d.ts.map +1 -0
- package/lib/browser/menu/browser-menu-node-factory.js +54 -0
- package/lib/browser/menu/browser-menu-node-factory.js.map +1 -0
- package/lib/browser/menu/browser-menu-plugin.d.ts +12 -30
- package/lib/browser/menu/browser-menu-plugin.d.ts.map +1 -1
- package/lib/browser/menu/browser-menu-plugin.js +78 -159
- package/lib/browser/menu/browser-menu-plugin.js.map +1 -1
- package/lib/browser/menu/composite-menu-node.d.ts +49 -0
- package/lib/browser/menu/composite-menu-node.d.ts.map +1 -0
- package/lib/browser/menu/composite-menu-node.js +127 -0
- package/lib/browser/menu/composite-menu-node.js.map +1 -0
- package/lib/browser/menu/menu.spec.d.ts.map +1 -0
- package/lib/{common → browser}/menu/menu.spec.js +38 -13
- package/lib/browser/menu/menu.spec.js.map +1 -0
- package/lib/browser/open-with-service.d.ts +1 -1
- package/lib/browser/saveable-service.d.ts.map +1 -1
- package/lib/browser/saveable-service.js +6 -1
- package/lib/browser/saveable-service.js.map +1 -1
- package/lib/browser/shell/application-shell.d.ts +7 -5
- package/lib/browser/shell/application-shell.d.ts.map +1 -1
- package/lib/browser/shell/application-shell.js +82 -28
- package/lib/browser/shell/application-shell.js.map +1 -1
- package/lib/browser/shell/index.d.ts +1 -0
- package/lib/browser/shell/index.d.ts.map +1 -1
- package/lib/browser/shell/index.js +1 -0
- package/lib/browser/shell/index.js.map +1 -1
- package/lib/browser/shell/sidebar-bottom-menu-widget.d.ts.map +1 -1
- package/lib/browser/shell/sidebar-bottom-menu-widget.js +2 -1
- package/lib/browser/shell/sidebar-bottom-menu-widget.js.map +1 -1
- package/lib/browser/shell/sidebar-menu-widget.d.ts +4 -1
- package/lib/browser/shell/sidebar-menu-widget.d.ts.map +1 -1
- package/lib/browser/shell/sidebar-menu-widget.js +14 -1
- package/lib/browser/shell/sidebar-menu-widget.js.map +1 -1
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.d.ts +66 -8
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.d.ts.map +1 -1
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.js +161 -8
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.js.map +1 -1
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-registry.d.ts +18 -32
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-registry.d.ts.map +1 -1
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-registry.js +52 -88
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-registry.js.map +1 -1
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.d.ts +17 -21
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.d.ts.map +1 -1
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.js +9 -9
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.js.map +1 -1
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.d.ts +7 -39
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.d.ts.map +1 -1
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.js +30 -238
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.js.map +1 -1
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.spec.js +13 -13
- package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.spec.js.map +1 -1
- package/lib/browser/shell/tab-bar-toolbar/tab-toolbar-item.d.ts +56 -0
- package/lib/browser/shell/tab-bar-toolbar/tab-toolbar-item.d.ts.map +1 -0
- package/lib/browser/shell/tab-bar-toolbar/tab-toolbar-item.js +208 -0
- package/lib/browser/shell/tab-bar-toolbar/tab-toolbar-item.js.map +1 -0
- package/lib/browser/shell/tab-bars.d.ts.map +1 -1
- package/lib/browser/shell/tab-bars.js +2 -1
- package/lib/browser/shell/tab-bars.js.map +1 -1
- package/lib/browser/shell/theia-dock-panel.d.ts +4 -10
- package/lib/browser/shell/theia-dock-panel.d.ts.map +1 -1
- package/lib/browser/shell/theia-dock-panel.js +7 -84
- package/lib/browser/shell/theia-dock-panel.js.map +1 -1
- package/lib/browser/shell/theia-split-panel.d.ts +6 -0
- package/lib/browser/shell/theia-split-panel.d.ts.map +1 -0
- package/lib/browser/shell/theia-split-panel.js +56 -0
- package/lib/browser/shell/theia-split-panel.js.map +1 -0
- package/lib/browser/tree/tree-widget.d.ts +1 -0
- package/lib/browser/tree/tree-widget.d.ts.map +1 -1
- package/lib/browser/tree/tree-widget.js +6 -0
- package/lib/browser/tree/tree-widget.js.map +1 -1
- package/lib/browser/view-container.d.ts +6 -3
- package/lib/browser/view-container.d.ts.map +1 -1
- package/lib/browser/view-container.js +36 -26
- package/lib/browser/view-container.js.map +1 -1
- package/lib/browser/window/default-secondary-window-service.d.ts +1 -0
- package/lib/browser/window/default-secondary-window-service.d.ts.map +1 -1
- package/lib/browser/window/default-secondary-window-service.js +3 -0
- package/lib/browser/window/default-secondary-window-service.js.map +1 -1
- package/lib/common/listener.d.ts +21 -0
- package/lib/common/listener.d.ts.map +1 -0
- package/lib/common/listener.js +81 -0
- package/lib/common/listener.js.map +1 -0
- package/lib/common/listener.spec.d.ts +2 -0
- package/lib/common/listener.spec.d.ts.map +1 -0
- package/lib/common/listener.spec.js +255 -0
- package/lib/common/listener.spec.js.map +1 -0
- package/lib/common/menu/index.d.ts +2 -3
- package/lib/common/menu/index.d.ts.map +1 -1
- package/lib/common/menu/index.js +2 -3
- package/lib/common/menu/index.js.map +1 -1
- package/lib/common/menu/menu-model-registry.d.ts +37 -50
- package/lib/common/menu/menu-model-registry.d.ts.map +1 -1
- package/lib/common/menu/menu-model-registry.js +176 -225
- package/lib/common/menu/menu-model-registry.js.map +1 -1
- package/lib/common/menu/menu-types.d.ts +58 -96
- package/lib/common/menu/menu-types.d.ts.map +1 -1
- package/lib/common/menu/menu-types.js +43 -39
- package/lib/common/menu/menu-types.js.map +1 -1
- package/lib/common/messaging/proxy-factory.d.ts.map +1 -1
- package/lib/common/messaging/proxy-factory.js +4 -0
- package/lib/common/messaging/proxy-factory.js.map +1 -1
- package/lib/electron-browser/menu/electron-context-menu-renderer.d.ts +15 -5
- package/lib/electron-browser/menu/electron-context-menu-renderer.d.ts.map +1 -1
- package/lib/electron-browser/menu/electron-context-menu-renderer.js +21 -14
- package/lib/electron-browser/menu/electron-context-menu-renderer.js.map +1 -1
- package/lib/electron-browser/menu/electron-main-menu-factory.d.ts +4 -16
- package/lib/electron-browser/menu/electron-main-menu-factory.d.ts.map +1 -1
- package/lib/electron-browser/menu/electron-main-menu-factory.js +84 -104
- package/lib/electron-browser/menu/electron-main-menu-factory.js.map +1 -1
- package/lib/electron-browser/menu/electron-menu-contribution.d.ts.map +1 -1
- package/lib/electron-browser/menu/electron-menu-contribution.js +1 -4
- package/lib/electron-browser/menu/electron-menu-contribution.js.map +1 -1
- package/lib/electron-browser/menu/electron-menu-module.d.ts.map +1 -1
- package/lib/electron-browser/menu/electron-menu-module.js +5 -0
- package/lib/electron-browser/menu/electron-menu-module.js.map +1 -1
- package/lib/electron-browser/window/electron-secondary-window-service.d.ts +1 -0
- package/lib/electron-browser/window/electron-secondary-window-service.d.ts.map +1 -1
- package/lib/electron-browser/window/electron-secondary-window-service.js +20 -0
- package/lib/electron-browser/window/electron-secondary-window-service.js.map +1 -1
- package/lib/electron-browser/window/electron-window-service.d.ts +3 -0
- package/lib/electron-browser/window/electron-window-service.d.ts.map +1 -1
- package/lib/electron-browser/window/electron-window-service.js +10 -1
- package/lib/electron-browser/window/electron-window-service.js.map +1 -1
- package/lib/electron-main/theia-electron-window.d.ts.map +1 -1
- package/lib/electron-main/theia-electron-window.js +2 -0
- package/lib/electron-main/theia-electron-window.js.map +1 -1
- package/package.json +7 -8
- package/src/browser/common-frontend-contribution.ts +14 -14
- package/src/browser/context-menu-renderer.ts +33 -5
- package/src/browser/frontend-application-module.ts +1 -7
- package/src/browser/hover-service.ts +7 -0
- package/src/browser/menu/action-menu-node.ts +128 -0
- package/src/browser/menu/browser-context-menu-renderer.ts +18 -11
- package/src/browser/menu/browser-menu-module.ts +4 -0
- package/src/browser/menu/browser-menu-node-factory.ts +48 -0
- package/src/browser/menu/browser-menu-plugin.ts +80 -168
- package/src/browser/menu/composite-menu-node.ts +140 -0
- package/src/{common → browser}/menu/menu.spec.ts +47 -15
- package/src/browser/open-with-service.ts +1 -1
- package/src/browser/saveable-service.ts +6 -1
- package/src/browser/shell/application-shell.ts +91 -29
- package/src/browser/shell/index.ts +1 -0
- package/src/browser/shell/sidebar-bottom-menu-widget.tsx +2 -1
- package/src/browser/shell/sidebar-menu-widget.tsx +12 -2
- package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.tsx +239 -0
- package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-registry.ts +59 -102
- package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.ts +14 -23
- package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar.spec.ts +14 -14
- package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar.tsx +34 -261
- package/src/browser/shell/tab-bar-toolbar/tab-toolbar-item.tsx +251 -0
- package/src/browser/shell/tab-bars.ts +2 -1
- package/src/browser/shell/theia-dock-panel.ts +10 -91
- package/src/browser/shell/theia-split-panel.ts +56 -0
- package/src/browser/style/hover-service.css +6 -1
- package/src/browser/style/index.css +3 -11
- package/src/browser/style/view-container.css +17 -31
- package/src/browser/tree/tree-widget.tsx +7 -0
- package/src/browser/view-container.ts +51 -30
- package/src/browser/window/default-secondary-window-service.ts +4 -0
- package/src/common/listener.spec.ts +315 -0
- package/src/common/listener.ts +88 -0
- package/src/common/menu/index.ts +2 -3
- package/src/common/menu/menu-model-registry.ts +187 -230
- package/src/common/menu/menu-types.ts +82 -128
- package/src/common/messaging/proxy-factory.ts +4 -1
- package/src/electron-browser/menu/electron-context-menu-renderer.ts +29 -13
- package/src/electron-browser/menu/electron-main-menu-factory.ts +92 -116
- package/src/electron-browser/menu/electron-menu-contribution.ts +1 -4
- package/src/electron-browser/menu/electron-menu-module.ts +6 -1
- package/src/electron-browser/window/electron-secondary-window-service.ts +22 -0
- package/src/electron-browser/window/electron-window-service.ts +11 -1
- package/src/electron-main/theia-electron-window.ts +2 -0
- package/lib/common/menu/action-menu-node.d.ts +0 -20
- package/lib/common/menu/action-menu-node.d.ts.map +0 -1
- package/lib/common/menu/action-menu-node.js +0 -57
- package/lib/common/menu/action-menu-node.js.map +0 -1
- package/lib/common/menu/composite-menu-node.d.ts +0 -47
- package/lib/common/menu/composite-menu-node.d.ts.map +0 -1
- package/lib/common/menu/composite-menu-node.js +0 -96
- package/lib/common/menu/composite-menu-node.js.map +0 -1
- package/lib/common/menu/composite-menu-node.spec.d.ts +0 -2
- package/lib/common/menu/composite-menu-node.spec.d.ts.map +0 -1
- package/lib/common/menu/composite-menu-node.spec.js +0 -68
- package/lib/common/menu/composite-menu-node.spec.js.map +0 -1
- package/lib/common/menu/menu-adapter.d.ts +0 -36
- package/lib/common/menu/menu-adapter.d.ts.map +0 -1
- package/lib/common/menu/menu-adapter.js +0 -93
- package/lib/common/menu/menu-adapter.js.map +0 -1
- package/lib/common/menu/menu.spec.d.ts.map +0 -1
- package/lib/common/menu/menu.spec.js.map +0 -1
- package/lib/common/test/mock-menu.d.ts +0 -8
- package/lib/common/test/mock-menu.d.ts.map +0 -1
- package/lib/common/test/mock-menu.js +0 -35
- package/lib/common/test/mock-menu.js.map +0 -1
- package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.ts +0 -31
- package/src/common/menu/action-menu-node.ts +0 -65
- package/src/common/menu/composite-menu-node.spec.ts +0 -67
- package/src/common/menu/composite-menu-node.ts +0 -116
- package/src/common/menu/menu-adapter.ts +0 -103
- package/src/common/test/mock-menu.ts +0 -35
- /package/lib/{common → browser}/menu/menu.spec.d.ts +0 -0
|
@@ -15,13 +15,12 @@
|
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
17
|
import { inject, injectable, named } from 'inversify';
|
|
18
|
-
import {
|
|
18
|
+
import { CommandMenu, CompoundMenuNode, Group, MAIN_MENU_BAR, MenuAction, MenuNode, MenuPath, MutableCompoundMenuNode, Submenu } from './menu-types';
|
|
19
|
+
import { Event } from 'vscode-languageserver-protocol';
|
|
19
20
|
import { ContributionProvider } from '../contribution-provider';
|
|
21
|
+
import { Command, CommandRegistry } from '../command';
|
|
22
|
+
import { Emitter } from '../event';
|
|
20
23
|
import { Disposable } from '../disposable';
|
|
21
|
-
import { Emitter, Event } from '../event';
|
|
22
|
-
import { ActionMenuNode } from './action-menu-node';
|
|
23
|
-
import { CompositeMenuNode, CompositeMenuNodeWrapper } from './composite-menu-node';
|
|
24
|
-
import { CompoundMenuNode, MenuAction, MenuNode, MenuNodeMetadata, MenuPath, MutableCompoundMenuNode, SubMenuOptions } from './menu-types';
|
|
25
24
|
|
|
26
25
|
export const MenuContribution = Symbol('MenuContribution');
|
|
27
26
|
|
|
@@ -81,6 +80,15 @@ export namespace StructuralMenuChange {
|
|
|
81
80
|
return evt.kind !== ChangeKind.CHANGED;
|
|
82
81
|
}
|
|
83
82
|
}
|
|
83
|
+
export const MenuNodeFactory = Symbol('MenuNodeFactory');
|
|
84
|
+
|
|
85
|
+
export interface MenuNodeFactory {
|
|
86
|
+
createGroup(id: string, orderString?: string, when?: string): Group & MutableCompoundMenuNode;
|
|
87
|
+
createCommandMenu(item: MenuAction): CommandMenu;
|
|
88
|
+
createSubmenu(id: string, label: string, contextKeyOverlays: Record<string, string> | undefined,
|
|
89
|
+
orderString?: string, icon?: string, when?: string): Submenu & MutableCompoundMenuNode
|
|
90
|
+
createSubmenuLink(delegate: Submenu, sortString?: string, when?: string): MenuNode;
|
|
91
|
+
}
|
|
84
92
|
|
|
85
93
|
/**
|
|
86
94
|
* The MenuModelRegistry allows to register and unregister menus, submenus and actions
|
|
@@ -89,23 +97,27 @@ export namespace StructuralMenuChange {
|
|
|
89
97
|
*/
|
|
90
98
|
@injectable()
|
|
91
99
|
export class MenuModelRegistry {
|
|
92
|
-
protected
|
|
93
|
-
protected readonly independentSubmenus = new Map<string, MutableCompoundMenuNode>();
|
|
100
|
+
protected root: Group & MutableCompoundMenuNode;
|
|
94
101
|
|
|
95
102
|
protected readonly onDidChangeEmitter = new Emitter<MenuChangedEvent>();
|
|
96
103
|
|
|
104
|
+
constructor(
|
|
105
|
+
@inject(ContributionProvider) @named(MenuContribution)
|
|
106
|
+
protected readonly contributions: ContributionProvider<MenuContribution>,
|
|
107
|
+
@inject(CommandRegistry)
|
|
108
|
+
protected readonly commands: CommandRegistry,
|
|
109
|
+
@inject(MenuNodeFactory)
|
|
110
|
+
protected readonly menuNodeFactory: MenuNodeFactory) {
|
|
111
|
+
this.root = this.menuNodeFactory.createGroup('root', 'root');
|
|
112
|
+
this.root.addNode(this.menuNodeFactory.createGroup(MAIN_MENU_BAR[0]));
|
|
113
|
+
}
|
|
114
|
+
|
|
97
115
|
get onDidChange(): Event<MenuChangedEvent> {
|
|
98
116
|
return this.onDidChangeEmitter.event;
|
|
99
117
|
}
|
|
100
118
|
|
|
101
119
|
protected isReady = false;
|
|
102
120
|
|
|
103
|
-
constructor(
|
|
104
|
-
@inject(ContributionProvider) @named(MenuContribution)
|
|
105
|
-
protected readonly contributions: ContributionProvider<MenuContribution>,
|
|
106
|
-
@inject(CommandRegistry) protected readonly commands: CommandRegistry
|
|
107
|
-
) { }
|
|
108
|
-
|
|
109
121
|
onStart(): void {
|
|
110
122
|
for (const contrib of this.contributions.getContributions()) {
|
|
111
123
|
contrib.registerMenus(this);
|
|
@@ -118,47 +130,48 @@ export class MenuModelRegistry {
|
|
|
118
130
|
*
|
|
119
131
|
* @returns a disposable which, when called, will remove the menu action again.
|
|
120
132
|
*/
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
133
|
+
registerCommandMenu(menuPath: MenuPath, item: CommandMenu): Disposable {
|
|
134
|
+
const parent = this.root.getOrCreate(menuPath, 0, menuPath.length);
|
|
135
|
+
const existing = parent.children.find(node => node.id === menuPath[menuPath.length - 1]);
|
|
136
|
+
if (existing) {
|
|
137
|
+
throw new Error(`A menu node with path ${JSON.stringify(menuPath)} already exists`);
|
|
138
|
+
} else {
|
|
139
|
+
parent.addNode(item);
|
|
140
|
+
return Disposable.create(() => {
|
|
141
|
+
parent.removeNode(item);
|
|
142
|
+
this.fireChangeEvent({
|
|
143
|
+
kind: ChangeKind.REMOVED,
|
|
144
|
+
path: menuPath.slice(0, menuPath.length - 1),
|
|
145
|
+
affectedChildId: item.id
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
124
150
|
}
|
|
125
151
|
|
|
126
152
|
/**
|
|
127
|
-
* Adds the given menu
|
|
153
|
+
* Adds the given menu action to the menu denoted by the given path.
|
|
128
154
|
*
|
|
129
|
-
* @returns a disposable which, when called, will remove the menu
|
|
155
|
+
* @returns a disposable which, when called, will remove the menu action again.
|
|
130
156
|
*/
|
|
131
|
-
|
|
132
|
-
const parent = this.
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
kind: ChangeKind.ADDED,
|
|
137
|
-
path: parentPath,
|
|
138
|
-
affectedChildId: menuNode.id
|
|
139
|
-
});
|
|
140
|
-
return this.changeEventOnDispose(parentPath, menuNode.id, disposable);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
protected getParentPath(menuPath: MenuPath | string, group?: string): string[] {
|
|
144
|
-
if (typeof menuPath === 'string') {
|
|
145
|
-
return group ? [menuPath, group] : [menuPath];
|
|
157
|
+
registerMenuAction(menuPath: MenuPath, item: MenuAction): Disposable {
|
|
158
|
+
const parent = this.root.getOrCreate(menuPath, 0, menuPath.length);
|
|
159
|
+
const existing = parent.children.find(node => node.id === item.commandId);
|
|
160
|
+
if (existing) {
|
|
161
|
+
throw new Error(`A menu node with id ${item.commandId} in path ${JSON.stringify(menuPath)} already exists`);
|
|
146
162
|
} else {
|
|
147
|
-
|
|
163
|
+
const node = this.menuNodeFactory.createCommandMenu(item);
|
|
164
|
+
parent.addNode(node);
|
|
165
|
+
return Disposable.create(() => {
|
|
166
|
+
parent.removeNode(node);
|
|
167
|
+
this.fireChangeEvent({
|
|
168
|
+
kind: ChangeKind.REMOVED,
|
|
169
|
+
path: menuPath.slice(0, menuPath.length - 1),
|
|
170
|
+
affectedChildId: node.id
|
|
171
|
+
});
|
|
172
|
+
});
|
|
148
173
|
}
|
|
149
|
-
}
|
|
150
174
|
|
|
151
|
-
getMenuNode(menuPath: MenuPath | string, group?: string): MutableCompoundMenuNode {
|
|
152
|
-
if (typeof menuPath === 'string') {
|
|
153
|
-
const target = this.independentSubmenus.get(menuPath);
|
|
154
|
-
if (!target) { throw new Error(`Could not find submenu with id ${menuPath}`); }
|
|
155
|
-
if (group) {
|
|
156
|
-
return this.findSubMenu(target, group);
|
|
157
|
-
}
|
|
158
|
-
return target;
|
|
159
|
-
} else {
|
|
160
|
-
return this.findGroup(group ? menuPath.concat(group) : menuPath);
|
|
161
|
-
}
|
|
162
175
|
}
|
|
163
176
|
|
|
164
177
|
/**
|
|
@@ -176,72 +189,84 @@ export class MenuModelRegistry {
|
|
|
176
189
|
* Note that if the menu already existed and was registered with a different label an error
|
|
177
190
|
* will be thrown.
|
|
178
191
|
*/
|
|
179
|
-
registerSubmenu(menuPath: MenuPath, label: string,
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
groupNode = new CompositeMenuNode(menuId, label, options, parent);
|
|
191
|
-
disposable = this.changeEventOnDispose(groupPath, menuId, parent.addNode(groupNode));
|
|
192
|
+
registerSubmenu(menuPath: MenuPath, label: string,
|
|
193
|
+
options: { sortString?: string, icon?: string, when?: string, contextKeyOverlay?: Record<string, string> } = {}): Disposable {
|
|
194
|
+
const { contextKeyOverlay, sortString, icon, when } = options;
|
|
195
|
+
|
|
196
|
+
const parent = this.root.getOrCreate(menuPath, 0, menuPath.length - 1);
|
|
197
|
+
const existing = parent.children.find(node => node.id === menuPath[menuPath.length - 1]);
|
|
198
|
+
if (Group.is(existing)) {
|
|
199
|
+
parent.removeNode(existing);
|
|
200
|
+
const newMenu = this.menuNodeFactory.createSubmenu(menuPath[menuPath.length - 1], label, contextKeyOverlay, sortString, icon, when);
|
|
201
|
+
newMenu.addNode(...existing.children);
|
|
202
|
+
parent.addNode(newMenu);
|
|
192
203
|
this.fireChangeEvent({
|
|
193
|
-
kind: ChangeKind.
|
|
194
|
-
path:
|
|
195
|
-
|
|
204
|
+
kind: ChangeKind.CHANGED,
|
|
205
|
+
path: menuPath
|
|
206
|
+
});
|
|
207
|
+
return Disposable.create(() => {
|
|
208
|
+
parent.removeNode(newMenu);
|
|
209
|
+
this.fireChangeEvent({
|
|
210
|
+
kind: ChangeKind.REMOVED,
|
|
211
|
+
path: menuPath.slice(0, menuPath.length - 1),
|
|
212
|
+
affectedChildId: newMenu.id
|
|
213
|
+
});
|
|
196
214
|
});
|
|
197
215
|
} else {
|
|
216
|
+
const newMenu = this.menuNodeFactory.createSubmenu(menuPath[menuPath.length - 1], label, contextKeyOverlay, sortString, icon, when);
|
|
217
|
+
parent.addNode(newMenu);
|
|
198
218
|
this.fireChangeEvent({
|
|
199
|
-
kind: ChangeKind.
|
|
200
|
-
path:
|
|
219
|
+
kind: ChangeKind.ADDED,
|
|
220
|
+
path: menuPath.slice(0, menuPath.length - 1),
|
|
221
|
+
affectedChildId: newMenu.id
|
|
222
|
+
});
|
|
223
|
+
return Disposable.create(() => {
|
|
224
|
+
parent.removeNode(newMenu);
|
|
225
|
+
this.fireChangeEvent({
|
|
226
|
+
kind: ChangeKind.REMOVED,
|
|
227
|
+
path: menuPath.slice(0, menuPath.length - 1),
|
|
228
|
+
affectedChildId: newMenu.id
|
|
229
|
+
});
|
|
201
230
|
});
|
|
202
|
-
groupNode.updateOptions({ ...options, label });
|
|
203
231
|
}
|
|
204
|
-
return disposable;
|
|
205
232
|
}
|
|
206
233
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
234
|
+
linkCompoundMenuNode(params: { newParentPath: MenuPath, submenuPath: MenuPath, order?: string, when?: string }): Disposable {
|
|
235
|
+
const { newParentPath, submenuPath, order, when } = params;
|
|
236
|
+
// add a wrapper here
|
|
237
|
+
let i = 0;
|
|
238
|
+
while (i < newParentPath.length && i < submenuPath.length && newParentPath[i] === submenuPath[i]) {
|
|
239
|
+
i++;
|
|
210
240
|
}
|
|
211
|
-
this.independentSubmenus.set(id, new CompositeMenuNode(id, label, options));
|
|
212
|
-
return this.changeEventOnDispose([], id, Disposable.create(() => this.independentSubmenus.delete(id)));
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
linkSubmenu(parentPath: MenuPath | string, childId: string | MenuPath, options?: SubMenuOptions, group?: string): Disposable {
|
|
216
|
-
const child = this.getMenuNode(childId);
|
|
217
|
-
const parent = this.getMenuNode(parentPath, group);
|
|
218
|
-
const affectedPath = this.getParentPath(parentPath, group);
|
|
219
241
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return true;
|
|
223
|
-
}
|
|
224
|
-
if (node.parent) {
|
|
225
|
-
return isRecursive(node.parent, childNode);
|
|
226
|
-
}
|
|
227
|
-
return false;
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
// check for menu contribution recursion
|
|
231
|
-
if (isRecursive(parent, child)) {
|
|
232
|
-
console.warn(`Recursive menu contribution detected: ${child.id} is already in hierarchy of ${parent.id}.`);
|
|
233
|
-
return Disposable.NULL;
|
|
242
|
+
if (i === newParentPath.length || i === submenuPath.length) {
|
|
243
|
+
throw new Error(`trying to recursively link ${JSON.stringify(submenuPath)} into ${JSON.stringify(newParentPath)}`);
|
|
234
244
|
}
|
|
235
245
|
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
246
|
+
const child = this.getMenu(submenuPath) as Submenu;
|
|
247
|
+
if (!child) {
|
|
248
|
+
throw new Error(`Not a menu node: ${JSON.stringify(submenuPath)}`);
|
|
249
|
+
}
|
|
250
|
+
const newParent = this.root.getOrCreate(newParentPath, 0, newParentPath.length);
|
|
251
|
+
if (MutableCompoundMenuNode.is(newParent)) {
|
|
252
|
+
const link = this.menuNodeFactory.createSubmenuLink(child, order, when);
|
|
253
|
+
newParent.addNode(link);
|
|
254
|
+
this.fireChangeEvent({
|
|
255
|
+
kind: ChangeKind.LINKED,
|
|
256
|
+
path: newParentPath,
|
|
257
|
+
affectedChildId: child.id
|
|
258
|
+
});
|
|
259
|
+
return Disposable.create(() => {
|
|
260
|
+
newParent.removeNode(link);
|
|
261
|
+
this.fireChangeEvent({
|
|
262
|
+
kind: ChangeKind.REMOVED,
|
|
263
|
+
path: newParentPath,
|
|
264
|
+
affectedChildId: child.id
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
} else {
|
|
268
|
+
throw new Error(`Not a compound menu node: ${JSON.stringify(newParentPath)}`);
|
|
269
|
+
}
|
|
245
270
|
}
|
|
246
271
|
|
|
247
272
|
/**
|
|
@@ -265,89 +290,58 @@ export class MenuModelRegistry {
|
|
|
265
290
|
* @param menuPath if specified only nodes within the path will be unregistered.
|
|
266
291
|
*/
|
|
267
292
|
unregisterMenuAction(id: string, menuPath?: MenuPath): void;
|
|
268
|
-
unregisterMenuAction(itemOrCommandOrId: MenuAction | Command | string, menuPath
|
|
293
|
+
unregisterMenuAction(itemOrCommandOrId: MenuAction | Command | string, menuPath: MenuPath = []): void {
|
|
269
294
|
const id = MenuAction.is(itemOrCommandOrId) ? itemOrCommandOrId.commandId
|
|
270
295
|
: Command.is(itemOrCommandOrId) ? itemOrCommandOrId.id
|
|
271
296
|
: itemOrCommandOrId;
|
|
272
297
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
this.fireChangeEvent({
|
|
277
|
-
kind: ChangeKind.REMOVED,
|
|
278
|
-
path: menuPath,
|
|
279
|
-
affectedChildId: id
|
|
280
|
-
});
|
|
281
|
-
} else {
|
|
282
|
-
this.unregisterMenuNode(id);
|
|
298
|
+
const parent = this.findInNode(this.root, menuPath, 0);
|
|
299
|
+
if (parent) {
|
|
300
|
+
this.removeActionInSubtree(parent, id);
|
|
283
301
|
}
|
|
284
302
|
}
|
|
285
303
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
root.children.forEach(node => {
|
|
295
|
-
if (CompoundMenuNode.isMutable(node)) {
|
|
296
|
-
if (node.removeNode(id)) {
|
|
297
|
-
this.fireChangeEvent({
|
|
298
|
-
kind: ChangeKind.REMOVED,
|
|
299
|
-
path: parentPath,
|
|
300
|
-
affectedChildId: id
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
parentPath.push(node.id);
|
|
304
|
-
recurse(node);
|
|
305
|
-
parentPath.pop();
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
};
|
|
309
|
-
recurse(this.root);
|
|
304
|
+
protected removeActionInSubtree(parent: MenuNode, id: string): void {
|
|
305
|
+
if (MutableCompoundMenuNode.is(parent) && CompoundMenuNode.is(parent)) {
|
|
306
|
+
const action = parent.children.find(child => child.id === id);
|
|
307
|
+
if (action) {
|
|
308
|
+
parent.removeNode(action);
|
|
309
|
+
}
|
|
310
|
+
parent.children.forEach(child => this.removeActionInSubtree(child, id));
|
|
311
|
+
}
|
|
310
312
|
}
|
|
311
313
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
*/
|
|
316
|
-
protected findGroup(menuPath: MenuPath, options?: SubMenuOptions): MutableCompoundMenuNode {
|
|
317
|
-
let currentMenu: MutableCompoundMenuNode = this.root;
|
|
318
|
-
for (const segment of menuPath) {
|
|
319
|
-
currentMenu = this.findSubMenu(currentMenu, segment, options);
|
|
314
|
+
protected findInNode(root: CompoundMenuNode, menuPath: MenuPath, pathIndex: number): MenuNode | undefined {
|
|
315
|
+
if (pathIndex === menuPath.length) {
|
|
316
|
+
return root;
|
|
320
317
|
}
|
|
321
|
-
|
|
318
|
+
const child = root.children.find(c => c.id === menuPath[pathIndex]);
|
|
319
|
+
if (CompoundMenuNode.is(child)) {
|
|
320
|
+
return this.findInNode(child, menuPath, pathIndex + 1);
|
|
321
|
+
}
|
|
322
|
+
return undefined;
|
|
322
323
|
}
|
|
323
324
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
if (CompoundMenuNode.
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
if (sub) {
|
|
334
|
-
throw new Error(`'${menuId}' is not a menu group.`);
|
|
325
|
+
getMenuNode(menuPath: string[]): MenuNode | undefined {
|
|
326
|
+
return this.findInNode(this.root, menuPath, 0);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
getMenu(menuPath: MenuPath): CompoundMenuNode {
|
|
330
|
+
const node = this.getMenuNode(menuPath);
|
|
331
|
+
if (!CompoundMenuNode.is(node)) {
|
|
332
|
+
throw new Error(`not a compound menu node: ${JSON.stringify(menuPath)}`);
|
|
335
333
|
}
|
|
336
|
-
|
|
337
|
-
current.addNode(newSub);
|
|
338
|
-
return newSub;
|
|
334
|
+
return node;
|
|
339
335
|
}
|
|
340
336
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
getMenu(menuPath: MenuPath = []): MutableCompoundMenuNode {
|
|
350
|
-
return this.findGroup(menuPath);
|
|
337
|
+
static removeSingleRootNodes(fullMenuModel: CompoundMenuNode): CompoundMenuNode {
|
|
338
|
+
let current = fullMenuModel;
|
|
339
|
+
let previous = undefined;
|
|
340
|
+
while (current !== previous) {
|
|
341
|
+
previous = current;
|
|
342
|
+
current = this.removeSingleRootNode(current);
|
|
343
|
+
}
|
|
344
|
+
return current;
|
|
351
345
|
}
|
|
352
346
|
|
|
353
347
|
/**
|
|
@@ -358,82 +352,45 @@ export class MenuModelRegistry {
|
|
|
358
352
|
* @returns if the menu will show a single submenu this returns a menu that will show the child elements of the submenu,
|
|
359
353
|
* otherwise the given `fullMenuModel` is return
|
|
360
354
|
*/
|
|
361
|
-
removeSingleRootNode(fullMenuModel:
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
let nonEmptyNode = undefined;
|
|
355
|
+
static removeSingleRootNode(fullMenuModel: CompoundMenuNode): CompoundMenuNode {
|
|
356
|
+
|
|
357
|
+
let singleChild = undefined;
|
|
358
|
+
|
|
367
359
|
for (const child of fullMenuModel.children) {
|
|
368
|
-
if (
|
|
369
|
-
if (
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
360
|
+
if (CompoundMenuNode.is(child)) {
|
|
361
|
+
if (!MenuModelRegistry.isEmpty(child)) {
|
|
362
|
+
if (singleChild) {
|
|
363
|
+
return fullMenuModel;
|
|
364
|
+
} else {
|
|
365
|
+
singleChild = child;
|
|
366
|
+
}
|
|
373
367
|
}
|
|
368
|
+
} else {
|
|
369
|
+
return fullMenuModel;
|
|
374
370
|
}
|
|
375
371
|
}
|
|
376
|
-
|
|
377
|
-
if (CompoundMenuNode.is(nonEmptyNode) && nonEmptyNode.children.length === 1 && CompoundMenuNode.is(nonEmptyNode.children[0])) {
|
|
378
|
-
nonEmptyNode = nonEmptyNode.children[0];
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
return CompoundMenuNode.is(nonEmptyNode) ? nonEmptyNode : fullMenuModel;
|
|
372
|
+
return singleChild || fullMenuModel;
|
|
382
373
|
}
|
|
383
374
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
protected isEmpty(children: ReadonlyArray<MenuNode>): boolean {
|
|
389
|
-
if (children.length === 0) {
|
|
390
|
-
return true;
|
|
391
|
-
}
|
|
392
|
-
if (!this.allChildrenCompound(children)) {
|
|
393
|
-
return false;
|
|
394
|
-
}
|
|
395
|
-
for (const child of children) {
|
|
396
|
-
if (!this.isEmpty(child.children || [])) {
|
|
397
|
-
return false;
|
|
375
|
+
static isEmpty(node: MenuNode): boolean {
|
|
376
|
+
if (CompoundMenuNode.is(node)) {
|
|
377
|
+
if (node.children.length === 0) {
|
|
378
|
+
return true;
|
|
398
379
|
}
|
|
380
|
+
for (const child of node.children) {
|
|
381
|
+
if (!MenuModelRegistry.isEmpty(child)) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
} else {
|
|
386
|
+
return false;
|
|
399
387
|
}
|
|
400
388
|
return true;
|
|
401
389
|
}
|
|
402
390
|
|
|
403
|
-
protected changeEventOnDispose(path: MenuPath, id: string, disposable: Disposable): Disposable {
|
|
404
|
-
return Disposable.create(() => {
|
|
405
|
-
disposable.dispose();
|
|
406
|
-
this.fireChangeEvent({
|
|
407
|
-
path,
|
|
408
|
-
affectedChildId: id,
|
|
409
|
-
kind: ChangeKind.REMOVED
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
|
|
414
391
|
protected fireChangeEvent<T extends MenuChangedEvent>(evt: T): void {
|
|
415
392
|
if (this.isReady) {
|
|
416
393
|
this.onDidChangeEmitter.fire(evt);
|
|
417
394
|
}
|
|
418
395
|
}
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Returns the {@link MenuPath path} at which a given menu node can be accessed from this registry, if it can be determined.
|
|
422
|
-
* Returns `undefined` if the `parent` of any node in the chain is unknown.
|
|
423
|
-
*/
|
|
424
|
-
getPath(node: MenuNode): MenuPath | undefined {
|
|
425
|
-
const identifiers = [];
|
|
426
|
-
const visited: MenuNode[] = [];
|
|
427
|
-
let next: MenuNode | undefined = node;
|
|
428
|
-
|
|
429
|
-
while (next && !visited.includes(next)) {
|
|
430
|
-
if (next === this.root) {
|
|
431
|
-
return identifiers.reverse();
|
|
432
|
-
}
|
|
433
|
-
visited.push(next);
|
|
434
|
-
identifiers.push(next.id);
|
|
435
|
-
next = next.parent;
|
|
436
|
-
}
|
|
437
|
-
return undefined;
|
|
438
|
-
}
|
|
439
396
|
}
|