@theia/core 1.77.0-next.88 → 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 +12 -0
- 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/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/electron-browser/menu/electron-context-menu-renderer.ts +2 -1
- package/src/electron-browser/window/electron-secondary-window-service.ts +1 -0
|
@@ -16,15 +16,21 @@
|
|
|
16
16
|
|
|
17
17
|
import debounce = require('lodash.debounce');
|
|
18
18
|
import { inject, injectable, named } from 'inversify';
|
|
19
|
-
import {
|
|
19
|
+
import { toArray } from '@lumino/algorithm';
|
|
20
|
+
import { BoxLayout, DockLayout, DockPanel, ExtractableWidget, TabBar, Widget } from './widgets';
|
|
20
21
|
import { MessageService } from '../common/message-service';
|
|
21
22
|
import { ApplicationShell, DockPanelRenderer, MAIN_AREA_CLASS, MAIN_BOTTOM_AREA_CLASS } from './shell/application-shell';
|
|
22
23
|
import { Emitter } from '../common/event';
|
|
23
|
-
import {
|
|
24
|
+
import { environment } from '../common';
|
|
25
|
+
import { isSecondaryWindow, SecondaryWindowOptions, SecondaryWindowRootWidget, SecondaryWindowService } from './window/secondary-window-service';
|
|
24
26
|
import { KeybindingRegistry } from './keybinding';
|
|
25
27
|
import { MAIN_AREA_ID, TheiaDockPanel } from './shell/theia-dock-panel';
|
|
26
28
|
import { ILogger } from '../common/logger';
|
|
27
29
|
import { nls } from '../common/nls';
|
|
30
|
+
import { NativeTabDragService } from './shell/native-tab-drag-service';
|
|
31
|
+
import { WindowService } from './window/window-service';
|
|
32
|
+
import { PreferenceService } from '../common/preferences';
|
|
33
|
+
import { WindowFocusService } from './window/window-focus-service';
|
|
28
34
|
|
|
29
35
|
/** Widgets to be contained inside a DockPanel in the secondary window. */
|
|
30
36
|
class SecondaryWindowDockPanelWidget extends SecondaryWindowRootWidget {
|
|
@@ -32,11 +38,18 @@ class SecondaryWindowDockPanelWidget extends SecondaryWindowRootWidget {
|
|
|
32
38
|
protected _widgets: Widget[] = [];
|
|
33
39
|
protected dockPanel: TheiaDockPanel;
|
|
34
40
|
|
|
41
|
+
/** The bounds of the window when it was closed */
|
|
42
|
+
closedBounds: SecondaryWindowHandler.WindowBounds | undefined;
|
|
43
|
+
|
|
35
44
|
constructor(
|
|
36
45
|
dockPanelFactory: TheiaDockPanel.Factory,
|
|
37
46
|
dockPanelRendererFactory: (document?: Document | ShadowRoot) => DockPanelRenderer,
|
|
38
47
|
closeHandler: (sender: TabBar<Widget>, args: TabBar.ITabCloseRequestedArgs<Widget>) => boolean,
|
|
39
|
-
secondaryWindow: Window
|
|
48
|
+
secondaryWindow: Window,
|
|
49
|
+
dropOptions?: Pick<TheiaDockPanel.IOptions, 'canDropWidget' | 'onWillDropWidget'> & {
|
|
50
|
+
/** Called when a widget has been dropped on this window, it must be tracked with {@link track} */
|
|
51
|
+
onDidDropWidget(widget: Widget): void
|
|
52
|
+
}
|
|
40
53
|
) {
|
|
41
54
|
super();
|
|
42
55
|
this.secondaryWindow = secondaryWindow;
|
|
@@ -47,12 +60,22 @@ class SecondaryWindowDockPanelWidget extends SecondaryWindowRootWidget {
|
|
|
47
60
|
renderer.tabBarClasses.push(MAIN_BOTTOM_AREA_CLASS);
|
|
48
61
|
renderer.tabBarClasses.push(MAIN_AREA_CLASS);
|
|
49
62
|
this.dockPanel = dockPanelFactory({
|
|
50
|
-
disableDragAndDrop:
|
|
63
|
+
disableDragAndDrop: !dropOptions,
|
|
51
64
|
closeHandler,
|
|
52
65
|
mode: 'multiple-document',
|
|
53
66
|
renderer,
|
|
67
|
+
canDropWidget: dropOptions?.canDropWidget,
|
|
68
|
+
onWillDropWidget: dropOptions?.onWillDropWidget
|
|
54
69
|
});
|
|
55
70
|
this.dockPanel.id = MAIN_AREA_ID;
|
|
71
|
+
if (dropOptions) {
|
|
72
|
+
// widgets added through `addWidget` are tracked already
|
|
73
|
+
this.dockPanel.widgetAdded.connect((_, widget) => {
|
|
74
|
+
if (!this._widgets.includes(widget)) {
|
|
75
|
+
dropOptions.onDidDropWidget(widget);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
56
79
|
BoxLayout.setStretch(this.dockPanel, 1);
|
|
57
80
|
boxLayout.addWidget(this.dockPanel);
|
|
58
81
|
this.layout = boxLayout;
|
|
@@ -63,23 +86,59 @@ class SecondaryWindowDockPanelWidget extends SecondaryWindowRootWidget {
|
|
|
63
86
|
}
|
|
64
87
|
|
|
65
88
|
addWidget(widget: Widget, disposeCallback: () => void, options?: TheiaDockPanel.AddOptions): void {
|
|
66
|
-
this.
|
|
89
|
+
this.track(widget, disposeCallback);
|
|
67
90
|
this.dockPanel.addWidget(widget, options);
|
|
91
|
+
this.dockPanel.activateWidget(widget);
|
|
92
|
+
}
|
|
68
93
|
|
|
69
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Tracks the given widget, which has been added to the dock panel of this window.
|
|
96
|
+
*
|
|
97
|
+
* @param disposeCallback called when the widget leaves this window
|
|
98
|
+
*/
|
|
99
|
+
track(widget: Widget, disposeCallback: () => void): void {
|
|
100
|
+
this._widgets.push(widget);
|
|
101
|
+
|
|
102
|
+
// the widget leaves this window when it is disposed, moved back to the main window or dragged to another window
|
|
103
|
+
const onRemove = () => {
|
|
70
104
|
const index = this._widgets.indexOf(widget);
|
|
71
105
|
if (index > -1) {
|
|
72
106
|
this._widgets.splice(index, 1);
|
|
107
|
+
widget.disposed.disconnect(onRemove);
|
|
108
|
+
this.dockPanel.widgetRemoved.disconnect(onWidgetRemoved);
|
|
109
|
+
disposeCallback();
|
|
73
110
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
111
|
+
};
|
|
112
|
+
const onWidgetRemoved = (_: TheiaDockPanel, removed: Widget) => {
|
|
113
|
+
if (removed === widget) {
|
|
114
|
+
onRemove();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
widget.disposed.connect(onRemove);
|
|
118
|
+
this.dockPanel.widgetRemoved.connect(onWidgetRemoved);
|
|
78
119
|
}
|
|
79
120
|
|
|
80
121
|
override getTabBar(widget: Widget): TabBar<Widget> | undefined {
|
|
81
122
|
return this.dockPanel.findTabBar(widget.title);
|
|
82
123
|
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @returns the widgets in the order of the dock panel's layout
|
|
127
|
+
*/
|
|
128
|
+
getLayoutWidgets(): Widget[] {
|
|
129
|
+
return toArray(this.dockPanel.widgets());
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
saveLayout(): DockPanel.ILayoutConfig {
|
|
133
|
+
return this.dockPanel.saveLayout();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Restores the layout of the dock panel. The widgets of the layout must be tracked with {@link track} beforehand.
|
|
138
|
+
*/
|
|
139
|
+
restoreLayout(config: DockPanel.ILayoutConfig): void {
|
|
140
|
+
this.dockPanel.restoreLayout(config);
|
|
141
|
+
}
|
|
83
142
|
}
|
|
84
143
|
|
|
85
144
|
/**
|
|
@@ -130,6 +189,24 @@ export class SecondaryWindowHandler {
|
|
|
130
189
|
@inject(SecondaryWindowService)
|
|
131
190
|
protected readonly secondaryWindowService: SecondaryWindowService;
|
|
132
191
|
|
|
192
|
+
@inject(NativeTabDragService)
|
|
193
|
+
protected readonly nativeTabDragService: NativeTabDragService;
|
|
194
|
+
|
|
195
|
+
@inject(WindowService)
|
|
196
|
+
protected readonly windowService: WindowService;
|
|
197
|
+
|
|
198
|
+
@inject(PreferenceService)
|
|
199
|
+
protected readonly preferenceService: PreferenceService;
|
|
200
|
+
|
|
201
|
+
@inject(WindowFocusService)
|
|
202
|
+
protected readonly windowFocusService: WindowFocusService;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The secondary windows that are being restored, see {@link setLayoutData}, and have not been loaded yet.
|
|
206
|
+
* Their widgets are not tracked yet, so they are stored with the layout as they were restored.
|
|
207
|
+
*/
|
|
208
|
+
protected readonly pendingWindows = new Map<Window, SecondaryWindowHandler.LayoutData>();
|
|
209
|
+
|
|
133
210
|
/** @returns List of widgets in secondary windows. */
|
|
134
211
|
get widgets(): ReadonlyArray<Widget> {
|
|
135
212
|
// Create new array in case the original changes while this is used.
|
|
@@ -152,14 +229,33 @@ export class SecondaryWindowHandler {
|
|
|
152
229
|
this.dockPanelRendererFactory = dockPanelRendererFactory;
|
|
153
230
|
|
|
154
231
|
this.secondaryWindowService.beforeWidgetRestore(([widget, window]) => this.removeWidget(widget, window));
|
|
232
|
+
this.nativeTabDragService.onDidDropTab(({ title, window: target }) => this.focusDroppedWidget(title.owner, target));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Focuses the window in which a tab has been dropped and the widget of the tab. The drag started in another window,
|
|
237
|
+
* or outside of the main area, which keeps the focus otherwise.
|
|
238
|
+
*/
|
|
239
|
+
protected focusDroppedWidget(widget: Widget, target: Window): void {
|
|
240
|
+
if (widget.isDisposed) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (target === window) {
|
|
244
|
+
this.windowService.focus();
|
|
245
|
+
this.applicationShell.activateWidget(widget.id);
|
|
246
|
+
} else {
|
|
247
|
+
this.secondaryWindowService.focus(target);
|
|
248
|
+
widget.activate();
|
|
249
|
+
}
|
|
155
250
|
}
|
|
156
251
|
|
|
157
252
|
/**
|
|
158
253
|
* Moves the given widget to a new window.
|
|
159
254
|
*
|
|
160
255
|
* @param widget the widget to extract
|
|
256
|
+
* @param options optional options for the created window, e.g. its screen position
|
|
161
257
|
*/
|
|
162
|
-
moveWidgetToSecondaryWindow(widget: ExtractableWidget): void {
|
|
258
|
+
moveWidgetToSecondaryWindow(widget: ExtractableWidget, options?: SecondaryWindowOptions): void {
|
|
163
259
|
if (!this.applicationShell) {
|
|
164
260
|
this.logger.error('Widget cannot be extracted because the WidgetExtractionHandler has not been initialized.');
|
|
165
261
|
return;
|
|
@@ -169,17 +265,51 @@ export class SecondaryWindowHandler {
|
|
|
169
265
|
return;
|
|
170
266
|
}
|
|
171
267
|
|
|
172
|
-
|
|
268
|
+
// a widget that is moved from one secondary window to another one keeps the area to restore it to
|
|
269
|
+
const previousArea = widget.secondaryWindow ? widget.previousArea : this.applicationShell.getAreaFor(widget);
|
|
270
|
+
const opened = this.openSecondaryWindow(widget, options, (newWindow, rootWidget) => {
|
|
271
|
+
this.onWillAddWidgetEmitter.fire([widget, newWindow]);
|
|
173
272
|
|
|
174
|
-
|
|
273
|
+
widget.secondaryWindow = newWindow;
|
|
274
|
+
widget.previousArea = previousArea;
|
|
275
|
+
rootWidget.defaultRestoreArea = previousArea;
|
|
276
|
+
rootWidget.addWidget(widget, () => {
|
|
277
|
+
this.onWidgetRemove(widget, newWindow, rootWidget);
|
|
278
|
+
});
|
|
279
|
+
widget.show();
|
|
280
|
+
widget.update();
|
|
281
|
+
|
|
282
|
+
this.addWidget(widget, newWindow);
|
|
283
|
+
widget.activate();
|
|
284
|
+
});
|
|
285
|
+
if (!opened) {
|
|
175
286
|
this.messageService.error('The widget could not be moved to a secondary window because the window creation failed. Please make sure to allow popups.');
|
|
176
|
-
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Opens a secondary window and sets up its root widget once the window has been loaded.
|
|
292
|
+
*
|
|
293
|
+
* @param widget the widget the window is created for, its label is used as the window title
|
|
294
|
+
* @param options the options for the created window, e.g. its bounds
|
|
295
|
+
* @param populate adds the widgets to the root widget of the loaded window
|
|
296
|
+
* @param onDidFailToLoad called if the loaded window cannot host widgets, the window is closed then
|
|
297
|
+
* @returns the created window or `undefined` if it could not be created
|
|
298
|
+
*/
|
|
299
|
+
protected openSecondaryWindow(widget: ExtractableWidget, options: SecondaryWindowOptions | undefined,
|
|
300
|
+
populate: (newWindow: Window, rootWidget: SecondaryWindowDockPanelWidget) => void, onDidFailToLoad?: (newWindow: Window) => void): Window | undefined {
|
|
301
|
+
const newWindow = this.secondaryWindowService.createSecondaryWindow(widget, this.applicationShell, options);
|
|
302
|
+
if (!newWindow) {
|
|
303
|
+
return undefined;
|
|
177
304
|
}
|
|
178
305
|
|
|
179
306
|
const mainWindowTitle = document.title;
|
|
180
307
|
|
|
181
308
|
newWindow.addEventListener('load', () => {
|
|
182
309
|
this.keybindings.registerEventListeners(newWindow);
|
|
310
|
+
// tabs dragged from other windows must not be dropped on the default drop targets of this window
|
|
311
|
+
const tabDragRegistration = this.nativeTabDragService.installWindow(newWindow);
|
|
312
|
+
newWindow.addEventListener('pagehide', () => tabDragRegistration.dispose());
|
|
183
313
|
// Use the widget's title as the window title
|
|
184
314
|
// Even if the widget's label were malicious, this should be safe against XSS because the HTML standard defines this is inserted via a text node.
|
|
185
315
|
// See https://html.spec.whatwg.org/multipage/dom.html#document.title
|
|
@@ -190,29 +320,29 @@ export class SecondaryWindowHandler {
|
|
|
190
320
|
const element = newWindow.document.getElementById('widget-host');
|
|
191
321
|
if (!element) {
|
|
192
322
|
this.logger.error('Could not find dom element to attach to in secondary window');
|
|
323
|
+
newWindow.close();
|
|
324
|
+
onDidFailToLoad?.(newWindow);
|
|
193
325
|
return;
|
|
194
326
|
}
|
|
195
327
|
|
|
196
|
-
this.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
rootWidget.defaultRestoreArea = widget.previousArea;
|
|
328
|
+
const rootWidget: SecondaryWindowDockPanelWidget = new SecondaryWindowDockPanelWidget(this.dockPanelFactory, this.dockPanelRendererFactory, this.onTabCloseRequested,
|
|
329
|
+
newWindow, {
|
|
330
|
+
canDropWidget: dropped => this.canDropInSecondaryWindow(dropped),
|
|
331
|
+
onWillDropWidget: dropped => this.onWillDropInSecondaryWindow(dropped),
|
|
332
|
+
onDidDropWidget: dropped => this.onDidDropInSecondaryWindow(dropped, newWindow, rootWidget)
|
|
333
|
+
});
|
|
203
334
|
rootWidget.addClass('secondary-widget-root');
|
|
204
335
|
rootWidget.addClass('monaco-workbench'); // needed for compatility with VSCode styles
|
|
205
336
|
Widget.attach(rootWidget, element);
|
|
206
337
|
if (isSecondaryWindow(newWindow)) {
|
|
207
338
|
newWindow.rootWidget = rootWidget;
|
|
208
339
|
}
|
|
209
|
-
|
|
210
|
-
|
|
340
|
+
// the window is closed already when the layout is stored on shutdown
|
|
341
|
+
newWindow.addEventListener('pagehide', () => {
|
|
342
|
+
rootWidget.closedBounds = this.getWindowBounds(newWindow);
|
|
211
343
|
});
|
|
212
|
-
widget.show();
|
|
213
|
-
widget.update();
|
|
214
344
|
|
|
215
|
-
|
|
345
|
+
populate(newWindow, rootWidget);
|
|
216
346
|
|
|
217
347
|
// debounce to avoid rapid updates while resizing the secondary window
|
|
218
348
|
const updateWidget = debounce(() => {
|
|
@@ -221,8 +351,144 @@ export class SecondaryWindowHandler {
|
|
|
221
351
|
newWindow.addEventListener('resize', () => {
|
|
222
352
|
updateWidget();
|
|
223
353
|
});
|
|
224
|
-
widget.activate();
|
|
225
354
|
});
|
|
355
|
+
return newWindow;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* @returns the bounds of the given window, the size as expected by `window.open`
|
|
360
|
+
*/
|
|
361
|
+
protected getWindowBounds(win: Window): SecondaryWindowHandler.WindowBounds {
|
|
362
|
+
// Electron applies the size given to `window.open` to the window, browsers apply it to the content
|
|
363
|
+
return environment.electron.is()
|
|
364
|
+
? { x: win.screenX, y: win.screenY, width: win.outerWidth, height: win.outerHeight }
|
|
365
|
+
: { x: win.screenX, y: win.screenY, width: win.innerWidth, height: win.innerHeight };
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* @returns the data to restore the open secondary windows with their widgets, see {@link setLayoutData}
|
|
370
|
+
*/
|
|
371
|
+
getLayoutData(): SecondaryWindowHandler.LayoutData[] {
|
|
372
|
+
const rootWidgets = new Set<SecondaryWindowDockPanelWidget>();
|
|
373
|
+
for (const widget of this._widgets) {
|
|
374
|
+
const rootWidget = extractSecondaryWindowRootWidget(widget);
|
|
375
|
+
if (rootWidget instanceof SecondaryWindowDockPanelWidget) {
|
|
376
|
+
rootWidgets.add(rootWidget);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const openWindows: SecondaryWindowHandler.LayoutData[] = Array.from(rootWidgets, rootWidget => ({
|
|
380
|
+
bounds: rootWidget.secondaryWindow.closed ? rootWidget.closedBounds : this.getWindowBounds(rootWidget.secondaryWindow),
|
|
381
|
+
config: rootWidget.saveLayout(),
|
|
382
|
+
restoreAreas: rootWidget.getLayoutWidgets().map(widget =>
|
|
383
|
+
(ExtractableWidget.is(widget) ? widget.previousArea : undefined) ?? rootWidget.defaultRestoreArea ?? 'main')
|
|
384
|
+
}));
|
|
385
|
+
return [...openWindows, ...this.pendingWindows.values()];
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Opens secondary windows with the widgets of the given layout data, see {@link getLayoutData}.
|
|
390
|
+
* The widgets are added to the main window instead if the `window.restoreSecondaryWindows` preference is disabled,
|
|
391
|
+
* or if their window cannot be opened, e.g. because a browser blocks the popup.
|
|
392
|
+
*/
|
|
393
|
+
async setLayoutData(layoutData: SecondaryWindowHandler.LayoutData[]): Promise<void> {
|
|
394
|
+
if (!this.applicationShell) {
|
|
395
|
+
this.logger.error('Secondary windows cannot be restored because the SecondaryWindowHandler has not been initialized.');
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
// the layout may be restored before the preferences have been loaded
|
|
399
|
+
await this.preferenceService.ready;
|
|
400
|
+
const openWindows = this.preferenceService.get('window.restoreSecondaryWindows', true);
|
|
401
|
+
for (const data of layoutData) {
|
|
402
|
+
this.restoreSecondaryWindow(data, openWindows);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
protected restoreSecondaryWindow(data: SecondaryWindowHandler.LayoutData, openWindow: boolean): void {
|
|
407
|
+
const { bounds, config, restoreAreas } = data;
|
|
408
|
+
const widgets = this.collectLayoutWidgets(config.main);
|
|
409
|
+
// widgets that could not be stored or restored are missing from the layout, the areas cannot be matched with the widgets then
|
|
410
|
+
const previousArea = new Map<Widget, ApplicationShell.Area>();
|
|
411
|
+
if (restoreAreas?.length === widgets.length) {
|
|
412
|
+
widgets.forEach((widget, i) => previousArea.set(widget, restoreAreas[i]));
|
|
413
|
+
}
|
|
414
|
+
const getPreviousArea = (widget: Widget) => previousArea.get(widget) ?? 'main';
|
|
415
|
+
// widgets that have been added elsewhere in the meantime are not moved
|
|
416
|
+
const isAvailable = (widget: Widget) => !widget.parent && !widget.isDisposed;
|
|
417
|
+
const addToMainWindow = () => {
|
|
418
|
+
for (const widget of widgets.filter(isAvailable)) {
|
|
419
|
+
this.applicationShell.addWidget(widget, { area: SecondaryWindowHandler.getMainWindowArea(getPreviousArea(widget)) });
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
const extractable = widgets.find(widget => isAvailable(widget) && ExtractableWidget.is(widget) && widget.isExtractable) as ExtractableWidget | undefined;
|
|
424
|
+
const options: SecondaryWindowOptions | undefined = bounds && { position: { x: bounds.x, y: bounds.y }, size: { width: bounds.width, height: bounds.height } };
|
|
425
|
+
const opened = openWindow && extractable && this.openSecondaryWindow(extractable, options, (newWindow, rootWidget) => {
|
|
426
|
+
this.pendingWindows.delete(newWindow);
|
|
427
|
+
this.removeFromLayout(config.main, isAvailable);
|
|
428
|
+
const windowWidgets = this.collectLayoutWidgets(config.main);
|
|
429
|
+
if (windowWidgets.length === 0) {
|
|
430
|
+
newWindow.close();
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
rootWidget.defaultRestoreArea = getPreviousArea(windowWidgets[0]);
|
|
434
|
+
for (const widget of windowWidgets) {
|
|
435
|
+
this.onWillAddWidgetEmitter.fire([widget, newWindow]);
|
|
436
|
+
if (ExtractableWidget.is(widget)) {
|
|
437
|
+
widget.secondaryWindow = newWindow;
|
|
438
|
+
widget.previousArea = getPreviousArea(widget);
|
|
439
|
+
}
|
|
440
|
+
rootWidget.track(widget, () => {
|
|
441
|
+
this.onWidgetRemove(widget, newWindow, rootWidget);
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
rootWidget.restoreLayout(config);
|
|
445
|
+
for (const widget of windowWidgets) {
|
|
446
|
+
this.addWidget(widget, newWindow);
|
|
447
|
+
}
|
|
448
|
+
}, newWindow => {
|
|
449
|
+
this.pendingWindows.delete(newWindow);
|
|
450
|
+
addToMainWindow();
|
|
451
|
+
});
|
|
452
|
+
if (opened) {
|
|
453
|
+
this.pendingWindows.set(opened, data);
|
|
454
|
+
// the window may be closed before it has been populated, its widgets would not be shown anywhere then
|
|
455
|
+
const closeListener = this.secondaryWindowService.onWindowClosed(closed => {
|
|
456
|
+
if (closed === opened) {
|
|
457
|
+
closeListener.dispose();
|
|
458
|
+
if (this.pendingWindows.delete(opened)) {
|
|
459
|
+
addToMainWindow();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
} else {
|
|
464
|
+
addToMainWindow();
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
protected collectLayoutWidgets(area: DockLayout.AreaConfig | null): Widget[] {
|
|
469
|
+
if (!area) {
|
|
470
|
+
return [];
|
|
471
|
+
}
|
|
472
|
+
if (area.type === 'tab-area') {
|
|
473
|
+
return [...area.widgets];
|
|
474
|
+
}
|
|
475
|
+
return area.children.flatMap(child => this.collectLayoutWidgets(child));
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Removes the widgets that do not match the given predicate from the given layout. Empty areas are removed when the layout is restored.
|
|
480
|
+
*/
|
|
481
|
+
protected removeFromLayout(area: DockLayout.AreaConfig | null, keep: (widget: Widget) => boolean): void {
|
|
482
|
+
if (!area) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (area.type === 'tab-area') {
|
|
486
|
+
const current = area.widgets[area.currentIndex];
|
|
487
|
+
area.widgets = area.widgets.filter(keep);
|
|
488
|
+
area.currentIndex = Math.max(0, area.widgets.indexOf(current));
|
|
489
|
+
} else {
|
|
490
|
+
area.children.forEach(child => this.removeFromLayout(child, keep));
|
|
491
|
+
}
|
|
226
492
|
}
|
|
227
493
|
|
|
228
494
|
protected setupHtmlLanguageAttributes(element: HTMLElement): void {
|
|
@@ -230,15 +496,82 @@ export class SecondaryWindowHandler {
|
|
|
230
496
|
nls.setHtmlNoTranslate(element);
|
|
231
497
|
}
|
|
232
498
|
|
|
499
|
+
/**
|
|
500
|
+
* Moves the given widget from its secondary window back to the main window.
|
|
501
|
+
* The secondary window is closed once it does not contain any widgets anymore.
|
|
502
|
+
*
|
|
503
|
+
* @param widget the widget to move back
|
|
504
|
+
*/
|
|
505
|
+
async moveWidgetToMainWindow(widget: Widget): Promise<void> {
|
|
506
|
+
if (!this.applicationShell) {
|
|
507
|
+
this.logger.error('Widget cannot be moved back because the WidgetExtractionHandler has not been initialized.');
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
const secondaryWindow = extractSecondaryWindow(widget);
|
|
511
|
+
if (!secondaryWindow) {
|
|
512
|
+
this.logger.error('Widget is not contained in a secondary window.', widget.id);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
await this.secondaryWindowService.restoreWidget(widget, secondaryWindow, this.applicationShell);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Moves all widgets of the given secondary window back to the main window, which closes the secondary window.
|
|
520
|
+
*
|
|
521
|
+
* @param secondaryWindow the window to move the widgets from
|
|
522
|
+
*/
|
|
523
|
+
async moveAllWidgetsToMainWindow(secondaryWindow: Window): Promise<void> {
|
|
524
|
+
// copy, as moving a widget back removes it from the secondary window's widgets
|
|
525
|
+
for (const widget of [...getAllWidgetsFromSecondaryWindow(secondaryWindow) ?? []]) {
|
|
526
|
+
await this.moveWidgetToMainWindow(widget);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Only widgets that can be moved to secondary windows, or that are in a secondary window already, can be dropped on secondary windows.
|
|
532
|
+
*/
|
|
533
|
+
protected canDropInSecondaryWindow(widget: Widget): boolean {
|
|
534
|
+
return ExtractableWidget.is(widget) || this._widgets.includes(widget);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
protected onWillDropInSecondaryWindow(widget: Widget): void {
|
|
538
|
+
if (ExtractableWidget.is(widget) && widget.secondaryWindow === undefined) {
|
|
539
|
+
// the widget is still in the main window
|
|
540
|
+
widget.previousArea = this.applicationShell.getAreaFor(widget);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
protected onDidDropInSecondaryWindow(widget: Widget, secondaryWindow: Window, rootWidget: SecondaryWindowDockPanelWidget): void {
|
|
545
|
+
// the widget is part of the window's dock panel already, but not tracked yet
|
|
546
|
+
this.onWillAddWidgetEmitter.fire([widget, secondaryWindow]);
|
|
547
|
+
if (ExtractableWidget.is(widget)) {
|
|
548
|
+
widget.secondaryWindow = secondaryWindow;
|
|
549
|
+
}
|
|
550
|
+
rootWidget.track(widget, () => {
|
|
551
|
+
this.onWidgetRemove(widget, secondaryWindow, rootWidget);
|
|
552
|
+
});
|
|
553
|
+
this.addWidget(widget, secondaryWindow);
|
|
554
|
+
}
|
|
555
|
+
|
|
233
556
|
private onWidgetRemove(widget: Widget, newWindow: Window, rootWidget: SecondaryWindowRootWidget): void {
|
|
234
|
-
//
|
|
235
|
-
this.
|
|
236
|
-
|
|
557
|
+
// Widgets moved back to the main window have already been removed via `beforeWidgetRestore`
|
|
558
|
+
if (this._widgets.includes(widget)) {
|
|
559
|
+
this.onWillRemoveWidgetEmitter.fire([widget, newWindow]);
|
|
560
|
+
this.removeWidget(widget, newWindow);
|
|
561
|
+
}
|
|
562
|
+
// A widget dropped on another window is assigned to that window once it has been added there
|
|
563
|
+
if (ExtractableWidget.is(widget) && widget.secondaryWindow === newWindow) {
|
|
564
|
+
widget.secondaryWindow = undefined;
|
|
565
|
+
}
|
|
566
|
+
// Close the window if the widget is disposed, e.g. by a command closing all widgets, or the last widget was moved away.
|
|
237
567
|
if (!newWindow.closed && rootWidget.widgets.length === 0) {
|
|
238
|
-
//
|
|
239
|
-
|
|
568
|
+
// Close asynchronously, as the widget may have been dragged away by a drag that started in this window
|
|
569
|
+
setTimeout(() => {
|
|
570
|
+
if (!newWindow.closed && rootWidget.widgets.length === 0) {
|
|
571
|
+
newWindow.close();
|
|
572
|
+
}
|
|
573
|
+
});
|
|
240
574
|
}
|
|
241
|
-
|
|
242
575
|
}
|
|
243
576
|
|
|
244
577
|
addWidgetToSecondaryWindow(widget: Widget, secondaryWindow: Window, options?: TheiaDockPanel.AddOptions): void {
|
|
@@ -313,7 +646,7 @@ export class SecondaryWindowHandler {
|
|
|
313
646
|
}
|
|
314
647
|
|
|
315
648
|
getFocusedWindow(): Window | undefined {
|
|
316
|
-
return
|
|
649
|
+
return this.windowFocusService.focusedWindow;
|
|
317
650
|
}
|
|
318
651
|
|
|
319
652
|
protected addWidget(widget: Widget, win: Window): void {
|
|
@@ -341,6 +674,36 @@ export class SecondaryWindowHandler {
|
|
|
341
674
|
|
|
342
675
|
}
|
|
343
676
|
|
|
677
|
+
export namespace SecondaryWindowHandler {
|
|
678
|
+
/**
|
|
679
|
+
* The screen bounds of a secondary window.
|
|
680
|
+
*/
|
|
681
|
+
export interface WindowBounds {
|
|
682
|
+
x: number;
|
|
683
|
+
y: number;
|
|
684
|
+
width: number;
|
|
685
|
+
height: number;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Data to save and restore a secondary window with its widgets.
|
|
690
|
+
*/
|
|
691
|
+
export interface LayoutData {
|
|
692
|
+
bounds?: WindowBounds;
|
|
693
|
+
/** The layout of the window's dock panel */
|
|
694
|
+
config: DockPanel.ILayoutConfig;
|
|
695
|
+
/** The areas of the main window to move the widgets of `config` back to, in the order of the widgets in `config` */
|
|
696
|
+
restoreAreas?: ApplicationShell.Area[];
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* @returns the area of the main window to move a widget back to whose previous area is the given one
|
|
701
|
+
*/
|
|
702
|
+
export function getMainWindowArea(previousArea: ApplicationShell.Area | undefined): ApplicationShell.Area {
|
|
703
|
+
return previousArea === undefined || previousArea === 'top' || previousArea === 'secondaryWindow' ? 'main' : previousArea;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
344
707
|
export function getDefaultRestoreArea(window: Window): ApplicationShell.Area | undefined {
|
|
345
708
|
if (isSecondaryWindow(window) && window.rootWidget !== undefined) {
|
|
346
709
|
return window.rootWidget.defaultRestoreArea;
|
|
@@ -21,6 +21,7 @@ import { DisposableCollection, Disposable } from '../../common/disposable';
|
|
|
21
21
|
import { Emitter, Event } from '../../common/event';
|
|
22
22
|
import { FocusTracker, PanelLayout, SplitPanel } from '@lumino/widgets';
|
|
23
23
|
import { addEventListener, Widget } from '../widgets';
|
|
24
|
+
import { NativeTabDragService } from './native-tab-drag-service';
|
|
24
25
|
/**
|
|
25
26
|
* Contribution that tracks `mouseup` and `mousedown` events.
|
|
26
27
|
*
|
|
@@ -35,6 +36,9 @@ export class ApplicationShellMouseTracker implements FrontendApplicationContribu
|
|
|
35
36
|
@inject(ApplicationShell)
|
|
36
37
|
protected readonly applicationShell: ApplicationShell;
|
|
37
38
|
|
|
39
|
+
@inject(NativeTabDragService)
|
|
40
|
+
protected readonly nativeTabDragService: NativeTabDragService;
|
|
41
|
+
|
|
38
42
|
protected readonly toDispose = new DisposableCollection();
|
|
39
43
|
protected readonly toDisposeOnActiveChange = new DisposableCollection();
|
|
40
44
|
|
|
@@ -71,6 +75,12 @@ export class ApplicationShellMouseTracker implements FrontendApplicationContribu
|
|
|
71
75
|
// The `mouseup` event has to be tracked on the `document`. Lumino attaches to there.
|
|
72
76
|
document.addEventListener('mouseup', this.mouseupListener, true);
|
|
73
77
|
|
|
78
|
+
// Native tab drags end without a `mouseup` event. They may also start in a secondary window, whose `mousedown` events are not tracked.
|
|
79
|
+
this.toDispose.pushAll([
|
|
80
|
+
this.nativeTabDragService.onDidStartDrag(e => this.mousedownEmitter.fire(e)),
|
|
81
|
+
this.nativeTabDragService.onDidEndDrag(e => this.mouseupEmitter.fire(e))
|
|
82
|
+
]);
|
|
83
|
+
|
|
74
84
|
// Make sure it is disposed in the end.
|
|
75
85
|
this.toDispose.pushAll([
|
|
76
86
|
this.mousedownEmitter,
|