1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
18 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
19 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
20 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
21 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
22 | };
|
23 | var __metadata = (this && this.__metadata) || function (k, v) {
|
24 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
25 | };
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | exports.SecondaryWindowHandler = void 0;
|
28 | const debounce = require("lodash.debounce");
|
29 | const inversify_1 = require("inversify");
|
30 | const widgets_1 = require("./widgets");
|
31 | const message_service_1 = require("../common/message-service");
|
32 | const event_1 = require("../common/event");
|
33 | const secondary_window_service_1 = require("./window/secondary-window-service");
|
34 | const keybinding_1 = require("./keybinding");
|
35 | const color_application_contribution_1 = require("./color-application-contribution");
|
36 | const styling_service_1 = require("./styling-service");
|
37 |
|
38 | class SecondaryWindowRootWidget extends widgets_1.Widget {
|
39 | constructor() {
|
40 | super();
|
41 | this.layout = new widgets_1.BoxLayout();
|
42 | }
|
43 | addWidget(widget) {
|
44 | this.layout.addWidget(widget);
|
45 | widgets_1.BoxPanel.setStretch(widget, 1);
|
46 | }
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | let SecondaryWindowHandler = class SecondaryWindowHandler {
|
58 | constructor() {
|
59 |
|
60 | this._widgets = [];
|
61 | this.onDidAddWidgetEmitter = new event_1.Emitter();
|
62 |
|
63 | this.onDidAddWidget = this.onDidAddWidgetEmitter.event;
|
64 | this.onDidRemoveWidgetEmitter = new event_1.Emitter();
|
65 |
|
66 | this.onDidRemoveWidget = this.onDidRemoveWidgetEmitter.event;
|
67 | }
|
68 |
|
69 | get widgets() {
|
70 |
|
71 | return [...this._widgets];
|
72 | }
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | init(shell) {
|
80 | if (this.applicationShell) {
|
81 |
|
82 | return;
|
83 | }
|
84 | this.applicationShell = shell;
|
85 | }
|
86 | |
87 |
|
88 |
|
89 |
|
90 |
|
91 | moveWidgetToSecondaryWindow(widget) {
|
92 | if (!this.applicationShell) {
|
93 | console.error('Widget cannot be extracted because the WidgetExtractionHandler has not been initialized.');
|
94 | return;
|
95 | }
|
96 | if (!widget.isExtractable) {
|
97 | console.error('Widget is not extractable.', widget.id);
|
98 | return;
|
99 | }
|
100 | const newWindow = this.secondaryWindowService.createSecondaryWindow(widget, this.applicationShell);
|
101 | if (!newWindow) {
|
102 | this.messageService.error('The widget could not be moved to a secondary window because the window creation failed. Please make sure to allow popups.');
|
103 | return;
|
104 | }
|
105 | const mainWindowTitle = document.title;
|
106 | newWindow.onload = () => {
|
107 | this.keybindings.registerEventListeners(newWindow);
|
108 |
|
109 |
|
110 |
|
111 | newWindow.document.title = `${widget.title.label} — ${mainWindowTitle}`;
|
112 | const element = newWindow.document.getElementById('widget-host');
|
113 | if (!element) {
|
114 | console.error('Could not find dom element to attach to in secondary window');
|
115 | return;
|
116 | }
|
117 | const unregisterWithColorContribution = this.colorAppContribution.registerWindow(newWindow);
|
118 | const unregisterWithStylingService = this.stylingService.registerWindow(newWindow);
|
119 | widget.secondaryWindow = newWindow;
|
120 | const rootWidget = new SecondaryWindowRootWidget();
|
121 | rootWidget.addClass('secondary-widget-root');
|
122 | widgets_1.Widget.attach(rootWidget, element);
|
123 | rootWidget.addWidget(widget);
|
124 | widget.show();
|
125 | widget.update();
|
126 | this.addWidget(widget);
|
127 |
|
128 | widget.disposed.connect(() => {
|
129 | unregisterWithColorContribution.dispose();
|
130 | unregisterWithStylingService.dispose();
|
131 | this.removeWidget(widget);
|
132 | if (!newWindow.closed) {
|
133 | newWindow.close();
|
134 | }
|
135 | });
|
136 |
|
137 | const updateWidget = debounce(() => {
|
138 | rootWidget.update();
|
139 | }, 100);
|
140 | newWindow.addEventListener('resize', () => {
|
141 | updateWidget();
|
142 | });
|
143 | widget.activate();
|
144 | };
|
145 | }
|
146 | |
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | activateWidget(widgetId) {
|
153 | const trackedWidget = this.revealWidget(widgetId);
|
154 | trackedWidget === null || trackedWidget === void 0 ? void 0 : trackedWidget.activate();
|
155 | return trackedWidget;
|
156 | }
|
157 | |
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | revealWidget(widgetId) {
|
164 | const trackedWidget = this._widgets.find(w => w.id === widgetId);
|
165 | if (trackedWidget) {
|
166 | this.secondaryWindowService.focus(trackedWidget.secondaryWindow);
|
167 | return trackedWidget;
|
168 | }
|
169 | return undefined;
|
170 | }
|
171 | addWidget(widget) {
|
172 | if (!this._widgets.includes(widget)) {
|
173 | this._widgets.push(widget);
|
174 | this.onDidAddWidgetEmitter.fire(widget);
|
175 | }
|
176 | }
|
177 | removeWidget(widget) {
|
178 | const index = this._widgets.indexOf(widget);
|
179 | if (index > -1) {
|
180 | this._widgets.splice(index, 1);
|
181 | this.onDidRemoveWidgetEmitter.fire(widget);
|
182 | }
|
183 | }
|
184 | };
|
185 | __decorate([
|
186 | (0, inversify_1.inject)(keybinding_1.KeybindingRegistry),
|
187 | __metadata("design:type", keybinding_1.KeybindingRegistry)
|
188 | ], SecondaryWindowHandler.prototype, "keybindings", void 0);
|
189 | __decorate([
|
190 | (0, inversify_1.inject)(color_application_contribution_1.ColorApplicationContribution),
|
191 | __metadata("design:type", color_application_contribution_1.ColorApplicationContribution)
|
192 | ], SecondaryWindowHandler.prototype, "colorAppContribution", void 0);
|
193 | __decorate([
|
194 | (0, inversify_1.inject)(styling_service_1.StylingService),
|
195 | __metadata("design:type", styling_service_1.StylingService)
|
196 | ], SecondaryWindowHandler.prototype, "stylingService", void 0);
|
197 | __decorate([
|
198 | (0, inversify_1.inject)(message_service_1.MessageService),
|
199 | __metadata("design:type", message_service_1.MessageService)
|
200 | ], SecondaryWindowHandler.prototype, "messageService", void 0);
|
201 | __decorate([
|
202 | (0, inversify_1.inject)(secondary_window_service_1.SecondaryWindowService),
|
203 | __metadata("design:type", Object)
|
204 | ], SecondaryWindowHandler.prototype, "secondaryWindowService", void 0);
|
205 | SecondaryWindowHandler = __decorate([
|
206 | (0, inversify_1.injectable)()
|
207 | ], SecondaryWindowHandler);
|
208 | exports.SecondaryWindowHandler = SecondaryWindowHandler;
|
209 |
|
\ | No newline at end of file |