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

7 8
import { TPromise } from 'vs/base/common/winjs.base';
import * as errors from 'vs/base/common/errors';
J
Johannes Rieken 已提交
9
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
C
Christof Marti 已提交
10
import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickInput';
J
Johannes Rieken 已提交
11
import { Sash, ISashEvent, IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider, Orientation } from 'vs/base/browser/ui/sash/sash';
12
import { IPartService, Position, ILayoutOptions, Parts } from 'vs/workbench/services/part/common/partService';
B
Benjamin Pasero 已提交
13
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
J
Johannes Rieken 已提交
14 15
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
16
import { Disposable } from 'vs/base/common/lifecycle';
17
import { getZoomFactor } from 'vs/base/browser/browser';
18
import { IThemeService } from 'vs/platform/theme/common/themeService';
19
import { memoize } from 'vs/base/common/decorators';
20
import { NotificationsCenter } from 'vs/workbench/browser/parts/notifications/notificationsCenter';
21
import { NotificationsToasts } from 'vs/workbench/browser/parts/notifications/notificationsToasts';
22
import { Dimension, getClientArea, size, position, hide, show } from 'vs/base/browser/dom';
23
import { INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService';
24 25 26 27 28 29 30 31 32 33
import { NextEditorPart } from 'vs/workbench/browser/parts/editor2/nextEditorPart';
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';

const TITLE_BAR_HEIGHT = 22;
const STATUS_BAR_HEIGHT = 22;
const ACTIVITY_BAR_WIDTH = 50;
E
Erich Gamma 已提交
34

35
const MIN_SIDEBAR_PART_WIDTH = 170;
36
const DEFAULT_SIDEBAR_PART_WIDTH = 300;
37 38
const HIDE_SIDEBAR_WIDTH_THRESHOLD = 50;

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

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

52 53 54 55
	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 已提交
56 57

	private workbenchSize: Dimension;
58

59 60
	private sashXOne: Sash;
	private sashXTwo: Sash;
I
isidor 已提交
61
	private sashY: Sash;
62

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

I
isidor 已提交
72
	// Take parts as an object bag since instatation service does not have typings for constructors with 9+ arguments
E
Erich Gamma 已提交
73
	constructor(
74 75 76 77 78 79 80 81 82
		private parent: HTMLElement,
		private workbenchContainer: HTMLElement,
		private parts: {
			titlebar: TitlebarPart,
			activitybar: ActivitybarPart,
			editor: NextEditorPart,
			sidebar: SidebarPart,
			panel: PanelPart,
			statusbar: StatusbarPart
I
isidor 已提交
83
		},
84 85 86 87
		private quickopen: QuickOpenController,
		private quickInput: QuickInputService,
		private notificationsCenter: NotificationsCenter,
		private notificationsToasts: NotificationsToasts,
E
Erich Gamma 已提交
88 89
		@IStorageService private storageService: IStorageService,
		@IContextViewService private contextViewService: IContextViewService,
M
Martin Aeschlimann 已提交
90
		@IPartService private partService: IPartService,
M
Maxime Quandalle 已提交
91
		@IViewletService private viewletService: IViewletService,
92
		@IThemeService private themeService: IThemeService,
93
		@INextEditorGroupsService private nextEditorGroupsService: INextEditorGroupsService
E
Erich Gamma 已提交
94
	) {
95
		super();
96

97 98
		// Restore state
		this.restorePreviousState();
99

100 101 102 103
		// Create layout sashes
		this.sashXOne = new Sash(this.workbenchContainer, this, { baseSize: 5 });
		this.sashXTwo = new Sash(this.workbenchContainer, this, { baseSize: 5 });
		this.sashY = new Sash(this.workbenchContainer, this, { baseSize: 4, orientation: Orientation.HORIZONTAL });
104

105 106
		this.registerListeners();
	}
E
Erich Gamma 已提交
107

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

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

114 115 116
		this.panelMaximized = false;
		this.panelSizeBeforeMaximized = this.storageService.getInteger(WorkbenchLayout.panelSizeBeforeMaximizedKey, StorageScope.GLOBAL, 0);
	}
117

118 119
	private registerListeners(): void {
		this._register(this.themeService.onThemeChange(_ => this.layout()));
120
		this._register(this.parts.editor.onDidPreferredSizeChange(() => this.onDidPreferredSizeChange()));
M
Martin Aeschlimann 已提交
121

E
Erich Gamma 已提交
122 123 124
		this.registerSashListeners();
	}

125
	private onDidPreferredSizeChange(): void {
126 127
		if (this.workbenchSize && (this.sidebarWidth || this.panelHeight)) {
			if (this.nextEditorGroupsService.count > 1) {
128
				const preferredEditorPartSize = this.parts.editor.preferredSize;
129

130
				const sidebarOverflow = this.workbenchSize.width - this.sidebarWidth < preferredEditorPartSize.width;
131

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

				// 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();
				}
			}
		}
146 147
	}

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

		return 0;
	}

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

		return this._panelHeight;
	}

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

	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) {
179 180 181 182 183
		this._panelWidth = Math.min(this.computeMaxPanelWidth(), Math.max(this.partLayoutInfo.panel.minWidth, value));
	}

	private computeMaxPanelWidth(): number {
		const minSidebarSize = this.partService.isVisible(Parts.SIDEBAR_PART) ? (this.partService.getSideBarPosition() === Position.LEFT ? this.partLayoutInfo.sidebar.minWidth : this.sidebarWidth) : 0;
184 185
		const preferredEditorPartSize = this.parts.editor.preferredSize;
		return Math.max(this.partLayoutInfo.panel.minWidth, this.workbenchSize.width - preferredEditorPartSize.width - minSidebarSize - this.activitybarWidth);
186 187 188
	}

	private computeMaxPanelHeight(): number {
189 190
		const preferredEditorPartSize = this.parts.editor.preferredSize;
		return Math.max(this.partLayoutInfo.panel.minHeight, this.sidebarHeight - preferredEditorPartSize.height);
191 192 193 194 195 196 197 198 199 200 201
	}

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

		return 0;
	}

	private set sidebarWidth(value: number) {
202
		const preferredEditorPartSize = this.parts.editor.preferredSize;
203
		const panelMinWidth = this.partService.getPanelPosition() === Position.RIGHT && this.partService.isVisible(Parts.PANEL_PART) ? this.partLayoutInfo.panel.minWidth : 0;
204
		const maxSidebarWidth = this.workbenchSize.width - this.activitybarWidth - preferredEditorPartSize.width - panelMinWidth;
205

I
isidor 已提交
206
		this._sidebarWidth = Math.max(this.partLayoutInfo.sidebar.minWidth, Math.min(maxSidebarWidth, value));
207 208
	}

209
	@memoize
210
	private get partLayoutInfo() {
211 212 213 214 215 216 217 218 219 220 221
		return {
			titlebar: {
				height: TITLE_BAR_HEIGHT
			},
			activitybar: {
				width: ACTIVITY_BAR_WIDTH
			},
			sidebar: {
				minWidth: MIN_SIDEBAR_PART_WIDTH
			},
			panel: {
I
isidor 已提交
222 223
				minHeight: MIN_PANEL_PART_HEIGHT,
				minWidth: MIN_PANEL_PART_WIDTH
224 225 226 227 228 229 230
			},
			statusbar: {
				height: STATUS_BAR_HEIGHT
			}
		};
	}

E
Erich Gamma 已提交
231 232
	private registerSashListeners(): void {
		let startX: number = 0;
I
isidor 已提交
233
		let startY: number = 0;
234
		let startXTwo: number = 0;
235 236 237
		let startSidebarWidth: number;
		let startPanelHeight: number;
		let startPanelWidth: number;
E
Erich Gamma 已提交
238

239
		this._register(this.sashXOne.onDidStart((e: ISashEvent) => {
240
			startSidebarWidth = this.sidebarWidth;
E
Erich Gamma 已提交
241
			startX = e.startX;
242
		}));
E
Erich Gamma 已提交
243

244
		this._register(this.sashY.onDidStart((e: ISashEvent) => {
245
			startPanelHeight = this.panelHeight;
I
isidor 已提交
246
			startY = e.startY;
247 248
		}));

249
		this._register(this.sashXTwo.onDidStart((e: ISashEvent) => {
250
			startPanelWidth = this.panelWidth;
251
			startXTwo = e.startX;
252
		}));
I
isidor 已提交
253

254
		this._register(this.sashXOne.onDidChange((e: ISashEvent) => {
E
Erich Gamma 已提交
255 256
			let doLayout = false;
			let sidebarPosition = this.partService.getSideBarPosition();
257
			let isSidebarVisible = this.partService.isVisible(Parts.SIDEBAR_PART);
258
			let newSashWidth = (sidebarPosition === Position.LEFT) ? startSidebarWidth + e.currentX - startX : startSidebarWidth - e.currentX + startX;
259
			let promise = TPromise.wrap<void>(null);
E
Erich Gamma 已提交
260 261

			// Sidebar visible
262
			if (isSidebarVisible) {
E
Erich Gamma 已提交
263 264

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

				// Otherwise size the sidebar accordingly
				else {
274 275
					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 已提交
276 277 278 279 280
				}
			}

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

			if (doLayout) {
290
				promise.done(() => this.layout({ source: Parts.SIDEBAR_PART }), errors.onUnexpectedError);
E
Erich Gamma 已提交
291
			}
292
		}));
E
Erich Gamma 已提交
293

294
		this._register(this.sashY.onDidChange((e: ISashEvent) => {
I
isidor 已提交
295
			let doLayout = false;
296
			let isPanelVisible = this.partService.isVisible(Parts.PANEL_PART);
297
			let newSashHeight = startPanelHeight - (e.currentY - startY);
298
			let promise = TPromise.wrap<void>(null);
I
isidor 已提交
299 300

			// Panel visible
301
			if (isPanelVisible) {
302

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

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

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

I
isidor 已提交
327
			if (doLayout) {
328
				promise.done(() => this.layout({ source: Parts.PANEL_PART }), errors.onUnexpectedError);
I
isidor 已提交
329
			}
330
		}));
I
isidor 已提交
331

332
		this._register(this.sashXTwo.onDidChange((e: ISashEvent) => {
333 334 335
			let doLayout = false;
			let isPanelVisible = this.partService.isVisible(Parts.PANEL_PART);
			let newSashWidth = startPanelWidth - (e.currentX - startXTwo);
336
			let promise = TPromise.wrap<void>(null);
337 338 339 340 341 342

			// Panel visible
			if (isPanelVisible) {

				// Automatically hide panel when a certain threshold is met
				if (newSashWidth + HIDE_PANEL_WIDTH_THRESHOLD < this.partLayoutInfo.panel.minWidth) {
343
					let dragCompensation = this.partLayoutInfo.panel.minWidth - HIDE_PANEL_WIDTH_THRESHOLD;
344 345 346 347 348 349 350
					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 {
351
					this.panelWidth = newSashWidth;
352 353 354 355 356 357 358 359 360 361 362 363 364 365
					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) {
366
				promise.done(() => this.layout({ source: Parts.PANEL_PART }), errors.onUnexpectedError);
367
			}
368
		}));
M
Maxime Quandalle 已提交
369

370
		this._register(this.sashXOne.onDidEnd(() => {
371 372 373
			this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
		}));

374
		this._register(this.sashY.onDidEnd(() => {
I
isidor 已提交
375
			this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
376 377
		}));

378
		this._register(this.sashXTwo.onDidEnd(() => {
379 380
			this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
		}));
M
Maxime Quandalle 已提交
381

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

388
		this._register(this.sashXOne.onDidReset(() => {
M
Maxime Quandalle 已提交
389 390
			let activeViewlet = this.viewletService.getActiveViewlet();
			let optimalWidth = activeViewlet && activeViewlet.getOptimalWidth();
391
			this.sidebarWidth = Math.max(optimalWidth, DEFAULT_SIDEBAR_PART_WIDTH);
392
			this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
393
			this.partService.setSideBarHidden(false).done(() => this.layout(), errors.onUnexpectedError);
394 395
		}));

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

403
	layout(options?: ILayoutOptions): void {
404
		this.workbenchSize = getClientArea(this.parent);
E
Erich Gamma 已提交
405

406
		const isActivityBarHidden = !this.partService.isVisible(Parts.ACTIVITYBAR_PART);
407 408 409 410
		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 已提交
411
		const sidebarPosition = this.partService.getSideBarPosition();
412
		const panelPosition = this.partService.getPanelPosition();
E
Erich Gamma 已提交
413 414

		// Sidebar
I
isidor 已提交
415
		if (this.sidebarWidth === -1) {
416
			this.sidebarWidth = this.workbenchSize.width / 5;
E
Erich Gamma 已提交
417
		}
B
Benjamin Pasero 已提交
418

419 420
		this.statusbarHeight = isStatusbarHidden ? 0 : this.partLayoutInfo.statusbar.height;
		this.titlebarHeight = isTitlebarHidden ? 0 : this.partLayoutInfo.titlebar.height / getZoomFactor(); // adjust for zoom prevention
E
Erich Gamma 已提交
421

422
		this.sidebarHeight = this.workbenchSize.height - this.statusbarHeight - this.titlebarHeight;
423
		let sidebarSize = new Dimension(this.sidebarWidth, this.sidebarHeight);
E
Erich Gamma 已提交
424 425

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

I
isidor 已提交
428 429
		// Panel part
		let panelHeight: number;
I
isidor 已提交
430
		let panelWidth: number;
431 432
		const maxPanelHeight = this.computeMaxPanelHeight();
		const maxPanelWidth = this.computeMaxPanelWidth();
I
isidor 已提交
433

I
isidor 已提交
434
		if (isPanelHidden) {
I
isidor 已提交
435
			panelHeight = 0;
I
isidor 已提交
436 437
			panelWidth = 0;
		} else if (panelPosition === Position.BOTTOM) {
438
			if (this.panelHeight > 0) {
I
isidor 已提交
439 440 441 442 443
				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;
444 445 446 447 448 449 450 451 452

			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 已提交
453
		} else {
I
isidor 已提交
454 455 456 457 458 459
			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;
			}
460 461 462 463 464 465 466 467 468

			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 已提交
469
		}
470
		this.storageService.store(WorkbenchLayout.panelSizeBeforeMaximizedKey, this.panelSizeBeforeMaximized, StorageScope.GLOBAL);
I
isidor 已提交
471
		const panelDimension = new Dimension(panelWidth, panelHeight);
I
isidor 已提交
472

E
Erich Gamma 已提交
473 474 475
		// Editor
		let editorSize = {
			width: 0,
I
isidor 已提交
476
			height: 0
E
Erich Gamma 已提交
477 478
		};

I
isidor 已提交
479 480
		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 已提交
481 482

		// Assert Sidebar and Editor Size to not overflow
483 484 485 486
		const preferredEditorPartSize = this.parts.editor.preferredSize;
		if (editorSize.width < preferredEditorPartSize.width) {
			let diff = preferredEditorPartSize.width - editorSize.width;
			editorSize.width = preferredEditorPartSize.width;
487
			if (panelPosition === Position.BOTTOM) {
488
				panelDimension.width = preferredEditorPartSize.width;
489
			} else if (panelDimension.width >= diff && (!options || options.source !== Parts.PANEL_PART)) {
I
isidor 已提交
490
				const oldWidth = panelDimension.width;
491
				panelDimension.width = Math.max(this.partLayoutInfo.panel.minWidth, panelDimension.width - diff);
I
isidor 已提交
492
				diff = diff - (oldWidth - panelDimension.width);
493 494
			}

I
isidor 已提交
495 496
			if (sidebarSize.width >= diff) {
				sidebarSize.width -= diff;
497
				sidebarSize.width = Math.max(this.partLayoutInfo.sidebar.minWidth, sidebarSize.width);
I
isidor 已提交
498
			}
499 500
		}

501 502 503
		if (editorSize.height < preferredEditorPartSize.height && panelPosition === Position.BOTTOM) {
			let diff = preferredEditorPartSize.height - editorSize.height;
			editorSize.height = preferredEditorPartSize.height;
504 505

			panelDimension.height -= diff;
506
			panelDimension.height = Math.max(this.partLayoutInfo.panel.minHeight, panelDimension.height);
507
		}
E
Erich Gamma 已提交
508 509 510

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

I
isidor 已提交
514
		if (!isPanelHidden) {
515 516 517 518 519 520 521
			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 已提交
522 523
		}

E
Erich Gamma 已提交
524
		// Workbench
525 526
		position(this.workbenchContainer, 0, 0, 0, 0, 'relative');
		size(this.workbenchContainer, this.workbenchSize.width, this.workbenchSize.height);
E
Erich Gamma 已提交
527

B
Benjamin Pasero 已提交
528
		// Bug on Chrome: Sometimes Chrome wants to scroll the workbench container on layout changes. The fix is to reset scrolling in this case.
529
		const workbenchContainer = this.workbenchContainer;
B
Benjamin Pasero 已提交
530 531 532 533 534
		if (workbenchContainer.scrollTop > 0) {
			workbenchContainer.scrollTop = 0;
		}
		if (workbenchContainer.scrollLeft > 0) {
			workbenchContainer.scrollLeft = 0;
E
Erich Gamma 已提交
535 536
		}

537
		// Title Part
538
		const titleContainer = this.parts.titlebar.getContainer();
539
		if (isTitlebarHidden) {
540
			hide(titleContainer);
541
		} else {
542
			show(titleContainer);
543 544
		}

I
isidor 已提交
545
		// Editor Part and Panel part
546 547
		const editorContainer = this.parts.editor.getContainer();
		const panelContainer = this.parts.panel.getContainer();
548 549
		size(editorContainer, editorSize.width, editorSize.height);
		size(panelContainer, panelDimension.width, panelDimension.height);
E
Erich Gamma 已提交
550

I
isidor 已提交
551 552
		if (panelPosition === Position.BOTTOM) {
			if (sidebarPosition === Position.LEFT) {
553 554
				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 已提交
555
			} else {
556 557
				position(editorContainer, this.titlebarHeight, sidebarSize.width, this.statusbarHeight + panelDimension.height, 0);
				position(panelContainer, editorSize.height + this.titlebarHeight, sidebarSize.width, this.statusbarHeight, 0);
I
isidor 已提交
558
			}
E
Erich Gamma 已提交
559
		} else {
I
isidor 已提交
560
			if (sidebarPosition === Position.LEFT) {
561 562
				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 已提交
563
			} else {
564 565
				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 已提交
566
			}
E
Erich Gamma 已提交
567 568 569
		}

		// Activity Bar Part
570
		const activitybarContainer = this.parts.activitybar.getContainer();
571
		size(activitybarContainer, null, activityBarSize.height);
E
Erich Gamma 已提交
572
		if (sidebarPosition === Position.LEFT) {
573
			this.parts.activitybar.getContainer().style.right = '';
574
			position(activitybarContainer, this.titlebarHeight, null, 0, 0);
E
Erich Gamma 已提交
575
		} else {
576
			this.parts.activitybar.getContainer().style.left = '';
577
			position(activitybarContainer, this.titlebarHeight, 0, 0, null);
E
Erich Gamma 已提交
578
		}
B
Benjamin Pasero 已提交
579
		if (isActivityBarHidden) {
580
			hide(activitybarContainer);
B
Benjamin Pasero 已提交
581
		} else {
582
			show(activitybarContainer);
B
Benjamin Pasero 已提交
583
		}
E
Erich Gamma 已提交
584 585

		// Sidebar Part
586
		const sidebarContainer = this.parts.sidebar.getContainer();
587
		size(sidebarContainer, sidebarSize.width, sidebarSize.height);
588
		const editorAndPanelWidth = editorSize.width + (panelPosition === Position.RIGHT ? panelWidth : 0);
E
Erich Gamma 已提交
589
		if (sidebarPosition === Position.LEFT) {
590
			position(sidebarContainer, this.titlebarHeight, editorAndPanelWidth, this.statusbarHeight, activityBarSize.width);
E
Erich Gamma 已提交
591
		} else {
592
			position(sidebarContainer, this.titlebarHeight, activityBarSize.width, this.statusbarHeight, editorAndPanelWidth);
E
Erich Gamma 已提交
593 594 595
		}

		// Statusbar Part
596
		const statusbarContainer = this.parts.statusbar.getContainer();
597
		position(statusbarContainer, this.workbenchSize.height - this.statusbarHeight);
598
		if (isStatusbarHidden) {
599
			hide(statusbarContainer);
600
		} else {
601
			show(statusbarContainer);
602
		}
E
Erich Gamma 已提交
603 604 605 606

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

C
Christof Marti 已提交
607 608 609
		// Quick input
		this.quickInput.layout(this.workbenchSize);

610 611
		// Notifications
		this.notificationsCenter.layout(this.workbenchSize);
612
		this.notificationsToasts.layout(this.workbenchSize);
613

I
isidor 已提交
614
		// Sashes
615 616 617
		this.sashXOne.layout();
		if (panelPosition === Position.BOTTOM) {
			this.sashXTwo.hide();
618 619
			this.sashY.layout();
			this.sashY.show();
620 621 622
		} else {
			this.sashY.hide();
			this.sashXTwo.layout();
623
			this.sashXTwo.show();
624
		}
E
Erich Gamma 已提交
625 626

		// Propagate to Part Layouts
627 628 629 630 631
		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 已提交
632 633

		// Propagate to Context View
B
Benjamin Pasero 已提交
634
		this.contextViewService.layout();
E
Erich Gamma 已提交
635 636
	}

637
	getVerticalSashTop(sash: Sash): number {
638
		return this.titlebarHeight;
E
Erich Gamma 已提交
639 640
	}

641
	getVerticalSashLeft(sash: Sash): number {
E
Erich Gamma 已提交
642
		let sidebarPosition = this.partService.getSideBarPosition();
643
		if (sash === this.sashXOne) {
E
Erich Gamma 已提交
644

645
			if (sidebarPosition === Position.LEFT) {
646
				return this.sidebarWidth + this.activitybarWidth;
647 648
			}

649
			return this.workbenchSize.width - this.sidebarWidth - this.activitybarWidth;
E
Erich Gamma 已提交
650 651
		}

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

655
	getVerticalSashHeight(sash: Sash): number {
656 657 658 659
		if (sash === this.sashXTwo && !this.partService.isVisible(Parts.PANEL_PART)) {
			return 0;
		}

I
isidor 已提交
660
		return this.sidebarHeight;
E
Erich Gamma 已提交
661 662
	}

663 664 665
	getHorizontalSashTop(sash: Sash): number {
		const offset = 2; // Horizontal sash should be a bit lower than the editor area, thus add 2px #5524
		return offset + (this.partService.isVisible(Parts.PANEL_PART) ? this.sidebarHeight - this.panelHeight + this.titlebarHeight : this.sidebarHeight + this.titlebarHeight);
I
isidor 已提交
666 667
	}

668
	getHorizontalSashLeft(sash: Sash): number {
669 670 671 672 673
		if (this.partService.getSideBarPosition() === Position.RIGHT) {
			return 0;
		}

		return this.sidebarWidth + this.activitybarWidth;
I
isidor 已提交
674 675
	}

676
	getHorizontalSashWidth(sash: Sash): number {
I
isidor 已提交
677
		return this.panelWidth;
I
isidor 已提交
678 679
	}

680
	isPanelMaximized(): boolean {
681 682 683
		return this.panelMaximized;
	}

684
	// change part size along the main axis
685
	resizePart(part: Parts, sizeChange: number): void {
686
		const panelPosition = this.partService.getPanelPosition();
687 688 689
		const sizeChangePxWidth = this.workbenchSize.width * (sizeChange / 100);
		const sizeChangePxHeight = this.workbenchSize.height * (sizeChange / 100);

B
Benjamin Pasero 已提交
690 691
		let doLayout = false;

692

693 694
		switch (part) {
			case Parts.SIDEBAR_PART:
695
				this.sidebarWidth = this.sidebarWidth + sizeChangePxWidth; // Sidebar can not become smaller than MIN_PART_WIDTH
696

697 698 699
				const preferredEditorPartSize = this.parts.editor.preferredSize;
				if (this.workbenchSize.width - this.sidebarWidth < preferredEditorPartSize.width) {
					this.sidebarWidth = this.workbenchSize.width - preferredEditorPartSize.width;
700 701 702 703 704
				}

				doLayout = true;
				break;
			case Parts.PANEL_PART:
705 706 707 708 709 710
				if (panelPosition === Position.BOTTOM) {
					this.panelHeight = this.panelHeight + sizeChangePxHeight;
				} else if (panelPosition === Position.RIGHT) {
					this.panelWidth = this.panelWidth + sizeChangePxWidth;
				}

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

731
					this.nextEditorGroupsService.resizeGroup(activeGroup, sizeChangePxWidth);
732 733 734 735 736
					doLayout = false;
				}
		}

		if (doLayout) {
B
Benjamin Pasero 已提交
737
			this.layout();
738 739
		}
	}
740
}