@theia/core 1.77.0-next.84 → 1.77.0-next.89
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 +33 -4
- package/lib/browser/color-application-contribution.d.ts +2 -2
- package/lib/browser/color-application-contribution.d.ts.map +1 -1
- package/lib/browser/color-application-contribution.js +7 -8
- package/lib/browser/color-application-contribution.js.map +1 -1
- package/lib/browser/common-frontend-contribution.d.ts.map +1 -1
- package/lib/browser/common-frontend-contribution.js +7 -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 +6 -0
- package/lib/browser/frontend-application-module.js.map +1 -1
- package/lib/browser/quick-input/quick-command-service.d.ts +2 -0
- package/lib/browser/quick-input/quick-command-service.d.ts.map +1 -1
- package/lib/browser/quick-input/quick-command-service.js +10 -2
- package/lib/browser/quick-input/quick-command-service.js.map +1 -1
- package/lib/browser/saveable-service.d.ts +4 -0
- package/lib/browser/saveable-service.d.ts.map +1 -1
- package/lib/browser/saveable-service.js +7 -0
- package/lib/browser/saveable-service.js.map +1 -1
- package/lib/browser/secondary-window-handler.d.ts +126 -3
- package/lib/browser/secondary-window-handler.d.ts.map +1 -1
- package/lib/browser/secondary-window-handler.js +354 -30
- package/lib/browser/secondary-window-handler.js.map +1 -1
- package/lib/browser/shell/application-shell-mouse-tracker.d.ts +2 -0
- package/lib/browser/shell/application-shell-mouse-tracker.d.ts.map +1 -1
- package/lib/browser/shell/application-shell-mouse-tracker.js +10 -0
- package/lib/browser/shell/application-shell-mouse-tracker.js.map +1 -1
- package/lib/browser/shell/application-shell.d.ts +11 -0
- package/lib/browser/shell/application-shell.d.ts.map +1 -1
- package/lib/browser/shell/application-shell.js +33 -4
- package/lib/browser/shell/application-shell.js.map +1 -1
- package/lib/browser/shell/index.d.ts +1 -0
- package/lib/browser/shell/index.d.ts.map +1 -1
- package/lib/browser/shell/index.js +1 -0
- package/lib/browser/shell/index.js.map +1 -1
- package/lib/browser/shell/native-tab-drag-service.d.ts +141 -0
- package/lib/browser/shell/native-tab-drag-service.d.ts.map +1 -0
- package/lib/browser/shell/native-tab-drag-service.js +349 -0
- package/lib/browser/shell/native-tab-drag-service.js.map +1 -0
- package/lib/browser/shell/native-tab-drag-service.spec.d.ts +2 -0
- package/lib/browser/shell/native-tab-drag-service.spec.d.ts.map +1 -0
- package/lib/browser/shell/native-tab-drag-service.spec.js +71 -0
- package/lib/browser/shell/native-tab-drag-service.spec.js.map +1 -0
- package/lib/browser/shell/shell-layout-restorer.d.ts +3 -0
- package/lib/browser/shell/shell-layout-restorer.d.ts.map +1 -1
- package/lib/browser/shell/shell-layout-restorer.js +20 -0
- package/lib/browser/shell/shell-layout-restorer.js.map +1 -1
- package/lib/browser/shell/shell-layout-restorer.spec.js +31 -0
- package/lib/browser/shell/shell-layout-restorer.spec.js.map +1 -1
- package/lib/browser/shell/side-panel-handler.d.ts +8 -0
- package/lib/browser/shell/side-panel-handler.d.ts.map +1 -1
- package/lib/browser/shell/side-panel-handler.js +14 -0
- package/lib/browser/shell/side-panel-handler.js.map +1 -1
- package/lib/browser/shell/tab-bars.d.ts +39 -0
- package/lib/browser/shell/tab-bars.d.ts.map +1 -1
- package/lib/browser/shell/tab-bars.js +127 -2
- package/lib/browser/shell/tab-bars.js.map +1 -1
- package/lib/browser/shell/tab-bars.spec.js +48 -0
- package/lib/browser/shell/tab-bars.spec.js.map +1 -1
- package/lib/browser/shell/tab-drop-helper.d.ts +32 -0
- package/lib/browser/shell/tab-drop-helper.d.ts.map +1 -0
- package/lib/browser/shell/tab-drop-helper.js +75 -0
- package/lib/browser/shell/tab-drop-helper.js.map +1 -0
- package/lib/browser/shell/theia-dock-panel.d.ts +25 -0
- package/lib/browser/shell/theia-dock-panel.d.ts.map +1 -1
- package/lib/browser/shell/theia-dock-panel.js +107 -11
- package/lib/browser/shell/theia-dock-panel.js.map +1 -1
- package/lib/browser/styling-service.d.ts +2 -2
- package/lib/browser/styling-service.d.ts.map +1 -1
- package/lib/browser/styling-service.js +7 -8
- package/lib/browser/styling-service.js.map +1 -1
- package/lib/browser/widget-open-handler.d.ts +10 -0
- package/lib/browser/widget-open-handler.d.ts.map +1 -1
- package/lib/browser/widget-open-handler.js +24 -1
- package/lib/browser/widget-open-handler.js.map +1 -1
- package/lib/browser/window/default-secondary-window-service.d.ts +17 -3
- package/lib/browser/window/default-secondary-window-service.d.ts.map +1 -1
- package/lib/browser/window/default-secondary-window-service.js +76 -23
- package/lib/browser/window/default-secondary-window-service.js.map +1 -1
- package/lib/browser/window/default-secondary-window-service.spec.d.ts +2 -0
- package/lib/browser/window/default-secondary-window-service.spec.d.ts.map +1 -0
- package/lib/browser/window/default-secondary-window-service.spec.js +49 -0
- package/lib/browser/window/default-secondary-window-service.spec.js.map +1 -0
- package/lib/browser/window/secondary-window-close-contribution.d.ts +23 -0
- package/lib/browser/window/secondary-window-close-contribution.d.ts.map +1 -0
- package/lib/browser/window/secondary-window-close-contribution.js +39 -0
- package/lib/browser/window/secondary-window-close-contribution.js.map +1 -0
- package/lib/browser/window/secondary-window-service.d.ts +24 -1
- package/lib/browser/window/secondary-window-service.d.ts.map +1 -1
- package/lib/browser/window/secondary-window-service.js.map +1 -1
- package/lib/browser/window/window-focus-service.d.ts +4 -0
- package/lib/browser/window/window-focus-service.d.ts.map +1 -1
- package/lib/browser/window/window-focus-service.js +8 -2
- package/lib/browser/window/window-focus-service.js.map +1 -1
- package/lib/common/core-preferences.d.ts +2 -0
- package/lib/common/core-preferences.d.ts.map +1 -1
- package/lib/common/core-preferences.js +15 -0
- package/lib/common/core-preferences.js.map +1 -1
- package/lib/common/preferences/preference-schema-service.d.ts.map +1 -1
- package/lib/common/preferences/preference-schema-service.js +9 -5
- package/lib/common/preferences/preference-schema-service.js.map +1 -1
- package/lib/common/preferences/preference-schema-service.spec.d.ts +2 -0
- package/lib/common/preferences/preference-schema-service.spec.d.ts.map +1 -0
- package/lib/common/preferences/preference-schema-service.spec.js +80 -0
- package/lib/common/preferences/preference-schema-service.spec.js.map +1 -0
- package/lib/electron-browser/menu/electron-context-menu-renderer.d.ts.map +1 -1
- package/lib/electron-browser/menu/electron-context-menu-renderer.js +2 -1
- package/lib/electron-browser/menu/electron-context-menu-renderer.js.map +1 -1
- package/lib/electron-browser/window/electron-secondary-window-service.d.ts.map +1 -1
- package/lib/electron-browser/window/electron-secondary-window-service.js +1 -0
- package/lib/electron-browser/window/electron-secondary-window-service.js.map +1 -1
- package/package.json +4 -4
- package/src/browser/color-application-contribution.ts +6 -7
- package/src/browser/common-frontend-contribution.ts +8 -0
- package/src/browser/frontend-application-module.ts +6 -0
- package/src/browser/quick-input/quick-command-service.ts +8 -2
- package/src/browser/saveable-service.ts +8 -0
- package/src/browser/secondary-window-handler.ts +397 -34
- package/src/browser/shell/application-shell-mouse-tracker.ts +10 -0
- package/src/browser/shell/application-shell.ts +38 -5
- package/src/browser/shell/index.ts +1 -0
- package/src/browser/shell/native-tab-drag-service.spec.ts +86 -0
- package/src/browser/shell/native-tab-drag-service.ts +402 -0
- package/src/browser/shell/shell-layout-restorer.spec.ts +42 -0
- package/src/browser/shell/shell-layout-restorer.ts +20 -0
- package/src/browser/shell/side-panel-handler.ts +15 -0
- package/src/browser/shell/tab-bars.spec.ts +56 -2
- package/src/browser/shell/tab-bars.ts +146 -3
- package/src/browser/shell/tab-drop-helper.ts +79 -0
- package/src/browser/shell/theia-dock-panel.ts +122 -11
- package/src/browser/style/dockpanel.css +9 -0
- package/src/browser/styling-service.ts +6 -7
- package/src/browser/widget-open-handler.ts +24 -3
- package/src/browser/window/default-secondary-window-service.spec.ts +54 -0
- package/src/browser/window/default-secondary-window-service.ts +78 -26
- package/src/browser/window/secondary-window-close-contribution.ts +47 -0
- package/src/browser/window/secondary-window-service.ts +20 -1
- package/src/browser/window/window-focus-service.ts +9 -2
- package/src/common/core-preferences.ts +19 -0
- package/src/common/preferences/preference-schema-service.spec.ts +99 -0
- package/src/common/preferences/preference-schema-service.ts +9 -5
- package/src/electron-browser/menu/electron-context-menu-renderer.ts +2 -1
- package/src/electron-browser/window/electron-secondary-window-service.ts +1 -0
|
@@ -29,6 +29,7 @@ import { StatusBarImpl, StatusBarEntry, StatusBarAlignment } from '../status-bar
|
|
|
29
29
|
import { TheiaDockPanel, BOTTOM_AREA_ID, MAIN_AREA_ID } from './theia-dock-panel';
|
|
30
30
|
import { SidePanelHandler, SidePanel, SidePanelHandlerFactory } from './side-panel-handler';
|
|
31
31
|
import { TabBarRendererFactory, SHELL_TABBAR_CONTEXT_MENU, ScrollableTabBar, ToolbarAwareTabBar } from './tab-bars';
|
|
32
|
+
import { NativeTabDragService } from './native-tab-drag-service';
|
|
32
33
|
import { SplitPositionHandler, SplitPositionOptions } from './split-panels';
|
|
33
34
|
import { FrontendApplicationStateService } from '../frontend-application-state';
|
|
34
35
|
import { TabBarToolbarRegistry, TabBarToolbarFactory } from './tab-bar-toolbar';
|
|
@@ -40,7 +41,7 @@ import { BreadcrumbsRendererFactory } from '../breadcrumbs/breadcrumbs-renderer'
|
|
|
40
41
|
import { Deferred } from '../../common/promise-util';
|
|
41
42
|
import { SaveableService } from '../saveable-service';
|
|
42
43
|
import { nls } from '../../common/nls';
|
|
43
|
-
import { extractSecondaryWindow, SecondaryWindowHandler } from '../secondary-window-handler';
|
|
44
|
+
import { extractSecondaryWindow, extractSecondaryWindowRootWidget, SecondaryWindowHandler } from '../secondary-window-handler';
|
|
44
45
|
import URI from '../../common/uri';
|
|
45
46
|
import { OpenerService } from '../opener-service';
|
|
46
47
|
import { PreviewableWidget } from '../widgets/previewable-widget';
|
|
@@ -97,6 +98,9 @@ export class DockPanelRenderer implements DockLayout.IRenderer {
|
|
|
97
98
|
|
|
98
99
|
private readonly onDidCreateTabBarEmitter = new Emitter<TabBar<Widget>>();
|
|
99
100
|
|
|
101
|
+
@inject(NativeTabDragService) @optional()
|
|
102
|
+
protected readonly nativeTabDragService?: NativeTabDragService;
|
|
103
|
+
|
|
100
104
|
constructor(
|
|
101
105
|
@inject(TabBarRendererFactory) protected readonly tabBarRendererFactory: TabBarRendererFactory,
|
|
102
106
|
@inject(TabBarToolbarRegistry) protected readonly tabBarToolbarRegistry: TabBarToolbarRegistry,
|
|
@@ -140,6 +144,7 @@ export class DockPanelRenderer implements DockLayout.IRenderer {
|
|
|
140
144
|
getDynamicTabOptions());
|
|
141
145
|
this.tabBarClasses.forEach(c => tabBar.addClass(c));
|
|
142
146
|
renderer.tabBar = tabBar;
|
|
147
|
+
tabBar.nativeTabDragService = this.nativeTabDragService;
|
|
143
148
|
renderer.contextMenuPath = SHELL_TABBAR_CONTEXT_MENU;
|
|
144
149
|
tabBar.currentChanged.connect(this.onCurrentTabChanged, this);
|
|
145
150
|
const prefChangeDisposable = this.corePreferences.onPreferenceChanged(change => {
|
|
@@ -385,7 +390,11 @@ export class ApplicationShell extends Widget {
|
|
|
385
390
|
this.rightPanelHandler.dockPanel.widgetRemoved.connect((_, widget) => this.fireDidRemoveWidget(widget));
|
|
386
391
|
|
|
387
392
|
this.secondaryWindowHandler.init(this, this.dockPanelRendererFactory);
|
|
388
|
-
this.secondaryWindowHandler.onDidAddWidget(([widget, window]) =>
|
|
393
|
+
this.secondaryWindowHandler.onDidAddWidget(([widget, window]) => {
|
|
394
|
+
// widgets restored in secondary windows on startup have never been added to the main window
|
|
395
|
+
this.track(widget);
|
|
396
|
+
this.fireDidAddWidget(widget);
|
|
397
|
+
});
|
|
389
398
|
this.secondaryWindowHandler.onDidRemoveWidget(([widget, window]) => this.fireDidRemoveWidget(widget));
|
|
390
399
|
|
|
391
400
|
this.layout = this.createLayout();
|
|
@@ -488,8 +497,10 @@ export class ApplicationShell extends Widget {
|
|
|
488
497
|
&& clientX <= offsetLeft + this.options.leftPanel.expandThreshold;
|
|
489
498
|
const expRight = allowExpansion && clientX <= offsetLeft + clientWidth
|
|
490
499
|
&& clientX >= offsetLeft + clientWidth - this.options.rightPanel.expandThreshold;
|
|
491
|
-
|
|
492
|
-
|
|
500
|
+
// The bottom panel is below the main area only, so don't expand it while dragging over an open side panel
|
|
501
|
+
const mainAreaBounds = this.mainPanel.node.getBoundingClientRect();
|
|
502
|
+
const expBottom = allowExpansion && !expLeft && !expRight && clientX >= mainAreaBounds.left && clientX <= mainAreaBounds.right
|
|
503
|
+
&& clientY <= offsetTop + clientHeight && clientY >= offsetTop + clientHeight - this.options.bottomPanel.expandThreshold;
|
|
493
504
|
// eslint-disable-next-line no-null/no-null
|
|
494
505
|
if (expLeft && !state.leftExpanded && this.leftPanelHandler.tabBar.currentTitle === null) {
|
|
495
506
|
// The mouse cursor is moved close to the left border
|
|
@@ -1104,7 +1115,24 @@ export class ApplicationShell extends Widget {
|
|
|
1104
1115
|
widgetNode = widgetNode.parentElement;
|
|
1105
1116
|
}
|
|
1106
1117
|
if (widgetNode) {
|
|
1107
|
-
return this.findWidgetForNode(widgetNode, this);
|
|
1118
|
+
return this.findWidgetForNode(widgetNode, this) ?? this.findSecondaryWindowWidgetForNode(widgetNode);
|
|
1119
|
+
}
|
|
1120
|
+
return undefined;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* Widgets in secondary windows are not part of the widget tree of the shell, but of the root widgets of their windows.
|
|
1125
|
+
*/
|
|
1126
|
+
private findSecondaryWindowWidgetForNode(widgetNode: HTMLElement): Widget | undefined {
|
|
1127
|
+
if (widgetNode.ownerDocument === this.node.ownerDocument) {
|
|
1128
|
+
return undefined;
|
|
1129
|
+
}
|
|
1130
|
+
const rootWidgets = new Set(this.secondaryWindowHandler.widgets.map(widget => extractSecondaryWindowRootWidget(widget)));
|
|
1131
|
+
for (const rootWidget of rootWidgets) {
|
|
1132
|
+
const result = rootWidget && this.findWidgetForNode(widgetNode, rootWidget);
|
|
1133
|
+
if (result) {
|
|
1134
|
+
return result;
|
|
1135
|
+
}
|
|
1108
1136
|
}
|
|
1109
1137
|
return undefined;
|
|
1110
1138
|
}
|
|
@@ -2367,6 +2395,11 @@ export namespace ApplicationShell {
|
|
|
2367
2395
|
leftPanel?: SidePanel.LayoutData;
|
|
2368
2396
|
rightPanel?: SidePanel.LayoutData;
|
|
2369
2397
|
activeWidgetId?: string;
|
|
2398
|
+
/**
|
|
2399
|
+
* The secondary windows to restore on startup. They are not part of perspectives, so they are
|
|
2400
|
+
* stored and restored by the `ShellLayoutRestorer` rather than by `getLayoutData` and `setLayoutData`.
|
|
2401
|
+
*/
|
|
2402
|
+
secondaryWindows?: SecondaryWindowHandler.LayoutData[];
|
|
2370
2403
|
}
|
|
2371
2404
|
|
|
2372
2405
|
/**
|
|
@@ -21,5 +21,6 @@ export * from './side-panel-item-visibility';
|
|
|
21
21
|
export * from './sidebar-menu-widget';
|
|
22
22
|
export * from './split-panels';
|
|
23
23
|
export * from './tab-bars';
|
|
24
|
+
export * from './native-tab-drag-service';
|
|
24
25
|
export * from './view-contribution';
|
|
25
26
|
export * from './theia-split-panel';
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 EclipseSource 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
|
+
import { expect } from 'chai';
|
|
20
|
+
|
|
21
|
+
import { NativeTabDragService } from './native-tab-drag-service';
|
|
22
|
+
|
|
23
|
+
disableJSDOM();
|
|
24
|
+
|
|
25
|
+
class TestableNativeTabDragService extends NativeTabDragService {
|
|
26
|
+
|
|
27
|
+
/** Sets the state of the main window as if the pointer had been over it, and had left it just now if `leaving` */
|
|
28
|
+
setPointerState(leaving: boolean): void {
|
|
29
|
+
const state = this.windows.get(window)!;
|
|
30
|
+
state.inside = true;
|
|
31
|
+
if (leaving) {
|
|
32
|
+
this.scheduleLeave(state);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
callIsInsideWindows(event: DragEvent): boolean {
|
|
37
|
+
return this.isInsideWindows(event);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
dispose(): void {
|
|
41
|
+
this.windows.forEach(state => this.cancelLeave(state));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('NativeTabDragService', () => {
|
|
46
|
+
|
|
47
|
+
let service: TestableNativeTabDragService;
|
|
48
|
+
|
|
49
|
+
before(() => {
|
|
50
|
+
disableJSDOM = enableJSDOM();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
after(() => {
|
|
54
|
+
disableJSDOM();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
service = new TestableNativeTabDragService();
|
|
59
|
+
service['init']();
|
|
60
|
+
Object.assign(window, { screenX: 100, screenY: 100, outerWidth: 800, outerHeight: 600 });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
service.dispose();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function dragEnd(screenX: number, screenY: number): DragEvent {
|
|
68
|
+
return { screenX, screenY } as DragEvent;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
it('should consider the pointer inside a window that it has not left', () => {
|
|
72
|
+
service.setPointerState(false);
|
|
73
|
+
expect(service.callIsInsideWindows(dragEnd(0, 0))).to.be.true;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should consider the pointer outside a window that it has just left if released outside of it', () => {
|
|
77
|
+
service.setPointerState(true);
|
|
78
|
+
expect(service.callIsInsideWindows(dragEnd(950, 300))).to.be.false;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should consider the pointer inside a window that it has just left if released within its bounds', () => {
|
|
82
|
+
service.setPointerState(true);
|
|
83
|
+
expect(service.callIsInsideWindows(dragEnd(500, 300))).to.be.true;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
});
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 EclipseSource 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 { injectable, postConstruct } from 'inversify';
|
|
18
|
+
import { MimeData } from '@lumino/coreutils';
|
|
19
|
+
import { Drag } from '@lumino/dragdrop';
|
|
20
|
+
import { TabBar, Title, Widget } from '@lumino/widgets';
|
|
21
|
+
import { Disposable } from '../../common/disposable';
|
|
22
|
+
import { Emitter, Event } from '../../common/event';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The mime type that Lumino drop targets, e.g. dock panels, expect for dragged widgets.
|
|
26
|
+
*/
|
|
27
|
+
export const WIDGET_FACTORY_MIME_TYPE = 'application/vnd.lumino.widget-factory';
|
|
28
|
+
|
|
29
|
+
export interface TabDropOutsideWindowsEvent {
|
|
30
|
+
/** The title of the dragged tab. */
|
|
31
|
+
title: Title<Widget>;
|
|
32
|
+
/** The horizontal screen coordinate at which the tab was released. */
|
|
33
|
+
screenX: number;
|
|
34
|
+
/** The vertical screen coordinate at which the tab was released. */
|
|
35
|
+
screenY: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface TabDropEvent {
|
|
39
|
+
/** The title of the dropped tab. */
|
|
40
|
+
title: Title<Widget>;
|
|
41
|
+
/** The window in which the tab has been dropped. */
|
|
42
|
+
window: Window;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type LuminoDragEventType = 'lm-dragenter' | 'lm-dragover' | 'lm-dragleave' | 'lm-dragexit' | 'lm-drop';
|
|
46
|
+
|
|
47
|
+
interface NativeTabDragSession {
|
|
48
|
+
readonly title: Title<Widget>;
|
|
49
|
+
readonly source: Widget;
|
|
50
|
+
readonly mimeData: MimeData;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface WindowDragState {
|
|
54
|
+
readonly window: Window;
|
|
55
|
+
/** The Lumino drag object used to create the Lumino drag events dispatched in this window. */
|
|
56
|
+
drag?: Drag;
|
|
57
|
+
/** The element under the pointer during the last drag event. */
|
|
58
|
+
currentElement?: Element;
|
|
59
|
+
/** The element that accepted the Lumino `lm-dragenter` event. */
|
|
60
|
+
currentTarget?: Element;
|
|
61
|
+
/** The drop action of the last `lm-dragover` event. */
|
|
62
|
+
dropAction: Drag.DropAction;
|
|
63
|
+
/** Whether the pointer is currently over this window. */
|
|
64
|
+
inside: boolean;
|
|
65
|
+
leaveTimeout?: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Drags the tabs of dock panels with native HTML drag and drop instead of Lumino's pointer based drag and drop.
|
|
70
|
+
* Native drags work across windows, e.g. secondary windows, and show the drag image outside of the window as well.
|
|
71
|
+
*
|
|
72
|
+
* Drop targets are not aware of this: the native drag events are translated to the Lumino drag events
|
|
73
|
+
* (`lm-dragenter`, `lm-dragover`, `lm-dragleave` and `lm-drop`) that Lumino drop targets handle.
|
|
74
|
+
*/
|
|
75
|
+
@injectable()
|
|
76
|
+
export class NativeTabDragService {
|
|
77
|
+
|
|
78
|
+
static readonly MIME_TYPE = 'application/vnd.theia.dock-panel-tab';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The time without native drag events in a window after which the pointer is considered to have left the window.
|
|
82
|
+
* Native `dragleave` events are also fired when the pointer moves between the elements of a window,
|
|
83
|
+
* while native `dragover` events are fired continuously as long as the pointer is over a window.
|
|
84
|
+
*/
|
|
85
|
+
protected static readonly LEAVE_DELAY = 150;
|
|
86
|
+
|
|
87
|
+
protected session: NativeTabDragSession | undefined;
|
|
88
|
+
protected readonly windows = new Map<Window, WindowDragState>();
|
|
89
|
+
|
|
90
|
+
protected readonly onDidDropTabOutsideWindowsEmitter = new Emitter<TabDropOutsideWindowsEvent>();
|
|
91
|
+
/**
|
|
92
|
+
* Emitted when a tab is released outside of all windows of the application, e.g. over the desktop.
|
|
93
|
+
*/
|
|
94
|
+
readonly onDidDropTabOutsideWindows: Event<TabDropOutsideWindowsEvent> = this.onDidDropTabOutsideWindowsEmitter.event;
|
|
95
|
+
|
|
96
|
+
protected readonly onDidDropTabEmitter = new Emitter<TabDropEvent>();
|
|
97
|
+
/**
|
|
98
|
+
* Emitted when a tab has been dropped on a drop target in one of the windows of the application.
|
|
99
|
+
*/
|
|
100
|
+
readonly onDidDropTab: Event<TabDropEvent> = this.onDidDropTabEmitter.event;
|
|
101
|
+
|
|
102
|
+
protected readonly onDidStartDragEmitter = new Emitter<DragEvent>();
|
|
103
|
+
/**
|
|
104
|
+
* Emitted when a tab drag has started, with its `dragstart` event.
|
|
105
|
+
*/
|
|
106
|
+
readonly onDidStartDrag: Event<DragEvent> = this.onDidStartDragEmitter.event;
|
|
107
|
+
|
|
108
|
+
protected readonly onDidEndDragEmitter = new Emitter<DragEvent>();
|
|
109
|
+
/**
|
|
110
|
+
* Emitted when a tab drag has ended, with its `dragend` event, or with the `drop` event of a successful drop.
|
|
111
|
+
* Native drags end without a `mouseup` event.
|
|
112
|
+
*/
|
|
113
|
+
readonly onDidEndDrag: Event<DragEvent> = this.onDidEndDragEmitter.event;
|
|
114
|
+
|
|
115
|
+
@postConstruct()
|
|
116
|
+
protected init(): void {
|
|
117
|
+
this.installWindow(window);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Translates the native drag events of tab drags in the given window to Lumino drag events.
|
|
122
|
+
*/
|
|
123
|
+
installWindow(win: Window): Disposable {
|
|
124
|
+
if (this.windows.has(win)) {
|
|
125
|
+
return Disposable.NULL;
|
|
126
|
+
}
|
|
127
|
+
const state: WindowDragState = { window: win, dropAction: 'none', inside: false };
|
|
128
|
+
this.windows.set(win, state);
|
|
129
|
+
const listener = (event: DragEvent) => this.handleDragEvent(state, event);
|
|
130
|
+
const types = ['dragenter', 'dragover', 'dragleave', 'drop'];
|
|
131
|
+
// Listen on the window in the capture phase to handle tab drags before any other drop target, e.g. Monaco or file drops.
|
|
132
|
+
types.forEach(type => win.addEventListener(type, listener, true));
|
|
133
|
+
return Disposable.create(() => {
|
|
134
|
+
types.forEach(type => win.removeEventListener(type, listener, true));
|
|
135
|
+
this.resetWindow(state);
|
|
136
|
+
this.windows.delete(win);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Starts dragging the given tab. To be called from the `dragstart` event of the tab.
|
|
142
|
+
*
|
|
143
|
+
* @param source the widget that is reported as the source of the Lumino drag events, i.e. the dock panel containing the tab bar
|
|
144
|
+
*/
|
|
145
|
+
startDrag(event: DragEvent, tabBar: TabBar<Widget>, title: Title<Widget>, source: Widget): void {
|
|
146
|
+
// not using `instanceof`, the tab may be in a secondary window, i.e. in another JavaScript realm
|
|
147
|
+
const tab = (event.target as Element | null)?.closest?.('.lm-TabBar-tab');
|
|
148
|
+
if (!event.dataTransfer || !tab) {
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// Only set our own type, so that other applications don't accept the drop.
|
|
153
|
+
event.dataTransfer.setData(NativeTabDragService.MIME_TYPE, title.owner.id);
|
|
154
|
+
// like VS Code, drop targets only ever move tabs, though
|
|
155
|
+
event.dataTransfer.effectAllowed = 'copyMove';
|
|
156
|
+
const tabRect = tab.getBoundingClientRect();
|
|
157
|
+
event.dataTransfer.setDragImage(tab, event.clientX - tabRect.left, event.clientY - tabRect.top);
|
|
158
|
+
|
|
159
|
+
const mimeData = new MimeData();
|
|
160
|
+
mimeData.setData(WIDGET_FACTORY_MIME_TYPE, () => title.owner);
|
|
161
|
+
this.session = { title, source, mimeData };
|
|
162
|
+
// The native drag cancels the pointer events, so Lumino never sees the release of its press on the tab.
|
|
163
|
+
tabBar.releaseMouse();
|
|
164
|
+
this.onDidStartDragEmitter.fire(event);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Ends the current tab drag. To be called from the `dragend` event of the tab.
|
|
169
|
+
*/
|
|
170
|
+
endDrag(event: DragEvent): void {
|
|
171
|
+
const session = this.session;
|
|
172
|
+
if (!session) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
// a successful drop has ended the session already, see `handleDrop`
|
|
176
|
+
const insideWindows = this.isInsideWindows(event);
|
|
177
|
+
this.endSession(event);
|
|
178
|
+
if (!insideWindows && event.dataTransfer?.dropEffect === 'none' && !session.title.owner.isDisposed) {
|
|
179
|
+
this.onDidDropTabOutsideWindowsEmitter.fire({ title: session.title, screenX: event.screenX, screenY: event.screenY });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
protected handleDragEvent(state: WindowDragState, event: DragEvent): void {
|
|
184
|
+
if (!this.session || !event.dataTransfer?.types.includes(NativeTabDragService.MIME_TYPE)) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
// Tab drags are only handled by Lumino drop targets.
|
|
188
|
+
event.stopPropagation();
|
|
189
|
+
switch (event.type) {
|
|
190
|
+
case 'dragenter':
|
|
191
|
+
case 'dragover':
|
|
192
|
+
this.handleDragOver(state, event);
|
|
193
|
+
break;
|
|
194
|
+
case 'dragleave':
|
|
195
|
+
this.scheduleLeave(state);
|
|
196
|
+
break;
|
|
197
|
+
case 'drop':
|
|
198
|
+
this.handleDrop(state, event);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
protected handleDragOver(state: WindowDragState, event: DragEvent): void {
|
|
204
|
+
state.inside = true;
|
|
205
|
+
this.cancelLeave(state);
|
|
206
|
+
this.updateCurrentTarget(state, event);
|
|
207
|
+
if (state.dropAction !== 'none') {
|
|
208
|
+
event.preventDefault();
|
|
209
|
+
event.dataTransfer!.dropEffect = 'move';
|
|
210
|
+
} else {
|
|
211
|
+
event.dataTransfer!.dropEffect = 'none';
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
protected handleDrop(state: WindowDragState, event: DragEvent): void {
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
this.cancelLeave(state);
|
|
218
|
+
this.updateCurrentTarget(state, event);
|
|
219
|
+
const target = state.currentTarget;
|
|
220
|
+
let action: Drag.DropAction = 'none';
|
|
221
|
+
if (target) {
|
|
222
|
+
if (state.dropAction === 'none') {
|
|
223
|
+
this.dispatch(state, 'lm-dragleave', target, event, undefined);
|
|
224
|
+
} else {
|
|
225
|
+
action = this.dispatch(state, 'lm-drop', target, event, undefined).dropAction;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// The drop target has handled the drop, so it must not get a leave event when the drag ends.
|
|
229
|
+
state.currentTarget = undefined;
|
|
230
|
+
state.currentElement = undefined;
|
|
231
|
+
state.dropAction = 'none';
|
|
232
|
+
const title = this.session?.title;
|
|
233
|
+
if (action !== 'none' && title) {
|
|
234
|
+
// The drop may close the window the drag started in, e.g. when its last tab has been moved, so `dragend` may never be fired.
|
|
235
|
+
this.endSession(event);
|
|
236
|
+
this.onDidDropTabEmitter.fire({ title, window: state.window });
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Ends the current drag session and notifies the drop targets under the pointer that the drag has left them.
|
|
242
|
+
*
|
|
243
|
+
* @param event the event that ends the drag, i.e. its `dragend` event or the `drop` event of a successful drop
|
|
244
|
+
*/
|
|
245
|
+
protected endSession(event: DragEvent): void {
|
|
246
|
+
this.session = undefined;
|
|
247
|
+
for (const state of this.windows.values()) {
|
|
248
|
+
this.resetWindow(state);
|
|
249
|
+
}
|
|
250
|
+
this.onDidEndDragEmitter.fire(event);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* @returns whether the pointer is over one of the windows at the end of the given drag event
|
|
255
|
+
*/
|
|
256
|
+
protected isInsideWindows(event: DragEvent): boolean {
|
|
257
|
+
for (const state of this.windows.values()) {
|
|
258
|
+
// A window is only considered left some time after its last `dragleave` event, see `LEAVE_DELAY`.
|
|
259
|
+
// If the drag ends in the meantime, the position of the pointer tells whether it has left the window.
|
|
260
|
+
if (state.inside && (state.leaveTimeout === undefined || this.containsScreenPoint(state.window, event.screenX, event.screenY))) {
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
protected containsScreenPoint(win: Window, screenX: number, screenY: number): boolean {
|
|
268
|
+
return !win.closed && screenX >= win.screenX && screenX < win.screenX + win.outerWidth
|
|
269
|
+
&& screenY >= win.screenY && screenY < win.screenY + win.outerHeight;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Updates the Lumino drop target under the pointer, following `Drag._updateCurrentTarget` in `@lumino/dragdrop`.
|
|
274
|
+
*/
|
|
275
|
+
protected updateCurrentTarget(state: WindowDragState, event: DragEvent): void {
|
|
276
|
+
const prevTarget = state.currentTarget;
|
|
277
|
+
let currTarget = state.currentTarget;
|
|
278
|
+
const prevElem = state.currentElement;
|
|
279
|
+
const currElem = state.window.document.elementFromPoint(event.clientX, event.clientY) ?? undefined;
|
|
280
|
+
state.currentElement = currElem;
|
|
281
|
+
if (currElem !== prevElem && currElem !== currTarget) {
|
|
282
|
+
if (currTarget) {
|
|
283
|
+
this.dispatch(state, 'lm-dragexit', currTarget, event, currElem);
|
|
284
|
+
}
|
|
285
|
+
currTarget = this.dispatchDragEnter(state, currElem, currTarget, event);
|
|
286
|
+
}
|
|
287
|
+
if (currTarget !== prevTarget) {
|
|
288
|
+
state.currentTarget = currTarget;
|
|
289
|
+
if (prevTarget) {
|
|
290
|
+
this.dispatch(state, 'lm-dragleave', prevTarget, event, currTarget);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (!currTarget) {
|
|
294
|
+
state.dropAction = 'none';
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const dragOver = this.dispatch(state, 'lm-dragover', currTarget, event, undefined);
|
|
298
|
+
state.dropAction = dragOver.defaultPrevented ? dragOver.dropAction : 'none';
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Follows `Private.dispatchDragEnter` in `@lumino/dragdrop`.
|
|
303
|
+
*/
|
|
304
|
+
protected dispatchDragEnter(state: WindowDragState, currElem: Element | undefined, currTarget: Element | undefined, event: DragEvent): Element | undefined {
|
|
305
|
+
if (!currElem) {
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|
|
308
|
+
if (this.dispatch(state, 'lm-dragenter', currElem, event, currTarget).defaultPrevented) {
|
|
309
|
+
this.rememberAncestors(currElem);
|
|
310
|
+
return currElem;
|
|
311
|
+
}
|
|
312
|
+
const body = state.window.document.body;
|
|
313
|
+
if (currElem === body) {
|
|
314
|
+
return currTarget;
|
|
315
|
+
}
|
|
316
|
+
this.dispatch(state, 'lm-dragenter', body, event, currTarget);
|
|
317
|
+
return body;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* The ancestors of the drop targets, see {@link rememberAncestors}.
|
|
322
|
+
*/
|
|
323
|
+
protected readonly targetAncestors = new WeakMap<Element, Element[]>();
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Drop targets are often elements that are replaced while dragging, e.g. the lines of an editor that is re-rendered
|
|
327
|
+
* because a side panel expands. Lumino drag events dispatched to a removed element don't reach the drop target that
|
|
328
|
+
* handles them, e.g. the dock panel that has to hide its drop overlay. Such events are dispatched to the nearest
|
|
329
|
+
* ancestor that is still attached instead.
|
|
330
|
+
*/
|
|
331
|
+
protected rememberAncestors(target: Element): void {
|
|
332
|
+
const ancestors: Element[] = [];
|
|
333
|
+
for (let ancestor = target.parentElement; ancestor; ancestor = ancestor.parentElement) {
|
|
334
|
+
ancestors.push(ancestor);
|
|
335
|
+
}
|
|
336
|
+
this.targetAncestors.set(target, ancestors);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
protected dispatch(state: WindowDragState, type: LuminoDragEventType, target: Element, event: DragEvent, related: Element | undefined): Drag.Event {
|
|
340
|
+
// `Drag.Event` is typed to take a `PointerEvent`, but it only copies `MouseEvent` properties (coordinates, button,
|
|
341
|
+
// modifier keys) into the new event, and does not keep a reference to the given event, so a `DragEvent` does as well.
|
|
342
|
+
const dragEvent = new Drag.Event(event as unknown as PointerEvent, {
|
|
343
|
+
drag: this.getDrag(state),
|
|
344
|
+
// eslint-disable-next-line no-null/no-null
|
|
345
|
+
related: related ?? null,
|
|
346
|
+
type
|
|
347
|
+
});
|
|
348
|
+
const attachedTarget = target.isConnected ? target : this.targetAncestors.get(target)?.find(ancestor => ancestor.isConnected);
|
|
349
|
+
attachedTarget?.dispatchEvent(dragEvent);
|
|
350
|
+
return dragEvent;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
protected getDrag(state: WindowDragState): Drag {
|
|
354
|
+
if (!state.drag || state.drag.mimeData !== this.session?.mimeData) {
|
|
355
|
+
// The drag is never started, it only provides the data of the Lumino drag events.
|
|
356
|
+
state.drag = new Drag({
|
|
357
|
+
document: state.window.document,
|
|
358
|
+
mimeData: this.session?.mimeData ?? new MimeData(),
|
|
359
|
+
proposedAction: 'move',
|
|
360
|
+
supportedActions: 'move',
|
|
361
|
+
source: this.session?.source
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
return state.drag;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
protected scheduleLeave(state: WindowDragState): void {
|
|
368
|
+
this.cancelLeave(state);
|
|
369
|
+
state.leaveTimeout = state.window.setTimeout(() => {
|
|
370
|
+
state.leaveTimeout = undefined;
|
|
371
|
+
this.leaveWindow(state);
|
|
372
|
+
}, NativeTabDragService.LEAVE_DELAY);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
protected cancelLeave(state: WindowDragState): void {
|
|
376
|
+
if (state.leaveTimeout !== undefined) {
|
|
377
|
+
state.window.clearTimeout(state.leaveTimeout);
|
|
378
|
+
state.leaveTimeout = undefined;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Notifies the current drop target, if any, that the pointer has left the window.
|
|
384
|
+
*/
|
|
385
|
+
protected leaveWindow(state: WindowDragState): void {
|
|
386
|
+
const target = state.currentTarget;
|
|
387
|
+
state.currentTarget = undefined;
|
|
388
|
+
state.currentElement = undefined;
|
|
389
|
+
state.dropAction = 'none';
|
|
390
|
+
state.inside = false;
|
|
391
|
+
if (target && !state.window.closed) {
|
|
392
|
+
// There is no native event at the time the pointer is known to have left the window.
|
|
393
|
+
this.dispatch(state, 'lm-dragleave', target, new DragEvent('dragleave'), undefined);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
protected resetWindow(state: WindowDragState): void {
|
|
398
|
+
this.cancelLeave(state);
|
|
399
|
+
this.leaveWindow(state);
|
|
400
|
+
state.drag = undefined;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
@@ -52,6 +52,7 @@ describe('ShellLayoutRestorer - Perspective Support', () => {
|
|
|
52
52
|
let mockWindowService: { isSafeToShutDown: sinon.SinonStub; reload: sinon.SinonStub };
|
|
53
53
|
let mockThemeService: { reset: sinon.SinonStub };
|
|
54
54
|
let mockSidePanelItemVisibility: { reset: sinon.SinonStub };
|
|
55
|
+
let mockSecondaryWindowHandler: { getLayoutData: sinon.SinonStub; setLayoutData: sinon.SinonStub };
|
|
55
56
|
let toTearDown: () => void;
|
|
56
57
|
|
|
57
58
|
beforeEach(() => {
|
|
@@ -97,6 +98,10 @@ describe('ShellLayoutRestorer - Perspective Support', () => {
|
|
|
97
98
|
mockThemeService = {
|
|
98
99
|
reset: sinon.stub()
|
|
99
100
|
};
|
|
101
|
+
mockSecondaryWindowHandler = {
|
|
102
|
+
getLayoutData: sinon.stub().returns([]),
|
|
103
|
+
setLayoutData: sinon.stub().resolves()
|
|
104
|
+
};
|
|
100
105
|
|
|
101
106
|
restorer = new ShellLayoutRestorer(
|
|
102
107
|
mockWidgetManager as never,
|
|
@@ -111,6 +116,7 @@ describe('ShellLayoutRestorer - Perspective Support', () => {
|
|
|
111
116
|
(restorer as unknown as Record<string, unknown>)['themeService'] = mockThemeService;
|
|
112
117
|
mockSidePanelItemVisibility = { reset: sinon.stub() };
|
|
113
118
|
(restorer as unknown as Record<string, unknown>)['sidePanelItemVisibility'] = mockSidePanelItemVisibility;
|
|
119
|
+
(restorer as unknown as Record<string, unknown>)['secondaryWindowHandler'] = mockSecondaryWindowHandler;
|
|
114
120
|
});
|
|
115
121
|
|
|
116
122
|
afterEach(() => {
|
|
@@ -405,6 +411,42 @@ describe('ShellLayoutRestorer - Perspective Support', () => {
|
|
|
405
411
|
});
|
|
406
412
|
});
|
|
407
413
|
|
|
414
|
+
describe('secondary windows', () => {
|
|
415
|
+
const secondaryWindow = { bounds: { x: 1, y: 2, width: 3, height: 4 }, config: {} };
|
|
416
|
+
|
|
417
|
+
it('should store the secondary windows with the active perspective layout', () => {
|
|
418
|
+
mockSecondaryWindowHandler.getLayoutData.returns([secondaryWindow]);
|
|
419
|
+
|
|
420
|
+
restorer.storeLayout(mockApp as never);
|
|
421
|
+
|
|
422
|
+
const [key, data] = mockStorageService.setData.firstCall.args as [string, string];
|
|
423
|
+
expect(key).to.equal('layout');
|
|
424
|
+
expect(JSON.parse(data).secondaryWindows).to.deep.equal([secondaryWindow]);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it('should not store secondary windows when there are none', () => {
|
|
428
|
+
restorer.storeLayout(mockApp as never);
|
|
429
|
+
|
|
430
|
+
const [, data] = mockStorageService.setData.firstCall.args as [string, string];
|
|
431
|
+
expect(JSON.parse(data)).to.not.have.property('secondaryWindows');
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it('should restore the secondary windows once, not with the perspective layout', async () => {
|
|
435
|
+
const layout = JSON.stringify({ version: 999, mainPanel: {}, bottomPanel: {}, secondaryWindows: [secondaryWindow] });
|
|
436
|
+
mockStorageService.getData.withArgs(PERSPECTIVE_LAYOUTS_STORAGE_KEY).resolves(undefined);
|
|
437
|
+
mockStorageService.getData.withArgs('layout').resolves(layout);
|
|
438
|
+
mockProvider.getSavedLayout.callsFake((id: string) => mockProvider.setSavedLayout.getCalls().find(
|
|
439
|
+
(c: sinon.SinonSpyCall) => c.args[0] === id
|
|
440
|
+
)?.args[1]);
|
|
441
|
+
|
|
442
|
+
await restorer.restoreLayout(mockApp as never);
|
|
443
|
+
|
|
444
|
+
expect(mockSecondaryWindowHandler.setLayoutData.calledOnceWith([secondaryWindow])).to.be.true;
|
|
445
|
+
// switching to the perspective later on must not open the windows again
|
|
446
|
+
expect(mockProvider.getSavedLayout('default')).to.not.have.property('secondaryWindows');
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
|
|
408
450
|
describe('legacy migration', () => {
|
|
409
451
|
it('should fall back to legacy key when perspective-layouts is absent', async () => {
|
|
410
452
|
|