UNPKG

9.78 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2018 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.TheiaDockPanel = exports.BOTTOM_AREA_ID = exports.MAIN_AREA_ID = exports.ACTIVE_TABBAR_CLASS = exports.MAXIMIZED_CLASS = void 0;
19const algorithm_1 = require("@phosphor/algorithm");
20const widgets_1 = require("@phosphor/widgets");
21const signaling_1 = require("@phosphor/signaling");
22const disposable_1 = require("../../common/disposable");
23const widgets_2 = require("../widgets");
24const common_1 = require("../../common");
25exports.MAXIMIZED_CLASS = 'theia-maximized';
26exports.ACTIVE_TABBAR_CLASS = 'theia-tabBar-active';
27const VISIBLE_MENU_MAXIMIZED_CLASS = 'theia-visible-menu-maximized';
28exports.MAIN_AREA_ID = 'theia-main-content-panel';
29exports.BOTTOM_AREA_ID = 'theia-bottom-content-panel';
30/**
31 * This specialization of DockPanel adds various events that are used for implementing the
32 * side panels of the application shell.
33 */
34class TheiaDockPanel extends widgets_1.DockPanel {
35 constructor(options, preferences) {
36 super(options);
37 this.preferences = preferences;
38 /**
39 * Emitted when a widget is added to the panel.
40 */
41 this.widgetAdded = new signaling_1.Signal(this);
42 /**
43 * Emitted when a widget is activated by calling `activateWidget`.
44 */
45 this.widgetActivated = new signaling_1.Signal(this);
46 /**
47 * Emitted when a widget is removed from the panel.
48 */
49 this.widgetRemoved = new signaling_1.Signal(this);
50 this.onDidToggleMaximizedEmitter = new common_1.Emitter();
51 this.onDidToggleMaximized = this.onDidToggleMaximizedEmitter.event;
52 this.onDidChangeCurrentEmitter = new common_1.Emitter();
53 this.toDisposeOnMarkAsCurrent = new disposable_1.DisposableCollection();
54 this.toDisposeOnToggleMaximized = new disposable_1.DisposableCollection();
55 this['_onCurrentChanged'] = (sender, args) => {
56 this.markAsCurrent(args.currentTitle || undefined);
57 super['_onCurrentChanged'](sender, args);
58 };
59 this['_onTabActivateRequested'] = (sender, args) => {
60 this.markAsCurrent(args.title);
61 super['_onTabActivateRequested'](sender, args);
62 };
63 if (preferences) {
64 preferences.onPreferenceChanged(preference => {
65 if (!this.isElectron() && preference.preferenceName === 'window.menuBarVisibility' && (preference.newValue === 'visible' || preference.oldValue === 'visible')) {
66 this.handleMenuBarVisibility(preference.newValue);
67 }
68 });
69 }
70 }
71 get onDidChangeCurrent() {
72 return this.onDidChangeCurrentEmitter.event;
73 }
74 isElectron() {
75 return common_1.environment.electron.is();
76 }
77 handleMenuBarVisibility(newValue) {
78 const areaContainer = this.node.parentElement;
79 const maximizedElement = this.getMaximizedElement();
80 if (areaContainer === maximizedElement) {
81 if (newValue === 'visible') {
82 this.addClass(VISIBLE_MENU_MAXIMIZED_CLASS);
83 }
84 else {
85 this.removeClass(VISIBLE_MENU_MAXIMIZED_CLASS);
86 }
87 }
88 }
89 get currentTitle() {
90 return this._currentTitle;
91 }
92 get currentTabBar() {
93 return this._currentTitle && this.findTabBar(this._currentTitle);
94 }
95 findTabBar(title) {
96 return (0, algorithm_1.find)(this.tabBars(), bar => algorithm_1.ArrayExt.firstIndexOf(bar.titles, title) > -1);
97 }
98 markAsCurrent(title) {
99 this.toDisposeOnMarkAsCurrent.dispose();
100 this._currentTitle = title;
101 this.markActiveTabBar(title);
102 if (title) {
103 const resetCurrent = () => this.markAsCurrent(undefined);
104 title.owner.disposed.connect(resetCurrent);
105 this.toDisposeOnMarkAsCurrent.push(disposable_1.Disposable.create(() => title.owner.disposed.disconnect(resetCurrent)));
106 }
107 this.onDidChangeCurrentEmitter.fire(title);
108 }
109 markActiveTabBar(title) {
110 const tabBars = (0, algorithm_1.toArray)(this.tabBars());
111 tabBars.forEach(tabBar => tabBar.removeClass(exports.ACTIVE_TABBAR_CLASS));
112 const activeTabBar = title && this.findTabBar(title);
113 if (activeTabBar) {
114 activeTabBar.addClass(exports.ACTIVE_TABBAR_CLASS);
115 }
116 else if (tabBars.length > 0) {
117 // At least one tabbar needs to be active
118 tabBars[0].addClass(exports.ACTIVE_TABBAR_CLASS);
119 }
120 }
121 addWidget(widget, options) {
122 if (this.mode === 'single-document' && widget.parent === this) {
123 return;
124 }
125 super.addWidget(widget, options);
126 this.widgetAdded.emit(widget);
127 this.markActiveTabBar(widget.title);
128 }
129 activateWidget(widget) {
130 super.activateWidget(widget);
131 this.widgetActivated.emit(widget);
132 this.markActiveTabBar(widget.title);
133 }
134 onChildRemoved(msg) {
135 super.onChildRemoved(msg);
136 this.widgetRemoved.emit(msg.child);
137 }
138 nextTabBarWidget(widget) {
139 const current = this.findTabBar(widget.title);
140 const next = current && this.nextTabBarInPanel(current);
141 return next && next.currentTitle && next.currentTitle.owner || undefined;
142 }
143 nextTabBarInPanel(tabBar) {
144 const tabBars = (0, algorithm_1.toArray)(this.tabBars());
145 const index = tabBars.indexOf(tabBar);
146 if (index !== -1) {
147 return tabBars[index + 1];
148 }
149 return undefined;
150 }
151 previousTabBarWidget(widget) {
152 const current = this.findTabBar(widget.title);
153 const previous = current && this.previousTabBarInPanel(current);
154 return previous && previous.currentTitle && previous.currentTitle.owner || undefined;
155 }
156 previousTabBarInPanel(tabBar) {
157 const tabBars = (0, algorithm_1.toArray)(this.tabBars());
158 const index = tabBars.indexOf(tabBar);
159 if (index !== -1) {
160 return tabBars[index - 1];
161 }
162 return undefined;
163 }
164 toggleMaximized() {
165 var _a;
166 const areaContainer = this.node.parentElement;
167 if (!areaContainer) {
168 return;
169 }
170 const maximizedElement = this.getMaximizedElement();
171 if (areaContainer === maximizedElement) {
172 this.toDisposeOnToggleMaximized.dispose();
173 return;
174 }
175 if (this.isAttached) {
176 widgets_2.UnsafeWidgetUtilities.detach(this);
177 }
178 maximizedElement.style.display = 'block';
179 this.addClass(exports.MAXIMIZED_CLASS);
180 const preference = (_a = this.preferences) === null || _a === void 0 ? void 0 : _a.get('window.menuBarVisibility');
181 if (!this.isElectron() && preference === 'visible') {
182 this.addClass(VISIBLE_MENU_MAXIMIZED_CLASS);
183 }
184 widgets_2.UnsafeWidgetUtilities.attach(this, maximizedElement);
185 this.fit();
186 this.onDidToggleMaximizedEmitter.fire(this);
187 this.toDisposeOnToggleMaximized.push(disposable_1.Disposable.create(() => {
188 maximizedElement.style.display = 'none';
189 this.removeClass(exports.MAXIMIZED_CLASS);
190 this.onDidToggleMaximizedEmitter.fire(this);
191 if (!this.isElectron()) {
192 this.removeClass(VISIBLE_MENU_MAXIMIZED_CLASS);
193 }
194 if (this.isAttached) {
195 widgets_2.UnsafeWidgetUtilities.detach(this);
196 }
197 widgets_2.UnsafeWidgetUtilities.attach(this, areaContainer);
198 this.fit();
199 }));
200 const layout = this.layout;
201 if (layout instanceof widgets_1.DockLayout) {
202 const onResize = layout['onResize'];
203 layout['onResize'] = () => onResize.bind(layout)(widgets_1.Widget.ResizeMessage.UnknownSize);
204 this.toDisposeOnToggleMaximized.push(disposable_1.Disposable.create(() => layout['onResize'] = onResize));
205 }
206 const removedListener = () => {
207 if (!this.widgets().next()) {
208 this.toDisposeOnToggleMaximized.dispose();
209 }
210 };
211 this.widgetRemoved.connect(removedListener);
212 this.toDisposeOnToggleMaximized.push(disposable_1.Disposable.create(() => this.widgetRemoved.disconnect(removedListener)));
213 }
214 getMaximizedElement() {
215 if (!this.maximizedElement) {
216 this.maximizedElement = document.createElement('div');
217 this.maximizedElement.style.display = 'none';
218 document.body.appendChild(this.maximizedElement);
219 }
220 return this.maximizedElement;
221 }
222}
223exports.TheiaDockPanel = TheiaDockPanel;
224(function (TheiaDockPanel) {
225 TheiaDockPanel.Factory = Symbol('TheiaDockPanel#Factory');
226})(TheiaDockPanel = exports.TheiaDockPanel || (exports.TheiaDockPanel = {}));
227//# sourceMappingURL=theia-dock-panel.js.map
\No newline at end of file