@theia/secondary-window 1.77.0-next.1 → 1.77.0-next.101

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.
@@ -1,11 +1,31 @@
1
1
  import { CommandRegistry, CommandContribution, Command } from '@theia/core/lib/common/command';
2
+ import { MenuContribution, MenuModelRegistry, MenuPath } from '@theia/core/lib/common/menu';
3
+ import { Widget } from '@theia/core/lib/browser/widgets';
4
+ import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
5
+ import { NativeTabDragService, TabDropOutsideWindowsEvent } from '@theia/core/lib/browser/shell/native-tab-drag-service';
2
6
  import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
3
7
  import { SecondaryWindowHandler } from '@theia/core/lib/browser/secondary-window-handler';
4
8
  export declare const EXTRACT_WIDGET: Command;
5
- /** Contributes the widget extraction command and registers it in the toolbar of extractable widgets. */
6
- export declare class SecondaryWindowContribution implements CommandContribution, TabBarToolbarContribution {
9
+ export declare const RESTORE_WIDGET: Command;
10
+ export declare const RESTORE_ALL_WIDGETS: Command;
11
+ export declare const SHELL_TABBAR_CONTEXT_SECONDARY_WINDOW: MenuPath;
12
+ /**
13
+ * Contributes the commands to move widgets to secondary windows and back, and registers them in the toolbar and in the context menu of tabs.
14
+ * In addition, extracts widgets whose tab is dragged out of the application's windows.
15
+ */
16
+ export declare class SecondaryWindowContribution implements CommandContribution, MenuContribution, TabBarToolbarContribution {
7
17
  protected readonly secondaryWindowHandler: SecondaryWindowHandler;
18
+ protected readonly nativeTabDragService: NativeTabDragService;
19
+ protected readonly shell: ApplicationShell;
20
+ protected init(): void;
21
+ protected onDidDropTabOutsideWindows({ title, screenX, screenY }: TabDropOutsideWindowsEvent): void;
8
22
  registerCommands(commands: CommandRegistry): void;
23
+ registerMenus(menus: MenuModelRegistry): void;
9
24
  registerToolbarItems(registry: TabBarToolbarRegistry): void;
25
+ /**
26
+ * @returns the widget a command is executed for: the widget passed by the tab bar toolbar, the widget of the tab
27
+ * whose context menu has been opened, or the current widget if no argument is passed, e.g. from the command palette
28
+ */
29
+ protected getTargetWidget(arg: unknown): Widget | undefined;
10
30
  }
11
31
  //# sourceMappingURL=secondary-window-frontend-contribution.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"secondary-window-frontend-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/secondary-window-frontend-contribution.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAE/F,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AACjH,OAAO,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAE1F,eAAO,MAAM,cAAc,SAGgB,CAAC;AAE5C,wGAAwG;AACxG,qBACa,2BAA4B,YAAW,mBAAmB,EAAE,yBAAyB;IAG9F,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB,CAAC;IAElE,gBAAgB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAQjD,oBAAoB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI;CAO9D"}
1
+ {"version":3,"file":"secondary-window-frontend-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/secondary-window-frontend-contribution.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC/F,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAA8B,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iDAAiD,CAAC;AAEnF,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,uDAAuD,CAAC;AACzH,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AACjH,OAAO,EAA4D,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAEpJ,eAAO,MAAM,cAAc,SAGgB,CAAC;AAE5C,eAAO,MAAM,cAAc,SAGgB,CAAC;AAE5C,eAAO,MAAM,mBAAmB,SAGgB,CAAC;AAEjD,eAAO,MAAM,qCAAqC,EAAE,QAA8D,CAAC;AAEnH;;;GAGG;AACH,qBACa,2BAA4B,YAAW,mBAAmB,EAAE,gBAAgB,EAAE,yBAAyB;IAGhH,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB,CAAC;IAGlE,SAAS,CAAC,QAAQ,CAAC,oBAAoB,EAAE,oBAAoB,CAAC;IAG9D,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IAG3C,SAAS,CAAC,IAAI,IAAI,IAAI;IAItB,SAAS,CAAC,0BAA0B,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,0BAA0B,GAAG,IAAI;IAWnG,gBAAgB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAsCjD,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;IAe7C,oBAAoB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI;IAc3D;;;OAGG;IACH,SAAS,CAAC,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS;CAU9D"}
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // *****************************************************************************
3
2
  // Copyright (C) 2022 STMicroelectronics, Ericsson, ARM, EclipseSource and others.
4
3
  //
@@ -14,40 +13,139 @@
14
13
  //
15
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
15
  // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.SecondaryWindowContribution = exports.EXTRACT_WIDGET = void 0;
19
- const tslib_1 = require("tslib");
20
- const inversify_1 = require("@theia/core/shared/inversify");
21
- const command_1 = require("@theia/core/lib/common/command");
22
- const widgets_1 = require("@theia/core/lib/browser/widgets");
23
- const secondary_window_handler_1 = require("@theia/core/lib/browser/secondary-window-handler");
24
- exports.EXTRACT_WIDGET = command_1.Command.toLocalizedCommand({
16
+ import { __decorate } from "tslib";
17
+ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
18
+ import { Command } from '@theia/core/lib/common/command';
19
+ import { codicon, ExtractableWidget, Widget } from '@theia/core/lib/browser/widgets';
20
+ import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
21
+ import { SHELL_TABBAR_CONTEXT_MENU } from '@theia/core/lib/browser/shell/tab-bars';
22
+ import { NativeTabDragService } from '@theia/core/lib/browser/shell/native-tab-drag-service';
23
+ import { extractSecondaryWindow, getAllWidgetsFromSecondaryWindow, SecondaryWindowHandler } from '@theia/core/lib/browser/secondary-window-handler';
24
+ export const EXTRACT_WIDGET = Command.toLocalizedCommand({
25
25
  id: 'extract-widget',
26
26
  label: 'Move View to Secondary Window'
27
27
  }, 'theia/secondary-window/extract-widget');
28
- /** Contributes the widget extraction command and registers it in the toolbar of extractable widgets. */
28
+ export const RESTORE_WIDGET = Command.toLocalizedCommand({
29
+ id: 'restore-widget',
30
+ label: 'Move View to Main Window'
31
+ }, 'theia/secondary-window/restore-widget');
32
+ export const RESTORE_ALL_WIDGETS = Command.toLocalizedCommand({
33
+ id: 'restore-all-widgets',
34
+ label: 'Move All Views to Main Window'
35
+ }, 'theia/secondary-window/restore-all-widgets');
36
+ export const SHELL_TABBAR_CONTEXT_SECONDARY_WINDOW = [...SHELL_TABBAR_CONTEXT_MENU, '6_secondaryWindow'];
37
+ /**
38
+ * Contributes the commands to move widgets to secondary windows and back, and registers them in the toolbar and in the context menu of tabs.
39
+ * In addition, extracts widgets whose tab is dragged out of the application's windows.
40
+ */
29
41
  let SecondaryWindowContribution = class SecondaryWindowContribution {
42
+ init() {
43
+ this.nativeTabDragService.onDidDropTabOutsideWindows(event => this.onDidDropTabOutsideWindows(event));
44
+ }
45
+ onDidDropTabOutsideWindows({ title, screenX, screenY }) {
46
+ const widget = title.owner;
47
+ const secondaryWindow = extractSecondaryWindow(widget);
48
+ if (secondaryWindow && getAllWidgetsFromSecondaryWindow(secondaryWindow)?.length === 1) {
49
+ // the widget is the only one in its secondary window, so move the window instead of opening a new one
50
+ secondaryWindow.moveTo(screenX, screenY);
51
+ }
52
+ else if (ExtractableWidget.is(widget)) {
53
+ this.secondaryWindowHandler.moveWidgetToSecondaryWindow(widget, { position: { x: screenX, y: screenY } });
54
+ }
55
+ }
30
56
  registerCommands(commands) {
31
- commands.registerCommand(exports.EXTRACT_WIDGET, {
32
- execute: async (widget) => this.secondaryWindowHandler.moveWidgetToSecondaryWindow(widget),
33
- isVisible: widget => widgets_1.ExtractableWidget.is(widget) && widget.secondaryWindow === undefined,
34
- isEnabled: widget => widgets_1.ExtractableWidget.is(widget) && widget.secondaryWindow === undefined,
57
+ const canExtract = (arg) => {
58
+ const widget = this.getTargetWidget(arg);
59
+ return ExtractableWidget.is(widget) && widget.secondaryWindow === undefined;
60
+ };
61
+ commands.registerCommand(EXTRACT_WIDGET, {
62
+ execute: async (arg) => {
63
+ const widget = this.getTargetWidget(arg);
64
+ if (ExtractableWidget.is(widget)) {
65
+ this.secondaryWindowHandler.moveWidgetToSecondaryWindow(widget);
66
+ }
67
+ },
68
+ isVisible: canExtract,
69
+ isEnabled: canExtract,
70
+ });
71
+ const isInSecondaryWindow = (arg) => extractSecondaryWindow(this.getTargetWidget(arg)) !== undefined;
72
+ commands.registerCommand(RESTORE_WIDGET, {
73
+ execute: async (arg) => {
74
+ const widget = this.getTargetWidget(arg);
75
+ if (widget) {
76
+ await this.secondaryWindowHandler.moveWidgetToMainWindow(widget);
77
+ }
78
+ },
79
+ isVisible: isInSecondaryWindow,
80
+ isEnabled: isInSecondaryWindow,
81
+ });
82
+ commands.registerCommand(RESTORE_ALL_WIDGETS, {
83
+ execute: async (arg) => {
84
+ const secondaryWindow = extractSecondaryWindow(this.getTargetWidget(arg));
85
+ if (secondaryWindow) {
86
+ await this.secondaryWindowHandler.moveAllWidgetsToMainWindow(secondaryWindow);
87
+ }
88
+ },
89
+ isVisible: isInSecondaryWindow,
90
+ isEnabled: isInSecondaryWindow,
91
+ });
92
+ }
93
+ registerMenus(menus) {
94
+ menus.registerMenuAction(SHELL_TABBAR_CONTEXT_SECONDARY_WINDOW, {
95
+ commandId: EXTRACT_WIDGET.id,
96
+ order: 'a'
97
+ });
98
+ menus.registerMenuAction(SHELL_TABBAR_CONTEXT_SECONDARY_WINDOW, {
99
+ commandId: RESTORE_WIDGET.id,
100
+ order: 'b'
101
+ });
102
+ menus.registerMenuAction(SHELL_TABBAR_CONTEXT_SECONDARY_WINDOW, {
103
+ commandId: RESTORE_ALL_WIDGETS.id,
104
+ order: 'c'
35
105
  });
36
106
  }
37
107
  registerToolbarItems(registry) {
38
108
  registry.registerItem({
39
- id: exports.EXTRACT_WIDGET.id,
40
- command: exports.EXTRACT_WIDGET.id,
41
- icon: (0, widgets_1.codicon)('window'),
109
+ id: EXTRACT_WIDGET.id,
110
+ command: EXTRACT_WIDGET.id,
111
+ icon: codicon('window'),
42
112
  });
113
+ registry.registerItem({
114
+ id: RESTORE_WIDGET.id,
115
+ command: RESTORE_WIDGET.id,
116
+ // TODO use `open-in-window` once the codicon font bundled with Monaco provides it, see #17789
117
+ icon: codicon('screen-normal'),
118
+ });
119
+ }
120
+ /**
121
+ * @returns the widget a command is executed for: the widget passed by the tab bar toolbar, the widget of the tab
122
+ * whose context menu has been opened, or the current widget if no argument is passed, e.g. from the command palette
123
+ */
124
+ getTargetWidget(arg) {
125
+ if (arg instanceof Widget) {
126
+ return arg;
127
+ }
128
+ // not using `instanceof Event`, the event may come from a secondary window, i.e. from another JavaScript realm
129
+ if (arg?.target) {
130
+ return this.shell.findTargetedWidget(arg);
131
+ }
132
+ return arg === undefined ? this.shell.currentWidget : undefined;
43
133
  }
44
134
  };
45
- exports.SecondaryWindowContribution = SecondaryWindowContribution;
46
- tslib_1.__decorate([
47
- (0, inversify_1.inject)(secondary_window_handler_1.SecondaryWindowHandler),
48
- tslib_1.__metadata("design:type", secondary_window_handler_1.SecondaryWindowHandler)
135
+ __decorate([
136
+ inject(SecondaryWindowHandler)
49
137
  ], SecondaryWindowContribution.prototype, "secondaryWindowHandler", void 0);
50
- exports.SecondaryWindowContribution = SecondaryWindowContribution = tslib_1.__decorate([
51
- (0, inversify_1.injectable)()
138
+ __decorate([
139
+ inject(NativeTabDragService)
140
+ ], SecondaryWindowContribution.prototype, "nativeTabDragService", void 0);
141
+ __decorate([
142
+ inject(ApplicationShell)
143
+ ], SecondaryWindowContribution.prototype, "shell", void 0);
144
+ __decorate([
145
+ postConstruct()
146
+ ], SecondaryWindowContribution.prototype, "init", null);
147
+ SecondaryWindowContribution = __decorate([
148
+ injectable()
52
149
  ], SecondaryWindowContribution);
150
+ export { SecondaryWindowContribution };
53
151
  //# sourceMappingURL=secondary-window-frontend-contribution.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"secondary-window-frontend-contribution.js","sourceRoot":"","sources":["../../src/browser/secondary-window-frontend-contribution.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,kFAAkF;AAClF,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,4DAAkE;AAClE,4DAA+F;AAC/F,6DAA6E;AAE7E,+FAA0F;AAE7E,QAAA,cAAc,GAAG,iBAAO,CAAC,kBAAkB,CAAC;IACrD,EAAE,EAAE,gBAAgB;IACpB,KAAK,EAAE,+BAA+B;CACzC,EAAE,uCAAuC,CAAC,CAAC;AAE5C,wGAAwG;AAEjG,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAKpC,gBAAgB,CAAC,QAAyB;QACtC,QAAQ,CAAC,eAAe,CAAC,sBAAc,EAAE;YACrC,OAAO,EAAE,KAAK,EAAC,MAAM,EAAC,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,2BAA2B,CAAC,MAAM,CAAC;YACxF,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,2BAAiB,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,eAAe,KAAK,SAAS;YACzF,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,2BAAiB,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,eAAe,KAAK,SAAS;SAC5F,CAAC,CAAC;IACP,CAAC;IAED,oBAAoB,CAAC,QAA+B;QAChD,QAAQ,CAAC,YAAY,CAAC;YAClB,EAAE,EAAE,sBAAc,CAAC,EAAE;YACrB,OAAO,EAAE,sBAAc,CAAC,EAAE;YAC1B,IAAI,EAAE,IAAA,iBAAO,EAAC,QAAQ,CAAC;SAC1B,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AApBY,kEAA2B;AAGjB;IADlB,IAAA,kBAAM,EAAC,iDAAsB,CAAC;sCACY,iDAAsB;2EAAC;sCAHzD,2BAA2B;IADvC,IAAA,sBAAU,GAAE;GACA,2BAA2B,CAoBvC"}
1
+ {"version":3,"file":"secondary-window-frontend-contribution.js","sourceRoot":"","sources":["../../src/browser/secondary-window-frontend-contribution.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,kFAAkF;AAClF,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,EAAwC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rB,OAAO,EAAE,cAAc,CAAC,EAAE;YAC1B,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC;SAC1B,CAAC,CAAC;QACH,QAAQ,CAAC,YAAY,CAAC;YAClB,EAAE,EAAE,cAAc,CAAC,EAAE;YACrB,OAAO,EAAE,cAAc,CAAC,EAAE;YAC1B,8FAA8F;YAC9F,IAAI,EAAE,OAAO,CAAC,eAAe,CAAC;SACjC,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACO,eAAe,CAAC,GAAY;QAClC,IAAI,GAAG,YAAY,MAAM,EAAE,CAAC;YACxB,OAAO,GAAG,CAAC;QACf,CAAC;QACD,+GAA+G;QAC/G,IAAK,GAAyB,EAAE,MAAM,EAAE,CAAC;YACrC,OAAO,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,GAAY,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;IACpE,CAAC;CACJ,CAAA;AAzGsB;IADlB,MAAM,CAAC,sBAAsB,CAAC;2EACmC;AAG/C;IADlB,MAAM,CAAC,oBAAoB,CAAC;yEACiC;AAG3C;IADlB,MAAM,CAAC,gBAAgB,CAAC;0DACkB;AAGjC;IADT,aAAa,EAAE;uDAGf;AAdQ,2BAA2B;IADvC,UAAU,EAAE;GACA,2BAA2B,CA4GvC"}
@@ -1 +1 @@
1
- {"version":3,"file":"secondary-window-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/secondary-window-frontend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAK/D,wBAIG"}
1
+ {"version":3,"file":"secondary-window-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/secondary-window-frontend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAM/D,wBAKG"}
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // *****************************************************************************
3
2
  // Copyright (C) 2022 STMicroelectronics, Ericsson, ARM, EclipseSource and others.
4
3
  //
@@ -14,14 +13,15 @@
14
13
  //
15
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
15
  // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const inversify_1 = require("@theia/core/shared/inversify");
19
- const secondary_window_frontend_contribution_1 = require("./secondary-window-frontend-contribution");
20
- const command_1 = require("@theia/core/lib/common/command");
21
- const tab_bar_toolbar_1 = require("@theia/core/lib/browser/shell/tab-bar-toolbar");
22
- exports.default = new inversify_1.ContainerModule(bind => {
23
- bind(secondary_window_frontend_contribution_1.SecondaryWindowContribution).toSelf().inSingletonScope();
24
- bind(command_1.CommandContribution).toService(secondary_window_frontend_contribution_1.SecondaryWindowContribution);
25
- bind(tab_bar_toolbar_1.TabBarToolbarContribution).toService(secondary_window_frontend_contribution_1.SecondaryWindowContribution);
16
+ import { ContainerModule } from '@theia/core/shared/inversify';
17
+ import { SecondaryWindowContribution } from './secondary-window-frontend-contribution.js';
18
+ import { CommandContribution } from '@theia/core/lib/common/command';
19
+ import { MenuContribution } from '@theia/core/lib/common/menu';
20
+ import { TabBarToolbarContribution } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
21
+ export default new ContainerModule(bind => {
22
+ bind(SecondaryWindowContribution).toSelf().inSingletonScope();
23
+ bind(CommandContribution).toService(SecondaryWindowContribution);
24
+ bind(MenuContribution).toService(SecondaryWindowContribution);
25
+ bind(TabBarToolbarContribution).toService(SecondaryWindowContribution);
26
26
  });
27
27
  //# sourceMappingURL=secondary-window-frontend-module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"secondary-window-frontend-module.js","sourceRoot":"","sources":["../../src/browser/secondary-window-frontend-module.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,kFAAkF;AAClF,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,4DAA+D;AAC/D,qGAAuF;AACvF,4DAAqE;AACrE,mFAA0F;AAE1F,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,oEAA2B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC9D,IAAI,CAAC,6BAAmB,CAAC,CAAC,SAAS,CAAC,oEAA2B,CAAC,CAAC;IACjE,IAAI,CAAC,2CAAyB,CAAC,CAAC,SAAS,CAAC,oEAA2B,CAAC,CAAC;AAC3E,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"secondary-window-frontend-module.js","sourceRoot":"","sources":["../../src/browser/secondary-window-frontend-module.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,kFAAkF;AAClF,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,6CAA6C,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,+CAA+C,CAAC;AAE1F,eAAe,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,2BAA2B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC9D,IAAI,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;IACjE,IAAI,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;IAC9D,IAAI,CAAC,yBAAyB,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;AAC3E,CAAC,CAAC,CAAC"}
@@ -1 +1,2 @@
1
+ export {};
1
2
  //# sourceMappingURL=package.spec.d.ts.map
@@ -16,4 +16,5 @@
16
16
  describe('secondary-window package', () => {
17
17
  it('supports code coverage statistics', () => true);
18
18
  });
19
+ export {};
19
20
  //# sourceMappingURL=package.spec.js.map
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@theia/secondary-window",
3
- "version": "1.77.0-next.1+8b94967c4",
3
+ "version": "1.77.0-next.101+8308c936b",
4
4
  "description": "Theia - Secondary Window Extension",
5
+ "type": "module",
5
6
  "dependencies": {
6
- "@theia/core": "1.77.0-next.1+8b94967c4",
7
+ "@theia/core": "1.77.0-next.101+8308c936b",
7
8
  "tslib": "^2.8.1"
8
9
  },
9
10
  "publishConfig": {
@@ -41,5 +42,12 @@
41
42
  "devDependencies": {
42
43
  "@theia/ext-scripts": "1.76.0"
43
44
  },
44
- "gitHead": "8b94967c4cfa0dcf688a345d28b3ac2e0d7e298a"
45
+ "gitHead": "8308c936be596c357a51fc815ef30022aa62b3d5",
46
+ "exports": {
47
+ "./package.json": "./package.json",
48
+ "./lib/*.json": "./lib/*.json",
49
+ "./lib/*.js": "./lib/*.js",
50
+ "./lib/*": "./lib/*.js",
51
+ "./*": "./*"
52
+ }
45
53
  }
@@ -14,29 +14,115 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import { inject, injectable } from '@theia/core/shared/inversify';
17
+ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
18
18
  import { CommandRegistry, CommandContribution, Command } from '@theia/core/lib/common/command';
19
- import { codicon, ExtractableWidget } from '@theia/core/lib/browser/widgets';
19
+ import { MenuContribution, MenuModelRegistry, MenuPath } from '@theia/core/lib/common/menu';
20
+ import { codicon, ExtractableWidget, Widget } from '@theia/core/lib/browser/widgets';
21
+ import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
22
+ import { SHELL_TABBAR_CONTEXT_MENU } from '@theia/core/lib/browser/shell/tab-bars';
23
+ import { NativeTabDragService, TabDropOutsideWindowsEvent } from '@theia/core/lib/browser/shell/native-tab-drag-service';
20
24
  import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
21
- import { SecondaryWindowHandler } from '@theia/core/lib/browser/secondary-window-handler';
25
+ import { extractSecondaryWindow, getAllWidgetsFromSecondaryWindow, SecondaryWindowHandler } from '@theia/core/lib/browser/secondary-window-handler';
22
26
 
23
27
  export const EXTRACT_WIDGET = Command.toLocalizedCommand({
24
28
  id: 'extract-widget',
25
29
  label: 'Move View to Secondary Window'
26
30
  }, 'theia/secondary-window/extract-widget');
27
31
 
28
- /** Contributes the widget extraction command and registers it in the toolbar of extractable widgets. */
32
+ export const RESTORE_WIDGET = Command.toLocalizedCommand({
33
+ id: 'restore-widget',
34
+ label: 'Move View to Main Window'
35
+ }, 'theia/secondary-window/restore-widget');
36
+
37
+ export const RESTORE_ALL_WIDGETS = Command.toLocalizedCommand({
38
+ id: 'restore-all-widgets',
39
+ label: 'Move All Views to Main Window'
40
+ }, 'theia/secondary-window/restore-all-widgets');
41
+
42
+ export const SHELL_TABBAR_CONTEXT_SECONDARY_WINDOW: MenuPath = [...SHELL_TABBAR_CONTEXT_MENU, '6_secondaryWindow'];
43
+
44
+ /**
45
+ * Contributes the commands to move widgets to secondary windows and back, and registers them in the toolbar and in the context menu of tabs.
46
+ * In addition, extracts widgets whose tab is dragged out of the application's windows.
47
+ */
29
48
  @injectable()
30
- export class SecondaryWindowContribution implements CommandContribution, TabBarToolbarContribution {
49
+ export class SecondaryWindowContribution implements CommandContribution, MenuContribution, TabBarToolbarContribution {
31
50
 
32
51
  @inject(SecondaryWindowHandler)
33
52
  protected readonly secondaryWindowHandler: SecondaryWindowHandler;
34
53
 
54
+ @inject(NativeTabDragService)
55
+ protected readonly nativeTabDragService: NativeTabDragService;
56
+
57
+ @inject(ApplicationShell)
58
+ protected readonly shell: ApplicationShell;
59
+
60
+ @postConstruct()
61
+ protected init(): void {
62
+ this.nativeTabDragService.onDidDropTabOutsideWindows(event => this.onDidDropTabOutsideWindows(event));
63
+ }
64
+
65
+ protected onDidDropTabOutsideWindows({ title, screenX, screenY }: TabDropOutsideWindowsEvent): void {
66
+ const widget = title.owner;
67
+ const secondaryWindow = extractSecondaryWindow(widget);
68
+ if (secondaryWindow && getAllWidgetsFromSecondaryWindow(secondaryWindow)?.length === 1) {
69
+ // the widget is the only one in its secondary window, so move the window instead of opening a new one
70
+ secondaryWindow.moveTo(screenX, screenY);
71
+ } else if (ExtractableWidget.is(widget)) {
72
+ this.secondaryWindowHandler.moveWidgetToSecondaryWindow(widget, { position: { x: screenX, y: screenY } });
73
+ }
74
+ }
75
+
35
76
  registerCommands(commands: CommandRegistry): void {
77
+ const canExtract = (arg?: unknown) => {
78
+ const widget = this.getTargetWidget(arg);
79
+ return ExtractableWidget.is(widget) && widget.secondaryWindow === undefined;
80
+ };
36
81
  commands.registerCommand(EXTRACT_WIDGET, {
37
- execute: async widget => this.secondaryWindowHandler.moveWidgetToSecondaryWindow(widget),
38
- isVisible: widget => ExtractableWidget.is(widget) && widget.secondaryWindow === undefined,
39
- isEnabled: widget => ExtractableWidget.is(widget) && widget.secondaryWindow === undefined,
82
+ execute: async arg => {
83
+ const widget = this.getTargetWidget(arg);
84
+ if (ExtractableWidget.is(widget)) {
85
+ this.secondaryWindowHandler.moveWidgetToSecondaryWindow(widget);
86
+ }
87
+ },
88
+ isVisible: canExtract,
89
+ isEnabled: canExtract,
90
+ });
91
+ const isInSecondaryWindow = (arg?: unknown) => extractSecondaryWindow(this.getTargetWidget(arg)) !== undefined;
92
+ commands.registerCommand(RESTORE_WIDGET, {
93
+ execute: async arg => {
94
+ const widget = this.getTargetWidget(arg);
95
+ if (widget) {
96
+ await this.secondaryWindowHandler.moveWidgetToMainWindow(widget);
97
+ }
98
+ },
99
+ isVisible: isInSecondaryWindow,
100
+ isEnabled: isInSecondaryWindow,
101
+ });
102
+ commands.registerCommand(RESTORE_ALL_WIDGETS, {
103
+ execute: async arg => {
104
+ const secondaryWindow = extractSecondaryWindow(this.getTargetWidget(arg));
105
+ if (secondaryWindow) {
106
+ await this.secondaryWindowHandler.moveAllWidgetsToMainWindow(secondaryWindow);
107
+ }
108
+ },
109
+ isVisible: isInSecondaryWindow,
110
+ isEnabled: isInSecondaryWindow,
111
+ });
112
+ }
113
+
114
+ registerMenus(menus: MenuModelRegistry): void {
115
+ menus.registerMenuAction(SHELL_TABBAR_CONTEXT_SECONDARY_WINDOW, {
116
+ commandId: EXTRACT_WIDGET.id,
117
+ order: 'a'
118
+ });
119
+ menus.registerMenuAction(SHELL_TABBAR_CONTEXT_SECONDARY_WINDOW, {
120
+ commandId: RESTORE_WIDGET.id,
121
+ order: 'b'
122
+ });
123
+ menus.registerMenuAction(SHELL_TABBAR_CONTEXT_SECONDARY_WINDOW, {
124
+ commandId: RESTORE_ALL_WIDGETS.id,
125
+ order: 'c'
40
126
  });
41
127
  }
42
128
 
@@ -46,5 +132,26 @@ export class SecondaryWindowContribution implements CommandContribution, TabBarT
46
132
  command: EXTRACT_WIDGET.id,
47
133
  icon: codicon('window'),
48
134
  });
135
+ registry.registerItem({
136
+ id: RESTORE_WIDGET.id,
137
+ command: RESTORE_WIDGET.id,
138
+ // TODO use `open-in-window` once the codicon font bundled with Monaco provides it, see #17789
139
+ icon: codicon('screen-normal'),
140
+ });
141
+ }
142
+
143
+ /**
144
+ * @returns the widget a command is executed for: the widget passed by the tab bar toolbar, the widget of the tab
145
+ * whose context menu has been opened, or the current widget if no argument is passed, e.g. from the command palette
146
+ */
147
+ protected getTargetWidget(arg: unknown): Widget | undefined {
148
+ if (arg instanceof Widget) {
149
+ return arg;
150
+ }
151
+ // not using `instanceof Event`, the event may come from a secondary window, i.e. from another JavaScript realm
152
+ if ((arg as Event | undefined)?.target) {
153
+ return this.shell.findTargetedWidget(arg as Event);
154
+ }
155
+ return arg === undefined ? this.shell.currentWidget : undefined;
49
156
  }
50
157
  }
@@ -15,13 +15,15 @@
15
15
  // *****************************************************************************
16
16
 
17
17
  import { ContainerModule } from '@theia/core/shared/inversify';
18
- import { SecondaryWindowContribution } from './secondary-window-frontend-contribution';
18
+ import { SecondaryWindowContribution } from './secondary-window-frontend-contribution.js';
19
19
  import { CommandContribution } from '@theia/core/lib/common/command';
20
+ import { MenuContribution } from '@theia/core/lib/common/menu';
20
21
  import { TabBarToolbarContribution } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
21
22
 
22
23
  export default new ContainerModule(bind => {
23
24
  bind(SecondaryWindowContribution).toSelf().inSingletonScope();
24
25
  bind(CommandContribution).toService(SecondaryWindowContribution);
26
+ bind(MenuContribution).toService(SecondaryWindowContribution);
25
27
  bind(TabBarToolbarContribution).toService(SecondaryWindowContribution);
26
28
  });
27
29