@theia/core 1.77.0-next.66 → 1.77.0-next.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/catalog.json +6 -0
- package/lib/browser/common-commands.d.ts +3 -0
- package/lib/browser/common-commands.d.ts.map +1 -1
- package/lib/browser/common-commands.js +15 -0
- package/lib/browser/common-commands.js.map +1 -1
- package/lib/browser/common-frontend-contribution.d.ts +2 -0
- package/lib/browser/common-frontend-contribution.d.ts.map +1 -1
- package/lib/browser/common-frontend-contribution.js +27 -0
- package/lib/browser/common-frontend-contribution.js.map +1 -1
- package/lib/browser/frontend-application-module.d.ts.map +1 -1
- package/lib/browser/frontend-application-module.js +3 -0
- package/lib/browser/frontend-application-module.js.map +1 -1
- package/lib/browser/shell/index.d.ts +1 -0
- package/lib/browser/shell/index.d.ts.map +1 -1
- package/lib/browser/shell/index.js +1 -0
- package/lib/browser/shell/index.js.map +1 -1
- package/lib/browser/shell/shell-layout-restorer.d.ts +2 -0
- package/lib/browser/shell/shell-layout-restorer.d.ts.map +1 -1
- package/lib/browser/shell/shell-layout-restorer.js +6 -0
- package/lib/browser/shell/shell-layout-restorer.js.map +1 -1
- package/lib/browser/shell/shell-layout-restorer.spec.js +7 -0
- package/lib/browser/shell/shell-layout-restorer.spec.js.map +1 -1
- package/lib/browser/shell/side-panel-handler.d.ts +12 -1
- package/lib/browser/shell/side-panel-handler.d.ts.map +1 -1
- package/lib/browser/shell/side-panel-handler.js +73 -0
- package/lib/browser/shell/side-panel-handler.js.map +1 -1
- package/lib/browser/shell/side-panel-handler.spec.d.ts +2 -0
- package/lib/browser/shell/side-panel-handler.spec.d.ts.map +1 -0
- package/lib/browser/shell/side-panel-handler.spec.js +85 -0
- package/lib/browser/shell/side-panel-handler.spec.js.map +1 -0
- package/lib/browser/shell/side-panel-item-visibility.d.ts +55 -0
- package/lib/browser/shell/side-panel-item-visibility.d.ts.map +1 -0
- package/lib/browser/shell/side-panel-item-visibility.js +100 -0
- package/lib/browser/shell/side-panel-item-visibility.js.map +1 -0
- package/lib/browser/shell/side-panel-item-visibility.spec.d.ts +2 -0
- package/lib/browser/shell/side-panel-item-visibility.spec.d.ts.map +1 -0
- package/lib/browser/shell/side-panel-item-visibility.spec.js +80 -0
- package/lib/browser/shell/side-panel-item-visibility.spec.js.map +1 -0
- package/lib/browser/shell/tab-bars.d.ts +17 -0
- package/lib/browser/shell/tab-bars.d.ts.map +1 -1
- package/lib/browser/shell/tab-bars.js +31 -14
- package/lib/browser/shell/tab-bars.js.map +1 -1
- package/lib/browser/shell/tab-bars.spec.js +86 -0
- package/lib/browser/shell/tab-bars.spec.js.map +1 -1
- package/package.json +4 -4
- package/src/browser/common-commands.ts +15 -0
- package/src/browser/common-frontend-contribution.ts +29 -1
- package/src/browser/frontend-application-module.ts +3 -0
- package/src/browser/shell/index.ts +1 -0
- package/src/browser/shell/shell-layout-restorer.spec.ts +10 -0
- package/src/browser/shell/shell-layout-restorer.ts +5 -0
- package/src/browser/shell/side-panel-handler.spec.ts +94 -0
- package/src/browser/shell/side-panel-handler.ts +75 -1
- package/src/browser/shell/side-panel-item-visibility.spec.ts +91 -0
- package/src/browser/shell/side-panel-item-visibility.ts +115 -0
- package/src/browser/shell/tab-bars.spec.ts +96 -1
- package/src/browser/shell/tab-bars.ts +36 -13
|
@@ -19,6 +19,7 @@ import { Widget } from '@lumino/widgets';
|
|
|
19
19
|
import { FrontendApplication } from '../frontend-application';
|
|
20
20
|
import { WidgetManager, WidgetConstructionOptions } from '../widget-manager';
|
|
21
21
|
import { StorageService } from '../storage-service';
|
|
22
|
+
import { SidePanelItemVisibility } from './side-panel-item-visibility';
|
|
22
23
|
import { ILogger } from '../../common/logger';
|
|
23
24
|
import { CommandContribution, CommandRegistry, Command } from '../../common/command';
|
|
24
25
|
import { ThemeService } from '../theming';
|
|
@@ -152,6 +153,9 @@ export class ShellLayoutRestorer implements CommandContribution {
|
|
|
152
153
|
@inject(PerspectiveServiceInternal)
|
|
153
154
|
protected readonly perspectiveService: PerspectiveServiceInternal;
|
|
154
155
|
|
|
156
|
+
@inject(SidePanelItemVisibility)
|
|
157
|
+
protected readonly sidePanelItemVisibility: SidePanelItemVisibility;
|
|
158
|
+
|
|
155
159
|
constructor(
|
|
156
160
|
@inject(WidgetManager) protected widgetManager: WidgetManager,
|
|
157
161
|
@inject(ILogger) @named('core:ShellLayoutRestorer')
|
|
@@ -172,6 +176,7 @@ export class ShellLayoutRestorer implements CommandContribution {
|
|
|
172
176
|
this.perspectiveService.clearSavedLayouts();
|
|
173
177
|
this.storageService.setData(PERSPECTIVE_LAYOUTS_STORAGE_KEY, undefined);
|
|
174
178
|
this.themeService.reset();
|
|
179
|
+
this.sidePanelItemVisibility.reset();
|
|
175
180
|
this.logger.info('<<< The layout has been successfully reset.');
|
|
176
181
|
this.windowService.reload();
|
|
177
182
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 JuliaHub 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { enableJSDOM } from '../test/jsdom';
|
|
18
|
+
let disableJSDOM = enableJSDOM();
|
|
19
|
+
|
|
20
|
+
import { expect } from 'chai';
|
|
21
|
+
import { Title, Widget } from '@lumino/widgets';
|
|
22
|
+
import { SidePanelHandler } from './side-panel-handler';
|
|
23
|
+
import { CommandMenu, CompoundMenuNode } from '../../common/menu';
|
|
24
|
+
import { RenderContextMenuOptions } from '../context-menu-renderer';
|
|
25
|
+
disableJSDOM();
|
|
26
|
+
|
|
27
|
+
describe('SidePanelHandler', () => {
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
disableJSDOM = enableJSDOM();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
disableJSDOM();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function createHandler(ids: string[]): { titles: Title<Widget>[], hidden: Set<string>, openItemsMenu(): CommandMenu[] } {
|
|
38
|
+
const titles = ids.map(id => {
|
|
39
|
+
const widget = new Widget();
|
|
40
|
+
widget.id = id;
|
|
41
|
+
widget.title.label = id;
|
|
42
|
+
return widget.title;
|
|
43
|
+
});
|
|
44
|
+
const hidden = new Set<string>();
|
|
45
|
+
let menu: CompoundMenuNode | undefined;
|
|
46
|
+
const handler = Object.create(SidePanelHandler.prototype) as SidePanelHandler;
|
|
47
|
+
Object.assign(handler, {
|
|
48
|
+
side: 'left',
|
|
49
|
+
tabBar: {
|
|
50
|
+
titles,
|
|
51
|
+
node: document.createElement('div'),
|
|
52
|
+
canHideTitle: (title: Title<Widget>) => !hidden.has(title.owner.id) && titles.some(other => other !== title && !hidden.has(other.owner.id))
|
|
53
|
+
},
|
|
54
|
+
itemVisibility: {
|
|
55
|
+
isHidden: (id: string) => hidden.has(id),
|
|
56
|
+
setHidden: (id: string, value: boolean) => value ? hidden.add(id) : hidden.delete(id)
|
|
57
|
+
},
|
|
58
|
+
contextMenuRenderer: {
|
|
59
|
+
render: (options: RenderContextMenuOptions) => {
|
|
60
|
+
menu = options.menu;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
titles,
|
|
66
|
+
hidden,
|
|
67
|
+
openItemsMenu: () => {
|
|
68
|
+
handler['showItemsContextMenu'](new MouseEvent('contextmenu'));
|
|
69
|
+
return (menu?.children ?? []).filter(CommandMenu.is);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
it('lists every item as a checked toggle that hides it when run', async () => {
|
|
75
|
+
const { hidden, openItemsMenu } = createHandler(['explorer', 'search']);
|
|
76
|
+
|
|
77
|
+
const [explorer, search] = openItemsMenu();
|
|
78
|
+
expect([explorer.label, search.label]).to.deep.equal(['explorer', 'search']);
|
|
79
|
+
expect(search.isToggled([])).to.be.true;
|
|
80
|
+
|
|
81
|
+
await search.run([]);
|
|
82
|
+
expect(hidden.has('search')).to.be.true;
|
|
83
|
+
expect(search.isToggled([])).to.be.false;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('disables the toggle of the last visible item', () => {
|
|
87
|
+
const { hidden, openItemsMenu } = createHandler(['explorer', 'search']);
|
|
88
|
+
hidden.add('search');
|
|
89
|
+
|
|
90
|
+
const [explorer, search] = openItemsMenu();
|
|
91
|
+
expect(explorer.isEnabled([])).to.be.false;
|
|
92
|
+
expect(search.isEnabled([])).to.be.true;
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -30,11 +30,12 @@ import { SidePanelToolbar } from './side-panel-toolbar';
|
|
|
30
30
|
import { TabBarToolbarRegistry, TabBarToolbarFactory, TabBarToolbar } from './tab-bar-toolbar';
|
|
31
31
|
import { DisposableCollection, Disposable } from '../../common/disposable';
|
|
32
32
|
import { ContextMenuRenderer } from '../context-menu-renderer';
|
|
33
|
-
import { MenuPath } from '../../common/menu';
|
|
33
|
+
import { CommandMenu, GroupImpl, MenuPath } from '../../common/menu';
|
|
34
34
|
import { SidebarBottomMenuWidget } from './sidebar-bottom-menu-widget';
|
|
35
35
|
import { SidebarTopMenuWidget } from './sidebar-top-menu-widget';
|
|
36
36
|
import { PINNED_CLASS } from '../widgets';
|
|
37
37
|
import { AdditionalViewsMenuWidget, AdditionalViewsMenuWidgetFactory } from './additional-views-menu-widget';
|
|
38
|
+
import { SidePanelItemVisibility } from './side-panel-item-visibility';
|
|
38
39
|
|
|
39
40
|
/** The class name added to the left and right area panels. */
|
|
40
41
|
export const LEFT_RIGHT_AREA_CLASS = 'theia-app-sides';
|
|
@@ -132,6 +133,9 @@ export class SidePanelHandler {
|
|
|
132
133
|
@inject(ContextMenuRenderer)
|
|
133
134
|
protected readonly contextMenuRenderer: ContextMenuRenderer;
|
|
134
135
|
|
|
136
|
+
@inject(SidePanelItemVisibility)
|
|
137
|
+
protected readonly itemVisibility: SidePanelItemVisibility;
|
|
138
|
+
|
|
135
139
|
/**
|
|
136
140
|
* Create the side bar and dock panel widgets.
|
|
137
141
|
*/
|
|
@@ -184,6 +188,13 @@ export class SidePanelHandler {
|
|
|
184
188
|
sideBar.currentChanged.connect(this.onCurrentTabChanged, this);
|
|
185
189
|
sideBar.tabDetachRequested.connect(this.onTabDetachRequested, this);
|
|
186
190
|
sideBar.tabsOverflowChanged.connect(this.onTabsOverflowChanged, this);
|
|
191
|
+
sideBar.shouldHideTitle = title => this.itemVisibility.isHidden(title.owner.id);
|
|
192
|
+
sideBar.node.addEventListener('contextmenu', e => this.showItemsContextMenu(e));
|
|
193
|
+
this.itemVisibility.onDidChange(widgetId => this.onItemVisibilityChanged(widgetId));
|
|
194
|
+
// A reset or the stored choices loading only change what renders: the current item stays current
|
|
195
|
+
// even when it turns out hidden, the same as opening a hidden item.
|
|
196
|
+
this.itemVisibility.onDidReset(() => sideBar.update());
|
|
197
|
+
this.itemVisibility.ready.then(() => sideBar.update());
|
|
187
198
|
return sideBar;
|
|
188
199
|
}
|
|
189
200
|
|
|
@@ -245,6 +256,69 @@ export class SidePanelHandler {
|
|
|
245
256
|
});
|
|
246
257
|
}
|
|
247
258
|
|
|
259
|
+
protected onItemVisibilityChanged(widgetId: string): void {
|
|
260
|
+
const current = this.tabBar.currentTitle;
|
|
261
|
+
if (current?.owner.id === widgetId && this.itemVisibility.isHidden(widgetId)) {
|
|
262
|
+
this.moveOffHiddenItem(current);
|
|
263
|
+
}
|
|
264
|
+
this.tabBar.update();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Makes the next item that is not hidden current, else the previous one, or collapses the panel
|
|
269
|
+
* if there is none.
|
|
270
|
+
*/
|
|
271
|
+
protected moveOffHiddenItem(title: Title<Widget>): void {
|
|
272
|
+
const titles = this.tabBar.titles;
|
|
273
|
+
const index = titles.indexOf(title);
|
|
274
|
+
const isShown = (other: Title<Widget>) => !this.itemVisibility.isHidden(other.owner.id);
|
|
275
|
+
const next = titles.slice(index + 1).find(isShown) ?? titles.slice(0, index).reverse().find(isShown);
|
|
276
|
+
if (next) {
|
|
277
|
+
this.tabBar.currentTitle = next;
|
|
278
|
+
} else {
|
|
279
|
+
this.collapse();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
protected showItemsContextMenu(e: MouseEvent): void {
|
|
284
|
+
if (this.tabBar.titles.length === 0) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
e.stopPropagation();
|
|
288
|
+
e.preventDefault();
|
|
289
|
+
const menu = new GroupImpl('sidePanelItems');
|
|
290
|
+
menu.addNode(...this.tabBar.titles.map((title, index) => this.createItemMenuNode(title, index)));
|
|
291
|
+
this.contextMenuRenderer.render({
|
|
292
|
+
menu,
|
|
293
|
+
menuPath: ['side-panel-items'],
|
|
294
|
+
anchor: e,
|
|
295
|
+
context: this.tabBar.node
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
protected createItemMenuNode(title: Title<Widget>, index: number): CommandMenu {
|
|
300
|
+
const widgetId = title.owner.id;
|
|
301
|
+
return {
|
|
302
|
+
id: widgetId,
|
|
303
|
+
label: title.label || title.caption,
|
|
304
|
+
sortString: index.toString().padStart(4, '0'),
|
|
305
|
+
isVisible: () => true,
|
|
306
|
+
isEnabled: () => this.itemVisibility.isHidden(widgetId) || this.tabBar.canHideTitle(title),
|
|
307
|
+
isToggled: () => !this.itemVisibility.isHidden(widgetId),
|
|
308
|
+
run: async () => this.toggleItem(title)
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
protected toggleItem(title: Title<Widget>): void {
|
|
313
|
+
const id = title.owner.id;
|
|
314
|
+
if (this.itemVisibility.isHidden(id)) {
|
|
315
|
+
this.itemVisibility.setHidden(id, false);
|
|
316
|
+
this.activate(id);
|
|
317
|
+
} else {
|
|
318
|
+
this.itemVisibility.setHidden(id, true);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
248
322
|
protected createContainer(): Panel {
|
|
249
323
|
const contentBox = new BoxLayout({ direction: 'top-to-bottom', spacing: 0 });
|
|
250
324
|
BoxPanel.setStretch(this.toolBar, 0);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 JuliaHub 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import { Container, injectable } from 'inversify';
|
|
19
|
+
import { LocalStorageService } from '../storage-service';
|
|
20
|
+
import { MockStorageService } from '../test/mock-storage-service';
|
|
21
|
+
import { SidePanelItemVisibilityImpl } from './side-panel-item-visibility';
|
|
22
|
+
|
|
23
|
+
const STORAGE_KEY = SidePanelItemVisibilityImpl.STORAGE_KEY;
|
|
24
|
+
|
|
25
|
+
@injectable()
|
|
26
|
+
class DebugHiddenByDefault extends SidePanelItemVisibilityImpl {
|
|
27
|
+
protected override isHiddenByDefault(widgetId: string): boolean {
|
|
28
|
+
return widgetId === 'debug';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('SidePanelItemVisibility', () => {
|
|
33
|
+
|
|
34
|
+
let storage: MockStorageService;
|
|
35
|
+
|
|
36
|
+
async function create(implementation: typeof SidePanelItemVisibilityImpl = SidePanelItemVisibilityImpl): Promise<SidePanelItemVisibilityImpl> {
|
|
37
|
+
const container = new Container();
|
|
38
|
+
container.bind(LocalStorageService).toConstantValue(storage as unknown as LocalStorageService);
|
|
39
|
+
container.bind(implementation).toSelf();
|
|
40
|
+
const visibility = container.get(implementation);
|
|
41
|
+
await visibility.ready;
|
|
42
|
+
return visibility;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
storage = new MockStorageService();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('shows items by default', async () => {
|
|
50
|
+
const visibility = await create();
|
|
51
|
+
expect(visibility.isHidden('explorer-view-container')).to.be.false;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('persists only explicit choices and restores them', async () => {
|
|
55
|
+
const visibility = await create();
|
|
56
|
+
const changed: string[] = [];
|
|
57
|
+
visibility.onDidChange(id => changed.push(id));
|
|
58
|
+
|
|
59
|
+
visibility.setHidden('explorer-view-container', true);
|
|
60
|
+
visibility.setHidden('explorer-view-container', true);
|
|
61
|
+
|
|
62
|
+
expect(changed).to.deep.equal(['explorer-view-container']);
|
|
63
|
+
expect(storage.data.get(STORAGE_KEY)).to.deep.equal({ 'explorer-view-container': true });
|
|
64
|
+
expect((await create()).isHidden('explorer-view-container')).to.be.true;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('lets an explicit choice override the default', async () => {
|
|
68
|
+
const visibility = await create(DebugHiddenByDefault);
|
|
69
|
+
expect(visibility.isHidden('debug')).to.be.true;
|
|
70
|
+
|
|
71
|
+
visibility.setHidden('debug', false);
|
|
72
|
+
|
|
73
|
+
expect(visibility.isHidden('debug')).to.be.false;
|
|
74
|
+
expect(storage.data.get(STORAGE_KEY)).to.deep.equal({ debug: false });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('falls back to the defaults on reset and clears storage', async () => {
|
|
78
|
+
const visibility = await create(DebugHiddenByDefault);
|
|
79
|
+
visibility.setHidden('debug', false);
|
|
80
|
+
visibility.setHidden('scm-view-container', true);
|
|
81
|
+
let resets = 0;
|
|
82
|
+
visibility.onDidReset(() => resets++);
|
|
83
|
+
|
|
84
|
+
visibility.reset();
|
|
85
|
+
|
|
86
|
+
expect(visibility.isHidden('debug')).to.be.true;
|
|
87
|
+
expect(visibility.isHidden('scm-view-container')).to.be.false;
|
|
88
|
+
expect(storage.data.get(STORAGE_KEY)).to.be.undefined;
|
|
89
|
+
expect(resets).to.equal(1);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 JuliaHub 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { inject, injectable, postConstruct } from 'inversify';
|
|
18
|
+
import { Emitter, Event } from '../../common/event';
|
|
19
|
+
import { Deferred } from '../../common/promise-util';
|
|
20
|
+
import { LocalStorageService } from '../storage-service';
|
|
21
|
+
|
|
22
|
+
export const SidePanelItemVisibility = Symbol('SidePanelItemVisibility');
|
|
23
|
+
/**
|
|
24
|
+
* Tracks which side panel items are hidden from the side bar. A hidden item keeps its widget
|
|
25
|
+
* attached: its view still opens through commands and its tab shows while it is the current one.
|
|
26
|
+
* Items are identified by the id of the widget that owns the tab.
|
|
27
|
+
*/
|
|
28
|
+
export interface SidePanelItemVisibility {
|
|
29
|
+
/** Fires with the id of the widget whose hidden state the user changed. */
|
|
30
|
+
readonly onDidChange: Event<string>;
|
|
31
|
+
/** Fires when the user's choices are discarded and every item falls back to its default. */
|
|
32
|
+
readonly onDidReset: Event<void>;
|
|
33
|
+
/** Resolves once the user's stored choices are loaded; until then every item has its default state. */
|
|
34
|
+
readonly ready: Promise<void>;
|
|
35
|
+
isHidden(widgetId: string): boolean;
|
|
36
|
+
setHidden(widgetId: string, hidden: boolean): void;
|
|
37
|
+
/** Discards the user's choices so every item falls back to its default. */
|
|
38
|
+
reset(): void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* To keep the user's choices somewhere other than local storage, override `load()` and `save()`
|
|
43
|
+
* rather than rebinding `LocalStorageService`, which every other consumer of it shares.
|
|
44
|
+
*/
|
|
45
|
+
@injectable()
|
|
46
|
+
export class SidePanelItemVisibilityImpl implements SidePanelItemVisibility {
|
|
47
|
+
|
|
48
|
+
static readonly STORAGE_KEY = 'sidePanel.hiddenItems';
|
|
49
|
+
|
|
50
|
+
/** Hidden items hold across workspaces, and `@theia/workspace` scopes the bound `StorageService` per workspace. */
|
|
51
|
+
@inject(LocalStorageService)
|
|
52
|
+
protected readonly storageService: LocalStorageService;
|
|
53
|
+
|
|
54
|
+
protected readonly onDidChangeEmitter = new Emitter<string>();
|
|
55
|
+
readonly onDidChange = this.onDidChangeEmitter.event;
|
|
56
|
+
|
|
57
|
+
protected readonly onDidResetEmitter = new Emitter<void>();
|
|
58
|
+
readonly onDidReset = this.onDidResetEmitter.event;
|
|
59
|
+
|
|
60
|
+
protected readonly loaded = new Deferred<void>();
|
|
61
|
+
readonly ready = this.loaded.promise;
|
|
62
|
+
|
|
63
|
+
/** Explicit user choices only, so items the user never touched follow `isHiddenByDefault`. */
|
|
64
|
+
protected overrides: Record<string, boolean> = {};
|
|
65
|
+
|
|
66
|
+
@postConstruct()
|
|
67
|
+
protected init(): void {
|
|
68
|
+
this.load().finally(() => this.loaded.resolve());
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
protected async load(): Promise<void> {
|
|
72
|
+
const stored = await this.storageService.getData<Record<string, boolean>>(SidePanelItemVisibilityImpl.STORAGE_KEY);
|
|
73
|
+
this.overrides = { ...stored, ...this.overrides };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
isHidden(widgetId: string): boolean {
|
|
77
|
+
return this.overrides[widgetId] ?? this.isHiddenByDefault(widgetId);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
setHidden(widgetId: string, hidden: boolean): void {
|
|
81
|
+
if (this.isHidden(widgetId) === hidden) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.overrides[widgetId] = hidden;
|
|
85
|
+
this.save();
|
|
86
|
+
this.onDidChangeEmitter.fire(widgetId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
reset(): void {
|
|
90
|
+
if (Object.keys(this.overrides).length === 0) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.overrides = {};
|
|
94
|
+
this.save();
|
|
95
|
+
this.onDidResetEmitter.fire();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Whether an item the user has neither hidden nor shown starts hidden. Override this to
|
|
100
|
+
* give an application its own defaults.
|
|
101
|
+
*
|
|
102
|
+
* Defaults are not limited to leaving one item visible per side the way the user's choices are,
|
|
103
|
+
* so an application can start every item on a side hidden. Expanding a side panel without naming
|
|
104
|
+
* a view can still open a hidden item, through the last active index or the first tab, and its
|
|
105
|
+
* tab then shows while it is current, the same as opening it by command.
|
|
106
|
+
*/
|
|
107
|
+
protected isHiddenByDefault(widgetId: string): boolean {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
protected save(): void {
|
|
112
|
+
const data = Object.keys(this.overrides).length > 0 ? this.overrides : undefined;
|
|
113
|
+
this.storageService.setData(SidePanelItemVisibilityImpl.STORAGE_KEY, data);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -19,7 +19,7 @@ let disableJSDOM = enableJSDOM();
|
|
|
19
19
|
import { expect } from 'chai';
|
|
20
20
|
|
|
21
21
|
import { Title, Widget } from '@lumino/widgets';
|
|
22
|
-
import { TabBarRenderer } from './tab-bars';
|
|
22
|
+
import { SideTabBar, TabBarRenderer } from './tab-bars';
|
|
23
23
|
|
|
24
24
|
disableJSDOM();
|
|
25
25
|
|
|
@@ -60,4 +60,99 @@ describe('tab bar', () => {
|
|
|
60
60
|
expect(pathMap.get(tabPaths[5])).to.be.equal('.../ccc');
|
|
61
61
|
expect(pathMap.get(tabPaths[6])).to.be.equal(undefined);
|
|
62
62
|
});
|
|
63
|
+
|
|
64
|
+
describe('side tab bar', () => {
|
|
65
|
+
|
|
66
|
+
class TestSideTabBar extends SideTabBar {
|
|
67
|
+
render(): void {
|
|
68
|
+
this.renderTabs(this.contentNode);
|
|
69
|
+
}
|
|
70
|
+
renderedClasses(): string[] {
|
|
71
|
+
return Array.from(this.contentNode.children, tab => tab.className);
|
|
72
|
+
}
|
|
73
|
+
overflowFrom(startIndex: number): void {
|
|
74
|
+
this.hideOverflowingTabs = () => startIndex;
|
|
75
|
+
this.computeOverflowingTabsData();
|
|
76
|
+
}
|
|
77
|
+
firstOverflowingIndex(): number {
|
|
78
|
+
return this.hideOverflowingTabs();
|
|
79
|
+
}
|
|
80
|
+
setOverflowData(): void {
|
|
81
|
+
this.tabsOverflowData = { titles: [], startIndex: 0 };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function createSideTabBar(hiddenIds: string[]): { bar: TestSideTabBar, titles: Title<Widget>[] } {
|
|
86
|
+
const renderer = new TabBarRenderer();
|
|
87
|
+
const bar = new TestSideTabBar({ orientation: 'vertical', renderer });
|
|
88
|
+
const titles = ['explorer', 'debug', 'search'].map(id => {
|
|
89
|
+
const owner = new Widget();
|
|
90
|
+
owner.id = id;
|
|
91
|
+
owner.title.label = id;
|
|
92
|
+
return bar.addTab(owner.title);
|
|
93
|
+
});
|
|
94
|
+
bar.shouldHideTitle = title => hiddenIds.includes(title.owner.id);
|
|
95
|
+
return { bar, titles };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
it('keeps a hidden tab in the DOM at its title index, hidden unless it is current', () => {
|
|
99
|
+
const { bar, titles } = createSideTabBar(['debug']);
|
|
100
|
+
|
|
101
|
+
bar.currentTitle = titles[0];
|
|
102
|
+
bar.render();
|
|
103
|
+
expect(bar.renderedClasses().map(c => c.includes('lm-mod-hidden'))).to.deep.equal([false, true, false]);
|
|
104
|
+
|
|
105
|
+
bar.currentTitle = titles[1];
|
|
106
|
+
bar.render();
|
|
107
|
+
expect(bar.renderedClasses().map(c => c.includes('lm-mod-hidden'))).to.deep.equal([false, false, false]);
|
|
108
|
+
expect(bar.isHiddenTab(titles[1])).to.be.false;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('refuses to hide the last title that is not hidden', () => {
|
|
112
|
+
const { bar, titles } = createSideTabBar(['debug', 'search']);
|
|
113
|
+
expect(bar.canHideTitle(titles[0])).to.be.false;
|
|
114
|
+
expect(bar.canHideTitle(titles[1])).to.be.false;
|
|
115
|
+
bar.shouldHideTitle = title => title.owner.id === 'debug';
|
|
116
|
+
expect(bar.canHideTitle(titles[0])).to.be.true;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('leaves hidden tabs out of the overflow menu', () => {
|
|
120
|
+
const { bar, titles } = createSideTabBar(['debug']);
|
|
121
|
+
bar.currentTitle = titles[0];
|
|
122
|
+
const overflowing: string[][] = [];
|
|
123
|
+
bar.tabsOverflowChanged.connect((_, { titles: overflow }) => overflowing.push(overflow.map(title => title.owner.id)));
|
|
124
|
+
const requestAnimationFrame = window.requestAnimationFrame;
|
|
125
|
+
window.requestAnimationFrame = callback => {
|
|
126
|
+
callback(0);
|
|
127
|
+
return 0;
|
|
128
|
+
};
|
|
129
|
+
try {
|
|
130
|
+
bar.overflowFrom(1);
|
|
131
|
+
} finally {
|
|
132
|
+
window.requestAnimationFrame = requestAnimationFrame;
|
|
133
|
+
}
|
|
134
|
+
expect(overflowing).to.deep.equal([['search']]);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('keeps the last shown tab when it fits beside the overflow menu, even with hidden tabs after it', () => {
|
|
138
|
+
const { bar, titles } = createSideTabBar(['search']);
|
|
139
|
+
bar.currentTitle = titles[0];
|
|
140
|
+
bar.render();
|
|
141
|
+
const parent = document.createElement('div');
|
|
142
|
+
const overflowMenu = document.createElement('div');
|
|
143
|
+
overflowMenu.className = 'theia-additional-views-menu';
|
|
144
|
+
Object.defineProperty(overflowMenu, 'offsetHeight', { value: 20 });
|
|
145
|
+
parent.append(bar.node, overflowMenu);
|
|
146
|
+
Object.defineProperty(bar.node, 'clientHeight', { value: 70 });
|
|
147
|
+
// explorer and debug stack 40px each; search is hidden, so it measures 0 like a `display: none` tab.
|
|
148
|
+
const tabs = Array.from(bar.contentNode.children);
|
|
149
|
+
[[0, 40], [40, 40], [0, 0]].forEach(([offsetTop, offsetHeight], i) => {
|
|
150
|
+
Object.defineProperty(tabs[i], 'offsetTop', { value: offsetTop });
|
|
151
|
+
Object.defineProperty(tabs[i], 'offsetHeight', { value: offsetHeight });
|
|
152
|
+
});
|
|
153
|
+
bar.setOverflowData();
|
|
154
|
+
|
|
155
|
+
expect(bar.firstOverflowingIndex()).to.equal(-1);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
63
158
|
});
|
|
@@ -49,7 +49,7 @@ const HIDDEN_CONTENT_CLASS = 'theia-TabBar-hidden-content';
|
|
|
49
49
|
export const SHELL_TABBAR_CONTEXT_MENU: MenuPath = ['shell-tabbar-context-menu'];
|
|
50
50
|
export const SHELL_TABBAR_CONTEXT_CLOSE: MenuPath = [...SHELL_TABBAR_CONTEXT_MENU, '0_close'];
|
|
51
51
|
export const SHELL_TABBAR_CONTEXT_COPY: MenuPath = [...SHELL_TABBAR_CONTEXT_MENU, '1_copy'];
|
|
52
|
-
|
|
52
|
+
export const SHELL_TABBAR_CONTEXT_HIDE: MenuPath = [...SHELL_TABBAR_CONTEXT_MENU, '3_hide'];
|
|
53
53
|
export const SHELL_TABBAR_CONTEXT_PIN: MenuPath = [...SHELL_TABBAR_CONTEXT_MENU, '4_pin'];
|
|
54
54
|
export const SHELL_TABBAR_CONTEXT_SPLIT: MenuPath = [...SHELL_TABBAR_CONTEXT_MENU, '5_split'];
|
|
55
55
|
|
|
@@ -72,7 +72,9 @@ export interface SideBarRenderData extends TabBar.IRenderData<Widget> {
|
|
|
72
72
|
iconSize?: SizeData;
|
|
73
73
|
paddingTop?: number;
|
|
74
74
|
paddingBottom?: number;
|
|
75
|
-
visible?: boolean
|
|
75
|
+
visible?: boolean;
|
|
76
|
+
/** Leaves the tab out of the side bar while keeping its DOM position aligned with its title index. */
|
|
77
|
+
hidden?: boolean;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
export interface ScrollableRenderData extends TabBar.IRenderData<Widget> {
|
|
@@ -223,6 +225,9 @@ export class TabBarRenderer extends TabBar.Renderer {
|
|
|
223
225
|
if (!(data.visible ?? true)) {
|
|
224
226
|
tabClass += ' lm-mod-invisible';
|
|
225
227
|
}
|
|
228
|
+
if (data.hidden) {
|
|
229
|
+
tabClass += ' lm-mod-hidden';
|
|
230
|
+
}
|
|
226
231
|
return tabClass;
|
|
227
232
|
}
|
|
228
233
|
|
|
@@ -1104,6 +1109,12 @@ export class SideTabBar extends ScrollableTabBar {
|
|
|
1104
1109
|
startIndex: number
|
|
1105
1110
|
};
|
|
1106
1111
|
|
|
1112
|
+
/**
|
|
1113
|
+
* Tabs for which this returns `true` are not rendered in the side bar unless they are current.
|
|
1114
|
+
* Call `update()` after the outcome changes.
|
|
1115
|
+
*/
|
|
1116
|
+
shouldHideTitle: (title: Title<Widget>) => boolean = () => false;
|
|
1117
|
+
|
|
1107
1118
|
constructor(options?: TabBar.IOptions<Widget> & PerfectScrollbar.Options) {
|
|
1108
1119
|
super(options);
|
|
1109
1120
|
|
|
@@ -1241,7 +1252,7 @@ export class SideTabBar extends ScrollableTabBar {
|
|
|
1241
1252
|
}
|
|
1242
1253
|
return;
|
|
1243
1254
|
}
|
|
1244
|
-
const newOverflowingTabs = this.titles.slice(startIndex);
|
|
1255
|
+
const newOverflowingTabs = this.titles.slice(startIndex).filter(title => !this.isHiddenTab(title));
|
|
1245
1256
|
|
|
1246
1257
|
if (!this.tabsOverflowData) {
|
|
1247
1258
|
this.tabsOverflowData = { titles: newOverflowingTabs, startIndex };
|
|
@@ -1265,16 +1276,17 @@ export class SideTabBar extends ScrollableTabBar {
|
|
|
1265
1276
|
const invisibleClass = 'lm-mod-invisible';
|
|
1266
1277
|
let startIndex = -1;
|
|
1267
1278
|
const n = this.contentNode.children.length;
|
|
1279
|
+
const lastShownIndex = ArrayExt.findLastIndex(this.titles, title => !this.isHiddenTab(title));
|
|
1268
1280
|
for (let i = 0; i < n; i++) {
|
|
1269
1281
|
const tab = this.contentNode.children[i] as HTMLLIElement;
|
|
1270
1282
|
if (tab.offsetTop + tab.offsetHeight >= availableHeight) {
|
|
1271
1283
|
tab.classList.add(invisibleClass);
|
|
1272
1284
|
if (startIndex === -1) {
|
|
1273
1285
|
startIndex = i;
|
|
1274
|
-
/* If only
|
|
1275
|
-
* there might already be enough space to show
|
|
1276
|
-
* additional menu widget and recheck if the last tab is visible */
|
|
1277
|
-
if (startIndex ===
|
|
1286
|
+
/* If only the last shown tab is overflowing and the additional menu widget is visible (i.e. this.tabsOverflowData is set)
|
|
1287
|
+
* there might already be enough space to show it. In this case, we need to include the size of the
|
|
1288
|
+
* additional menu widget and recheck if the last shown tab is visible */
|
|
1289
|
+
if (startIndex === lastShownIndex && this.tabsOverflowData) {
|
|
1278
1290
|
const additionalViewsMenu = this.node.parentElement?.querySelector('.theia-additional-views-menu') as HTMLDivElement;
|
|
1279
1291
|
if (tab.offsetTop + tab.offsetHeight < availableHeight + additionalViewsMenu.offsetHeight) {
|
|
1280
1292
|
tab.classList.remove(invisibleClass);
|
|
@@ -1289,6 +1301,21 @@ export class SideTabBar extends ScrollableTabBar {
|
|
|
1289
1301
|
return startIndex;
|
|
1290
1302
|
}
|
|
1291
1303
|
|
|
1304
|
+
/**
|
|
1305
|
+
* Whether the tab of the given title is currently left out of the side bar.
|
|
1306
|
+
*/
|
|
1307
|
+
isHiddenTab(title: Title<Widget>): boolean {
|
|
1308
|
+
return title !== this.currentTitle && this.shouldHideTitle(title);
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
/**
|
|
1312
|
+
* Whether the given title can be hidden. The last title that is not hidden stays, so the
|
|
1313
|
+
* side bar never loses every tab.
|
|
1314
|
+
*/
|
|
1315
|
+
canHideTitle(title: Title<Widget>): boolean {
|
|
1316
|
+
return !this.shouldHideTitle(title) && this.titles.some(other => other !== title && !this.shouldHideTitle(other));
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1292
1319
|
/**
|
|
1293
1320
|
* Render the tab bar using the given DOM element as host. The optional `renderData` is forwarded
|
|
1294
1321
|
* to the TabBarRenderer.
|
|
@@ -1303,12 +1330,8 @@ export class SideTabBar extends ScrollableTabBar {
|
|
|
1303
1330
|
const title = titles[i];
|
|
1304
1331
|
const current = title === currentTitle;
|
|
1305
1332
|
const zIndex = current ? n : n - i - 1;
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
rd = { title, current, zIndex, ...renderData[i] };
|
|
1309
|
-
} else {
|
|
1310
|
-
rd = { title, current, zIndex };
|
|
1311
|
-
}
|
|
1333
|
+
const hidden = this.isHiddenTab(title);
|
|
1334
|
+
const rd: SideBarRenderData = { title, current, zIndex, hidden, ...renderData?.[i] };
|
|
1312
1335
|
// Based on how renderTabs() is called, assume renderData will be undefined when invoked for this.hiddenContentNode
|
|
1313
1336
|
content[i] = renderer.renderTab(rd, true, renderData === undefined);
|
|
1314
1337
|
}
|