layout.ts 21.5 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
import { Dimension, Builder } from 'vs/base/browser/builder';
8 9
import { TPromise } from 'vs/base/common/winjs.base';
import * as errors from 'vs/base/common/errors';
J
Johannes Rieken 已提交
10 11 12 13
import { Part } from 'vs/workbench/browser/part';
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
import { Sash, ISashEvent, IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider, Orientation } from 'vs/base/browser/ui/sash/sash';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
14
import { IPartService, Position, ILayoutOptions, Parts } from 'vs/workbench/services/part/common/partService';
B
Benjamin Pasero 已提交
15
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
J
Johannes Rieken 已提交
16 17
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
18
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/themeService';
J
Johannes Rieken 已提交
19 20
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
21
import { getZoomFactor } from 'vs/base/browser/browser';
E
Erich Gamma 已提交
22

23 24 25 26
const MIN_SIDEBAR_PART_WIDTH = 170;
const MIN_EDITOR_PART_HEIGHT = 70;
const MIN_EDITOR_PART_WIDTH = 220;
const MIN_PANEL_PART_HEIGHT = 77;
I
isidor 已提交
27
const DEFAULT_PANEL_HEIGHT_COEFFICIENT = 0.4;
E
Erich Gamma 已提交
28
const HIDE_SIDEBAR_WIDTH_THRESHOLD = 50;
I
isidor 已提交
29
const HIDE_PANEL_HEIGHT_THRESHOLD = 50;
30 31 32
const TITLE_BAR_HEIGHT = 22;
const STATUS_BAR_HEIGHT = 22;
const ACTIVITY_BAR_WIDTH = 50;
E
Erich Gamma 已提交
33

34
interface PartLayoutInfo {
35 36
	titlebar: { height: number; };
	activitybar: { width: number; };
E
Erich Gamma 已提交
37
	sidebar: { minWidth: number; };
B
Benjamin Pasero 已提交
38
	panel: { minHeight: number; };
39
	editor: { minWidth: number; minHeight: number; };
E
Erich Gamma 已提交
40 41 42 43
	statusbar: { height: number; };
}

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

I
isidor 已提交
48
	private static sashXWidthSettingsKey = 'workbench.sidebar.width';
I
isidor 已提交
49
	private static sashYHeightSettingsKey = 'workbench.panel.height';
E
Erich Gamma 已提交
50 51 52

	private parent: Builder;
	private workbenchContainer: Builder;
53
	private titlebar: Part;
E
Erich Gamma 已提交
54 55 56
	private activitybar: Part;
	private editor: Part;
	private sidebar: Part;
B
Benjamin Pasero 已提交
57
	private panel: Part;
E
Erich Gamma 已提交
58 59
	private statusbar: Part;
	private quickopen: QuickOpenController;
M
Martin Aeschlimann 已提交
60
	private toUnbind: IDisposable[];
61
	private partLayoutInfo: PartLayoutInfo;
E
Erich Gamma 已提交
62
	private workbenchSize: Dimension;
I
isidor 已提交
63 64
	private sashX: Sash;
	private sashY: Sash;
E
Erich Gamma 已提交
65 66
	private startSidebarWidth: number;
	private sidebarWidth: number;
I
isidor 已提交
67
	private sidebarHeight: number;
68 69 70
	private titlebarHeight: number;
	private activitybarWidth: number;
	private statusbarHeight: number;
I
isidor 已提交
71 72
	private startPanelHeight: number;
	private panelHeight: number;
73
	private panelHeightBeforeMaximized: number;
I
isidor 已提交
74
	private panelMaximized: boolean;
I
isidor 已提交
75
	private panelWidth: number;
76
	private layoutEditorGroupsVertically: boolean;
E
Erich Gamma 已提交
77

I
isidor 已提交
78
	// Take parts as an object bag since instatation service does not have typings for constructors with 9+ arguments
E
Erich Gamma 已提交
79 80 81
	constructor(
		parent: Builder,
		workbenchContainer: Builder,
I
isidor 已提交
82
		parts: {
83
			titlebar: Part,
I
isidor 已提交
84 85 86 87 88 89
			activitybar: Part,
			editor: Part,
			sidebar: Part,
			panel: Part,
			statusbar: Part
		},
E
Erich Gamma 已提交
90 91 92 93
		quickopen: QuickOpenController,
		@IStorageService private storageService: IStorageService,
		@IContextViewService private contextViewService: IContextViewService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
94
		@IEditorGroupService private editorGroupService: IEditorGroupService,
M
Martin Aeschlimann 已提交
95
		@IPartService private partService: IPartService,
M
Maxime Quandalle 已提交
96
		@IViewletService private viewletService: IViewletService,
97
		@IWorkbenchThemeService themeService: IWorkbenchThemeService
E
Erich Gamma 已提交
98 99 100
	) {
		this.parent = parent;
		this.workbenchContainer = workbenchContainer;
101
		this.titlebar = parts.titlebar;
I
isidor 已提交
102 103 104
		this.activitybar = parts.activitybar;
		this.editor = parts.editor;
		this.sidebar = parts.sidebar;
B
Benjamin Pasero 已提交
105
		this.panel = parts.panel;
I
isidor 已提交
106
		this.statusbar = parts.statusbar;
E
Erich Gamma 已提交
107 108
		this.quickopen = quickopen;
		this.toUnbind = [];
109
		this.partLayoutInfo = this.getPartLayoutInfo();
I
isidor 已提交
110
		this.panelHeightBeforeMaximized = 0;
I
isidor 已提交
111
		this.panelMaximized = false;
112

I
isidor 已提交
113
		this.sashX = new Sash(this.workbenchContainer.getHTMLElement(), this, {
E
Erich Gamma 已提交
114 115
			baseSize: 5
		});
116

I
isidor 已提交
117
		this.sashY = new Sash(this.workbenchContainer.getHTMLElement(), this, {
I
isidor 已提交
118
			baseSize: 4,
I
isidor 已提交
119 120
			orientation: Orientation.HORIZONTAL
		});
E
Erich Gamma 已提交
121

I
isidor 已提交
122
		this.sidebarWidth = this.storageService.getInteger(WorkbenchLayout.sashXWidthSettingsKey, StorageScope.GLOBAL, -1);
I
isidor 已提交
123
		this.panelHeight = this.storageService.getInteger(WorkbenchLayout.sashYHeightSettingsKey, StorageScope.GLOBAL, 0);
E
Erich Gamma 已提交
124

125
		this.layoutEditorGroupsVertically = (this.editorGroupService.getGroupOrientation() !== 'horizontal');
126

127
		this.toUnbind.push(themeService.onDidColorThemeChange(_ => this.layout()));
128
		this.toUnbind.push(editorGroupService.onEditorsChanged(() => this.onEditorsChanged()));
129
		this.toUnbind.push(editorGroupService.onGroupOrientationChanged(e => this.onGroupOrientationChanged()));
M
Martin Aeschlimann 已提交
130

E
Erich Gamma 已提交
131 132 133
		this.registerSashListeners();
	}

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
	private getPartLayoutInfo(): PartLayoutInfo {
		return {
			titlebar: {
				height: TITLE_BAR_HEIGHT
			},
			activitybar: {
				width: ACTIVITY_BAR_WIDTH
			},
			sidebar: {
				minWidth: MIN_SIDEBAR_PART_WIDTH
			},
			panel: {
				minHeight: MIN_PANEL_PART_HEIGHT
			},
			editor: {
				minWidth: MIN_EDITOR_PART_WIDTH,
				minHeight: MIN_EDITOR_PART_HEIGHT
			},
			statusbar: {
				height: STATUS_BAR_HEIGHT
			}
		};
	}

E
Erich Gamma 已提交
158 159
	private registerSashListeners(): void {
		let startX: number = 0;
I
isidor 已提交
160
		let startY: number = 0;
E
Erich Gamma 已提交
161

A
Alex Dima 已提交
162
		this.sashX.addListener2('start', (e: ISashEvent) => {
E
Erich Gamma 已提交
163 164 165 166
			this.startSidebarWidth = this.sidebarWidth;
			startX = e.startX;
		});

A
Alex Dima 已提交
167
		this.sashY.addListener2('start', (e: ISashEvent) => {
I
isidor 已提交
168
			this.startPanelHeight = this.panelHeight;
I
isidor 已提交
169 170 171
			startY = e.startY;
		});

A
Alex Dima 已提交
172
		this.sashX.addListener2('change', (e: ISashEvent) => {
E
Erich Gamma 已提交
173 174
			let doLayout = false;
			let sidebarPosition = this.partService.getSideBarPosition();
175
			let isSidebarVisible = this.partService.isVisible(Parts.SIDEBAR_PART);
E
Erich Gamma 已提交
176
			let newSashWidth = (sidebarPosition === Position.LEFT) ? this.startSidebarWidth + e.currentX - startX : this.startSidebarWidth - e.currentX + startX;
177
			let promise = TPromise.as(null);
E
Erich Gamma 已提交
178 179

			// Sidebar visible
180
			if (isSidebarVisible) {
E
Erich Gamma 已提交
181 182

				// Automatically hide side bar when a certain threshold is met
183 184
				if (newSashWidth + HIDE_SIDEBAR_WIDTH_THRESHOLD < this.partLayoutInfo.sidebar.minWidth) {
					let dragCompensation = MIN_SIDEBAR_PART_WIDTH - HIDE_SIDEBAR_WIDTH_THRESHOLD;
185
					promise = this.partService.setSideBarHidden(true);
186
					startX = (sidebarPosition === Position.LEFT) ? Math.max(this.activitybarWidth, e.currentX - dragCompensation) : Math.min(e.currentX + dragCompensation, this.workbenchSize.width - this.activitybarWidth);
E
Erich Gamma 已提交
187 188 189 190 191
					this.sidebarWidth = this.startSidebarWidth; // when restoring sidebar, restore to the sidebar width we started from
				}

				// Otherwise size the sidebar accordingly
				else {
192 193
					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 已提交
194 195 196 197 198
				}
			}

			// Sidebar hidden
			else {
199 200 201 202
				if ((sidebarPosition === Position.LEFT && e.currentX - startX >= this.partLayoutInfo.sidebar.minWidth) ||
					(sidebarPosition === Position.RIGHT && startX - e.currentX >= this.partLayoutInfo.sidebar.minWidth)) {
					this.startSidebarWidth = this.partLayoutInfo.sidebar.minWidth - (sidebarPosition === Position.LEFT ? e.currentX - startX : startX - e.currentX);
					this.sidebarWidth = this.partLayoutInfo.sidebar.minWidth;
203
					promise = this.partService.setSideBarHidden(false);
E
Erich Gamma 已提交
204 205 206 207
				}
			}

			if (doLayout) {
208
				promise.done(() => this.layout(), errors.onUnexpectedError);
E
Erich Gamma 已提交
209 210 211
			}
		});

A
Alex Dima 已提交
212
		this.sashY.addListener2('change', (e: ISashEvent) => {
I
isidor 已提交
213
			let doLayout = false;
214
			let isPanelVisible = this.partService.isVisible(Parts.PANEL_PART);
I
isidor 已提交
215
			let newSashHeight = this.startPanelHeight - (e.currentY - startY);
216
			let promise = TPromise.as(null);
I
isidor 已提交
217 218

			// Panel visible
219
			if (isPanelVisible) {
220

221
				// Automatically hide panel when a certain threshold is met
222 223
				if (newSashHeight + HIDE_PANEL_HEIGHT_THRESHOLD < this.partLayoutInfo.panel.minHeight) {
					let dragCompensation = MIN_PANEL_PART_HEIGHT - HIDE_PANEL_HEIGHT_THRESHOLD;
224
					promise = this.partService.setPanelHidden(true);
225
					startY = Math.min(this.sidebarHeight - this.statusbarHeight - this.titlebarHeight, e.currentY + dragCompensation);
M
Maxime Quandalle 已提交
226
					this.panelHeight = this.startPanelHeight; // when restoring panel, restore to the panel height we started from
227 228 229 230
				}

				// Otherwise size the panel accordingly
				else {
231 232
					this.panelHeight = Math.max(this.partLayoutInfo.panel.minHeight, newSashHeight); // Panel can not become smaller than MIN_PART_HEIGHT
					doLayout = newSashHeight >= this.partLayoutInfo.panel.minHeight;
233 234
				}
			}
I
isidor 已提交
235

236 237
			// Panel hidden
			else {
238
				if (startY - e.currentY >= this.partLayoutInfo.panel.minHeight) {
239
					this.startPanelHeight = 0;
240
					this.panelHeight = this.partLayoutInfo.panel.minHeight;
241
					promise = this.partService.setPanelHidden(false);
242
				}
I
isidor 已提交
243
			}
244

I
isidor 已提交
245
			if (doLayout) {
246
				promise.done(() => this.layout(), errors.onUnexpectedError);
I
isidor 已提交
247 248 249
			}
		});

A
Alex Dima 已提交
250
		this.sashX.addListener2('end', () => {
I
isidor 已提交
251 252
			this.storageService.store(WorkbenchLayout.sashXWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
		});
M
Maxime Quandalle 已提交
253

A
Alex Dima 已提交
254
		this.sashY.addListener2('end', () => {
I
isidor 已提交
255
			this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
E
Erich Gamma 已提交
256
		});
M
Maxime Quandalle 已提交
257

A
Alex Dima 已提交
258
		this.sashY.addListener2('reset', () => {
I
isidor 已提交
259
			this.panelHeight = this.sidebarHeight * DEFAULT_PANEL_HEIGHT_COEFFICIENT;
M
Maxime Quandalle 已提交
260
			this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
261
			this.partService.setPanelHidden(false).done(() => this.layout(), errors.onUnexpectedError);
M
Maxime Quandalle 已提交
262 263
		});

A
Alex Dima 已提交
264
		this.sashX.addListener2('reset', () => {
M
Maxime Quandalle 已提交
265 266
			let activeViewlet = this.viewletService.getActiveViewlet();
			let optimalWidth = activeViewlet && activeViewlet.getOptimalWidth();
267
			this.sidebarWidth = Math.max(MIN_SIDEBAR_PART_WIDTH, optimalWidth || 0);
M
Maxime Quandalle 已提交
268
			this.storageService.store(WorkbenchLayout.sashXWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
269
			this.partService.setSideBarHidden(false).done(() => this.layout(), errors.onUnexpectedError);
M
Maxime Quandalle 已提交
270
		});
E
Erich Gamma 已提交
271 272
	}

273
	private onEditorsChanged(): void {
E
Erich Gamma 已提交
274

275
		// Make sure that we layout properly in case we detect that the sidebar or panel is large enought to cause
E
Erich Gamma 已提交
276 277
		// multiple opened editors to go below minimal size. The fix is to trigger a layout for any editor
		// input change that falls into this category.
278
		if (this.workbenchSize && (this.sidebarWidth || this.panelHeight)) {
E
Erich Gamma 已提交
279
			let visibleEditors = this.editorService.getVisibleEditors().length;
280
			if (visibleEditors > 1) {
281 282
				const sidebarOverflow = this.layoutEditorGroupsVertically && (this.workbenchSize.width - this.sidebarWidth < visibleEditors * MIN_EDITOR_PART_WIDTH);
				const panelOverflow = !this.layoutEditorGroupsVertically && (this.workbenchSize.height - this.panelHeight < visibleEditors * MIN_EDITOR_PART_HEIGHT);
283 284 285 286

				if (sidebarOverflow || panelOverflow) {
					this.layout();
				}
E
Erich Gamma 已提交
287 288 289 290
			}
		}
	}

291 292
	private onGroupOrientationChanged(): void {
		const newLayoutEditorGroupsVertically = (this.editorGroupService.getGroupOrientation() !== 'horizontal');
293

294 295
		const doLayout = this.layoutEditorGroupsVertically !== newLayoutEditorGroupsVertically;
		this.layoutEditorGroupsVertically = newLayoutEditorGroupsVertically;
296 297 298 299 300 301

		if (doLayout) {
			this.layout();
		}
	}

B
Benjamin Pasero 已提交
302
	public layout(options?: ILayoutOptions): void {
B
Benjamin Pasero 已提交
303
		this.workbenchSize = this.parent.getClientArea();
E
Erich Gamma 已提交
304

305
		const isActivityBarHidden = !this.partService.isVisible(Parts.ACTIVITYBAR_PART);
306 307 308 309
		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 已提交
310
		const sidebarPosition = this.partService.getSideBarPosition();
E
Erich Gamma 已提交
311 312 313 314 315 316

		// Sidebar
		let sidebarWidth: number;
		if (isSidebarHidden) {
			sidebarWidth = 0;
		} else if (this.sidebarWidth !== -1) {
317
			sidebarWidth = Math.max(this.partLayoutInfo.sidebar.minWidth, this.sidebarWidth);
E
Erich Gamma 已提交
318 319 320 321
		} else {
			sidebarWidth = this.workbenchSize.width / 5;
			this.sidebarWidth = sidebarWidth;
		}
B
Benjamin Pasero 已提交
322

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

326
		const previousMaxPanelHeight = this.sidebarHeight - MIN_EDITOR_PART_HEIGHT;
327
		this.sidebarHeight = this.workbenchSize.height - this.statusbarHeight - this.titlebarHeight;
I
isidor 已提交
328
		let sidebarSize = new Dimension(sidebarWidth, this.sidebarHeight);
E
Erich Gamma 已提交
329 330

		// Activity Bar
331
		this.activitybarWidth = isActivityBarHidden ? 0 : this.partLayoutInfo.activitybar.width;
332
		let activityBarSize = new Dimension(this.activitybarWidth, sidebarSize.height);
E
Erich Gamma 已提交
333

I
isidor 已提交
334 335
		// Panel part
		let panelHeight: number;
336
		const maxPanelHeight = sidebarSize.height - MIN_EDITOR_PART_HEIGHT;
I
isidor 已提交
337
		if (isPanelHidden) {
I
isidor 已提交
338
			panelHeight = 0;
339 340
		} else if (this.panelHeight === previousMaxPanelHeight) {
			panelHeight = maxPanelHeight;
I
isidor 已提交
341
		} else if (this.panelHeight > 0) {
342
			panelHeight = Math.min(maxPanelHeight, Math.max(this.partLayoutInfo.panel.minHeight, this.panelHeight));
I
isidor 已提交
343
		} else {
I
isidor 已提交
344
			panelHeight = sidebarSize.height * DEFAULT_PANEL_HEIGHT_COEFFICIENT;
I
isidor 已提交
345
		}
B
Benjamin Pasero 已提交
346
		if (options && options.toggleMaximizedPanel) {
I
isidor 已提交
347 348 349 350 351 352 353
			panelHeight = this.panelMaximized ? Math.max(this.partLayoutInfo.panel.minHeight, Math.min(this.panelHeightBeforeMaximized, maxPanelHeight)) : maxPanelHeight;
		}
		this.panelMaximized = panelHeight === maxPanelHeight;
		if (panelHeight / maxPanelHeight < 0.7) {
			// Remember the previous height only if the panel size is not too large.
			// To get a nice minimize effect even if a user dragged the panel sash to maximum.
			this.panelHeightBeforeMaximized = panelHeight;
I
isidor 已提交
354
		}
I
isidor 已提交
355
		const panelDimension = new Dimension(this.workbenchSize.width - sidebarSize.width - activityBarSize.width, panelHeight);
I
isidor 已提交
356
		this.panelWidth = panelDimension.width;
I
isidor 已提交
357

E
Erich Gamma 已提交
358 359 360 361 362 363 364 365
		// Editor
		let editorSize = {
			width: 0,
			height: 0,
			remainderLeft: 0,
			remainderRight: 0
		};

366 367
		editorSize.width = panelDimension.width;
		editorSize.height = sidebarSize.height - panelDimension.height;
E
Erich Gamma 已提交
368 369 370

		// Sidebar hidden
		if (isSidebarHidden) {
371
			editorSize.width = Math.min(this.workbenchSize.width - activityBarSize.width, this.workbenchSize.width - this.activitybarWidth);
E
Erich Gamma 已提交
372 373 374 375 376 377 378 379 380 381 382

			if (sidebarPosition === Position.LEFT) {
				editorSize.remainderLeft = Math.round((this.workbenchSize.width - editorSize.width + activityBarSize.width) / 2);
				editorSize.remainderRight = this.workbenchSize.width - editorSize.width - editorSize.remainderLeft;
			} else {
				editorSize.remainderRight = Math.round((this.workbenchSize.width - editorSize.width + activityBarSize.width) / 2);
				editorSize.remainderLeft = this.workbenchSize.width - editorSize.width - editorSize.remainderRight;
			}
		}

		// Assert Sidebar and Editor Size to not overflow
383 384
		let editorMinWidth = this.partLayoutInfo.editor.minWidth;
		let editorMinHeight = this.partLayoutInfo.editor.minHeight;
E
Erich Gamma 已提交
385 386
		let visibleEditorCount = this.editorService.getVisibleEditors().length;
		if (visibleEditorCount > 1) {
387
			if (this.layoutEditorGroupsVertically) {
388 389 390 391
				editorMinWidth *= visibleEditorCount; // when editors layout vertically, multiply the min editor width by number of visible editors
			} else {
				editorMinHeight *= visibleEditorCount; // when editors layout horizontally, multiply the min editor height by number of visible editors
			}
E
Erich Gamma 已提交
392
		}
B
Benjamin Pasero 已提交
393

E
Erich Gamma 已提交
394 395 396
		if (editorSize.width < editorMinWidth) {
			let diff = editorMinWidth - editorSize.width;
			editorSize.width = editorMinWidth;
397
			panelDimension.width = editorMinWidth;
E
Erich Gamma 已提交
398
			sidebarSize.width -= diff;
399
			sidebarSize.width = Math.max(MIN_SIDEBAR_PART_WIDTH, sidebarSize.width);
400 401 402 403 404 405
		}

		if (editorSize.height < editorMinHeight) {
			let diff = editorMinHeight - editorSize.height;
			editorSize.height = editorMinHeight;
			panelDimension.height -= diff;
406
			panelDimension.height = Math.max(MIN_PANEL_PART_HEIGHT, panelDimension.height);
E
Erich Gamma 已提交
407 408 409 410
		}

		if (!isSidebarHidden) {
			this.sidebarWidth = sidebarSize.width;
I
isidor 已提交
411
			this.storageService.store(WorkbenchLayout.sashXWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
E
Erich Gamma 已提交
412 413
		}

I
isidor 已提交
414 415 416
		if (!isPanelHidden) {
			this.panelHeight = panelDimension.height;
			this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
I
isidor 已提交
417 418
		}

E
Erich Gamma 已提交
419 420
		// Workbench
		this.workbenchContainer
421
			.position(0, 0, 0, 0, 'relative')
E
Erich Gamma 已提交
422 423
			.size(this.workbenchSize.width, this.workbenchSize.height);

B
Benjamin Pasero 已提交
424 425 426 427 428 429 430
		// Bug on Chrome: Sometimes Chrome wants to scroll the workbench container on layout changes. The fix is to reset scrolling in this case.
		const workbenchContainer = this.workbenchContainer.getHTMLElement();
		if (workbenchContainer.scrollTop > 0) {
			workbenchContainer.scrollTop = 0;
		}
		if (workbenchContainer.scrollLeft > 0) {
			workbenchContainer.scrollLeft = 0;
E
Erich Gamma 已提交
431 432
		}

433 434 435 436 437 438 439
		// Title Part
		if (isTitlebarHidden) {
			this.titlebar.getContainer().hide();
		} else {
			this.titlebar.getContainer().show();
		}

I
isidor 已提交
440
		// Editor Part and Panel part
E
Erich Gamma 已提交
441
		this.editor.getContainer().size(editorSize.width, editorSize.height);
B
Benjamin Pasero 已提交
442
		this.panel.getContainer().size(panelDimension.width, panelDimension.height);
E
Erich Gamma 已提交
443

444
		const editorBottom = this.statusbarHeight + panelDimension.height;
E
Erich Gamma 已提交
445
		if (isSidebarHidden) {
446 447
			this.editor.getContainer().position(this.titlebarHeight, editorSize.remainderRight, editorBottom, editorSize.remainderLeft);
			this.panel.getContainer().position(editorSize.height + this.titlebarHeight, editorSize.remainderRight, this.statusbarHeight, editorSize.remainderLeft);
E
Erich Gamma 已提交
448
		} else if (sidebarPosition === Position.LEFT) {
449 450
			this.editor.getContainer().position(this.titlebarHeight, 0, editorBottom, sidebarSize.width + activityBarSize.width);
			this.panel.getContainer().position(editorSize.height + this.titlebarHeight, 0, this.statusbarHeight, sidebarSize.width + activityBarSize.width);
E
Erich Gamma 已提交
451
		} else {
452 453
			this.editor.getContainer().position(this.titlebarHeight, sidebarSize.width, editorBottom, 0);
			this.panel.getContainer().position(editorSize.height + this.titlebarHeight, sidebarSize.width, this.statusbarHeight, 0);
E
Erich Gamma 已提交
454 455 456
		}

		// Activity Bar Part
B
Benjamin Pasero 已提交
457
		this.activitybar.getContainer().size(null, activityBarSize.height);
E
Erich Gamma 已提交
458 459
		if (sidebarPosition === Position.LEFT) {
			this.activitybar.getContainer().getHTMLElement().style.right = '';
460
			this.activitybar.getContainer().position(this.titlebarHeight, null, 0, 0);
E
Erich Gamma 已提交
461 462
		} else {
			this.activitybar.getContainer().getHTMLElement().style.left = '';
463
			this.activitybar.getContainer().position(this.titlebarHeight, 0, 0, null);
E
Erich Gamma 已提交
464
		}
B
Benjamin Pasero 已提交
465 466 467 468 469
		if (isActivityBarHidden) {
			this.activitybar.getContainer().hide();
		} else {
			this.activitybar.getContainer().show();
		}
E
Erich Gamma 已提交
470 471 472 473 474

		// Sidebar Part
		this.sidebar.getContainer().size(sidebarSize.width, sidebarSize.height);

		if (sidebarPosition === Position.LEFT) {
475
			this.sidebar.getContainer().position(this.titlebarHeight, editorSize.width, 0, activityBarSize.width);
E
Erich Gamma 已提交
476
		} else {
477
			this.sidebar.getContainer().position(this.titlebarHeight, null, 0, editorSize.width);
E
Erich Gamma 已提交
478 479 480
		}

		// Statusbar Part
481
		this.statusbar.getContainer().position(this.workbenchSize.height - this.statusbarHeight);
482 483 484 485 486
		if (isStatusbarHidden) {
			this.statusbar.getContainer().hide();
		} else {
			this.statusbar.getContainer().show();
		}
E
Erich Gamma 已提交
487 488 489 490

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

I
isidor 已提交
491 492 493
		// Sashes
		this.sashX.layout();
		this.sashY.layout();
E
Erich Gamma 已提交
494 495

		// Propagate to Part Layouts
496
		this.titlebar.layout(new Dimension(this.workbenchSize.width, this.titlebarHeight));
E
Erich Gamma 已提交
497 498
		this.editor.layout(new Dimension(editorSize.width, editorSize.height));
		this.sidebar.layout(sidebarSize);
B
Benjamin Pasero 已提交
499
		this.panel.layout(panelDimension);
500
		this.activitybar.layout(activityBarSize);
E
Erich Gamma 已提交
501 502

		// Propagate to Context View
B
Benjamin Pasero 已提交
503
		this.contextViewService.layout();
E
Erich Gamma 已提交
504 505 506
	}

	public getVerticalSashTop(sash: Sash): number {
507
		return this.titlebarHeight;
E
Erich Gamma 已提交
508 509 510
	}

	public getVerticalSashLeft(sash: Sash): number {
511
		let isSidebarVisible = this.partService.isVisible(Parts.SIDEBAR_PART);
E
Erich Gamma 已提交
512 513 514
		let sidebarPosition = this.partService.getSideBarPosition();

		if (sidebarPosition === Position.LEFT) {
515
			return isSidebarVisible ? this.sidebarWidth + this.activitybarWidth : this.activitybarWidth;
E
Erich Gamma 已提交
516 517
		}

518
		return isSidebarVisible ? this.workbenchSize.width - this.sidebarWidth - this.activitybarWidth : this.workbenchSize.width - this.activitybarWidth;
E
Erich Gamma 已提交
519 520 521
	}

	public getVerticalSashHeight(sash: Sash): number {
I
isidor 已提交
522
		return this.sidebarHeight;
E
Erich Gamma 已提交
523 524
	}

I
isidor 已提交
525
	public getHorizontalSashTop(sash: Sash): number {
526 527
		// Horizontal sash should be a bit lower than the editor area, thus add 2px #5524
		return 2 + (this.partService.isVisible(Parts.PANEL_PART) ? this.sidebarHeight - this.panelHeight + this.titlebarHeight : this.sidebarHeight + this.titlebarHeight);
I
isidor 已提交
528 529 530
	}

	public getHorizontalSashLeft(sash: Sash): number {
531
		return this.partService.getSideBarPosition() === Position.LEFT ? this.getVerticalSashLeft(sash) : 0;
I
isidor 已提交
532 533 534
	}

	public getHorizontalSashWidth(sash: Sash): number {
I
isidor 已提交
535
		return this.panelWidth;
I
isidor 已提交
536 537
	}

I
isidor 已提交
538 539 540 541
	public isPanelMaximized(): boolean {
		return this.panelMaximized;
	}

E
Erich Gamma 已提交
542
	public dispose(): void {
M
Martin Aeschlimann 已提交
543 544 545
		if (this.toUnbind) {
			dispose(this.toUnbind);
			this.toUnbind = null;
E
Erich Gamma 已提交
546 547
		}
	}
B
Benjamin Pasero 已提交
548
}