layout.ts 24.9 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 18 19
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
20
import { getZoomFactor } from 'vs/base/browser/browser';
21
import { IThemeService } from 'vs/platform/theme/common/themeService';
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

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

	private parent: Builder;
	private workbenchContainer: Builder;
54
	private titlebar: Part;
E
Erich Gamma 已提交
55 56 57
	private activitybar: Part;
	private editor: Part;
	private sidebar: Part;
B
Benjamin Pasero 已提交
58
	private panel: Part;
E
Erich Gamma 已提交
59 60
	private statusbar: Part;
	private quickopen: QuickOpenController;
M
Martin Aeschlimann 已提交
61
	private toUnbind: IDisposable[];
62
	private partLayoutInfo: PartLayoutInfo;
E
Erich Gamma 已提交
63
	private workbenchSize: Dimension;
64 65
	private sashXOne: Sash;
	private sashXTwo: Sash;
I
isidor 已提交
66
	private sashY: Sash;
E
Erich Gamma 已提交
67
	private sidebarWidth: number;
I
isidor 已提交
68
	private sidebarHeight: number;
69 70 71
	private titlebarHeight: number;
	private activitybarWidth: number;
	private statusbarHeight: number;
I
isidor 已提交
72
	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
		@IThemeService themeService: IThemeService
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

113 114 115 116 117
		this.sashXOne = new Sash(this.workbenchContainer.getHTMLElement(), this, {
			baseSize: 5
		});

		this.sashXTwo = new Sash(this.workbenchContainer.getHTMLElement(), this, {
E
Erich Gamma 已提交
118 119
			baseSize: 5
		});
120

I
isidor 已提交
121
		this.sashY = new Sash(this.workbenchContainer.getHTMLElement(), this, {
I
isidor 已提交
122
			baseSize: 4,
I
isidor 已提交
123 124
			orientation: Orientation.HORIZONTAL
		});
E
Erich Gamma 已提交
125

126
		this.sidebarWidth = this.storageService.getInteger(WorkbenchLayout.sashXOneWidthSettingsKey, StorageScope.GLOBAL, -1);
I
isidor 已提交
127
		this.panelHeight = this.storageService.getInteger(WorkbenchLayout.sashYHeightSettingsKey, StorageScope.GLOBAL, 0);
128
		this.panelWidth = this.storageService.getInteger(WorkbenchLayout.sashXTwoWidthSettingsKey, StorageScope.GLOBAL, 0);
E
Erich Gamma 已提交
129

130
		this.layoutEditorGroupsVertically = (this.editorGroupService.getGroupOrientation() !== 'horizontal');
131

132
		this.toUnbind.push(themeService.onThemeChange(_ => this.layout()));
133
		this.toUnbind.push(editorGroupService.onEditorsChanged(() => this.onEditorsChanged()));
134
		this.toUnbind.push(editorGroupService.onGroupOrientationChanged(e => this.onGroupOrientationChanged()));
M
Martin Aeschlimann 已提交
135

E
Erich Gamma 已提交
136 137 138
		this.registerSashListeners();
	}

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
	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 已提交
163 164
	private registerSashListeners(): void {
		let startX: number = 0;
I
isidor 已提交
165
		let startY: number = 0;
166 167 168 169
		let startX2: number = 0;
		let startSidebarWidth: number;
		let startPanelHeight: number;
		let startPanelWidth: number;
E
Erich Gamma 已提交
170

171 172
		this.toUnbind.push(this.sashXOne.addListener('start', (e: ISashEvent) => {
			startSidebarWidth = this.sidebarWidth;
E
Erich Gamma 已提交
173
			startX = e.startX;
174
		}));
E
Erich Gamma 已提交
175

176 177
		this.toUnbind.push(this.sashY.addListener('start', (e: ISashEvent) => {
			startPanelHeight = this.panelHeight;
I
isidor 已提交
178
			startY = e.startY;
179 180 181 182 183 184
		}));

		this.toUnbind.push(this.sashXTwo.addListener('start', (e: ISashEvent) => {
			startPanelWidth = this.panelWidth;
			startX2 = e.startX;
		}));
I
isidor 已提交
185

186
		this.toUnbind.push(this.sashXOne.addListener('change', (e: ISashEvent) => {
E
Erich Gamma 已提交
187 188
			let doLayout = false;
			let sidebarPosition = this.partService.getSideBarPosition();
189
			let isSidebarVisible = this.partService.isVisible(Parts.SIDEBAR_PART);
190
			let newSashWidth = (sidebarPosition === Position.LEFT) ? startSidebarWidth + e.currentX - startX : startSidebarWidth - e.currentX + startX;
191
			let promise = TPromise.as<void>(null);
E
Erich Gamma 已提交
192 193

			// Sidebar visible
194
			if (isSidebarVisible) {
E
Erich Gamma 已提交
195 196

				// Automatically hide side bar when a certain threshold is met
197 198
				if (newSashWidth + HIDE_SIDEBAR_WIDTH_THRESHOLD < this.partLayoutInfo.sidebar.minWidth) {
					let dragCompensation = MIN_SIDEBAR_PART_WIDTH - HIDE_SIDEBAR_WIDTH_THRESHOLD;
199
					promise = this.partService.setSideBarHidden(true);
200
					startX = (sidebarPosition === Position.LEFT) ? Math.max(this.activitybarWidth, e.currentX - dragCompensation) : Math.min(e.currentX + dragCompensation, this.workbenchSize.width - this.activitybarWidth);
201
					this.sidebarWidth = startSidebarWidth; // when restoring sidebar, restore to the sidebar width we started from
E
Erich Gamma 已提交
202 203 204 205
				}

				// Otherwise size the sidebar accordingly
				else {
206 207
					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 已提交
208 209 210 211 212
				}
			}

			// Sidebar hidden
			else {
213 214
				if ((sidebarPosition === Position.LEFT && e.currentX - startX >= this.partLayoutInfo.sidebar.minWidth) ||
					(sidebarPosition === Position.RIGHT && startX - e.currentX >= this.partLayoutInfo.sidebar.minWidth)) {
215
					startSidebarWidth = this.partLayoutInfo.sidebar.minWidth - (sidebarPosition === Position.LEFT ? e.currentX - startX : startX - e.currentX);
216
					this.sidebarWidth = this.partLayoutInfo.sidebar.minWidth;
217
					promise = this.partService.setSideBarHidden(false);
E
Erich Gamma 已提交
218 219 220 221
				}
			}

			if (doLayout) {
222
				promise.done(() => this.layout(), errors.onUnexpectedError);
E
Erich Gamma 已提交
223
			}
224
		}));
E
Erich Gamma 已提交
225

226
		this.toUnbind.push(this.sashY.addListener('change', (e: ISashEvent) => {
I
isidor 已提交
227
			let doLayout = false;
228
			let isPanelVisible = this.partService.isVisible(Parts.PANEL_PART);
229
			let newSashHeight = startPanelHeight - (e.currentY - startY);
230
			let promise = TPromise.as<void>(null);
I
isidor 已提交
231 232

			// Panel visible
233
			if (isPanelVisible) {
234

235
				// Automatically hide panel when a certain threshold is met
236 237
				if (newSashHeight + HIDE_PANEL_HEIGHT_THRESHOLD < this.partLayoutInfo.panel.minHeight) {
					let dragCompensation = MIN_PANEL_PART_HEIGHT - HIDE_PANEL_HEIGHT_THRESHOLD;
238
					promise = this.partService.setPanelHidden(true);
239
					startY = Math.min(this.sidebarHeight - this.statusbarHeight - this.titlebarHeight, e.currentY + dragCompensation);
240
					this.panelHeight = startPanelHeight; // when restoring panel, restore to the panel height we started from
241 242 243 244
				}

				// Otherwise size the panel accordingly
				else {
245 246
					this.panelHeight = Math.max(this.partLayoutInfo.panel.minHeight, newSashHeight); // Panel can not become smaller than MIN_PART_HEIGHT
					doLayout = newSashHeight >= this.partLayoutInfo.panel.minHeight;
247 248
				}
			}
I
isidor 已提交
249

250 251
			// Panel hidden
			else {
252
				if (startY - e.currentY >= this.partLayoutInfo.panel.minHeight) {
253
					startPanelHeight = 0;
254
					this.panelHeight = this.partLayoutInfo.panel.minHeight;
255
					promise = this.partService.setPanelHidden(false);
256
				}
I
isidor 已提交
257
			}
258

I
isidor 已提交
259
			if (doLayout) {
260
				promise.done(() => this.layout(), errors.onUnexpectedError);
I
isidor 已提交
261
			}
262
		}));
I
isidor 已提交
263

264 265 266 267
		this.toUnbind.push(this.sashXTwo.addListener('change', (e: ISashEvent) => {
			console.log('change');
			// TODO@Isidor
		}));
M
Maxime Quandalle 已提交
268

269 270 271 272 273
		this.toUnbind.push(this.sashXOne.addListener('end', () => {
			this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
		}));

		this.toUnbind.push(this.sashY.addListener('end', () => {
I
isidor 已提交
274
			this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
275 276 277 278 279
		}));

		this.toUnbind.push(this.sashXTwo.addListener('end', () => {
			this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
		}));
M
Maxime Quandalle 已提交
280

281
		this.toUnbind.push(this.sashY.addListener('reset', () => {
I
isidor 已提交
282
			this.panelHeight = this.sidebarHeight * DEFAULT_PANEL_HEIGHT_COEFFICIENT;
M
Maxime Quandalle 已提交
283
			this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
284 285
			this.layout();
		}));
M
Maxime Quandalle 已提交
286

287
		this.toUnbind.push(this.sashXOne.addListener('reset', () => {
M
Maxime Quandalle 已提交
288 289
			let activeViewlet = this.viewletService.getActiveViewlet();
			let optimalWidth = activeViewlet && activeViewlet.getOptimalWidth();
290
			this.sidebarWidth = Math.max(MIN_SIDEBAR_PART_WIDTH, optimalWidth || 0);
291
			this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
292
			this.partService.setSideBarHidden(false).done(() => this.layout(), errors.onUnexpectedError);
293 294 295 296 297 298 299
		}));

		this.toUnbind.push(this.sashXTwo.addListener('reset', () => {
			this.panelWidth = 0; // TODO@ISIDOR
			this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
			this.layout();
		}));
E
Erich Gamma 已提交
300 301
	}

302
	private onEditorsChanged(): void {
E
Erich Gamma 已提交
303

304
		// Make sure that we layout properly in case we detect that the sidebar or panel is large enought to cause
E
Erich Gamma 已提交
305 306
		// 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.
307
		if (this.workbenchSize && (this.sidebarWidth || this.panelHeight)) {
E
Erich Gamma 已提交
308
			let visibleEditors = this.editorService.getVisibleEditors().length;
309
			if (visibleEditors > 1) {
310 311
				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);
312 313 314 315

				if (sidebarOverflow || panelOverflow) {
					this.layout();
				}
E
Erich Gamma 已提交
316 317 318 319
			}
		}
	}

320 321
	private onGroupOrientationChanged(): void {
		const newLayoutEditorGroupsVertically = (this.editorGroupService.getGroupOrientation() !== 'horizontal');
322

323 324
		const doLayout = this.layoutEditorGroupsVertically !== newLayoutEditorGroupsVertically;
		this.layoutEditorGroupsVertically = newLayoutEditorGroupsVertically;
325 326 327 328 329 330

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

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

334
		const isActivityBarHidden = !this.partService.isVisible(Parts.ACTIVITYBAR_PART);
335 336 337 338
		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 已提交
339
		const sidebarPosition = this.partService.getSideBarPosition();
340
		const panelPosition = this.partService.getPanelPosition();
E
Erich Gamma 已提交
341 342 343 344 345 346

		// Sidebar
		let sidebarWidth: number;
		if (isSidebarHidden) {
			sidebarWidth = 0;
		} else if (this.sidebarWidth !== -1) {
347
			sidebarWidth = Math.max(this.partLayoutInfo.sidebar.minWidth, this.sidebarWidth);
E
Erich Gamma 已提交
348 349 350 351
		} else {
			sidebarWidth = this.workbenchSize.width / 5;
			this.sidebarWidth = sidebarWidth;
		}
B
Benjamin Pasero 已提交
352

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

356
		const previousMaxPanelHeight = this.sidebarHeight - MIN_EDITOR_PART_HEIGHT;
357
		this.sidebarHeight = this.workbenchSize.height - this.statusbarHeight - this.titlebarHeight;
I
isidor 已提交
358
		let sidebarSize = new Dimension(sidebarWidth, this.sidebarHeight);
E
Erich Gamma 已提交
359 360

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

I
isidor 已提交
364 365
		// Panel part
		let panelHeight: number;
I
isidor 已提交
366 367
		const editorCountForHeight = this.editorGroupService.getGroupOrientation() === 'horizontal' ? this.editorGroupService.getStacksModel().groups.length : 1;
		const maxPanelHeight = sidebarSize.height - editorCountForHeight * MIN_EDITOR_PART_HEIGHT;
I
isidor 已提交
368
		if (isPanelHidden) {
I
isidor 已提交
369
			panelHeight = 0;
370 371
		} else if (this.panelHeight === previousMaxPanelHeight) {
			panelHeight = maxPanelHeight;
I
isidor 已提交
372
		} else if (this.panelHeight > 0) {
373
			panelHeight = Math.min(maxPanelHeight, Math.max(this.partLayoutInfo.panel.minHeight, this.panelHeight));
I
isidor 已提交
374
		} else {
I
isidor 已提交
375
			panelHeight = sidebarSize.height * DEFAULT_PANEL_HEIGHT_COEFFICIENT;
I
isidor 已提交
376
		}
B
Benjamin Pasero 已提交
377
		if (options && options.toggleMaximizedPanel) {
I
isidor 已提交
378 379 380 381 382 383 384
			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 已提交
385
		}
I
isidor 已提交
386
		const panelDimension = new Dimension(this.workbenchSize.width - sidebarSize.width - activityBarSize.width, panelHeight);
I
isidor 已提交
387
		this.panelWidth = panelDimension.width;
I
isidor 已提交
388

E
Erich Gamma 已提交
389 390 391 392 393 394 395 396
		// Editor
		let editorSize = {
			width: 0,
			height: 0,
			remainderLeft: 0,
			remainderRight: 0
		};

397 398
		editorSize.width = panelDimension.width;
		editorSize.height = sidebarSize.height - panelDimension.height;
E
Erich Gamma 已提交
399 400 401

		// Sidebar hidden
		if (isSidebarHidden) {
402
			editorSize.width = this.workbenchSize.width - activityBarSize.width;
E
Erich Gamma 已提交
403 404 405 406 407 408 409 410 411 412 413

			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
414 415
		let editorMinWidth = this.partLayoutInfo.editor.minWidth;
		let editorMinHeight = this.partLayoutInfo.editor.minHeight;
E
Erich Gamma 已提交
416 417
		let visibleEditorCount = this.editorService.getVisibleEditors().length;
		if (visibleEditorCount > 1) {
418
			if (this.layoutEditorGroupsVertically) {
419 420 421 422
				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 已提交
423
		}
B
Benjamin Pasero 已提交
424

E
Erich Gamma 已提交
425 426 427
		if (editorSize.width < editorMinWidth) {
			let diff = editorMinWidth - editorSize.width;
			editorSize.width = editorMinWidth;
428
			panelDimension.width = editorMinWidth;
E
Erich Gamma 已提交
429
			sidebarSize.width -= diff;
430
			sidebarSize.width = Math.max(MIN_SIDEBAR_PART_WIDTH, sidebarSize.width);
431 432 433 434 435 436
		}

		if (editorSize.height < editorMinHeight) {
			let diff = editorMinHeight - editorSize.height;
			editorSize.height = editorMinHeight;
			panelDimension.height -= diff;
437
			panelDimension.height = Math.max(MIN_PANEL_PART_HEIGHT, panelDimension.height);
E
Erich Gamma 已提交
438 439 440 441
		}

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

I
isidor 已提交
445 446
		if (!isPanelHidden) {
			this.panelHeight = panelDimension.height;
447
			this.panelWidth = panelDimension.width;
I
isidor 已提交
448
			this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
449
			this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
I
isidor 已提交
450 451
		}

E
Erich Gamma 已提交
452 453
		// Workbench
		this.workbenchContainer
454
			.position(0, 0, 0, 0, 'relative')
E
Erich Gamma 已提交
455 456
			.size(this.workbenchSize.width, this.workbenchSize.height);

B
Benjamin Pasero 已提交
457 458 459 460 461 462 463
		// 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 已提交
464 465
		}

466 467 468 469 470 471 472
		// Title Part
		if (isTitlebarHidden) {
			this.titlebar.getContainer().hide();
		} else {
			this.titlebar.getContainer().show();
		}

I
isidor 已提交
473
		// Editor Part and Panel part
E
Erich Gamma 已提交
474
		this.editor.getContainer().size(editorSize.width, editorSize.height);
B
Benjamin Pasero 已提交
475
		this.panel.getContainer().size(panelDimension.width, panelDimension.height);
E
Erich Gamma 已提交
476

477
		const editorBottom = this.statusbarHeight + panelDimension.height;
E
Erich Gamma 已提交
478
		if (isSidebarHidden) {
479 480
			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 已提交
481
		} else if (sidebarPosition === Position.LEFT) {
482 483
			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 已提交
484
		} else {
485 486
			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 已提交
487 488 489
		}

		// Activity Bar Part
B
Benjamin Pasero 已提交
490
		this.activitybar.getContainer().size(null, activityBarSize.height);
E
Erich Gamma 已提交
491 492
		if (sidebarPosition === Position.LEFT) {
			this.activitybar.getContainer().getHTMLElement().style.right = '';
493
			this.activitybar.getContainer().position(this.titlebarHeight, null, 0, 0);
E
Erich Gamma 已提交
494 495
		} else {
			this.activitybar.getContainer().getHTMLElement().style.left = '';
496
			this.activitybar.getContainer().position(this.titlebarHeight, 0, 0, null);
E
Erich Gamma 已提交
497
		}
B
Benjamin Pasero 已提交
498 499 500 501 502
		if (isActivityBarHidden) {
			this.activitybar.getContainer().hide();
		} else {
			this.activitybar.getContainer().show();
		}
E
Erich Gamma 已提交
503 504 505 506 507

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

		if (sidebarPosition === Position.LEFT) {
508
			this.sidebar.getContainer().position(this.titlebarHeight, editorSize.width, 0, activityBarSize.width);
E
Erich Gamma 已提交
509
		} else {
510
			this.sidebar.getContainer().position(this.titlebarHeight, null, 0, editorSize.width);
E
Erich Gamma 已提交
511 512 513
		}

		// Statusbar Part
514
		this.statusbar.getContainer().position(this.workbenchSize.height - this.statusbarHeight);
515 516 517 518 519
		if (isStatusbarHidden) {
			this.statusbar.getContainer().hide();
		} else {
			this.statusbar.getContainer().show();
		}
E
Erich Gamma 已提交
520 521 522 523

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

I
isidor 已提交
524
		// Sashes
525 526 527 528 529 530 531 532
		this.sashXOne.layout();
		if (panelPosition === Position.BOTTOM) {
			this.sashY.layout();
			this.sashXTwo.hide();
		} else {
			this.sashY.hide();
			this.sashXTwo.layout();
		}
E
Erich Gamma 已提交
533 534

		// Propagate to Part Layouts
535
		this.titlebar.layout(new Dimension(this.workbenchSize.width, this.titlebarHeight));
E
Erich Gamma 已提交
536 537
		this.editor.layout(new Dimension(editorSize.width, editorSize.height));
		this.sidebar.layout(sidebarSize);
B
Benjamin Pasero 已提交
538
		this.panel.layout(panelDimension);
539
		this.activitybar.layout(activityBarSize);
E
Erich Gamma 已提交
540 541

		// Propagate to Context View
B
Benjamin Pasero 已提交
542
		this.contextViewService.layout();
E
Erich Gamma 已提交
543 544 545
	}

	public getVerticalSashTop(sash: Sash): number {
546
		return this.titlebarHeight;
E
Erich Gamma 已提交
547 548 549
	}

	public getVerticalSashLeft(sash: Sash): number {
550
		let isSidebarVisible = this.partService.isVisible(Parts.SIDEBAR_PART);
E
Erich Gamma 已提交
551
		let sidebarPosition = this.partService.getSideBarPosition();
552
		if (sash === this.sashXOne) {
E
Erich Gamma 已提交
553

554 555 556 557 558
			if (sidebarPosition === Position.LEFT) {
				return isSidebarVisible ? this.sidebarWidth + this.activitybarWidth : this.activitybarWidth;
			}

			return isSidebarVisible ? this.workbenchSize.width - this.sidebarWidth - this.activitybarWidth : this.workbenchSize.width - this.activitybarWidth;
E
Erich Gamma 已提交
559 560
		}

561
		return this.workbenchSize.width - this.panelWidth - (sidebarPosition === Position.RIGHT && isSidebarVisible ? this.sidebarWidth + this.activitybarWidth : 0);
E
Erich Gamma 已提交
562 563 564
	}

	public getVerticalSashHeight(sash: Sash): number {
I
isidor 已提交
565
		return this.sidebarHeight;
E
Erich Gamma 已提交
566 567
	}

I
isidor 已提交
568
	public getHorizontalSashTop(sash: Sash): number {
569 570
		// 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 已提交
571 572 573
	}

	public getHorizontalSashLeft(sash: Sash): number {
574
		return this.partService.getSideBarPosition() === Position.LEFT ? this.getVerticalSashLeft(sash) : 0;
I
isidor 已提交
575 576 577
	}

	public getHorizontalSashWidth(sash: Sash): number {
I
isidor 已提交
578
		return this.panelWidth;
I
isidor 已提交
579 580
	}

I
isidor 已提交
581 582 583 584
	public isPanelMaximized(): boolean {
		return this.panelMaximized;
	}

585
	// change part size along the main axis
B
Benjamin Pasero 已提交
586 587
	public resizePart(part: Parts, sizeChange: number): void {
		const visibleEditors = this.editorService.getVisibleEditors().length;
588 589 590
		const sizeChangePxWidth = this.workbenchSize.width * (sizeChange / 100);
		const sizeChangePxHeight = this.workbenchSize.height * (sizeChange / 100);

B
Benjamin Pasero 已提交
591 592 593
		let doLayout = false;
		let newSashSize: number = 0;

594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
		switch (part) {
			case Parts.SIDEBAR_PART:
				newSashSize = this.sidebarWidth + sizeChangePxWidth;
				this.sidebarWidth = Math.max(this.partLayoutInfo.sidebar.minWidth, newSashSize); // Sidebar can not become smaller than MIN_PART_WIDTH

				if (this.layoutEditorGroupsVertically && (this.workbenchSize.width - this.sidebarWidth < visibleEditors * MIN_EDITOR_PART_WIDTH)) {
					this.sidebarWidth = (this.workbenchSize.width - visibleEditors * MIN_EDITOR_PART_WIDTH);
				}

				doLayout = true;
				break;
			case Parts.PANEL_PART:
				newSashSize = this.panelHeight + sizeChangePxHeight;
				this.panelHeight = Math.max(this.partLayoutInfo.panel.minHeight, newSashSize);
				doLayout = true;
				break;
			case Parts.EDITOR_PART:
				// If we have one editor we can cheat and resize sidebar with the negative delta
				const visibleEditorCount = this.editorService.getVisibleEditors().length;

				if (visibleEditorCount === 1) {
					this.sidebarWidth = this.sidebarWidth - sizeChangePxWidth;
					doLayout = true;
B
Benjamin Pasero 已提交
617 618 619
				} else {
					const stacks = this.editorGroupService.getStacksModel();
					const activeGroup = stacks.positionOfGroup(stacks.activeGroup);
620 621 622 623 624 625 626

					this.editorGroupService.resizeGroup(activeGroup, sizeChangePxWidth);
					doLayout = false;
				}
		}

		if (doLayout) {
B
Benjamin Pasero 已提交
627
			this.layout();
628 629 630
		}
	}

E
Erich Gamma 已提交
631
	public dispose(): void {
M
Martin Aeschlimann 已提交
632 633 634
		if (this.toUnbind) {
			dispose(this.toUnbind);
			this.toUnbind = null;
E
Erich Gamma 已提交
635 636
		}
	}
B
Benjamin Pasero 已提交
637
}