@opensumi/ide-main-layout 2.12.1-next-079c1930

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 (80) hide show
  1. package/README.md +296 -0
  2. package/lib/browser/accordion/accordion.service.d.ts +85 -0
  3. package/lib/browser/accordion/accordion.service.d.ts.map +1 -0
  4. package/lib/browser/accordion/accordion.service.js +538 -0
  5. package/lib/browser/accordion/accordion.service.js.map +1 -0
  6. package/lib/browser/accordion/accordion.view.d.ts +19 -0
  7. package/lib/browser/accordion/accordion.view.d.ts.map +1 -0
  8. package/lib/browser/accordion/accordion.view.js +43 -0
  9. package/lib/browser/accordion/accordion.view.js.map +1 -0
  10. package/lib/browser/accordion/section.view.d.ts +24 -0
  11. package/lib/browser/accordion/section.view.d.ts.map +1 -0
  12. package/lib/browser/accordion/section.view.js +58 -0
  13. package/lib/browser/accordion/section.view.js.map +1 -0
  14. package/lib/browser/accordion/styles.module.less +189 -0
  15. package/lib/browser/accordion/titlebar.view.d.ts +6 -0
  16. package/lib/browser/accordion/titlebar.view.d.ts.map +1 -0
  17. package/lib/browser/accordion/titlebar.view.js +13 -0
  18. package/lib/browser/accordion/titlebar.view.js.map +1 -0
  19. package/lib/browser/default-config.d.ts +3 -0
  20. package/lib/browser/default-config.d.ts.map +1 -0
  21. package/lib/browser/default-config.js +32 -0
  22. package/lib/browser/default-config.js.map +1 -0
  23. package/lib/browser/index.d.ts +7 -0
  24. package/lib/browser/index.d.ts.map +1 -0
  25. package/lib/browser/index.js +52 -0
  26. package/lib/browser/index.js.map +1 -0
  27. package/lib/browser/input/index.d.ts +6 -0
  28. package/lib/browser/input/index.d.ts.map +1 -0
  29. package/lib/browser/input/index.js +33 -0
  30. package/lib/browser/input/index.js.map +1 -0
  31. package/lib/browser/layout.service.d.ts +58 -0
  32. package/lib/browser/layout.service.d.ts.map +1 -0
  33. package/lib/browser/layout.service.js +431 -0
  34. package/lib/browser/layout.service.js.map +1 -0
  35. package/lib/browser/main-layout.contribution.d.ts +41 -0
  36. package/lib/browser/main-layout.contribution.d.ts.map +1 -0
  37. package/lib/browser/main-layout.contribution.js +304 -0
  38. package/lib/browser/main-layout.contribution.js.map +1 -0
  39. package/lib/browser/tabbar/bar.view.d.ts +28 -0
  40. package/lib/browser/tabbar/bar.view.d.ts.map +1 -0
  41. package/lib/browser/tabbar/bar.view.js +150 -0
  42. package/lib/browser/tabbar/bar.view.js.map +1 -0
  43. package/lib/browser/tabbar/panel.view.d.ts +16 -0
  44. package/lib/browser/tabbar/panel.view.d.ts.map +1 -0
  45. package/lib/browser/tabbar/panel.view.js +108 -0
  46. package/lib/browser/tabbar/panel.view.js.map +1 -0
  47. package/lib/browser/tabbar/renderer.view.d.ts +34 -0
  48. package/lib/browser/tabbar/renderer.view.d.ts.map +1 -0
  49. package/lib/browser/tabbar/renderer.view.js +64 -0
  50. package/lib/browser/tabbar/renderer.view.js.map +1 -0
  51. package/lib/browser/tabbar/styles.module.less +367 -0
  52. package/lib/browser/tabbar/tabbar.service.d.ts +100 -0
  53. package/lib/browser/tabbar/tabbar.service.d.ts.map +1 -0
  54. package/lib/browser/tabbar/tabbar.service.js +675 -0
  55. package/lib/browser/tabbar/tabbar.service.js.map +1 -0
  56. package/lib/browser/tabbar-handler.d.ts +91 -0
  57. package/lib/browser/tabbar-handler.d.ts.map +1 -0
  58. package/lib/browser/tabbar-handler.js +172 -0
  59. package/lib/browser/tabbar-handler.js.map +1 -0
  60. package/lib/browser/views-registry.d.ts +33 -0
  61. package/lib/browser/views-registry.d.ts.map +1 -0
  62. package/lib/browser/views-registry.js +131 -0
  63. package/lib/browser/views-registry.js.map +1 -0
  64. package/lib/browser/welcome.view.d.ts +11 -0
  65. package/lib/browser/welcome.view.d.ts.map +1 -0
  66. package/lib/browser/welcome.view.js +106 -0
  67. package/lib/browser/welcome.view.js.map +1 -0
  68. package/lib/common/index.d.ts +2 -0
  69. package/lib/common/index.d.ts.map +1 -0
  70. package/lib/common/index.js +5 -0
  71. package/lib/common/index.js.map +1 -0
  72. package/lib/common/main-layout.defination.d.ts +101 -0
  73. package/lib/common/main-layout.defination.d.ts.map +1 -0
  74. package/lib/common/main-layout.defination.js +18 -0
  75. package/lib/common/main-layout.defination.js.map +1 -0
  76. package/lib/index.d.ts +2 -0
  77. package/lib/index.d.ts.map +1 -0
  78. package/lib/index.js +5 -0
  79. package/lib/index.js.map +1 -0
  80. package/package.json +28 -0
@@ -0,0 +1,675 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TabbarService = exports.TabbarServiceFactory = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const ide_core_browser_1 = require("@opensumi/ide-core-browser");
6
+ const di_1 = require("@opensumi/di");
7
+ const mobx_1 = require("mobx");
8
+ const next_1 = require("@opensumi/ide-core-browser/lib/menu/next");
9
+ const main_layout_contribution_1 = require("../main-layout.contribution");
10
+ const debounce = require("lodash.debounce");
11
+ const common_1 = require("../../common");
12
+ const layout_state_1 = require("@opensumi/ide-core-browser/lib/layout/layout-state");
13
+ const progress_1 = require("@opensumi/ide-core-browser/lib/progress");
14
+ exports.TabbarServiceFactory = Symbol('TabbarServiceFactory');
15
+ const CONTAINER_NAME_MAP = {
16
+ left: 'view',
17
+ right: 'extendView',
18
+ bottom: 'panel',
19
+ };
20
+ let TabbarService = class TabbarService extends ide_core_browser_1.WithEventBus {
21
+ constructor(location) {
22
+ super();
23
+ this.location = location;
24
+ this.previousContainerId = '';
25
+ // 由于 observable.map (即使是deep:false) 会把值转换成observableValue,不希望这样
26
+ this.containersMap = new Map();
27
+ this.state = new Map();
28
+ this.storedState = {};
29
+ this.viewReady = new ide_core_browser_1.Deferred();
30
+ // 提供给Mobx强刷
31
+ this.forceUpdate = 0;
32
+ this.accordionRestored = new Set();
33
+ this.onCurrentChangeEmitter = new ide_core_browser_1.Emitter();
34
+ this.onCurrentChange = this.onCurrentChangeEmitter.event;
35
+ this.onSizeChangeEmitter = new ide_core_browser_1.Emitter();
36
+ this.onSizeChange = this.onSizeChangeEmitter.event;
37
+ this.menuId = `tabbar/${this.location}`;
38
+ this.moreMenuId = `tabbar/${this.location}/more`;
39
+ this.isLatter = this.location === ide_core_browser_1.SlotLocation.right || this.location === ide_core_browser_1.SlotLocation.bottom;
40
+ this.sortedContainers = [];
41
+ this.disposableMap = new Map();
42
+ this.tabInMoreKeyMap = new Map();
43
+ this.updatePanel = debounce((show) => {
44
+ if (this.resizeHandle) {
45
+ this.resizeHandle.hidePanel(show);
46
+ }
47
+ }, 60);
48
+ // 针对 containerId 对 menu 进行缓存
49
+ this._menuMap = new Map();
50
+ this.scopedCtxKeyService = this.contextKeyService.createScoped();
51
+ this.scopedCtxKeyService.createKey('triggerWithTab', true);
52
+ this.menuRegistry.registerMenuItem(this.menuId, {
53
+ command: {
54
+ id: this.registerGlobalToggleCommand(),
55
+ label: (0, ide_core_browser_1.localize)('layout.tabbar.hide', '隐藏'),
56
+ },
57
+ group: '0_global',
58
+ when: 'triggerWithTab == true',
59
+ });
60
+ this.activatedKey = this.contextKeyService.createKey((0, ide_core_browser_1.getTabbarCtxKey)(this.location), '');
61
+ if (this.location === 'bottom') {
62
+ this.registerPanelMenus();
63
+ }
64
+ }
65
+ getContainerState(containerId) {
66
+ const viewState = this.state.get(containerId);
67
+ return viewState;
68
+ }
69
+ updatePanelVisibility(show) {
70
+ if (show === undefined) {
71
+ show = this.containersMap.size > 0;
72
+ }
73
+ this.updatePanel(show);
74
+ }
75
+ updateTabInMoreKey(containerId, value) {
76
+ const ctxKey = this.tabInMoreKeyMap.get(containerId);
77
+ if (ctxKey) {
78
+ ctxKey.set(value);
79
+ }
80
+ }
81
+ get visibleContainers() {
82
+ const components = [];
83
+ this.containersMap.forEach((component) => {
84
+ const state = this.state.get(component.options.containerId);
85
+ if (!state || !state.hidden) {
86
+ components.push(component);
87
+ }
88
+ });
89
+ // TODO 使用object来存state的话,初始containersMap为空,貌似就无法实现这个监听(无法引用到一个observable的属性)
90
+ // tslint:disable-next-line:no-unused-variable
91
+ const size = this.state.size; // 监听state长度
92
+ // 排序策略:默认根据priority来做一次排序,后续根据存储的index来排序,未存储过的(新插入的,比如插件)在渲染后(时序控制)始终放在最后
93
+ // 排序为 state的 priority 从小到大 (注意和 componentInfo 中的 options 的 priority的含义不同,为了不breaking change,保留这种语义)
94
+ return components.sort((pre, next) => this.getContainerState(pre.options.containerId).priority - this.getContainerState(next.options.containerId).priority);
95
+ }
96
+ registerResizeHandle(resizeHandle) {
97
+ const { setSize, setRelativeSize, getSize, getRelativeSize, lockSize, setMaxSize, hidePanel } = resizeHandle;
98
+ this.resizeHandle = {
99
+ setSize: (size) => setSize(size, this.isLatter),
100
+ setRelativeSize: (prev, next) => setRelativeSize(prev, next, this.isLatter),
101
+ getSize: () => getSize(this.isLatter),
102
+ getRelativeSize: () => getRelativeSize(this.isLatter),
103
+ setMaxSize: (lock) => setMaxSize(lock, this.isLatter),
104
+ lockSize: (lock) => lockSize(lock, this.isLatter),
105
+ hidePanel: (show) => hidePanel(show),
106
+ };
107
+ this.listenCurrentChange();
108
+ }
109
+ registerContainer(containerId, componentInfo) {
110
+ if (this.containersMap.has(containerId)) {
111
+ return;
112
+ }
113
+ const disposables = new ide_core_browser_1.DisposableCollection();
114
+ let options = componentInfo.options;
115
+ if (!options) {
116
+ options = {
117
+ containerId,
118
+ };
119
+ componentInfo.options = options;
120
+ }
121
+ this.containersMap.set(containerId, {
122
+ views: componentInfo.views,
123
+ options: mobx_1.observable.object(options, undefined, { deep: false }),
124
+ });
125
+ disposables.push({ dispose: () => {
126
+ this.containersMap.delete(containerId);
127
+ this.state.delete(containerId);
128
+ } });
129
+ this.updatePanelVisibility(this.containersMap.size > 0);
130
+ // 需要立刻设置state,lazy 逻辑会导致computed 的 visibleContainers 可能在计算时触发变更,抛出mobx invariant错误
131
+ // 另外由于containersMap不是observable, 这边setState来触发visibaleContainers更新
132
+ // 注册时直接根据priority排序,restoreState时恢复到记录的状态(对于集成侧在onDidStart之后注册的视图,不提供顺序状态恢复能力)
133
+ let insertIndex = this.sortedContainers.findIndex((item) => (item.options.priority || 1) <= (componentInfo.options.priority || 1));
134
+ if (insertIndex === -1) {
135
+ insertIndex = this.sortedContainers.length;
136
+ }
137
+ this.sortedContainers.splice(insertIndex, 0, componentInfo);
138
+ for (let i = insertIndex; i < this.sortedContainers.length; i++) {
139
+ const info = this.sortedContainers[i];
140
+ const prevState = this.getContainerState(containerId) || {}; // 保留原有的hidden状态
141
+ this.state.set(info.options.containerId, { hidden: prevState.hidden, priority: i });
142
+ }
143
+ disposables.push(this.registerSideEffects(componentInfo));
144
+ this.eventBus.fire(new common_1.TabBarRegistrationEvent({ tabBarId: containerId }));
145
+ if (containerId === this.currentContainerId) {
146
+ // 需要重新触发currentChange副作用
147
+ this.handleChange(containerId, '');
148
+ }
149
+ this.viewContextKeyRegistry.registerContextKeyService(containerId, this.contextKeyService.createScoped()).createKey('view', containerId);
150
+ this.disposableMap.set(containerId, disposables);
151
+ }
152
+ registerSideEffects(componentInfo) {
153
+ var _a;
154
+ const disposables = new ide_core_browser_1.DisposableCollection();
155
+ if (!((_a = componentInfo.options) === null || _a === void 0 ? void 0 : _a.hideTab)) {
156
+ // 注册切换tab显隐的菜单
157
+ disposables.push(this.registerHideMenu(componentInfo));
158
+ // 注册溢出后的菜单
159
+ disposables.push(this.registerMoreMenu(componentInfo));
160
+ }
161
+ // 注册激活快捷键
162
+ disposables.push(this.registerActivateKeyBinding(componentInfo, componentInfo.options.fromExtension));
163
+ // 注册视图是否存在的contextKey
164
+ const containerExistKey = this.contextKeyService.createKey(`workbench.${CONTAINER_NAME_MAP[this.location] || 'view'}.${componentInfo.options.containerId}`, true);
165
+ disposables.push({
166
+ dispose: () => {
167
+ containerExistKey.set(false);
168
+ },
169
+ });
170
+ // 注册progressIndicator
171
+ disposables.push(this.progressService.registerProgressIndicator(componentInfo.options.containerId));
172
+ return disposables;
173
+ }
174
+ registerHideMenu(componentInfo) {
175
+ const disposables = new ide_core_browser_1.DisposableCollection();
176
+ disposables.push(this.menuRegistry.registerMenuItem(this.menuId, {
177
+ command: {
178
+ id: this.registerVisibleToggleCommand(componentInfo.options.containerId, disposables),
179
+ label: componentInfo.options.title || '',
180
+ },
181
+ group: '1_widgets',
182
+ }));
183
+ return disposables;
184
+ }
185
+ registerMoreMenu(componentInfo) {
186
+ const disposables = new ide_core_browser_1.DisposableCollection();
187
+ const containerId = componentInfo.options.containerId;
188
+ const tabInMoreKey = this.scopedCtxKeyService.createKey(this.getTabInMoreCtxKey(containerId), false);
189
+ this.tabInMoreKeyMap.set(containerId, tabInMoreKey);
190
+ disposables.push({
191
+ dispose: () => this.tabInMoreKeyMap.delete(containerId),
192
+ });
193
+ disposables.push(this.menuRegistry.registerMenuItem(this.moreMenuId, {
194
+ command: {
195
+ id: this.registerMoreToggleCommand(componentInfo, disposables),
196
+ label: componentInfo.options.title || containerId,
197
+ },
198
+ group: 'inline',
199
+ when: `${this.getTabInMoreCtxKey(containerId)} == true`,
200
+ toggledWhen: `${(0, ide_core_browser_1.getTabbarCtxKey)(this.location)} == ${containerId}`,
201
+ iconClass: componentInfo.options.iconClass,
202
+ }));
203
+ return disposables;
204
+ }
205
+ disposeContainer(containerId) {
206
+ const disposables = this.disposableMap.get(containerId);
207
+ if (disposables) {
208
+ disposables.dispose();
209
+ }
210
+ if (this.currentContainerId === containerId) {
211
+ this.currentContainerId = this.visibleContainers[0].options.containerId;
212
+ }
213
+ }
214
+ getContainer(containerId) {
215
+ return this.containersMap.get(containerId);
216
+ }
217
+ getTitleToolbarMenu(containerId) {
218
+ const existedMenu = this._menuMap.get(containerId);
219
+ if (existedMenu) {
220
+ return existedMenu;
221
+ }
222
+ const menu = this.menuService.createMenu(next_1.MenuId.ViewTitle, this.viewContextKeyRegistry.getContextKeyService(containerId));
223
+ this._menuMap.set(containerId, menu);
224
+ // 添加到 containerId 对应的 disposable 中
225
+ // 在 containerId 对应的 view dispose 时会将 menu 对象和缓存清理掉
226
+ const disposables = this.disposableMap.get(containerId);
227
+ const toDispose = [
228
+ menu,
229
+ (0, ide_core_browser_1.toDisposable)(() => {
230
+ this._menuMap.delete(containerId);
231
+ }),
232
+ ];
233
+ if (disposables) {
234
+ disposables.pushAll(toDispose);
235
+ }
236
+ else {
237
+ // 避免出现不必要的内存泄露
238
+ this.addDispose(toDispose);
239
+ }
240
+ return menu;
241
+ }
242
+ doExpand(expand) {
243
+ const { setRelativeSize } = this.resizeHandle;
244
+ if (expand) {
245
+ if (!this.isLatter) {
246
+ setRelativeSize(1, 0);
247
+ }
248
+ else {
249
+ setRelativeSize(0, 1);
250
+ }
251
+ }
252
+ else {
253
+ // FIXME 底部需要额外的字段记录展开前的尺寸
254
+ setRelativeSize(2, 1);
255
+ }
256
+ }
257
+ get isExpanded() {
258
+ const { getRelativeSize } = this.resizeHandle;
259
+ const relativeSizes = getRelativeSize().join(',');
260
+ return this.isLatter ? relativeSizes === '0,1' : relativeSizes === '1,0';
261
+ }
262
+ handleTabClick(e, forbidCollapse) {
263
+ const containerId = e.currentTarget.id;
264
+ if (containerId === this.currentContainerId && !forbidCollapse) {
265
+ this.currentContainerId = '';
266
+ }
267
+ else {
268
+ this.currentContainerId = containerId;
269
+ }
270
+ }
271
+ handleContextMenu(event, containerId) {
272
+ event.preventDefault();
273
+ event.stopPropagation();
274
+ const menus = this.menuService.createMenu(this.menuId, containerId ? this.scopedCtxKeyService : this.contextKeyService);
275
+ const menuNodes = (0, next_1.generateCtxMenu)({ menus, args: [{ containerId }] });
276
+ this.contextMenuRenderer.show({ menuNodes: menuNodes[1], anchor: {
277
+ x: event.clientX,
278
+ y: event.clientY,
279
+ } });
280
+ }
281
+ showMoreMenu(event, lastContainerId) {
282
+ const menus = this.menuService.createMenu(this.moreMenuId, this.scopedCtxKeyService);
283
+ const menuNodes = (0, next_1.generateCtxMenu)({ menus, args: [{ lastContainerId }] });
284
+ this.contextMenuRenderer.show({ menuNodes: menuNodes[1], anchor: {
285
+ x: event.clientX,
286
+ y: event.clientY,
287
+ } });
288
+ }
289
+ // drag & drop
290
+ handleDragStart(e, containerId) {
291
+ e.dataTransfer.setData('containerId', containerId);
292
+ }
293
+ handleDrop(e, target) {
294
+ if (e.dataTransfer.getData('containerId')) {
295
+ const source = e.dataTransfer.getData('containerId');
296
+ const containers = this.visibleContainers;
297
+ const sourceIndex = containers.findIndex((containerInfo) => source === containerInfo.options.containerId);
298
+ const targetIndex = containers.findIndex((containerInfo) => target === containerInfo.options.containerId);
299
+ this.doInsertTab(containers, sourceIndex, targetIndex);
300
+ this.storeState();
301
+ }
302
+ }
303
+ restoreState() {
304
+ this.storedState = this.layoutState.getState(layout_state_1.LAYOUT_STATE.getTabbarSpace(this.location), {});
305
+ for (const containerId of this.state.keys()) {
306
+ if (this.storedState[containerId]) {
307
+ this.state.set(containerId, this.storedState[containerId]);
308
+ }
309
+ }
310
+ this.visibleContainers.forEach((container) => {
311
+ if (common_1.SUPPORT_ACCORDION_LOCATION.has(this.location)) {
312
+ this.tryRestoreAccordionSize(container.options.containerId);
313
+ }
314
+ });
315
+ }
316
+ doInsertTab(containers, sourceIndex, targetIndex) {
317
+ const targetPriority = this.getContainerState(containers[targetIndex].options.containerId).priority;
318
+ const changePriority = (sourceIndex, targetIndex) => {
319
+ const sourceState = this.getContainerState(containers[sourceIndex].options.containerId);
320
+ const targetState = this.getContainerState(containers[targetIndex].options.containerId);
321
+ sourceState.priority = targetState.priority;
322
+ };
323
+ let index;
324
+ if (sourceIndex > targetIndex) {
325
+ // 后往前拖,中间的tab依次下移
326
+ for (index = targetIndex; index < sourceIndex; index++) {
327
+ changePriority(index, index + 1);
328
+ }
329
+ }
330
+ else {
331
+ // 前往后拖,中间的上移
332
+ for (index = targetIndex; index > sourceIndex; index--) {
333
+ changePriority(index, index - 1);
334
+ }
335
+ }
336
+ this.getContainerState(containers[index].options.containerId).priority = targetPriority;
337
+ }
338
+ storeState() {
339
+ const stateObj = {};
340
+ this.state.forEach((value, key) => {
341
+ stateObj[key] = value;
342
+ });
343
+ this.layoutState.setState(layout_state_1.LAYOUT_STATE.getTabbarSpace(this.location), stateObj);
344
+ }
345
+ // 注册Tab的激活快捷键,对于底部panel,为切换快捷键
346
+ registerActivateKeyBinding(component, fromExtension) {
347
+ const options = component.options;
348
+ const containerId = options.containerId;
349
+ // vscode内插件注册的是workbench.view.extension.containerId
350
+ const activateCommandId = fromExtension ? `workbench.view.extension.${containerId}` : `workbench.view.${containerId}`;
351
+ const disposables = new ide_core_browser_1.DisposableCollection();
352
+ disposables.push(this.commandRegistry.registerCommand({
353
+ id: activateCommandId,
354
+ }, {
355
+ execute: ({ forceShow } = {}) => {
356
+ // 支持toggle
357
+ if (this.location === 'bottom' && !forceShow) {
358
+ this.currentContainerId = this.currentContainerId === containerId ? '' : containerId;
359
+ }
360
+ else {
361
+ this.currentContainerId = containerId;
362
+ }
363
+ },
364
+ }));
365
+ if (options.activateKeyBinding) {
366
+ disposables.push(this.keybindingRegistry.registerKeybinding({
367
+ command: activateCommandId,
368
+ keybinding: options.activateKeyBinding,
369
+ }));
370
+ }
371
+ return disposables;
372
+ }
373
+ registerGlobalToggleCommand() {
374
+ const commandId = `activity.bar.toggle.${this.location}`;
375
+ this.commandRegistry.registerCommand({
376
+ id: commandId,
377
+ }, {
378
+ execute: ({ containerId }) => {
379
+ this.doToggleTab(containerId);
380
+ },
381
+ isEnabled: () => {
382
+ return this.visibleContainers.length > 1;
383
+ },
384
+ });
385
+ return commandId;
386
+ }
387
+ // 注册tab的隐藏显示功能
388
+ registerVisibleToggleCommand(containerId, disposables) {
389
+ const commandId = `activity.bar.toggle.${containerId}`;
390
+ disposables.push(this.commandRegistry.registerCommand({
391
+ id: commandId,
392
+ }, {
393
+ execute: ({ forceShow } = {}) => {
394
+ this.doToggleTab(containerId, forceShow);
395
+ },
396
+ isToggled: () => {
397
+ const state = this.getContainerState(containerId);
398
+ return !state.hidden;
399
+ },
400
+ isEnabled: () => {
401
+ const state = this.getContainerState(containerId);
402
+ return state.hidden || this.visibleContainers.length !== 1;
403
+ },
404
+ }));
405
+ return commandId;
406
+ }
407
+ registerMoreToggleCommand(component, disposables) {
408
+ const { options } = component;
409
+ const { containerId } = options;
410
+ const commandId = `activity.bar.activate.more.${containerId}`;
411
+ disposables.push(this.commandRegistry.registerCommand({
412
+ id: commandId,
413
+ }, {
414
+ execute: ({ lastContainerId }) => {
415
+ // 切换激活tab
416
+ this.currentContainerId = containerId;
417
+ if (lastContainerId) {
418
+ // 替换最后一个可见tab
419
+ const sourceState = this.getContainerState(containerId);
420
+ const targetState = this.getContainerState(lastContainerId);
421
+ const sourcePriority = sourceState.priority;
422
+ sourceState.priority = targetState.priority;
423
+ targetState.priority = sourcePriority;
424
+ this.storeState();
425
+ }
426
+ },
427
+ }));
428
+ return commandId;
429
+ }
430
+ getTabInMoreCtxKey(containerId) {
431
+ return `${containerId}.isInMore`;
432
+ }
433
+ registerPanelMenus() {
434
+ this.menuRegistry.registerMenuItems('tabbar/bottom/common', [
435
+ {
436
+ command: main_layout_contribution_1.EXPAND_BOTTOM_PANEL.id,
437
+ group: 'navigation',
438
+ when: '!bottomFullExpanded',
439
+ order: 1,
440
+ },
441
+ {
442
+ command: main_layout_contribution_1.RETRACT_BOTTOM_PANEL.id,
443
+ group: 'navigation',
444
+ when: 'bottomFullExpanded',
445
+ order: 1,
446
+ },
447
+ {
448
+ command: main_layout_contribution_1.TOGGLE_BOTTOM_PANEL_COMMAND.id,
449
+ group: 'navigation',
450
+ order: 2,
451
+ },
452
+ ]);
453
+ this.commonTitleMenu = this.ctxmenuService.createMenu({
454
+ id: 'tabbar/bottom/common',
455
+ });
456
+ }
457
+ doToggleTab(containerId, forceShow) {
458
+ const state = this.getContainerState(containerId);
459
+ if (forceShow === undefined) {
460
+ state.hidden = !state.hidden;
461
+ }
462
+ else {
463
+ state.hidden = !forceShow;
464
+ }
465
+ if (state.hidden) {
466
+ if (this.currentContainerId === containerId) {
467
+ this.currentContainerId = this.visibleContainers[0].options.containerId;
468
+ }
469
+ }
470
+ this.storeState();
471
+ }
472
+ shouldExpand(containerId) {
473
+ const info = this.getContainer(containerId);
474
+ return info && info.options && info.options.expanded;
475
+ }
476
+ onResize(e) {
477
+ if (e.payload.slotLocation === this.location) {
478
+ if (!this.currentContainerId || !this.resizeHandle) {
479
+ // 折叠时不监听变化
480
+ return;
481
+ }
482
+ const size = this.resizeHandle.getSize();
483
+ if (size !== this.barSize && !this.shouldExpand(this.currentContainerId)) {
484
+ this.prevSize = size;
485
+ this.onSizeChangeEmitter.fire({ size });
486
+ }
487
+ }
488
+ }
489
+ listenCurrentChange() {
490
+ (0, mobx_1.observe)(this, 'currentContainerId', (change) => {
491
+ if (this.prevSize === undefined) {
492
+ }
493
+ this.previousContainerId = change.oldValue || '';
494
+ const currentId = change.newValue;
495
+ this.handleChange(currentId, this.previousContainerId);
496
+ });
497
+ }
498
+ handleChange(currentId, previousId) {
499
+ const { getSize, setSize, lockSize } = this.resizeHandle;
500
+ this.onCurrentChangeEmitter.fire({ previousId, currentId });
501
+ const isCurrentExpanded = this.shouldExpand(currentId);
502
+ if (this.shouldExpand(this.previousContainerId) || isCurrentExpanded) {
503
+ this.handleFullExpanded(currentId, isCurrentExpanded);
504
+ }
505
+ else {
506
+ if (currentId) {
507
+ if (previousId && currentId !== previousId) {
508
+ this.prevSize = getSize();
509
+ }
510
+ setSize(this.prevSize || (this.panelSize + this.barSize));
511
+ const containerInfo = this.getContainer(currentId);
512
+ if (containerInfo && containerInfo.options.noResize) {
513
+ lockSize(true);
514
+ }
515
+ else {
516
+ lockSize(false);
517
+ }
518
+ this.activatedKey.set(currentId);
519
+ }
520
+ else {
521
+ setSize(this.barSize);
522
+ lockSize(true);
523
+ }
524
+ }
525
+ }
526
+ tryRestoreAccordionSize(containerId) {
527
+ var _a;
528
+ if (this.accordionRestored.has(containerId)) {
529
+ return;
530
+ }
531
+ const containerInfo = this.containersMap.get(containerId);
532
+ // 使用自定义视图取代手风琴的面板不需要 restore
533
+ // scm 视图例外,因为在新版本 Gitlens 中可以将自己注册到 scm 中
534
+ // 暂时用这种方式使 scm 面板状态可以被持久化
535
+ if ((!containerInfo || containerInfo.options.component) &&
536
+ ((_a = containerInfo === null || containerInfo === void 0 ? void 0 : containerInfo.options) === null || _a === void 0 ? void 0 : _a.containerId) !== 'scm') {
537
+ return;
538
+ }
539
+ const accordionService = this.layoutService.getAccordionService(containerId);
540
+ // 需要保证此时tab切换已完成dom渲染
541
+ accordionService.restoreState();
542
+ this.accordionRestored.add(containerId);
543
+ }
544
+ handleFullExpanded(currentId, isCurrentExpanded) {
545
+ const { setRelativeSize, setSize } = this.resizeHandle;
546
+ if (currentId) {
547
+ if (isCurrentExpanded) {
548
+ if (!this.isLatter) {
549
+ setRelativeSize(1, 0);
550
+ }
551
+ else {
552
+ setRelativeSize(0, 1);
553
+ }
554
+ }
555
+ else {
556
+ setSize(this.prevSize || (this.panelSize + this.barSize));
557
+ }
558
+ }
559
+ else {
560
+ setSize(this.barSize);
561
+ }
562
+ }
563
+ };
564
+ (0, tslib_1.__decorate)([
565
+ mobx_1.observable,
566
+ (0, tslib_1.__metadata)("design:type", String)
567
+ ], TabbarService.prototype, "currentContainerId", void 0);
568
+ (0, tslib_1.__decorate)([
569
+ mobx_1.observable,
570
+ (0, tslib_1.__metadata)("design:type", Map)
571
+ ], TabbarService.prototype, "state", void 0);
572
+ (0, tslib_1.__decorate)([
573
+ (0, di_1.Autowired)(next_1.AbstractMenuService),
574
+ (0, tslib_1.__metadata)("design:type", next_1.AbstractMenuService)
575
+ ], TabbarService.prototype, "menuService", void 0);
576
+ (0, tslib_1.__decorate)([
577
+ (0, di_1.Autowired)(next_1.AbstractContextMenuService),
578
+ (0, tslib_1.__metadata)("design:type", next_1.AbstractContextMenuService)
579
+ ], TabbarService.prototype, "ctxmenuService", void 0);
580
+ (0, tslib_1.__decorate)([
581
+ (0, di_1.Autowired)(next_1.IMenuRegistry),
582
+ (0, tslib_1.__metadata)("design:type", next_1.IMenuRegistry)
583
+ ], TabbarService.prototype, "menuRegistry", void 0);
584
+ (0, tslib_1.__decorate)([
585
+ (0, di_1.Autowired)(ide_core_browser_1.CommandRegistry),
586
+ (0, tslib_1.__metadata)("design:type", Object)
587
+ ], TabbarService.prototype, "commandRegistry", void 0);
588
+ (0, tslib_1.__decorate)([
589
+ (0, di_1.Autowired)(next_1.ICtxMenuRenderer),
590
+ (0, tslib_1.__metadata)("design:type", next_1.ICtxMenuRenderer)
591
+ ], TabbarService.prototype, "contextMenuRenderer", void 0);
592
+ (0, tslib_1.__decorate)([
593
+ (0, di_1.Autowired)(ide_core_browser_1.KeybindingRegistry),
594
+ (0, tslib_1.__metadata)("design:type", Object)
595
+ ], TabbarService.prototype, "keybindingRegistry", void 0);
596
+ (0, tslib_1.__decorate)([
597
+ (0, di_1.Autowired)(),
598
+ (0, tslib_1.__metadata)("design:type", ide_core_browser_1.ViewContextKeyRegistry)
599
+ ], TabbarService.prototype, "viewContextKeyRegistry", void 0);
600
+ (0, tslib_1.__decorate)([
601
+ (0, di_1.Autowired)(ide_core_browser_1.IContextKeyService),
602
+ (0, tslib_1.__metadata)("design:type", Object)
603
+ ], TabbarService.prototype, "contextKeyService", void 0);
604
+ (0, tslib_1.__decorate)([
605
+ (0, di_1.Autowired)(common_1.IMainLayoutService),
606
+ (0, tslib_1.__metadata)("design:type", Object)
607
+ ], TabbarService.prototype, "layoutService", void 0);
608
+ (0, tslib_1.__decorate)([
609
+ (0, di_1.Autowired)(),
610
+ (0, tslib_1.__metadata)("design:type", layout_state_1.LayoutState)
611
+ ], TabbarService.prototype, "layoutState", void 0);
612
+ (0, tslib_1.__decorate)([
613
+ (0, di_1.Autowired)(progress_1.IProgressService),
614
+ (0, tslib_1.__metadata)("design:type", Object)
615
+ ], TabbarService.prototype, "progressService", void 0);
616
+ (0, tslib_1.__decorate)([
617
+ mobx_1.observable,
618
+ (0, tslib_1.__metadata)("design:type", Number)
619
+ ], TabbarService.prototype, "forceUpdate", void 0);
620
+ (0, tslib_1.__decorate)([
621
+ (0, mobx_1.computed)({ equals: visibleContainerEquals }),
622
+ (0, tslib_1.__metadata)("design:type", Object),
623
+ (0, tslib_1.__metadata)("design:paramtypes", [])
624
+ ], TabbarService.prototype, "visibleContainers", null);
625
+ (0, tslib_1.__decorate)([
626
+ mobx_1.action,
627
+ (0, tslib_1.__metadata)("design:type", Function),
628
+ (0, tslib_1.__metadata)("design:paramtypes", [String, Object]),
629
+ (0, tslib_1.__metadata)("design:returntype", void 0)
630
+ ], TabbarService.prototype, "registerContainer", null);
631
+ (0, tslib_1.__decorate)([
632
+ mobx_1.action,
633
+ (0, tslib_1.__metadata)("design:type", Function),
634
+ (0, tslib_1.__metadata)("design:paramtypes", [String]),
635
+ (0, tslib_1.__metadata)("design:returntype", void 0)
636
+ ], TabbarService.prototype, "disposeContainer", null);
637
+ (0, tslib_1.__decorate)([
638
+ mobx_1.action.bound,
639
+ (0, tslib_1.__metadata)("design:type", Function),
640
+ (0, tslib_1.__metadata)("design:paramtypes", [Object, Boolean]),
641
+ (0, tslib_1.__metadata)("design:returntype", void 0)
642
+ ], TabbarService.prototype, "handleTabClick", null);
643
+ (0, tslib_1.__decorate)([
644
+ mobx_1.action.bound,
645
+ (0, tslib_1.__metadata)("design:type", Function),
646
+ (0, tslib_1.__metadata)("design:paramtypes", [Object, String]),
647
+ (0, tslib_1.__metadata)("design:returntype", void 0)
648
+ ], TabbarService.prototype, "handleContextMenu", null);
649
+ (0, tslib_1.__decorate)([
650
+ (0, ide_core_browser_1.OnEvent)(ide_core_browser_1.ResizeEvent),
651
+ (0, tslib_1.__metadata)("design:type", Function),
652
+ (0, tslib_1.__metadata)("design:paramtypes", [ide_core_browser_1.ResizeEvent]),
653
+ (0, tslib_1.__metadata)("design:returntype", void 0)
654
+ ], TabbarService.prototype, "onResize", null);
655
+ TabbarService = (0, tslib_1.__decorate)([
656
+ (0, di_1.Injectable)({ multiple: true }),
657
+ (0, tslib_1.__metadata)("design:paramtypes", [String])
658
+ ], TabbarService);
659
+ exports.TabbarService = TabbarService;
660
+ function visibleContainerEquals(a, b) {
661
+ if (a.length !== b.length) {
662
+ return false;
663
+ }
664
+ else {
665
+ let isEqual = true;
666
+ for (let i = 0; i < a.length; i++) {
667
+ if (a[i] !== b[i]) {
668
+ isEqual = false;
669
+ break;
670
+ }
671
+ }
672
+ return isEqual;
673
+ }
674
+ }
675
+ //# sourceMappingURL=tabbar.service.js.map