@theia/core 1.28.0-next.7 → 1.28.0

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.
Files changed (206) hide show
  1. package/README.md +6 -6
  2. package/i18n/nls.cs.json +33 -2
  3. package/i18n/nls.de.json +33 -2
  4. package/i18n/nls.es.json +33 -2
  5. package/i18n/nls.fr.json +33 -2
  6. package/i18n/nls.hu.json +33 -2
  7. package/i18n/nls.it.json +33 -2
  8. package/i18n/nls.ja.json +33 -2
  9. package/i18n/nls.json +35 -4
  10. package/i18n/nls.pl.json +33 -2
  11. package/i18n/nls.pt-br.json +33 -2
  12. package/i18n/nls.pt-pt.json +33 -2
  13. package/i18n/nls.ru.json +33 -2
  14. package/i18n/nls.zh-cn.json +33 -2
  15. package/lib/browser/common-frontend-contribution.d.ts +1 -1
  16. package/lib/browser/common-frontend-contribution.d.ts.map +1 -1
  17. package/lib/browser/common-frontend-contribution.js +6 -5
  18. package/lib/browser/common-frontend-contribution.js.map +1 -1
  19. package/lib/browser/context-key-service.d.ts +3 -1
  20. package/lib/browser/context-key-service.d.ts.map +1 -1
  21. package/lib/browser/context-menu-renderer.d.ts +5 -0
  22. package/lib/browser/context-menu-renderer.d.ts.map +1 -1
  23. package/lib/browser/frontend-application-module.d.ts.map +1 -1
  24. package/lib/browser/frontend-application-module.js +2 -0
  25. package/lib/browser/frontend-application-module.js.map +1 -1
  26. package/lib/browser/frontend-application.d.ts +3 -2
  27. package/lib/browser/frontend-application.d.ts.map +1 -1
  28. package/lib/browser/frontend-application.js.map +1 -1
  29. package/lib/browser/keybinding.d.ts.map +1 -1
  30. package/lib/browser/keybinding.js +9 -7
  31. package/lib/browser/keybinding.js.map +1 -1
  32. package/lib/browser/keybinding.spec.js +13 -3
  33. package/lib/browser/keybinding.spec.js.map +1 -1
  34. package/lib/browser/menu/browser-context-menu-renderer.d.ts +1 -1
  35. package/lib/browser/menu/browser-context-menu-renderer.d.ts.map +1 -1
  36. package/lib/browser/menu/browser-context-menu-renderer.js +2 -2
  37. package/lib/browser/menu/browser-context-menu-renderer.js.map +1 -1
  38. package/lib/browser/menu/browser-menu-plugin.d.ts +23 -24
  39. package/lib/browser/menu/browser-menu-plugin.d.ts.map +1 -1
  40. package/lib/browser/menu/browser-menu-plugin.js +62 -79
  41. package/lib/browser/menu/browser-menu-plugin.js.map +1 -1
  42. package/lib/browser/resource-context-key.d.ts +1 -0
  43. package/lib/browser/resource-context-key.d.ts.map +1 -1
  44. package/lib/browser/resource-context-key.js +8 -6
  45. package/lib/browser/resource-context-key.js.map +1 -1
  46. package/lib/browser/shell/shell-layout-restorer.d.ts.map +1 -1
  47. package/lib/browser/shell/shell-layout-restorer.js +2 -1
  48. package/lib/browser/shell/shell-layout-restorer.js.map +1 -1
  49. package/lib/browser/shell/side-panel-toolbar.d.ts.map +1 -1
  50. package/lib/browser/shell/side-panel-toolbar.js +0 -1
  51. package/lib/browser/shell/side-panel-toolbar.js.map +1 -1
  52. package/lib/browser/shell/tab-bar-toolbar/index.d.ts +4 -0
  53. package/lib/browser/shell/tab-bar-toolbar/index.d.ts.map +1 -0
  54. package/lib/browser/shell/tab-bar-toolbar/index.js +31 -0
  55. package/lib/browser/shell/tab-bar-toolbar/index.js.map +1 -0
  56. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.d.ts +16 -0
  57. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.d.ts.map +1 -0
  58. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.js +36 -0
  59. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.js.map +1 -0
  60. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-registry.d.ts +51 -0
  61. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-registry.d.ts.map +1 -0
  62. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-registry.js +173 -0
  63. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-registry.js.map +1 -0
  64. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.d.ts +119 -0
  65. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.d.ts.map +1 -0
  66. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.js +67 -0
  67. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.js.map +1 -0
  68. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.d.ts +53 -0
  69. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.d.ts.map +1 -0
  70. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.js +264 -0
  71. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.js.map +1 -0
  72. package/lib/browser/shell/{tab-bar-toolbar.spec.d.ts → tab-bar-toolbar/tab-bar-toolbar.spec.d.ts} +0 -0
  73. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.spec.d.ts.map +1 -0
  74. package/lib/browser/shell/{tab-bar-toolbar.spec.js → tab-bar-toolbar/tab-bar-toolbar.spec.js} +3 -3
  75. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.spec.js.map +1 -0
  76. package/lib/browser/view-container.d.ts.map +1 -1
  77. package/lib/browser/view-container.js +1 -10
  78. package/lib/browser/view-container.js.map +1 -1
  79. package/lib/browser/widget-manager.d.ts.map +1 -1
  80. package/lib/browser/widget-manager.js +2 -1
  81. package/lib/browser/widget-manager.js.map +1 -1
  82. package/lib/browser/widget-manager.spec.js +13 -0
  83. package/lib/browser/widget-manager.spec.js.map +1 -1
  84. package/lib/browser/window/default-window-service.d.ts +2 -1
  85. package/lib/browser/window/default-window-service.d.ts.map +1 -1
  86. package/lib/browser/window/default-window-service.js +9 -4
  87. package/lib/browser/window/default-window-service.js.map +1 -1
  88. package/lib/browser/window/window-service.d.ts +2 -1
  89. package/lib/browser/window/window-service.d.ts.map +1 -1
  90. package/lib/browser/window/window-service.js.map +1 -1
  91. package/lib/common/color.d.ts +3 -0
  92. package/lib/common/color.d.ts.map +1 -1
  93. package/lib/common/frontend-application-state.d.ts +14 -0
  94. package/lib/common/frontend-application-state.d.ts.map +1 -1
  95. package/lib/common/frontend-application-state.js +16 -0
  96. package/lib/common/frontend-application-state.js.map +1 -1
  97. package/lib/common/menu/action-menu-node.d.ts +20 -0
  98. package/lib/common/menu/action-menu-node.d.ts.map +1 -0
  99. package/lib/common/menu/action-menu-node.js +57 -0
  100. package/lib/common/menu/action-menu-node.js.map +1 -0
  101. package/lib/common/menu/composite-menu-node.d.ts +52 -0
  102. package/lib/common/menu/composite-menu-node.d.ts.map +1 -0
  103. package/lib/common/menu/composite-menu-node.js +102 -0
  104. package/lib/common/menu/composite-menu-node.js.map +1 -0
  105. package/lib/common/menu/index.d.ts +6 -0
  106. package/lib/common/menu/index.d.ts.map +1 -0
  107. package/lib/common/menu/index.js +33 -0
  108. package/lib/common/menu/index.js.map +1 -0
  109. package/lib/common/menu/menu-adapter.d.ts +36 -0
  110. package/lib/common/menu/menu-adapter.d.ts.map +1 -0
  111. package/lib/common/menu/menu-adapter.js +101 -0
  112. package/lib/common/menu/menu-adapter.js.map +1 -0
  113. package/lib/common/{menu.d.ts → menu/menu-model-registry.d.ts} +22 -124
  114. package/lib/common/menu/menu-model-registry.d.ts.map +1 -0
  115. package/lib/common/{menu.js → menu/menu-model-registry.js} +71 -147
  116. package/lib/common/menu/menu-model-registry.js.map +1 -0
  117. package/lib/common/menu/menu-types.d.ts +120 -0
  118. package/lib/common/menu/menu-types.d.ts.map +1 -0
  119. package/lib/common/menu/menu-types.js +84 -0
  120. package/lib/common/menu/menu-types.js.map +1 -0
  121. package/lib/common/{menu.spec.d.ts → menu/menu.spec.d.ts} +0 -0
  122. package/lib/common/menu/menu.spec.d.ts.map +1 -0
  123. package/lib/common/{menu.spec.js → menu/menu.spec.js} +3 -3
  124. package/lib/common/menu/menu.spec.js.map +1 -0
  125. package/lib/common/message-rpc/rpc-message-encoder.d.ts +12 -11
  126. package/lib/common/message-rpc/rpc-message-encoder.d.ts.map +1 -1
  127. package/lib/common/message-rpc/rpc-message-encoder.js +21 -12
  128. package/lib/common/message-rpc/rpc-message-encoder.js.map +1 -1
  129. package/lib/common/messaging/abstract-connection-provider.d.ts +1 -1
  130. package/lib/common/messaging/abstract-connection-provider.js +3 -3
  131. package/lib/common/quick-pick-service.d.ts +1 -0
  132. package/lib/common/quick-pick-service.d.ts.map +1 -1
  133. package/lib/common/quick-pick-service.js.map +1 -1
  134. package/lib/electron-browser/menu/electron-context-menu-renderer.js +2 -2
  135. package/lib/electron-browser/menu/electron-context-menu-renderer.js.map +1 -1
  136. package/lib/electron-browser/menu/electron-main-menu-factory.d.ts +14 -5
  137. package/lib/electron-browser/menu/electron-main-menu-factory.d.ts.map +1 -1
  138. package/lib/electron-browser/menu/electron-main-menu-factory.js +71 -82
  139. package/lib/electron-browser/menu/electron-main-menu-factory.js.map +1 -1
  140. package/lib/electron-browser/menu/electron-menu-contribution.d.ts.map +1 -1
  141. package/lib/electron-browser/menu/electron-menu-contribution.js +6 -0
  142. package/lib/electron-browser/menu/electron-menu-contribution.js.map +1 -1
  143. package/lib/electron-browser/messaging/electron-ws-connection-provider.js +1 -1
  144. package/lib/electron-browser/window/electron-window-service.js +1 -1
  145. package/lib/electron-browser/window/electron-window-service.js.map +1 -1
  146. package/lib/electron-common/messaging/electron-messages.d.ts +3 -14
  147. package/lib/electron-common/messaging/electron-messages.d.ts.map +1 -1
  148. package/lib/electron-common/messaging/electron-messages.js +3 -16
  149. package/lib/electron-common/messaging/electron-messages.js.map +1 -1
  150. package/lib/electron-main/messaging/electron-messaging-contribution.d.ts +3 -3
  151. package/lib/electron-main/messaging/electron-messaging-contribution.js +6 -6
  152. package/package.json +7 -6
  153. package/src/browser/common-frontend-contribution.ts +6 -5
  154. package/src/browser/context-key-service.ts +1 -1
  155. package/src/browser/context-menu-renderer.ts +5 -0
  156. package/src/browser/frontend-application-module.ts +7 -1
  157. package/src/browser/frontend-application.ts +3 -2
  158. package/src/browser/keybinding.spec.ts +13 -3
  159. package/src/browser/keybinding.ts +8 -9
  160. package/src/browser/menu/browser-context-menu-renderer.ts +2 -2
  161. package/src/browser/menu/browser-menu-plugin.ts +74 -86
  162. package/src/browser/resource-context-key.ts +9 -6
  163. package/src/browser/shell/shell-layout-restorer.ts +2 -1
  164. package/src/browser/shell/side-panel-toolbar.ts +0 -1
  165. package/src/browser/shell/tab-bar-toolbar/index.ts +19 -0
  166. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.ts +31 -0
  167. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-registry.ts +170 -0
  168. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.ts +186 -0
  169. package/src/browser/shell/{tab-bar-toolbar.spec.ts → tab-bar-toolbar/tab-bar-toolbar.spec.ts} +2 -2
  170. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar.tsx +261 -0
  171. package/src/browser/style/alert-messages.css +6 -0
  172. package/src/browser/view-container.ts +1 -10
  173. package/src/browser/widget-manager.spec.ts +14 -0
  174. package/src/browser/widget-manager.ts +2 -1
  175. package/src/browser/window/default-window-service.ts +9 -4
  176. package/src/browser/window/window-service.ts +2 -1
  177. package/src/common/color.ts +3 -0
  178. package/src/common/frontend-application-state.ts +15 -0
  179. package/src/common/menu/action-menu-node.ts +65 -0
  180. package/src/common/menu/composite-menu-node.ts +121 -0
  181. package/src/common/menu/index.ts +21 -0
  182. package/src/common/menu/menu-adapter.ts +103 -0
  183. package/src/common/{menu.ts → menu/menu-model-registry.ts} +61 -222
  184. package/src/common/menu/menu-types.ts +183 -0
  185. package/src/common/{menu.spec.ts → menu/menu.spec.ts} +3 -2
  186. package/src/common/message-rpc/rpc-message-encoder.ts +24 -13
  187. package/src/common/messaging/abstract-connection-provider.ts +4 -4
  188. package/src/common/quick-pick-service.ts +1 -0
  189. package/src/electron-browser/menu/electron-context-menu-renderer.ts +2 -2
  190. package/src/electron-browser/menu/electron-main-menu-factory.ts +82 -96
  191. package/src/electron-browser/menu/electron-menu-contribution.ts +8 -0
  192. package/src/electron-browser/messaging/electron-ws-connection-provider.ts +1 -1
  193. package/src/electron-browser/window/electron-window-service.ts +1 -1
  194. package/src/electron-common/messaging/electron-messages.ts +4 -15
  195. package/src/electron-main/messaging/electron-messaging-contribution.ts +8 -8
  196. package/lib/browser/shell/tab-bar-toolbar.d.ts +0 -186
  197. package/lib/browser/shell/tab-bar-toolbar.d.ts.map +0 -1
  198. package/lib/browser/shell/tab-bar-toolbar.js +0 -362
  199. package/lib/browser/shell/tab-bar-toolbar.js.map +0 -1
  200. package/lib/browser/shell/tab-bar-toolbar.spec.d.ts.map +0 -1
  201. package/lib/browser/shell/tab-bar-toolbar.spec.js.map +0 -1
  202. package/lib/common/menu.d.ts.map +0 -1
  203. package/lib/common/menu.js.map +0 -1
  204. package/lib/common/menu.spec.d.ts.map +0 -1
  205. package/lib/common/menu.spec.js.map +0 -1
  206. package/src/browser/shell/tab-bar-toolbar.tsx +0 -495
@@ -0,0 +1,183 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /**
18
+ * A menu entry representing an action, e.g. "New File".
19
+ */
20
+ export interface MenuAction extends MenuNodeRenderingData, Pick<MenuNodeMetadata, 'when'> {
21
+ /**
22
+ * The command to execute.
23
+ */
24
+ commandId: string;
25
+ /**
26
+ * In addition to the mandatory command property, an alternative command can be defined.
27
+ * It will be shown and invoked when pressing Alt while opening a menu.
28
+ */
29
+ alt?: string;
30
+ /**
31
+ * Menu entries are sorted in ascending order based on their `order` strings. If omitted the determined
32
+ * label will be used instead.
33
+ */
34
+ order?: string;
35
+ }
36
+
37
+ export namespace MenuAction {
38
+ /* Determine whether object is a MenuAction */
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+ export function is(arg: MenuAction | any): arg is MenuAction {
41
+ return !!arg && arg === Object(arg) && 'commandId' in arg;
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Additional options when creating a new submenu.
47
+ */
48
+ export interface SubMenuOptions extends Pick<MenuAction, 'order'>, Pick<MenuNodeMetadata, 'when'>, Partial<Pick<CompoundMenuNodeMetadata, 'role'>> {
49
+ /**
50
+ * The class to use for the submenu icon.
51
+ */
52
+ iconClass?: string;
53
+ }
54
+
55
+ export type MenuPath = string[];
56
+
57
+ export const MAIN_MENU_BAR: MenuPath = ['menubar'];
58
+
59
+ export const SETTINGS_MENU: MenuPath = ['settings_menu'];
60
+ export const ACCOUNTS_MENU: MenuPath = ['accounts_menu'];
61
+ export const ACCOUNTS_SUBMENU = [...ACCOUNTS_MENU, '1_accounts_submenu'];
62
+
63
+ export interface MenuNodeMetadata {
64
+ /**
65
+ * technical identifier.
66
+ */
67
+ readonly id: string;
68
+ /**
69
+ * Menu nodes are sorted in ascending order based on their `sortString`.
70
+ */
71
+ readonly sortString: string;
72
+ /**
73
+ * Condition under which the menu node should be rendered.
74
+ * See https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts
75
+ */
76
+ readonly when?: string;
77
+ /**
78
+ * A reference to the parent node - useful for determining the menu path by which the node can be accessed.
79
+ */
80
+ readonly parent?: MenuNode;
81
+ }
82
+
83
+ export interface MenuNodeRenderingData {
84
+ /**
85
+ * Optional label. Will be rendered as text of the menu item.
86
+ */
87
+ readonly label?: string;
88
+ /**
89
+ * Icon classes for the menu node. If present, these will produce an icon to the left of the label in browser-style menus.
90
+ */
91
+ readonly icon?: string;
92
+ }
93
+
94
+ export const enum CompoundMenuNodeRole {
95
+ /** Indicates that the node should be rendered as submenu that opens a new menu on hover */
96
+ Submenu,
97
+ /** Indicates that the node's children should be rendered as group separated from other items by a separator */
98
+ Group,
99
+ /** Indicates that the node's children should be treated as though they were direct children of the node's parent */
100
+ Flat,
101
+ }
102
+
103
+ export interface CompoundMenuNode {
104
+ /**
105
+ * Items that are grouped under this menu.
106
+ */
107
+ readonly children: ReadonlyArray<MenuNode>
108
+ }
109
+
110
+ export namespace CompoundMenuNode {
111
+ export function is(node: MenuNode): node is MenuNode & CompoundMenuNode { return Array.isArray(node.children); }
112
+ export function getRole(node: MenuNode): CompoundMenuNodeRole | undefined {
113
+ if (!is(node)) { return undefined; }
114
+ return node.role ?? (node.label ? CompoundMenuNodeRole.Submenu : CompoundMenuNodeRole.Group);
115
+ }
116
+ export function sortChildren(m1: MenuNode, m2: MenuNode): number {
117
+ // The navigation group is special as it will always be sorted to the top/beginning of a menu.
118
+ if (isNavigationGroup(m1)) {
119
+ return -1;
120
+ }
121
+ if (isNavigationGroup(m2)) {
122
+ return 1;
123
+ }
124
+ return m1.sortString.localeCompare(m2.sortString);
125
+ }
126
+
127
+ /** Collapses the children of any subemenus with role {@link CompoundMenuNodeRole Flat} and sorts */
128
+ export function getFlatChildren(children: ReadonlyArray<MenuNode>): MenuNode[] {
129
+ const childrenToMerge: ReadonlyArray<MenuNode>[] = [];
130
+ return children.filter(child => {
131
+ if (getRole(child) === CompoundMenuNodeRole.Flat) {
132
+ childrenToMerge.push((child as CompoundMenuNode).children);
133
+ return false;
134
+ }
135
+ return true;
136
+ }).concat(...childrenToMerge).sort(sortChildren);
137
+ }
138
+
139
+ /**
140
+ * Indicates whether the given node is the special `navigation` menu.
141
+ *
142
+ * @param node the menu node to check.
143
+ * @returns `true` when the given node is a {@link CompoundMenuNode} with id `navigation`,
144
+ * `false` otherwise.
145
+ */
146
+ export function isNavigationGroup(node: MenuNode): node is MenuNode & CompoundMenuNode {
147
+ return is(node) && node.id === 'navigation';
148
+ }
149
+ }
150
+
151
+ export interface CompoundMenuNodeMetadata {
152
+ /**
153
+ * @deprecated @since 1.28 use `role` instead.
154
+ * Whether the item should be rendered as a submenu.
155
+ */
156
+ readonly isSubmenu: boolean;
157
+ /**
158
+ * How the node and its children should be rendered. See {@link CompoundMenuNodeRole}.
159
+ */
160
+ readonly role: CompoundMenuNodeRole;
161
+ }
162
+
163
+ export interface CommandMenuNode {
164
+ command: string;
165
+ }
166
+
167
+ export namespace CommandMenuNode {
168
+ export function is(candidate: MenuNode): candidate is MenuNode & CommandMenuNode { return Boolean(candidate.command); }
169
+ }
170
+
171
+ export interface AlternativeHandlerMenuNode {
172
+ altNode: MenuNodeMetadata & MenuNodeRenderingData & CommandMenuNode;
173
+ }
174
+
175
+ /**
176
+ * Base interface of the nodes used in the menu tree structure.
177
+ */
178
+ export interface MenuNode extends MenuNodeMetadata,
179
+ MenuNodeRenderingData,
180
+ Partial<CompoundMenuNode>,
181
+ Partial<CommandMenuNode>,
182
+ Partial<CompoundMenuNodeMetadata>,
183
+ Partial<AlternativeHandlerMenuNode> { }
@@ -14,9 +14,10 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import { CommandContribution, CommandRegistry } from './command';
18
- import { CompositeMenuNode, MenuContribution, MenuModelRegistry } from './menu';
17
+ import { CommandContribution, CommandRegistry } from '../command';
18
+ import { MenuContribution, MenuModelRegistry } from './menu-model-registry';
19
19
  import * as chai from 'chai';
20
+ import { CompositeMenuNode } from './composite-menu-node';
20
21
 
21
22
  const expect = chai.expect;
22
23
 
@@ -92,17 +92,18 @@ export enum ObjectType {
92
92
  JSON = 0,
93
93
  ByteArray = 1,
94
94
  ObjectArray = 2,
95
- Undefined = 3,
96
- Object = 4,
97
- String = 5,
98
- Boolean = 6,
99
- Number = 7,
95
+ Null = 3,
96
+ Undefined = 4,
97
+ Object = 5,
98
+ String = 6,
99
+ Boolean = 7,
100
+ Number = 8,
100
101
  // eslint-disable-next-line @typescript-eslint/no-shadow
101
- ResponseError = 8,
102
- Error = 9,
103
- Map = 10,
104
- Set = 11,
105
- Function = 12
102
+ ResponseError = 9,
103
+ Error = 10,
104
+ Map = 11,
105
+ Set = 12,
106
+ Function = 13
106
107
 
107
108
  }
108
109
 
@@ -110,7 +111,7 @@ export enum ObjectType {
110
111
  * A value encoder writes javascript values to a write buffer. Encoders will be asked
111
112
  * in turn (ordered by their tag value, descending) whether they can encode a given value
112
113
  * This means encoders with higher tag values have priority. Since the default encoders
113
- * have tag values from 1-12, they can be easily overridden.
114
+ * have tag values from 1-13, they can be easily overridden.
114
115
  */
115
116
  export interface ValueEncoder {
116
117
  /**
@@ -200,6 +201,11 @@ export class RpcMessageDecoder {
200
201
  read: () => undefined
201
202
  });
202
203
 
204
+ this.registerDecoder(ObjectType.Null, {
205
+ // eslint-disable-next-line no-null/no-null
206
+ read: () => null
207
+ });
208
+
203
209
  this.registerDecoder(ObjectType.Object, {
204
210
  read: (buf, recursiveRead) => {
205
211
  const propertyCount = buf.readLength();
@@ -429,9 +435,14 @@ export class RpcMessageEncoder {
429
435
  write: (buf, value: Set<any>, visitedObjects) => this.writeArray(buf, [...value], visitedObjects)
430
436
  });
431
437
 
432
- this.registerEncoder(ObjectType.Undefined, {
438
+ this.registerEncoder(ObjectType.Null, {
433
439
  // eslint-disable-next-line no-null/no-null
434
- is: value => value == null,
440
+ is: value => value === null,
441
+ write: () => { }
442
+ });
443
+
444
+ this.registerEncoder(ObjectType.Undefined, {
445
+ is: value => value === undefined,
435
446
  write: () => { }
436
447
  });
437
448
 
@@ -71,7 +71,7 @@ export abstract class AbstractConnectionProvider<AbstractOptions extends object>
71
71
  return factory.createProxy();
72
72
  }
73
73
 
74
- protected channelMultiPlexer?: ChannelMultiplexer;
74
+ protected channelMultiplexer?: ChannelMultiplexer;
75
75
 
76
76
  // A set of channel opening functions that are executed if the backend reconnects to restore the
77
77
  // the channels that were open before the disconnect occurred.
@@ -80,7 +80,7 @@ export abstract class AbstractConnectionProvider<AbstractOptions extends object>
80
80
  protected initializeMultiplexer(): void {
81
81
  const mainChannel = this.createMainChannel();
82
82
  mainChannel.onMessage(() => this.onIncomingMessageActivityEmitter.fire());
83
- this.channelMultiPlexer = new ChannelMultiplexer(mainChannel);
83
+ this.channelMultiplexer = new ChannelMultiplexer(mainChannel);
84
84
  }
85
85
 
86
86
  /**
@@ -93,10 +93,10 @@ export abstract class AbstractConnectionProvider<AbstractOptions extends object>
93
93
  }
94
94
 
95
95
  async openChannel(path: string, handler: (channel: Channel) => void, options?: AbstractOptions): Promise<void> {
96
- if (!this.channelMultiPlexer) {
96
+ if (!this.channelMultiplexer) {
97
97
  throw new Error('The channel multiplexer has not been initialized yet!');
98
98
  }
99
- const newChannel = await this.channelMultiPlexer.open(path);
99
+ const newChannel = await this.channelMultiplexer.open(path);
100
100
  newChannel.onClose(() => {
101
101
  const { reconnecting } = { reconnecting: true, ...options };
102
102
  if (reconnecting) {
@@ -195,6 +195,7 @@ export interface QuickPick<T extends QuickPickItemOrSeparator> extends QuickInpu
195
195
  }
196
196
 
197
197
  export interface PickOptions<T extends QuickPickItem> {
198
+ title?: string;
198
199
  placeHolder?: string;
199
200
  matchOnDescription?: boolean;
200
201
  matchOnDetail?: boolean;
@@ -101,8 +101,8 @@ export class ElectronContextMenuRenderer extends BrowserContextMenuRenderer {
101
101
 
102
102
  protected override doRender(options: RenderContextMenuOptions): ContextMenuAccess {
103
103
  if (this.useNativeStyle) {
104
- const { menuPath, anchor, args, onHide } = options;
105
- const menu = this.electronMenuFactory.createElectronContextMenu(menuPath, args);
104
+ const { menuPath, anchor, args, onHide, context } = options;
105
+ const menu = this.electronMenuFactory.createElectronContextMenu(menuPath, args, context);
106
106
  const { x, y } = coordinateFromAnchor(anchor);
107
107
  const zoom = electron.webFrame.getZoomFactor();
108
108
  // TODO: Remove the offset once Electron fixes https://github.com/electron/electron/issues/31641
@@ -18,9 +18,7 @@
18
18
 
19
19
  import * as electronRemote from '../../../electron-shared/@electron/remote';
20
20
  import { inject, injectable, postConstruct } from 'inversify';
21
- import {
22
- isOSX, ActionMenuNode, CompositeMenuNode, MAIN_MENU_BAR, MenuPath, MenuNode
23
- } from '../../common';
21
+ import { isOSX, MAIN_MENU_BAR, MenuPath, MenuNode, CommandMenuNode, CompoundMenuNode, CompoundMenuNodeRole } from '../../common';
24
22
  import { Keybinding } from '../../common/keybinding';
25
23
  import { PreferenceService, CommonCommands } from '../../browser';
26
24
  import debounce = require('lodash.debounce');
@@ -36,6 +34,15 @@ export interface ElectronMenuOptions {
36
34
  * Defaults to `true`.
37
35
  */
38
36
  readonly showDisabled?: boolean;
37
+ /**
38
+ * A DOM context to use when evaluating any `when` clauses
39
+ * of menu items registered for this item.
40
+ */
41
+ context?: HTMLElement;
42
+ /**
43
+ * The root menu path for which the menu is being built.
44
+ */
45
+ rootMenuPath: MenuPath
39
46
  }
40
47
 
41
48
  /**
@@ -100,7 +107,7 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
100
107
  const maxWidget = document.getElementsByClassName(MAXIMIZED_CLASS);
101
108
  if (preference === 'visible' || (preference === 'classic' && maxWidget.length === 0)) {
102
109
  const menuModel = this.menuProvider.getMenu(MAIN_MENU_BAR);
103
- const template = this.fillMenuTemplate([], menuModel);
110
+ const template = this.fillMenuTemplate([], menuModel, [], { rootMenuPath: MAIN_MENU_BAR });
104
111
  if (isOSX) {
105
112
  template.unshift(this.createOSXMenu());
106
113
  }
@@ -116,111 +123,90 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
116
123
  return null;
117
124
  }
118
125
 
119
- createElectronContextMenu(menuPath: MenuPath, args?: any[]): Electron.Menu {
126
+ createElectronContextMenu(menuPath: MenuPath, args?: any[], context?: HTMLElement): Electron.Menu {
120
127
  const menuModel = this.menuProvider.getMenu(menuPath);
121
- const template = this.fillMenuTemplate([], menuModel, args, { showDisabled: false });
128
+ const template = this.fillMenuTemplate([], menuModel, args, { showDisabled: false, context, rootMenuPath: menuPath });
122
129
  return electronRemote.Menu.buildFromTemplate(template);
123
130
  }
124
131
 
125
- protected fillMenuTemplate(items: Electron.MenuItemConstructorOptions[],
126
- menuModel: CompositeMenuNode,
127
- args: any[] = [],
128
- options?: ElectronMenuOptions
132
+ protected fillMenuTemplate(parentItems: Electron.MenuItemConstructorOptions[],
133
+ menu: MenuNode,
134
+ args: unknown[] = [],
135
+ options: ElectronMenuOptions
129
136
  ): Electron.MenuItemConstructorOptions[] {
130
- const showDisabled = (options?.showDisabled === undefined) ? true : options?.showDisabled;
131
- for (const menu of menuModel.children) {
132
- if (menu instanceof CompositeMenuNode) {
133
- if (menu.children.length > 0) {
134
- // do not render empty nodes
135
-
136
- if (menu.isSubmenu) { // submenu node
137
-
138
- const submenu = this.fillMenuTemplate([], menu, args, options);
139
- if (submenu.length === 0) {
140
- continue;
141
- }
142
-
143
- items.push({
144
- label: menu.label,
145
- submenu
146
- });
147
-
148
- } else { // group node
149
-
150
- // process children
151
- const submenu = this.fillMenuTemplate([], menu, args, options);
152
- if (submenu.length === 0) {
153
- continue;
154
- }
155
-
156
- if (items.length > 0) {
157
- // do not put a separator above the first group
158
-
159
- items.push({
160
- type: 'separator'
161
- });
162
- }
163
-
164
- // render children
165
- items.push(...submenu);
166
- }
167
- }
168
- } else if (menu instanceof ActionMenuNode) {
169
- const node = menu.altNode && this.context.altPressed ? menu.altNode : menu;
170
- const commandId = node.action.commandId;
171
-
172
- // That is only a sanity check at application startup.
173
- if (!this.commandRegistry.getCommand(commandId)) {
174
- console.debug(`Skipping menu item with missing command: "${commandId}".`);
175
- continue;
137
+ const showDisabled = options?.showDisabled !== false;
138
+
139
+ if (CompoundMenuNode.is(menu) && menu.children.length && this.undefinedOrMatch(menu.when, options.context)) {
140
+ const role = CompoundMenuNode.getRole(menu);
141
+ if (role === CompoundMenuNodeRole.Group && menu.id === 'inline') { return parentItems; }
142
+ const children = CompoundMenuNode.getFlatChildren(menu.children);
143
+ const myItems: Electron.MenuItemConstructorOptions[] = [];
144
+ children.forEach(child => this.fillMenuTemplate(myItems, child, args, options));
145
+ if (myItems.length === 0) { return parentItems; }
146
+ if (role === CompoundMenuNodeRole.Submenu) {
147
+ parentItems.push({ label: menu.label, submenu: myItems });
148
+ } else if (role === CompoundMenuNodeRole.Group && menu.id !== 'inline') {
149
+ if (parentItems.length && parentItems[parentItems.length - 1].type !== 'separator') {
150
+ parentItems.push({ type: 'separator' });
176
151
  }
152
+ parentItems.push(...myItems);
153
+ parentItems.push({ type: 'separator' });
154
+ }
155
+ } else if (menu.command) {
156
+ const node = menu.altNode && this.context.altPressed ? menu.altNode : (menu as MenuNode & CommandMenuNode);
157
+ const commandId = node.command;
158
+
159
+ // That is only a sanity check at application startup.
160
+ if (!this.commandRegistry.getCommand(commandId)) {
161
+ console.debug(`Skipping menu item with missing command: "${commandId}".`);
162
+ return parentItems;
163
+ }
177
164
 
178
- if (!this.commandRegistry.isVisible(commandId, ...args)
179
- || (!!node.action.when && !this.contextKeyService.match(node.action.when))) {
180
- continue;
181
- }
165
+ if (!this.menuCommandExecutor.isVisible(options.rootMenuPath, commandId, ...args) || !this.undefinedOrMatch(node.when, options.context)) {
166
+ return parentItems;
167
+ }
182
168
 
183
- // We should omit rendering context-menu items which are disabled.
184
- if (!showDisabled && !this.commandRegistry.isEnabled(commandId, ...args)) {
185
- continue;
186
- }
169
+ // We should omit rendering context-menu items which are disabled.
170
+ if (!showDisabled && !this.menuCommandExecutor.isEnabled(options.rootMenuPath, commandId, ...args)) {
171
+ return parentItems;
172
+ }
187
173
 
188
- const bindings = this.keybindingRegistry.getKeybindingsForCommand(commandId);
174
+ const bindings = this.keybindingRegistry.getKeybindingsForCommand(commandId);
189
175
 
190
- const accelerator = bindings[0] && this.acceleratorFor(bindings[0]);
176
+ const accelerator = bindings[0] && this.acceleratorFor(bindings[0]);
191
177
 
192
- const menuItem: Electron.MenuItemConstructorOptions = {
193
- id: node.id,
194
- label: node.label,
195
- type: this.commandRegistry.getToggledHandler(commandId, ...args) ? 'checkbox' : 'normal',
196
- checked: this.commandRegistry.isToggled(commandId, ...args),
197
- enabled: true, // https://github.com/eclipse-theia/theia/issues/446
198
- visible: true,
199
- accelerator,
200
- click: () => this.execute(commandId, args)
201
- };
178
+ const menuItem: Electron.MenuItemConstructorOptions = {
179
+ id: node.id,
180
+ label: node.label,
181
+ type: this.commandRegistry.getToggledHandler(commandId, ...args) ? 'checkbox' : 'normal',
182
+ checked: this.commandRegistry.isToggled(commandId, ...args),
183
+ enabled: true, // https://github.com/eclipse-theia/theia/issues/446
184
+ visible: true,
185
+ accelerator,
186
+ click: () => this.execute(commandId, args, options.rootMenuPath)
187
+ };
202
188
 
203
- if (isOSX) {
204
- const role = this.roleFor(node.id);
205
- if (role) {
206
- menuItem.role = role;
207
- delete menuItem.click;
208
- }
189
+ if (isOSX) {
190
+ const role = this.roleFor(node.id);
191
+ if (role) {
192
+ menuItem.role = role;
193
+ delete menuItem.click;
209
194
  }
210
- items.push(menuItem);
195
+ }
196
+ parentItems.push(menuItem);
211
197
 
212
- if (this.commandRegistry.getToggledHandler(commandId, ...args)) {
213
- this._toggledCommands.add(commandId);
214
- }
215
- } else {
216
- items.push(...this.handleElectronDefault(menu, args, options));
198
+ if (this.commandRegistry.getToggledHandler(commandId, ...args)) {
199
+ this._toggledCommands.add(commandId);
217
200
  }
218
201
  }
219
- return items;
202
+ return parentItems;
220
203
  }
221
204
 
222
- protected handleElectronDefault(menuNode: MenuNode, args: any[] = [], options?: ElectronMenuOptions): Electron.MenuItemConstructorOptions[] {
223
- return [];
205
+ protected undefinedOrMatch(expression?: string, context?: HTMLElement): boolean {
206
+ if (expression) {
207
+ return this.contextKeyService.match(expression, context);
208
+ }
209
+ return true;
224
210
  }
225
211
 
226
212
  /**
@@ -268,17 +254,17 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
268
254
  return role;
269
255
  }
270
256
 
271
- protected async execute(command: string, args: any[]): Promise<void> {
257
+ protected async execute(command: string, args: any[], menuPath: MenuPath): Promise<void> {
272
258
  try {
273
259
  // This is workaround for https://github.com/eclipse-theia/theia/issues/446.
274
260
  // Electron menus do not update based on the `isEnabled`, `isVisible` property of the command.
275
261
  // We need to check if we can execute it.
276
- if (this.commandRegistry.isEnabled(command, ...args)) {
277
- await this.commandRegistry.executeCommand(command, ...args);
278
- if (this._menu && this.commandRegistry.isVisible(command, ...args)) {
262
+ if (this.menuCommandExecutor.isEnabled(menuPath, command, ...args)) {
263
+ await this.menuCommandExecutor.executeCommand(menuPath, command, ...args);
264
+ if (this._menu && this.menuCommandExecutor.isVisible(menuPath, command, ...args)) {
279
265
  const item = this._menu.getMenuItemById(command);
280
266
  if (item) {
281
- item.checked = this.commandRegistry.isToggled(command, ...args);
267
+ item.checked = this.menuCommandExecutor.isToggled(menuPath, command, ...args);
282
268
  electronRemote.getCurrentWindow().setMenu(this._menu);
283
269
  }
284
270
  }
@@ -337,6 +337,14 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
337
337
  command: ElectronCommands.ZOOM_IN.id,
338
338
  keybinding: 'ctrlcmd+='
339
339
  },
340
+ {
341
+ command: ElectronCommands.ZOOM_IN.id,
342
+ keybinding: 'ctrlcmd+add'
343
+ },
344
+ {
345
+ command: ElectronCommands.ZOOM_OUT.id,
346
+ keybinding: 'ctrlcmd+subtract'
347
+ },
340
348
  {
341
349
  command: ElectronCommands.ZOOM_OUT.id,
342
350
  keybinding: 'ctrlcmd+-'
@@ -37,7 +37,7 @@ export class ElectronWebSocketConnectionProvider extends WebSocketConnectionProv
37
37
  // Manually close the websocket connections `onStop`. Otherwise, the channels will be closed with 30 sec (`MessagingContribution#checkAliveTimeout`) delay.
38
38
  // https://github.com/eclipse-theia/theia/issues/6499
39
39
  // `1001` indicates that an endpoint is "going away", such as a server going down or a browser having navigated away from a page.
40
- this.channelMultiPlexer?.onUnderlyingChannelClose({ reason: 'The frontend is "going away"', code: 1001 });
40
+ this.channelMultiplexer?.onUnderlyingChannelClose({ reason: 'The frontend is "going away"', code: 1001 });
41
41
  }
42
42
 
43
43
  override async openChannel(path: string, handler: (channel: Channel) => void, options?: WebSocketOptions): Promise<void> {
@@ -72,7 +72,7 @@ export class ElectronWindowService extends DefaultWindowService {
72
72
  * after running FrontendApplication `onWillStop` handlers or on the `cancelChannel` if it is not safe to exit.
73
73
  */
74
74
  protected async handleCloseRequestedEvent(event: CloseRequestArguments): Promise<void> {
75
- const safeToClose = await this.isSafeToShutDown();
75
+ const safeToClose = await this.isSafeToShutDown(event.reason);
76
76
  if (safeToClose) {
77
77
  console.debug(`Shutting down because of ${StopReason[event.reason]} request.`);
78
78
  electron.ipcRenderer.send(event.confirmChannel);
@@ -14,6 +14,10 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
+ import { StopReason } from '../../common/frontend-application-state';
18
+ /** @deprecated @since 1.28 import from common/frontend-application-state instead */
19
+ export { StopReason };
20
+
17
21
  export const RequestTitleBarStyle = 'requestTitleBarStyle';
18
22
  export const TitleBarStyleChanged = 'titleBarStyleChanged';
19
23
  export const TitleBarStyleAtStartup = 'titleBarStyleAtStartup';
@@ -31,21 +35,6 @@ export const RELOAD_REQUESTED_SIGNAL = 'reload-requested';
31
35
  */
32
36
  export const APPLICATION_STATE_CHANGE_SIGNAL = 'application-state-changed';
33
37
 
34
- export enum StopReason {
35
- /**
36
- * Closing the window with no prospect of restart.
37
- */
38
- Close,
39
- /**
40
- * Reload without closing the window.
41
- */
42
- Reload,
43
- /**
44
- * Reload that includes closing the window.
45
- */
46
- Restart, // eslint-disable-line @typescript-eslint/no-shadow
47
- }
48
-
49
38
  export interface CloseRequestArguments {
50
39
  confirmChannel: string;
51
40
  cancelChannel: string;
@@ -44,9 +44,9 @@ export class ElectronMessagingContribution implements ElectronMainApplicationCon
44
44
 
45
45
  protected readonly channelHandlers = new MessagingContribution.ConnectionHandlers<Channel>();
46
46
  /**
47
- * Each electron window has a main chanel and its own multiplexer to route multiple client messages the same IPC connection.
47
+ * Each electron window has a main channel and its own multiplexer to route multiple client messages the same IPC connection.
48
48
  */
49
- protected readonly windowChannelMultiplexer = new Map<number, { channel: ElectronWebContentChannel, multiPlexer: ChannelMultiplexer }>();
49
+ protected readonly windowChannelMultiplexer = new Map<number, { channel: ElectronWebContentChannel, multiplexer: ChannelMultiplexer }>();
50
50
 
51
51
  @postConstruct()
52
52
  protected init(): void {
@@ -67,10 +67,10 @@ export class ElectronMessagingContribution implements ElectronMainApplicationCon
67
67
  }
68
68
 
69
69
  // Creates a new multiplexer for a given sender/window
70
- protected createWindowChannelData(sender: Electron.WebContents): { channel: ElectronWebContentChannel, multiPlexer: ChannelMultiplexer } {
70
+ protected createWindowChannelData(sender: Electron.WebContents): { channel: ElectronWebContentChannel, multiplexer: ChannelMultiplexer } {
71
71
  const mainChannel = this.createWindowMainChannel(sender);
72
- const multiPlexer = new ChannelMultiplexer(mainChannel);
73
- multiPlexer.onDidOpenChannel(openEvent => {
72
+ const multiplexer = new ChannelMultiplexer(mainChannel);
73
+ multiplexer.onDidOpenChannel(openEvent => {
74
74
  const { channel, id } = openEvent;
75
75
  if (this.channelHandlers.route(id, channel)) {
76
76
  console.debug(`Opening channel for service path '${id}'.`);
@@ -78,9 +78,9 @@ export class ElectronMessagingContribution implements ElectronMainApplicationCon
78
78
  }
79
79
  });
80
80
 
81
- sender.once('did-navigate', () => multiPlexer.onUnderlyingChannelClose({ reason: 'Window was refreshed' })); // When refreshing the browser window.
82
- sender.once('destroyed', () => multiPlexer.onUnderlyingChannelClose({ reason: 'Window was closed' })); // When closing the browser window.
83
- const data = { channel: mainChannel, multiPlexer };
81
+ sender.once('did-navigate', () => multiplexer.onUnderlyingChannelClose({ reason: 'Window was refreshed' })); // When refreshing the browser window.
82
+ sender.once('destroyed', () => multiplexer.onUnderlyingChannelClose({ reason: 'Window was closed' })); // When closing the browser window.
83
+ const data = { channel: mainChannel, multiplexer };
84
84
  this.windowChannelMultiplexer.set(sender.id, data);
85
85
  return data;
86
86
  }