layout.ts 29.7 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

J
Johannes Rieken 已提交
6
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
C
Christof Marti 已提交
7
import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickInput';
J
Johannes Rieken 已提交
8
import { Sash, ISashEvent, IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider, Orientation } from 'vs/base/browser/ui/sash/sash';
9
import { IPartService, Position, ILayoutOptions, Parts } from 'vs/workbench/services/part/common/partService';
B
Benjamin Pasero 已提交
10
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
J
Johannes Rieken 已提交
11 12
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
13
import { Disposable } from 'vs/base/common/lifecycle';
14
import { IThemeService } from 'vs/platform/theme/common/themeService';
R
Ryan Adolf 已提交
15
import { isMacintosh } from 'vs/base/common/platform';
16
import { memoize } from 'vs/base/common/decorators';
17
import { NotificationsCenter } from 'vs/workbench/browser/parts/notifications/notificationsCenter';
18
import { NotificationsToasts } from 'vs/workbench/browser/parts/notifications/notificationsToasts';
19
import { Dimension, getClientArea, size, position, hide, show } from 'vs/base/browser/dom';
20
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
21
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
22 23 24 25 26
import { TitlebarPart } from 'vs/workbench/browser/parts/titlebar/titlebarPart';
import { ActivitybarPart } from 'vs/workbench/browser/parts/activitybar/activitybarPart';
import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
import { PanelPart } from 'vs/workbench/browser/parts/panel/panelPart';
import { StatusbarPart } from 'vs/workbench/browser/parts/statusbar/statusbarPart';
S
SteVen Batten 已提交
27
import { getZoomFactor } from 'vs/base/browser/browser';
28

29
const TITLE_BAR_HEIGHT = isMacintosh ? 22 : 30;
30 31
const STATUS_BAR_HEIGHT = 22;
const ACTIVITY_BAR_WIDTH = 50;
E
Erich Gamma 已提交
32

33
const MIN_SIDEBAR_PART_WIDTH = 170;
34
const DEFAULT_SIDEBAR_PART_WIDTH = 300;
35 36
const HIDE_SIDEBAR_WIDTH_THRESHOLD = 50;

37
const MIN_PANEL_PART_HEIGHT = 77;
I
isidor 已提交
38
const MIN_PANEL_PART_WIDTH = 300;
39
const DEFAULT_PANEL_PART_SIZE = 350;
I
isidor 已提交
40
const DEFAULT_PANEL_SIZE_COEFFICIENT = 0.4;
41
const PANEL_SIZE_BEFORE_MAXIMIZED_BOUNDARY = 0.7;
I
isidor 已提交
42
const HIDE_PANEL_HEIGHT_THRESHOLD = 50;
43
const HIDE_PANEL_WIDTH_THRESHOLD = 100;
E
Erich Gamma 已提交
44 45

/**
B
Benjamin Pasero 已提交
46
 * The workbench layout is responsible to lay out all parts that make the Workbench.
E
Erich Gamma 已提交
47
 */
48
export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider {
E
Erich Gamma 已提交
49

50 51 52 53
	private static readonly sashXOneWidthSettingsKey = 'workbench.sidebar.width';
	private static readonly sashXTwoWidthSettingsKey = 'workbench.panel.width';
	private static readonly sashYHeightSettingsKey = 'workbench.panel.height';
	private static readonly panelSizeBeforeMaximizedKey = 'workbench.panel.sizeBeforeMaximized';
E
Erich Gamma 已提交
54 55

	private workbenchSize: Dimension;
56

57 58
	private sashXOne: Sash;
	private sashXTwo: Sash;
I
isidor 已提交
59
	private sashY: Sash;
60

61
	private _sidebarWidth: number;
I
isidor 已提交
62
	private sidebarHeight: number;
63 64
	private titlebarHeight: number;
	private statusbarHeight: number;
65 66
	private panelSizeBeforeMaximized: number;
	private panelMaximized: boolean;
67 68
	private _panelHeight: number;
	private _panelWidth: number;
E
Erich Gamma 已提交
69 70

	constructor(
71 72 73 74 75
		private parent: HTMLElement,
		private workbenchContainer: HTMLElement,
		private parts: {
			titlebar: TitlebarPart,
			activitybar: ActivitybarPart,
76
			editor: EditorPart,
77 78 79
			sidebar: SidebarPart,
			panel: PanelPart,
			statusbar: StatusbarPart
I
isidor 已提交
80
		},
81 82 83 84
		private quickopen: QuickOpenController,
		private quickInput: QuickInputService,
		private notificationsCenter: NotificationsCenter,
		private notificationsToasts: NotificationsToasts,
E
Erich Gamma 已提交
85 86
		@IStorageService private storageService: IStorageService,
		@IContextViewService private contextViewService: IContextViewService,
M
Martin Aeschlimann 已提交
87
		@IPartService private partService: IPartService,
M
Maxime Quandalle 已提交
88
		@IViewletService private viewletService: IViewletService,
89
		@IThemeService private themeService: IThemeService,
90
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
E
Erich Gamma 已提交
91
	) {
92
		super();
93

94 95
		// Restore state
		this.restorePreviousState();
96

97
		// Create layout sashes
98 99 100
		this.sashXOne = new Sash(this.workbenchContainer, this);
		this.sashXTwo = new Sash(this.workbenchContainer, this);
		this.sashY = new Sash(this.workbenchContainer, this, { orientation: Orientation.HORIZONTAL });
101

102 103
		this.registerListeners();
	}
E
Erich Gamma 已提交
104

105
	private restorePreviousState(): void {
106
		this._sidebarWidth = Math.max(this.partLayoutInfo.sidebar.minWidth, this.storageService.getInteger(WorkbenchLayout.sashXOneWidthSettingsKey, StorageScope.GLOBAL, DEFAULT_SIDEBAR_PART_WIDTH));
107

108
		this._panelWidth = Math.max(this.partLayoutInfo.panel.minWidth, this.storageService.getInteger(WorkbenchLayout.sashXTwoWidthSettingsKey, StorageScope.GLOBAL, DEFAULT_PANEL_PART_SIZE));
109
		this._panelHeight = Math.max(this.partLayoutInfo.panel.minHeight, this.storageService.getInteger(WorkbenchLayout.sashYHeightSettingsKey, StorageScope.GLOBAL, DEFAULT_PANEL_PART_SIZE));
E
Erich Gamma 已提交
110

111 112 113
		this.panelMaximized = false;
		this.panelSizeBeforeMaximized = this.storageService.getInteger(WorkbenchLayout.panelSizeBeforeMaximizedKey, StorageScope.GLOBAL, 0);
	}
114

115 116
	private registerListeners(): void {
		this._register(this.themeService.onThemeChange(_ => this.layout()));
B
Benjamin Pasero 已提交
117
		this._register(this.parts.editor.onDidSizeConstraintsChange(() => this.onDidEditorSizeConstraintsChange()));
M
Martin Aeschlimann 已提交
118

E
Erich Gamma 已提交
119 120 121
		this.registerSashListeners();
	}

B
Benjamin Pasero 已提交
122
	private onDidEditorSizeConstraintsChange(): void {
123
		if (this.workbenchSize && (this.sidebarWidth || this.panelHeight)) {
124
			if (this.editorGroupService.count > 1) {
125
				const minimumEditorPartSize = new Dimension(this.parts.editor.minimumWidth, this.parts.editor.minimumHeight);
126

127
				const sidebarOverflow = this.workbenchSize.width - this.sidebarWidth < minimumEditorPartSize.width;
128

129 130
				let panelOverflow = false;
				if (this.partService.getPanelPosition() === Position.RIGHT) {
131
					panelOverflow = this.workbenchSize.width - this.panelWidth - this.sidebarWidth < minimumEditorPartSize.width;
132
				} else {
133
					panelOverflow = this.workbenchSize.height - this.panelHeight < minimumEditorPartSize.height;
134 135 136 137 138 139 140 141 142
				}

				// Trigger a layout if we detect that either sidebar or panel overflow
				// as a matter of a new editor group being added to the editor part
				if (sidebarOverflow || panelOverflow) {
					this.layout();
				}
			}
		}
143 144
	}

I
isidor 已提交
145 146 147 148 149 150 151 152
	private get activitybarWidth(): number {
		if (this.partService.isVisible(Parts.ACTIVITYBAR_PART)) {
			return this.partLayoutInfo.activitybar.width;
		}

		return 0;
	}

153 154 155 156 157 158 159 160 161 162
	private get panelHeight(): number {
		const panelPosition = this.partService.getPanelPosition();
		if (panelPosition === Position.RIGHT) {
			return this.sidebarHeight;
		}

		return this._panelHeight;
	}

	private set panelHeight(value: number) {
163
		this._panelHeight = Math.min(this.computeMaxPanelHeight(), Math.max(this.partLayoutInfo.panel.minHeight, value));
164 165 166 167 168 169 170 171 172 173 174 175
	}

	private get panelWidth(): number {
		const panelPosition = this.partService.getPanelPosition();
		if (panelPosition === Position.BOTTOM) {
			return this.workbenchSize.width - this.activitybarWidth - this.sidebarWidth;
		}

		return this._panelWidth;
	}

	private set panelWidth(value: number) {
176 177 178 179
		this._panelWidth = Math.min(this.computeMaxPanelWidth(), Math.max(this.partLayoutInfo.panel.minWidth, value));
	}

	private computeMaxPanelWidth(): number {
B
Benjamin Pasero 已提交
180 181 182 183 184 185 186 187 188 189 190
		let minSidebarWidth: number;
		if (this.partService.isVisible(Parts.SIDEBAR_PART)) {
			if (this.partService.getSideBarPosition() === Position.LEFT) {
				minSidebarWidth = this.partLayoutInfo.sidebar.minWidth;
			} else {
				minSidebarWidth = this.sidebarWidth;
			}
		} else {
			minSidebarWidth = 0;
		}

191
		return Math.max(this.partLayoutInfo.panel.minWidth, this.workbenchSize.width - this.parts.editor.minimumWidth - minSidebarWidth - this.activitybarWidth);
192 193 194
	}

	private computeMaxPanelHeight(): number {
195
		return Math.max(this.partLayoutInfo.panel.minHeight, this.sidebarHeight /* simplification for: window.height - status.height - title-height */ - this.parts.editor.minimumHeight);
196 197 198 199 200 201 202 203 204 205 206
	}

	private get sidebarWidth(): number {
		if (this.partService.isVisible(Parts.SIDEBAR_PART)) {
			return this._sidebarWidth;
		}

		return 0;
	}

	private set sidebarWidth(value: number) {
207
		const panelMinWidth = this.partService.getPanelPosition() === Position.RIGHT && this.partService.isVisible(Parts.PANEL_PART) ? this.partLayoutInfo.panel.minWidth : 0;
208
		const maxSidebarWidth = this.workbenchSize.width - this.activitybarWidth - this.parts.editor.minimumWidth - panelMinWidth;
209

I
isidor 已提交
210
		this._sidebarWidth = Math.max(this.partLayoutInfo.sidebar.minWidth, Math.min(maxSidebarWidth, value));
211 212
	}

213
	@memoize
S
SteVen Batten 已提交
214
	public get partLayoutInfo() {
215 216 217 218 219 220 221 222 223 224 225
		return {
			titlebar: {
				height: TITLE_BAR_HEIGHT
			},
			activitybar: {
				width: ACTIVITY_BAR_WIDTH
			},
			sidebar: {
				minWidth: MIN_SIDEBAR_PART_WIDTH
			},
			panel: {
I
isidor 已提交
226 227
				minHeight: MIN_PANEL_PART_HEIGHT,
				minWidth: MIN_PANEL_PART_WIDTH
228 229 230 231 232 233 234
			},
			statusbar: {
				height: STATUS_BAR_HEIGHT
			}
		};
	}

E
Erich Gamma 已提交
235 236
	private registerSashListeners(): void {
		let startX: number = 0;
I
isidor 已提交
237
		let startY: number = 0;
238
		let startXTwo: number = 0;
239 240 241
		let startSidebarWidth: number;
		let startPanelHeight: number;
		let startPanelWidth: number;
E
Erich Gamma 已提交
242

243
		this._register(this.sashXOne.onDidStart((e: ISashEvent) => {
244
			startSidebarWidth = this.sidebarWidth;
E
Erich Gamma 已提交
245
			startX = e.startX;
246
		}));
E
Erich Gamma 已提交
247

248
		this._register(this.sashY.onDidStart((e: ISashEvent) => {
249
			startPanelHeight = this.panelHeight;
I
isidor 已提交
250
			startY = e.startY;
251 252
		}));

253
		this._register(this.sashXTwo.onDidStart((e: ISashEvent) => {
254
			startPanelWidth = this.panelWidth;
255
			startXTwo = e.startX;
256
		}));
I
isidor 已提交
257

258
		this._register(this.sashXOne.onDidChange((e: ISashEvent) => {
E
Erich Gamma 已提交
259 260
			let doLayout = false;
			let sidebarPosition = this.partService.getSideBarPosition();
261
			let isSidebarVisible = this.partService.isVisible(Parts.SIDEBAR_PART);
262
			let newSashWidth = (sidebarPosition === Position.LEFT) ? startSidebarWidth + e.currentX - startX : startSidebarWidth - e.currentX + startX;
B
Benjamin Pasero 已提交
263
			let promise: Thenable<void> = Promise.resolve<void>(null);
E
Erich Gamma 已提交
264 265

			// Sidebar visible
266
			if (isSidebarVisible) {
E
Erich Gamma 已提交
267 268

				// Automatically hide side bar when a certain threshold is met
269
				if (newSashWidth + HIDE_SIDEBAR_WIDTH_THRESHOLD < this.partLayoutInfo.sidebar.minWidth) {
270
					let dragCompensation = this.partLayoutInfo.sidebar.minWidth - HIDE_SIDEBAR_WIDTH_THRESHOLD;
271
					promise = this.partService.setSideBarHidden(true);
272
					startX = (sidebarPosition === Position.LEFT) ? Math.max(this.activitybarWidth, e.currentX - dragCompensation) : Math.min(e.currentX + dragCompensation, this.workbenchSize.width - this.activitybarWidth);
273
					this.sidebarWidth = startSidebarWidth; // when restoring sidebar, restore to the sidebar width we started from
E
Erich Gamma 已提交
274 275 276 277
				}

				// Otherwise size the sidebar accordingly
				else {
278 279
					this.sidebarWidth = Math.max(this.partLayoutInfo.sidebar.minWidth, newSashWidth); // Sidebar can not become smaller than MIN_PART_WIDTH
					doLayout = newSashWidth >= this.partLayoutInfo.sidebar.minWidth;
E
Erich Gamma 已提交
280 281 282 283 284
				}
			}

			// Sidebar hidden
			else {
285 286
				if ((sidebarPosition === Position.LEFT && e.currentX - startX >= this.partLayoutInfo.sidebar.minWidth) ||
					(sidebarPosition === Position.RIGHT && startX - e.currentX >= this.partLayoutInfo.sidebar.minWidth)) {
287
					startSidebarWidth = this.partLayoutInfo.sidebar.minWidth - (sidebarPosition === Position.LEFT ? e.currentX - startX : startX - e.currentX);
288
					this.sidebarWidth = this.partLayoutInfo.sidebar.minWidth;
289
					promise = this.partService.setSideBarHidden(false);
E
Erich Gamma 已提交
290 291 292 293
				}
			}

			if (doLayout) {
294
				promise.then(() => this.layout({ source: Parts.SIDEBAR_PART }));
E
Erich Gamma 已提交
295
			}
296
		}));
E
Erich Gamma 已提交
297

298
		this._register(this.sashY.onDidChange((e: ISashEvent) => {
I
isidor 已提交
299
			let doLayout = false;
300
			let isPanelVisible = this.partService.isVisible(Parts.PANEL_PART);
301
			let newSashHeight = startPanelHeight - (e.currentY - startY);
B
Benjamin Pasero 已提交
302
			let promise: Thenable<void> = Promise.resolve<void>(null);
I
isidor 已提交
303 304

			// Panel visible
305
			if (isPanelVisible) {
306

307
				// Automatically hide panel when a certain threshold is met
308
				if (newSashHeight + HIDE_PANEL_HEIGHT_THRESHOLD < this.partLayoutInfo.panel.minHeight) {
309
					let dragCompensation = this.partLayoutInfo.panel.minHeight - HIDE_PANEL_HEIGHT_THRESHOLD;
310
					promise = this.partService.setPanelHidden(true);
S
SteVen Batten 已提交
311
					startY = Math.min(this.sidebarHeight - this.statusbarHeight - this.titlebarHeight, e.currentY + dragCompensation);
312
					this.panelHeight = startPanelHeight; // when restoring panel, restore to the panel height we started from
313 314 315 316
				}

				// Otherwise size the panel accordingly
				else {
317 318
					this.panelHeight = Math.max(this.partLayoutInfo.panel.minHeight, newSashHeight); // Panel can not become smaller than MIN_PART_HEIGHT
					doLayout = newSashHeight >= this.partLayoutInfo.panel.minHeight;
319 320
				}
			}
I
isidor 已提交
321

322 323
			// Panel hidden
			else {
324
				if (startY - e.currentY >= this.partLayoutInfo.panel.minHeight) {
325
					startPanelHeight = 0;
326
					this.panelHeight = this.partLayoutInfo.panel.minHeight;
327
					promise = this.partService.setPanelHidden(false);
328
				}
I
isidor 已提交
329
			}
330

I
isidor 已提交
331
			if (doLayout) {
332
				promise.then(() => this.layout({ source: Parts.PANEL_PART }));
I
isidor 已提交
333
			}
334
		}));
I
isidor 已提交
335

336
		this._register(this.sashXTwo.onDidChange((e: ISashEvent) => {
337 338 339
			let doLayout = false;
			let isPanelVisible = this.partService.isVisible(Parts.PANEL_PART);
			let newSashWidth = startPanelWidth - (e.currentX - startXTwo);
B
Benjamin Pasero 已提交
340
			let promise: Thenable<void> = Promise.resolve<void>(null);
341 342 343 344 345 346

			// Panel visible
			if (isPanelVisible) {

				// Automatically hide panel when a certain threshold is met
				if (newSashWidth + HIDE_PANEL_WIDTH_THRESHOLD < this.partLayoutInfo.panel.minWidth) {
347
					let dragCompensation = this.partLayoutInfo.panel.minWidth - HIDE_PANEL_WIDTH_THRESHOLD;
348 349 350 351 352 353 354
					promise = this.partService.setPanelHidden(true);
					startXTwo = Math.min(this.workbenchSize.width - this.activitybarWidth, e.currentX + dragCompensation);
					this.panelWidth = startPanelWidth; // when restoring panel, restore to the panel height we started from
				}

				// Otherwise size the panel accordingly
				else {
355
					this.panelWidth = newSashWidth;
356 357 358 359 360 361 362 363 364 365 366 367 368 369
					doLayout = newSashWidth >= this.partLayoutInfo.panel.minWidth;
				}
			}

			// Panel hidden
			else {
				if (startXTwo - e.currentX >= this.partLayoutInfo.panel.minWidth) {
					startPanelWidth = 0;
					this.panelWidth = this.partLayoutInfo.panel.minWidth;
					promise = this.partService.setPanelHidden(false);
				}
			}

			if (doLayout) {
370
				promise.then(() => this.layout({ source: Parts.PANEL_PART }));
371
			}
372
		}));
M
Maxime Quandalle 已提交
373

374
		this._register(this.sashXOne.onDidEnd(() => {
375 376 377
			this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
		}));

378
		this._register(this.sashY.onDidEnd(() => {
I
isidor 已提交
379
			this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
380 381
		}));

382
		this._register(this.sashXTwo.onDidEnd(() => {
383 384
			this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
		}));
M
Maxime Quandalle 已提交
385

386
		this._register(this.sashY.onDidReset(() => {
I
isidor 已提交
387
			this.panelHeight = this.sidebarHeight * DEFAULT_PANEL_SIZE_COEFFICIENT;
M
Maxime Quandalle 已提交
388
			this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
389 390
			this.layout();
		}));
M
Maxime Quandalle 已提交
391

392
		this._register(this.sashXOne.onDidReset(() => {
M
Maxime Quandalle 已提交
393 394
			let activeViewlet = this.viewletService.getActiveViewlet();
			let optimalWidth = activeViewlet && activeViewlet.getOptimalWidth();
395
			this.sidebarWidth = Math.max(optimalWidth, DEFAULT_SIDEBAR_PART_WIDTH);
396
			this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
397
			this.partService.setSideBarHidden(false).then(() => this.layout());
398 399
		}));

400
		this._register(this.sashXTwo.onDidReset(() => {
401
			this.panelWidth = (this.workbenchSize.width - this.sidebarWidth - this.activitybarWidth) * DEFAULT_PANEL_SIZE_COEFFICIENT;
402 403 404
			this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
			this.layout();
		}));
E
Erich Gamma 已提交
405 406
	}

407
	layout(options?: ILayoutOptions): void {
408
		this.workbenchSize = getClientArea(this.parent);
E
Erich Gamma 已提交
409

410
		const isActivityBarHidden = !this.partService.isVisible(Parts.ACTIVITYBAR_PART);
411 412 413 414
		const isTitlebarHidden = !this.partService.isVisible(Parts.TITLEBAR_PART);
		const isPanelHidden = !this.partService.isVisible(Parts.PANEL_PART);
		const isStatusbarHidden = !this.partService.isVisible(Parts.STATUSBAR_PART);
		const isSidebarHidden = !this.partService.isVisible(Parts.SIDEBAR_PART);
I
isidor 已提交
415
		const sidebarPosition = this.partService.getSideBarPosition();
416
		const panelPosition = this.partService.getPanelPosition();
S
SteVen Batten 已提交
417
		const menubarVisibility = this.partService.getMenubarVisibility();
E
Erich Gamma 已提交
418 419

		// Sidebar
I
isidor 已提交
420
		if (this.sidebarWidth === -1) {
421
			this.sidebarWidth = this.workbenchSize.width / 5;
E
Erich Gamma 已提交
422
		}
B
Benjamin Pasero 已提交
423

424
		this.statusbarHeight = isStatusbarHidden ? 0 : this.partLayoutInfo.statusbar.height;
S
SteVen Batten 已提交
425
		this.titlebarHeight = isTitlebarHidden ? 0 : this.partLayoutInfo.titlebar.height / (!menubarVisibility || menubarVisibility === 'hidden' ? getZoomFactor() : 1); // adjust for zoom prevention
E
Erich Gamma 已提交
426

S
SteVen Batten 已提交
427
		this.sidebarHeight = this.workbenchSize.height - this.statusbarHeight - this.titlebarHeight;
428
		let sidebarSize = new Dimension(this.sidebarWidth, this.sidebarHeight);
E
Erich Gamma 已提交
429 430

		// Activity Bar
431
		let activityBarSize = new Dimension(this.activitybarWidth, sidebarSize.height);
E
Erich Gamma 已提交
432

I
isidor 已提交
433 434
		// Panel part
		let panelHeight: number;
I
isidor 已提交
435
		let panelWidth: number;
436 437
		const maxPanelHeight = this.computeMaxPanelHeight();
		const maxPanelWidth = this.computeMaxPanelWidth();
I
isidor 已提交
438

I
isidor 已提交
439
		if (isPanelHidden) {
I
isidor 已提交
440
			panelHeight = 0;
I
isidor 已提交
441 442
			panelWidth = 0;
		} else if (panelPosition === Position.BOTTOM) {
443
			if (this.panelHeight > 0) {
I
isidor 已提交
444 445 446 447 448
				panelHeight = Math.min(maxPanelHeight, Math.max(this.partLayoutInfo.panel.minHeight, this.panelHeight));
			} else {
				panelHeight = sidebarSize.height * DEFAULT_PANEL_SIZE_COEFFICIENT;
			}
			panelWidth = this.workbenchSize.width - sidebarSize.width - activityBarSize.width;
449 450 451 452 453 454 455 456 457

			if (options && options.toggleMaximizedPanel) {
				panelHeight = this.panelMaximized ? Math.max(this.partLayoutInfo.panel.minHeight, Math.min(this.panelSizeBeforeMaximized, maxPanelHeight)) : maxPanelHeight;
			}

			this.panelMaximized = panelHeight === maxPanelHeight;
			if (panelHeight / maxPanelHeight < PANEL_SIZE_BEFORE_MAXIMIZED_BOUNDARY) {
				this.panelSizeBeforeMaximized = panelHeight;
			}
I
isidor 已提交
458
		} else {
I
isidor 已提交
459 460 461 462 463 464
			panelHeight = sidebarSize.height;
			if (this.panelWidth > 0) {
				panelWidth = Math.min(maxPanelWidth, Math.max(this.partLayoutInfo.panel.minWidth, this.panelWidth));
			} else {
				panelWidth = (this.workbenchSize.width - activityBarSize.width - sidebarSize.width) * DEFAULT_PANEL_SIZE_COEFFICIENT;
			}
465 466 467 468 469 470 471 472 473

			if (options && options.toggleMaximizedPanel) {
				panelWidth = this.panelMaximized ? Math.max(this.partLayoutInfo.panel.minWidth, Math.min(this.panelSizeBeforeMaximized, maxPanelWidth)) : maxPanelWidth;
			}

			this.panelMaximized = panelWidth === maxPanelWidth;
			if (panelWidth / maxPanelWidth < PANEL_SIZE_BEFORE_MAXIMIZED_BOUNDARY) {
				this.panelSizeBeforeMaximized = panelWidth;
			}
I
isidor 已提交
474
		}
475
		this.storageService.store(WorkbenchLayout.panelSizeBeforeMaximizedKey, this.panelSizeBeforeMaximized, StorageScope.GLOBAL);
I
isidor 已提交
476
		const panelDimension = new Dimension(panelWidth, panelHeight);
I
isidor 已提交
477

E
Erich Gamma 已提交
478 479 480
		// Editor
		let editorSize = {
			width: 0,
I
isidor 已提交
481
			height: 0
E
Erich Gamma 已提交
482 483
		};

I
isidor 已提交
484 485
		editorSize.width = this.workbenchSize.width - sidebarSize.width - activityBarSize.width - (panelPosition === Position.RIGHT ? panelDimension.width : 0);
		editorSize.height = sidebarSize.height - (panelPosition === Position.BOTTOM ? panelDimension.height : 0);
E
Erich Gamma 已提交
486

487 488 489 490
		// Adjust for Editor Part minimum width
		const minimumEditorPartSize = new Dimension(this.parts.editor.minimumWidth, this.parts.editor.minimumHeight);
		if (editorSize.width < minimumEditorPartSize.width) {
			const missingPreferredEditorWidth = minimumEditorPartSize.width - editorSize.width;
B
Benjamin Pasero 已提交
491 492 493 494 495 496 497
			let outstandingMissingPreferredEditorWidth = missingPreferredEditorWidth;

			// Take from Panel if Panel Position on the Right and Visible
			if (!isPanelHidden && panelPosition === Position.RIGHT && (!options || options.source !== Parts.PANEL_PART)) {
				const oldPanelWidth = panelDimension.width;
				panelDimension.width = Math.max(this.partLayoutInfo.panel.minWidth, panelDimension.width - outstandingMissingPreferredEditorWidth);
				outstandingMissingPreferredEditorWidth -= oldPanelWidth - panelDimension.width;
498 499
			}

B
Benjamin Pasero 已提交
500 501 502 503 504 505 506 507 508 509
			// Take from Sidebar if Visible
			if (!isSidebarHidden && outstandingMissingPreferredEditorWidth > 0) {
				const oldSidebarWidth = sidebarSize.width;
				sidebarSize.width = Math.max(this.partLayoutInfo.sidebar.minWidth, sidebarSize.width - outstandingMissingPreferredEditorWidth);
				outstandingMissingPreferredEditorWidth -= oldSidebarWidth - sidebarSize.width;
			}

			editorSize.width += missingPreferredEditorWidth - outstandingMissingPreferredEditorWidth;
			if (!isPanelHidden && panelPosition === Position.BOTTOM) {
				panelDimension.width = editorSize.width; // ensure panel width is always following editor width
I
isidor 已提交
510
			}
511 512
		}

513 514 515
		// Adjust for Editor Part minimum height
		if (editorSize.height < minimumEditorPartSize.height) {
			const missingPreferredEditorHeight = minimumEditorPartSize.height - editorSize.height;
B
Benjamin Pasero 已提交
516 517 518 519 520 521 522 523
			let outstandingMissingPreferredEditorHeight = missingPreferredEditorHeight;

			// Take from Panel if Panel Position on the Bottom and Visible
			if (!isPanelHidden && panelPosition === Position.BOTTOM) {
				const oldPanelHeight = panelDimension.height;
				panelDimension.height = Math.max(this.partLayoutInfo.panel.minHeight, panelDimension.height - outstandingMissingPreferredEditorHeight);
				outstandingMissingPreferredEditorHeight -= oldPanelHeight - panelDimension.height;
			}
524

B
Benjamin Pasero 已提交
525
			editorSize.height += missingPreferredEditorHeight - outstandingMissingPreferredEditorHeight;
526
		}
E
Erich Gamma 已提交
527 528 529

		if (!isSidebarHidden) {
			this.sidebarWidth = sidebarSize.width;
530
			this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
E
Erich Gamma 已提交
531 532
		}

I
isidor 已提交
533
		if (!isPanelHidden) {
534 535 536 537 538 539 540
			if (panelPosition === Position.BOTTOM) {
				this.panelHeight = panelDimension.height;
				this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
			} else {
				this.panelWidth = panelDimension.width;
				this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
			}
I
isidor 已提交
541 542
		}

E
Erich Gamma 已提交
543
		// Workbench
544 545
		position(this.workbenchContainer, 0, 0, 0, 0, 'relative');
		size(this.workbenchContainer, this.workbenchSize.width, this.workbenchSize.height);
E
Erich Gamma 已提交
546

547
		// Title Part
548
		const titleContainer = this.parts.titlebar.getContainer();
549
		if (isTitlebarHidden) {
550
			hide(titleContainer);
551
		} else {
552
			show(titleContainer);
553 554
		}

I
isidor 已提交
555
		// Editor Part and Panel part
556 557
		const editorContainer = this.parts.editor.getContainer();
		const panelContainer = this.parts.panel.getContainer();
558 559
		size(editorContainer, editorSize.width, editorSize.height);
		size(panelContainer, panelDimension.width, panelDimension.height);
E
Erich Gamma 已提交
560

I
isidor 已提交
561 562
		if (panelPosition === Position.BOTTOM) {
			if (sidebarPosition === Position.LEFT) {
S
SteVen Batten 已提交
563 564
				position(editorContainer, this.titlebarHeight, 0, this.statusbarHeight + panelDimension.height, sidebarSize.width + activityBarSize.width);
				position(panelContainer, editorSize.height + this.titlebarHeight, 0, this.statusbarHeight, sidebarSize.width + activityBarSize.width);
I
isidor 已提交
565
			} else {
S
SteVen Batten 已提交
566 567
				position(editorContainer, this.titlebarHeight, sidebarSize.width, this.statusbarHeight + panelDimension.height, 0);
				position(panelContainer, editorSize.height + this.titlebarHeight, sidebarSize.width, this.statusbarHeight, 0);
I
isidor 已提交
568
			}
E
Erich Gamma 已提交
569
		} else {
I
isidor 已提交
570
			if (sidebarPosition === Position.LEFT) {
S
SteVen Batten 已提交
571 572
				position(editorContainer, this.titlebarHeight, panelDimension.width, this.statusbarHeight, sidebarSize.width + activityBarSize.width);
				position(panelContainer, this.titlebarHeight, 0, this.statusbarHeight, sidebarSize.width + activityBarSize.width + editorSize.width);
I
isidor 已提交
573
			} else {
S
SteVen Batten 已提交
574 575
				position(editorContainer, this.titlebarHeight, sidebarSize.width + activityBarSize.width + panelWidth, this.statusbarHeight, 0);
				position(panelContainer, this.titlebarHeight, sidebarSize.width + activityBarSize.width, this.statusbarHeight, editorSize.width);
I
isidor 已提交
576
			}
E
Erich Gamma 已提交
577 578 579
		}

		// Activity Bar Part
580
		const activitybarContainer = this.parts.activitybar.getContainer();
581
		size(activitybarContainer, null, activityBarSize.height);
E
Erich Gamma 已提交
582
		if (sidebarPosition === Position.LEFT) {
583
			this.parts.activitybar.getContainer().style.right = '';
S
SteVen Batten 已提交
584
			position(activitybarContainer, this.titlebarHeight, null, 0, 0);
E
Erich Gamma 已提交
585
		} else {
586
			this.parts.activitybar.getContainer().style.left = '';
S
SteVen Batten 已提交
587
			position(activitybarContainer, this.titlebarHeight, 0, 0, null);
E
Erich Gamma 已提交
588
		}
B
Benjamin Pasero 已提交
589
		if (isActivityBarHidden) {
590
			hide(activitybarContainer);
B
Benjamin Pasero 已提交
591
		} else {
592
			show(activitybarContainer);
B
Benjamin Pasero 已提交
593
		}
E
Erich Gamma 已提交
594 595

		// Sidebar Part
596
		const sidebarContainer = this.parts.sidebar.getContainer();
597
		size(sidebarContainer, sidebarSize.width, sidebarSize.height);
598
		const editorAndPanelWidth = editorSize.width + (panelPosition === Position.RIGHT ? panelWidth : 0);
E
Erich Gamma 已提交
599
		if (sidebarPosition === Position.LEFT) {
S
SteVen Batten 已提交
600
			position(sidebarContainer, this.titlebarHeight, editorAndPanelWidth, this.statusbarHeight, activityBarSize.width);
E
Erich Gamma 已提交
601
		} else {
S
SteVen Batten 已提交
602
			position(sidebarContainer, this.titlebarHeight, activityBarSize.width, this.statusbarHeight, editorAndPanelWidth);
E
Erich Gamma 已提交
603 604 605
		}

		// Statusbar Part
606
		const statusbarContainer = this.parts.statusbar.getContainer();
607
		position(statusbarContainer, this.workbenchSize.height - this.statusbarHeight);
608
		if (isStatusbarHidden) {
609
			hide(statusbarContainer);
610
		} else {
611
			show(statusbarContainer);
612
		}
E
Erich Gamma 已提交
613 614 615 616

		// Quick open
		this.quickopen.layout(this.workbenchSize);

C
Christof Marti 已提交
617 618 619
		// Quick input
		this.quickInput.layout(this.workbenchSize);

620 621
		// Notifications
		this.notificationsCenter.layout(this.workbenchSize);
622
		this.notificationsToasts.layout(this.workbenchSize);
623

I
isidor 已提交
624
		// Sashes
625 626 627
		this.sashXOne.layout();
		if (panelPosition === Position.BOTTOM) {
			this.sashXTwo.hide();
628 629
			this.sashY.layout();
			this.sashY.show();
630 631 632
		} else {
			this.sashY.hide();
			this.sashXTwo.layout();
633
			this.sashXTwo.show();
634
		}
E
Erich Gamma 已提交
635 636

		// Propagate to Part Layouts
637 638 639 640 641
		this.parts.titlebar.layout(new Dimension(this.workbenchSize.width, this.titlebarHeight));
		this.parts.editor.layout(new Dimension(editorSize.width, editorSize.height));
		this.parts.sidebar.layout(sidebarSize);
		this.parts.panel.layout(panelDimension);
		this.parts.activitybar.layout(activityBarSize);
E
Erich Gamma 已提交
642 643

		// Propagate to Context View
B
Benjamin Pasero 已提交
644
		this.contextViewService.layout();
E
Erich Gamma 已提交
645 646
	}

647
	getVerticalSashTop(sash: Sash): number {
S
SteVen Batten 已提交
648
		return this.titlebarHeight;
E
Erich Gamma 已提交
649 650
	}

651
	getVerticalSashLeft(sash: Sash): number {
E
Erich Gamma 已提交
652
		let sidebarPosition = this.partService.getSideBarPosition();
653
		if (sash === this.sashXOne) {
E
Erich Gamma 已提交
654

655
			if (sidebarPosition === Position.LEFT) {
656
				return this.sidebarWidth + this.activitybarWidth;
657 658
			}

659
			return this.workbenchSize.width - this.sidebarWidth - this.activitybarWidth;
E
Erich Gamma 已提交
660 661
		}

662
		return this.workbenchSize.width - this.panelWidth - (sidebarPosition === Position.RIGHT ? this.sidebarWidth + this.activitybarWidth : 0);
E
Erich Gamma 已提交
663 664
	}

665
	getVerticalSashHeight(sash: Sash): number {
666 667 668 669
		if (sash === this.sashXTwo && !this.partService.isVisible(Parts.PANEL_PART)) {
			return 0;
		}

I
isidor 已提交
670
		return this.sidebarHeight;
E
Erich Gamma 已提交
671 672
	}

673 674
	getHorizontalSashTop(sash: Sash): number {
		const offset = 2; // Horizontal sash should be a bit lower than the editor area, thus add 2px #5524
S
SteVen Batten 已提交
675
		return offset + (this.partService.isVisible(Parts.PANEL_PART) ? this.sidebarHeight - this.panelHeight + this.titlebarHeight : this.sidebarHeight + this.titlebarHeight);
I
isidor 已提交
676 677
	}

678
	getHorizontalSashLeft(sash: Sash): number {
679 680 681 682 683
		if (this.partService.getSideBarPosition() === Position.RIGHT) {
			return 0;
		}

		return this.sidebarWidth + this.activitybarWidth;
I
isidor 已提交
684 685
	}

686
	getHorizontalSashWidth(sash: Sash): number {
I
isidor 已提交
687
		return this.panelWidth;
I
isidor 已提交
688 689
	}

690
	isPanelMaximized(): boolean {
691 692 693
		return this.panelMaximized;
	}

694
	resizePart(part: Parts, sizeChange: number): void {
695
		const panelPosition = this.partService.getPanelPosition();
696 697 698
		const sizeChangePxWidth = this.workbenchSize.width * (sizeChange / 100);
		const sizeChangePxHeight = this.workbenchSize.height * (sizeChange / 100);

B
Benjamin Pasero 已提交
699
		let doLayout = false;
700 701
		switch (part) {
			case Parts.SIDEBAR_PART:
702
				this.sidebarWidth = this.sidebarWidth + sizeChangePxWidth; // Sidebar can not become smaller than MIN_PART_WIDTH
703

704 705
				if (this.workbenchSize.width - this.sidebarWidth < this.parts.editor.minimumWidth) {
					this.sidebarWidth = this.workbenchSize.width - this.parts.editor.minimumWidth;
706 707 708 709 710
				}

				doLayout = true;
				break;
			case Parts.PANEL_PART:
711 712 713 714 715 716
				if (panelPosition === Position.BOTTOM) {
					this.panelHeight = this.panelHeight + sizeChangePxHeight;
				} else if (panelPosition === Position.RIGHT) {
					this.panelWidth = this.panelWidth + sizeChangePxWidth;
				}

717 718 719 720
				doLayout = true;
				break;
			case Parts.EDITOR_PART:
				// If we have one editor we can cheat and resize sidebar with the negative delta
721
				// If the sidebar is not visible and panel is, resize panel main axis with negative Delta
722
				if (this.editorGroupService.count === 1) {
C
cleidigh 已提交
723
					if (this.partService.isVisible(Parts.SIDEBAR_PART)) {
724 725
						this.sidebarWidth = this.sidebarWidth - sizeChangePxWidth;
						doLayout = true;
C
cleidigh 已提交
726
					} else if (this.partService.isVisible(Parts.PANEL_PART)) {
727 728 729 730 731 732 733
						if (panelPosition === Position.BOTTOM) {
							this.panelHeight = this.panelHeight - sizeChangePxHeight;
						} else if (panelPosition === Position.RIGHT) {
							this.panelWidth = this.panelWidth - sizeChangePxWidth;
						}
						doLayout = true;
					}
B
Benjamin Pasero 已提交
734
				} else {
735
					const activeGroup = this.editorGroupService.activeGroup;
736

737 738
					const activeGroupSize = this.editorGroupService.getSize(activeGroup);
					this.editorGroupService.setSize(activeGroup, activeGroupSize + sizeChangePxWidth);
739 740 741 742
				}
		}

		if (doLayout) {
B
Benjamin Pasero 已提交
743
			this.layout();
744 745
		}
	}
746
}