@theia/core 1.28.0-next.9 → 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 (201) 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/messaging/abstract-connection-provider.d.ts +1 -1
  126. package/lib/common/messaging/abstract-connection-provider.js +3 -3
  127. package/lib/common/quick-pick-service.d.ts +1 -0
  128. package/lib/common/quick-pick-service.d.ts.map +1 -1
  129. package/lib/common/quick-pick-service.js.map +1 -1
  130. package/lib/electron-browser/menu/electron-context-menu-renderer.js +2 -2
  131. package/lib/electron-browser/menu/electron-context-menu-renderer.js.map +1 -1
  132. package/lib/electron-browser/menu/electron-main-menu-factory.d.ts +14 -5
  133. package/lib/electron-browser/menu/electron-main-menu-factory.d.ts.map +1 -1
  134. package/lib/electron-browser/menu/electron-main-menu-factory.js +71 -82
  135. package/lib/electron-browser/menu/electron-main-menu-factory.js.map +1 -1
  136. package/lib/electron-browser/menu/electron-menu-contribution.d.ts.map +1 -1
  137. package/lib/electron-browser/menu/electron-menu-contribution.js +6 -0
  138. package/lib/electron-browser/menu/electron-menu-contribution.js.map +1 -1
  139. package/lib/electron-browser/messaging/electron-ws-connection-provider.js +1 -1
  140. package/lib/electron-browser/window/electron-window-service.js +1 -1
  141. package/lib/electron-browser/window/electron-window-service.js.map +1 -1
  142. package/lib/electron-common/messaging/electron-messages.d.ts +3 -14
  143. package/lib/electron-common/messaging/electron-messages.d.ts.map +1 -1
  144. package/lib/electron-common/messaging/electron-messages.js +3 -16
  145. package/lib/electron-common/messaging/electron-messages.js.map +1 -1
  146. package/lib/electron-main/messaging/electron-messaging-contribution.d.ts +3 -3
  147. package/lib/electron-main/messaging/electron-messaging-contribution.js +6 -6
  148. package/package.json +7 -6
  149. package/src/browser/common-frontend-contribution.ts +6 -5
  150. package/src/browser/context-key-service.ts +1 -1
  151. package/src/browser/context-menu-renderer.ts +5 -0
  152. package/src/browser/frontend-application-module.ts +7 -1
  153. package/src/browser/frontend-application.ts +3 -2
  154. package/src/browser/keybinding.spec.ts +13 -3
  155. package/src/browser/keybinding.ts +8 -9
  156. package/src/browser/menu/browser-context-menu-renderer.ts +2 -2
  157. package/src/browser/menu/browser-menu-plugin.ts +74 -86
  158. package/src/browser/resource-context-key.ts +9 -6
  159. package/src/browser/shell/shell-layout-restorer.ts +2 -1
  160. package/src/browser/shell/side-panel-toolbar.ts +0 -1
  161. package/src/browser/shell/tab-bar-toolbar/index.ts +19 -0
  162. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.ts +31 -0
  163. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-registry.ts +170 -0
  164. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.ts +186 -0
  165. package/src/browser/shell/{tab-bar-toolbar.spec.ts → tab-bar-toolbar/tab-bar-toolbar.spec.ts} +2 -2
  166. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar.tsx +261 -0
  167. package/src/browser/style/alert-messages.css +6 -0
  168. package/src/browser/view-container.ts +1 -10
  169. package/src/browser/widget-manager.spec.ts +14 -0
  170. package/src/browser/widget-manager.ts +2 -1
  171. package/src/browser/window/default-window-service.ts +9 -4
  172. package/src/browser/window/window-service.ts +2 -1
  173. package/src/common/color.ts +3 -0
  174. package/src/common/frontend-application-state.ts +15 -0
  175. package/src/common/menu/action-menu-node.ts +65 -0
  176. package/src/common/menu/composite-menu-node.ts +121 -0
  177. package/src/common/menu/index.ts +21 -0
  178. package/src/common/menu/menu-adapter.ts +103 -0
  179. package/src/common/{menu.ts → menu/menu-model-registry.ts} +61 -222
  180. package/src/common/menu/menu-types.ts +183 -0
  181. package/src/common/{menu.spec.ts → menu/menu.spec.ts} +3 -2
  182. package/src/common/messaging/abstract-connection-provider.ts +4 -4
  183. package/src/common/quick-pick-service.ts +1 -0
  184. package/src/electron-browser/menu/electron-context-menu-renderer.ts +2 -2
  185. package/src/electron-browser/menu/electron-main-menu-factory.ts +82 -96
  186. package/src/electron-browser/menu/electron-menu-contribution.ts +8 -0
  187. package/src/electron-browser/messaging/electron-ws-connection-provider.ts +1 -1
  188. package/src/electron-browser/window/electron-window-service.ts +1 -1
  189. package/src/electron-common/messaging/electron-messages.ts +4 -15
  190. package/src/electron-main/messaging/electron-messaging-contribution.ts +8 -8
  191. package/lib/browser/shell/tab-bar-toolbar.d.ts +0 -186
  192. package/lib/browser/shell/tab-bar-toolbar.d.ts.map +0 -1
  193. package/lib/browser/shell/tab-bar-toolbar.js +0 -362
  194. package/lib/browser/shell/tab-bar-toolbar.js.map +0 -1
  195. package/lib/browser/shell/tab-bar-toolbar.spec.d.ts.map +0 -1
  196. package/lib/browser/shell/tab-bar-toolbar.spec.js.map +0 -1
  197. package/lib/common/menu.d.ts.map +0 -1
  198. package/lib/common/menu.js.map +0 -1
  199. package/lib/common/menu.spec.d.ts.map +0 -1
  200. package/lib/common/menu.spec.js.map +0 -1
  201. package/src/browser/shell/tab-bar-toolbar.tsx +0 -495
@@ -1,495 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 TypeFox 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
- import debounce = require('lodash.debounce');
18
- import * as React from 'react';
19
- import { inject, injectable, named } from 'inversify';
20
- import { Widget, ReactWidget, codicon, ACTION_ITEM } from '../widgets';
21
- import { LabelParser, LabelIcon } from '../label-parser';
22
- import { ContributionProvider } from '../../common/contribution-provider';
23
- import { FrontendApplicationContribution } from '../frontend-application';
24
- import { CommandRegistry } from '../../common/command';
25
- import { Disposable, DisposableCollection } from '../../common/disposable';
26
- import { ContextKeyService } from '../context-key-service';
27
- import { Event, Emitter } from '../../common/event';
28
- import { ContextMenuRenderer, Anchor } from '../context-menu-renderer';
29
- import { MenuModelRegistry } from '../../common/menu';
30
- import { nls } from '../../common/nls';
31
-
32
- /**
33
- * Clients should implement this interface if they want to contribute to the tab-bar toolbar.
34
- */
35
- export const TabBarToolbarContribution = Symbol('TabBarToolbarContribution');
36
- /**
37
- * Representation of a tabbar toolbar contribution.
38
- */
39
- export interface TabBarToolbarContribution {
40
- /**
41
- * Registers toolbar items.
42
- * @param registry the tabbar toolbar registry.
43
- */
44
- registerToolbarItems(registry: TabBarToolbarRegistry): void;
45
- }
46
-
47
- export interface TabBarDelegator extends Widget {
48
- getTabBarDelegate(): Widget | undefined;
49
- }
50
-
51
- export namespace TabBarDelegator {
52
- export const is = (candidate?: Widget): candidate is TabBarDelegator => {
53
- if (candidate) {
54
- const asDelegator = candidate as TabBarDelegator;
55
- return typeof asDelegator.getTabBarDelegate === 'function';
56
- }
57
- return false;
58
- };
59
- }
60
-
61
- /**
62
- * Representation of an item in the tab
63
- */
64
- export interface TabBarToolbarItem {
65
-
66
- /**
67
- * The unique ID of the toolbar item.
68
- */
69
- readonly id: string;
70
-
71
- /**
72
- * The command to execute.
73
- */
74
- readonly command: string;
75
-
76
- /**
77
- * Optional text of the item.
78
- *
79
- * Shamelessly copied and reused from `status-bar`:
80
- *
81
- * More details about the available `fontawesome` icons and CSS class names can be hound [here](http://fontawesome.io/icons/).
82
- * To set a text with icon use the following pattern in text string:
83
- * ```typescript
84
- * $(fontawesomeClassName)
85
- * ```
86
- *
87
- * To use animated icons use the following pattern:
88
- * ```typescript
89
- * $(fontawesomeClassName~typeOfAnimation)
90
- * ````
91
- * The type of animation can be either `spin` or `pulse`.
92
- * Look [here](http://fontawesome.io/examples/#animated) for more information to animated icons.
93
- */
94
- readonly text?: string;
95
-
96
- /**
97
- * Priority among the items. Can be negative. The smaller the number the left-most the item will be placed in the toolbar. It is `0` by default.
98
- */
99
- readonly priority?: number;
100
-
101
- /**
102
- * Optional group for the item. Default `navigation`.
103
- * `navigation` group will be inlined, while all the others will be within the `...` dropdown.
104
- * A group in format `submenu_group_1/submenu 1/.../submenu_group_n/ submenu n/item_group` means that the item will be located in a submenu(s) of the `...` dropdown.
105
- * The submenu's title is named by the submenu section name, e.g. `group/<submenu name>/subgroup`.
106
- */
107
- readonly group?: string;
108
-
109
- /**
110
- * Optional tooltip for the item.
111
- */
112
- readonly tooltip?: string;
113
-
114
- /**
115
- * Optional icon for the item.
116
- */
117
- readonly icon?: string | (() => string);
118
-
119
- /**
120
- * https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts
121
- */
122
- readonly when?: string;
123
-
124
- /**
125
- * When defined, the container tool-bar will be updated if this event is fired.
126
- *
127
- * Note: currently, each item of the container toolbar will be re-rendered if any of the items have changed.
128
- */
129
- readonly onDidChange?: Event<void>;
130
-
131
- }
132
-
133
- /**
134
- * Tab-bar toolbar item backed by a `React.ReactNode`.
135
- * Unlike the `TabBarToolbarItem`, this item is not connected to the command service.
136
- */
137
- export interface ReactTabBarToolbarItem {
138
- readonly id: string;
139
- render(widget?: Widget): React.ReactNode;
140
-
141
- readonly onDidChange?: Event<void>;
142
-
143
- // For the rest, see `TabBarToolbarItem`.
144
- // For conditional visibility.
145
- isVisible?(widget: Widget): boolean;
146
- readonly when?: string;
147
-
148
- // Ordering and grouping.
149
- readonly priority?: number;
150
- /**
151
- * Optional group for the item. Default `navigation`. Always inlined.
152
- */
153
- readonly group?: string;
154
- }
155
-
156
- export namespace TabBarToolbarItem {
157
-
158
- /**
159
- * Compares the items by `priority` in ascending. Undefined priorities will be treated as `0`.
160
- */
161
- export const PRIORITY_COMPARATOR = (left: TabBarToolbarItem, right: TabBarToolbarItem) => {
162
- // The navigation group is special as it will always be sorted to the top/beginning of a menu.
163
- const compareGroup = (leftGroup: string | undefined = 'navigation', rightGroup: string | undefined = 'navigation') => {
164
- if (leftGroup === 'navigation') {
165
- return rightGroup === 'navigation' ? 0 : -1;
166
- }
167
- if (rightGroup === 'navigation') {
168
- return leftGroup === 'navigation' ? 0 : 1;
169
- }
170
- return leftGroup.localeCompare(rightGroup);
171
- };
172
- const result = compareGroup(left.group, right.group);
173
- if (result !== 0) {
174
- return result;
175
- }
176
- return (left.priority || 0) - (right.priority || 0);
177
- };
178
-
179
- export function is(arg: Object | undefined): arg is TabBarToolbarItem {
180
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
181
- return !!arg && 'command' in arg && typeof (arg as any).command === 'string';
182
- }
183
-
184
- }
185
-
186
- /**
187
- * Main, shared registry for tab-bar toolbar items.
188
- */
189
- @injectable()
190
- export class TabBarToolbarRegistry implements FrontendApplicationContribution {
191
-
192
- protected items: Map<string, TabBarToolbarItem | ReactTabBarToolbarItem> = new Map();
193
-
194
- @inject(CommandRegistry)
195
- protected readonly commandRegistry: CommandRegistry;
196
-
197
- @inject(ContextKeyService)
198
- protected readonly contextKeyService: ContextKeyService;
199
-
200
- @inject(ContributionProvider)
201
- @named(TabBarToolbarContribution)
202
- protected readonly contributionProvider: ContributionProvider<TabBarToolbarContribution>;
203
-
204
- protected readonly onDidChangeEmitter = new Emitter<void>();
205
- readonly onDidChange: Event<void> = this.onDidChangeEmitter.event;
206
- // debounce in order to avoid to fire more than once in the same tick
207
- protected fireOnDidChange = debounce(() => this.onDidChangeEmitter.fire(undefined), 0);
208
-
209
- onStart(): void {
210
- const contributions = this.contributionProvider.getContributions();
211
- for (const contribution of contributions) {
212
- contribution.registerToolbarItems(this);
213
- }
214
- }
215
-
216
- /**
217
- * Registers the given item. Throws an error, if the corresponding command cannot be found or an item has been already registered for the desired command.
218
- *
219
- * @param item the item to register.
220
- */
221
- registerItem(item: TabBarToolbarItem | ReactTabBarToolbarItem): Disposable {
222
- const { id } = item;
223
- if (this.items.has(id)) {
224
- throw new Error(`A toolbar item is already registered with the '${id}' ID.`);
225
- }
226
- this.items.set(id, item);
227
- this.fireOnDidChange();
228
- const toDispose = new DisposableCollection(
229
- Disposable.create(() => this.fireOnDidChange()),
230
- Disposable.create(() => this.items.delete(id))
231
- );
232
- if (item.onDidChange) {
233
- toDispose.push(item.onDidChange(() => this.fireOnDidChange()));
234
- }
235
- return toDispose;
236
- }
237
-
238
- /**
239
- * Returns an array of tab-bar toolbar items which are visible when the `widget` argument is the current one.
240
- *
241
- * By default returns with all items where the command is enabled and `item.isVisible` is `true`.
242
- */
243
- visibleItems(widget: Widget): Array<TabBarToolbarItem | ReactTabBarToolbarItem> {
244
- if (widget.isDisposed) {
245
- return [];
246
- }
247
- const result = [];
248
- for (const item of this.items.values()) {
249
- const visible = TabBarToolbarItem.is(item)
250
- ? this.commandRegistry.isVisible(item.command, widget)
251
- : (!item.isVisible || item.isVisible(widget));
252
- if (visible && (!item.when || this.contextKeyService.match(item.when, widget.node))) {
253
- result.push(item);
254
- }
255
- }
256
- return result;
257
- }
258
-
259
- unregisterItem(itemOrId: TabBarToolbarItem | ReactTabBarToolbarItem | string): void {
260
- const id = typeof itemOrId === 'string' ? itemOrId : itemOrId.id;
261
- if (this.items.delete(id)) {
262
- this.fireOnDidChange();
263
- }
264
- }
265
-
266
- }
267
-
268
- /**
269
- * Factory for instantiating tab-bar toolbars.
270
- */
271
- export const TabBarToolbarFactory = Symbol('TabBarToolbarFactory');
272
- export interface TabBarToolbarFactory {
273
- (): TabBarToolbar;
274
- }
275
-
276
- /**
277
- * Tab-bar toolbar widget representing the active [tab-bar toolbar items](TabBarToolbarItem).
278
- */
279
- @injectable()
280
- export class TabBarToolbar extends ReactWidget {
281
-
282
- protected current: Widget | undefined;
283
- protected inline = new Map<string, TabBarToolbarItem | ReactTabBarToolbarItem>();
284
- protected more = new Map<string, TabBarToolbarItem>();
285
-
286
- @inject(CommandRegistry)
287
- protected readonly commands: CommandRegistry;
288
-
289
- @inject(LabelParser)
290
- protected readonly labelParser: LabelParser;
291
-
292
- @inject(MenuModelRegistry)
293
- protected readonly menus: MenuModelRegistry;
294
-
295
- @inject(ContextMenuRenderer)
296
- protected readonly contextMenuRenderer: ContextMenuRenderer;
297
-
298
- @inject(TabBarToolbarRegistry)
299
- protected readonly toolbarRegistry: TabBarToolbarRegistry;
300
-
301
- constructor() {
302
- super();
303
- this.addClass(TabBarToolbar.Styles.TAB_BAR_TOOLBAR);
304
- this.hide();
305
- }
306
-
307
- updateItems(items: Array<TabBarToolbarItem | ReactTabBarToolbarItem>, current: Widget | undefined): void {
308
- this.inline.clear();
309
- this.more.clear();
310
- for (const item of items.sort(TabBarToolbarItem.PRIORITY_COMPARATOR).reverse()) {
311
- if ('render' in item || item.group === undefined || item.group === 'navigation') {
312
- this.inline.set(item.id, item);
313
- } else {
314
- this.more.set(item.id, item);
315
- }
316
- }
317
- this.setCurrent(current);
318
- if (!items.length) {
319
- this.hide();
320
- }
321
- this.onRender.push(Disposable.create(() => {
322
- if (items.length) {
323
- this.show();
324
- }
325
- }));
326
- this.update();
327
- }
328
-
329
- updateTarget(current?: Widget): void {
330
- const operativeWidget = TabBarDelegator.is(current) ? current.getTabBarDelegate() : current;
331
- const items = operativeWidget ? this.toolbarRegistry.visibleItems(operativeWidget) : [];
332
- this.updateItems(items, operativeWidget);
333
- }
334
-
335
- protected readonly toDisposeOnSetCurrent = new DisposableCollection();
336
- protected setCurrent(current: Widget | undefined): void {
337
- this.toDisposeOnSetCurrent.dispose();
338
- this.toDispose.push(this.toDisposeOnSetCurrent);
339
- this.current = current;
340
- if (current) {
341
- const resetCurrent = () => {
342
- this.setCurrent(undefined);
343
- this.update();
344
- };
345
- current.disposed.connect(resetCurrent);
346
- this.toDisposeOnSetCurrent.push(Disposable.create(() =>
347
- current.disposed.disconnect(resetCurrent)
348
- ));
349
- }
350
- }
351
-
352
- protected render(): React.ReactNode {
353
- return <React.Fragment>
354
- {this.renderMore()}
355
- {[...this.inline.values()].map(item => TabBarToolbarItem.is(item) ? this.renderItem(item) : item.render(this.current))}
356
- </React.Fragment>;
357
- }
358
-
359
- protected renderItem(item: TabBarToolbarItem): React.ReactNode {
360
- let innerText = '';
361
- const classNames = [];
362
- if (item.text) {
363
- for (const labelPart of this.labelParser.parse(item.text)) {
364
- if (typeof labelPart !== 'string' && LabelIcon.is(labelPart)) {
365
- const className = `fa fa-${labelPart.name}${labelPart.animation ? ' fa-' + labelPart.animation : ''}`;
366
- classNames.push(...className.split(' '));
367
- } else {
368
- innerText = labelPart;
369
- }
370
- }
371
- }
372
- const command = this.commands.getCommand(item.command);
373
- let iconClass = (typeof item.icon === 'function' && item.icon()) || item.icon as string || (command && command.iconClass);
374
- if (iconClass) {
375
- iconClass += ` ${ACTION_ITEM}`;
376
- classNames.push(iconClass);
377
- }
378
- const tooltip = item.tooltip || (command && command.label);
379
- const toolbarItemClassNames = this.getToolbarItemClassNames(command?.id);
380
- return <div key={item.id}
381
- className={toolbarItemClassNames}
382
- onMouseDown={this.onMouseDownEvent}
383
- onMouseUp={this.onMouseUpEvent}
384
- onMouseOut={this.onMouseUpEvent} >
385
- <div id={item.id} className={classNames.join(' ')}
386
- onClick={this.executeCommand}
387
- title={tooltip}>{innerText}
388
- </div>
389
- </div>;
390
- }
391
-
392
- protected getToolbarItemClassNames(commandId: string | undefined): string {
393
- const classNames = [TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM];
394
- if (commandId) {
395
- if (this.commandIsEnabled(commandId)) {
396
- classNames.push('enabled');
397
- }
398
- if (this.commandIsToggled(commandId)) {
399
- classNames.push('toggled');
400
- }
401
- }
402
- return classNames.join(' ');
403
- }
404
-
405
- protected renderMore(): React.ReactNode {
406
- return !!this.more.size && <div key='__more__' className={TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM + ' enabled'}>
407
- <div id='__more__' className={codicon('ellipsis', true)} onClick={this.showMoreContextMenu}
408
- title={nls.localizeByDefault('More Actions...')} />
409
- </div>;
410
- }
411
-
412
- protected showMoreContextMenu = (event: React.MouseEvent) => {
413
- event.stopPropagation();
414
- event.preventDefault();
415
-
416
- this.renderMoreContextMenu(event.nativeEvent);
417
- };
418
-
419
- /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
420
- renderMoreContextMenu(anchor: Anchor): any {
421
- const menuPath = ['TAB_BAR_TOOLBAR_CONTEXT_MENU'];
422
- const toDisposeOnHide = new DisposableCollection();
423
- this.addClass('menu-open');
424
- toDisposeOnHide.push(Disposable.create(() => this.removeClass('menu-open')));
425
- for (const item of this.more.values()) {
426
- // Register a submenu for the item, if the group is in format `<submenu group>/<submenu name>/.../<item group>`
427
- if (item.group?.includes('/')) {
428
- const split = item.group.split('/');
429
- const paths: string[] = [];
430
- for (let i = 0; i < split.length - 1; i += 2) {
431
- paths.push(split[i], split[i + 1]);
432
- // TODO order is missing, items sorting will be alphabetic
433
- toDisposeOnHide.push(this.menus.registerSubmenu([...menuPath, ...paths], split[i + 1]));
434
- }
435
- }
436
- // TODO order is missing, items sorting will be alphabetic
437
- toDisposeOnHide.push(this.menus.registerMenuAction([...menuPath, ...item.group!.split('/')], {
438
- label: item.tooltip,
439
- commandId: item.command,
440
- when: item.when
441
- }));
442
- }
443
- return this.contextMenuRenderer.render({
444
- menuPath,
445
- args: [this.current],
446
- anchor,
447
- onHide: () => toDisposeOnHide.dispose()
448
- });
449
- }
450
-
451
- shouldHandleMouseEvent(event: MouseEvent): boolean {
452
- return event.target instanceof Element && this.node.contains(event.target);
453
- }
454
-
455
- protected commandIsEnabled(command: string): boolean {
456
- return this.commands.isEnabled(command, this.current);
457
- }
458
-
459
- protected commandIsToggled(command: string): boolean {
460
- return this.commands.isToggled(command, this.current);
461
- }
462
-
463
- protected executeCommand = (e: React.MouseEvent<HTMLElement>) => {
464
- e.preventDefault();
465
- e.stopPropagation();
466
-
467
- const item = this.inline.get(e.currentTarget.id);
468
- if (TabBarToolbarItem.is(item)) {
469
- this.commands.executeCommand(item.command, this.current);
470
- }
471
- this.update();
472
- };
473
-
474
- protected onMouseDownEvent = (e: React.MouseEvent<HTMLElement>) => {
475
- if (e.button === 0) {
476
- e.currentTarget.classList.add('active');
477
- }
478
- };
479
-
480
- protected onMouseUpEvent = (e: React.MouseEvent<HTMLElement>) => {
481
- e.currentTarget.classList.remove('active');
482
- };
483
-
484
- }
485
-
486
- export namespace TabBarToolbar {
487
-
488
- export namespace Styles {
489
-
490
- export const TAB_BAR_TOOLBAR = 'p-TabBar-toolbar';
491
- export const TAB_BAR_TOOLBAR_ITEM = 'item';
492
-
493
- }
494
-
495
- }