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

'use strict';

import 'vs/css!./media/workbench';
9

10
import { localize } from 'vs/nls';
11
import { TPromise } from 'vs/base/common/winjs.base';
12
import { IDisposable, dispose, toDisposable, Disposable } from 'vs/base/common/lifecycle';
M
Matt Bierner 已提交
13
import { Event, Emitter } from 'vs/base/common/event';
14
import * as DOM from 'vs/base/browser/dom';
B
Benjamin Pasero 已提交
15
import { Builder, $ } from 'vs/base/browser/builder';
16
import { RunOnceScheduler } from 'vs/base/common/async';
17
import * as browser from 'vs/base/browser/browser';
J
Johannes Rieken 已提交
18
import * as perf from 'vs/base/common/performance';
19
import * as errors from 'vs/base/common/errors';
20
import { BackupFileService } from 'vs/workbench/services/backup/node/backupFileService';
21
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
22
import { Registry } from 'vs/platform/registry/common/platform';
B
Benjamin Pasero 已提交
23
import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform';
B
Benjamin Pasero 已提交
24
import { Position as EditorPosition, IResourceDiffInput, IUntitledResourceInput, IEditor, IResourceInput } from 'vs/platform/editor/common/editor';
J
Johannes Rieken 已提交
25
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
26
import { IEditorInputFactoryRegistry, Extensions as EditorExtensions, TextCompareEditorVisibleContext, TEXT_DIFF_EDITOR_ID, EditorsVisibleContext, InEditorZenModeContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext } from 'vs/workbench/common/editor';
27
import { HistoryService } from 'vs/workbench/services/history/electron-browser/history';
J
Johannes Rieken 已提交
28 29 30 31
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';
B
Benjamin Pasero 已提交
32 33
import { TitlebarPart } from 'vs/workbench/browser/parts/titlebar/titlebarPart';
import { WorkbenchLayout } from 'vs/workbench/browser/layout';
34
import { IActionBarRegistry, Extensions as ActionBarExtensions } from 'vs/workbench/browser/actions';
J
Johannes Rieken 已提交
35 36
import { PanelRegistry, Extensions as PanelExtensions } from 'vs/workbench/browser/panel';
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
C
Christof Marti 已提交
37 38
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickInput';
J
Johannes Rieken 已提交
39
import { getServices } from 'vs/platform/instantiation/common/extensions';
40
import { Position, Parts, IPartService, ILayoutOptions, IDimension } from 'vs/workbench/services/part/common/partService';
41
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
J
Johannes Rieken 已提交
42 43 44 45
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ContextMenuService } from 'vs/workbench/services/contextview/electron-browser/contextmenuService';
import { WorkbenchKeybindingService } from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
46
import { WorkspaceService, DefaultConfigurationExportHelper } from 'vs/workbench/services/configuration/node/configurationService';
47 48
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
import { JSONEditingService } from 'vs/workbench/services/configuration/node/jsonEditingService';
J
Johannes Rieken 已提交
49 50
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
51
import { IKeybindingEditingService, KeybindingsEditingService } from 'vs/workbench/services/keybinding/common/keybindingEditing';
52
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
I
isidor 已提交
53
import { IActivityService } from 'vs/workbench/services/activity/common/activity';
B
Benjamin Pasero 已提交
54
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
P
Pine Wu 已提交
55
import { ViewletService } from 'vs/workbench/services/viewlet/browser/viewletService';
56
import { RemoteFileService } from 'vs/workbench/services/files/electron-browser/remoteFileService';
J
Johannes Rieken 已提交
57 58
import { IFileService } from 'vs/platform/files/common/files';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
59
import { ConfigurationResolverService } from 'vs/workbench/services/configurationResolver/electron-browser/configurationResolverService';
J
Johannes Rieken 已提交
60
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
B
Benjamin Pasero 已提交
61
import { ITitleService } from 'vs/workbench/services/title/common/titleService';
62
import { IWorkbenchEditorService, IResourceInputType, WorkbenchEditorService, NoOpEditorPart } from 'vs/workbench/services/editor/common/editorService';
J
Johannes Rieken 已提交
63
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
64 65
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { ClipboardService } from 'vs/platform/clipboard/electron-browser/clipboardService';
J
Johannes Rieken 已提交
66 67 68 69 70 71
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { TextFileService } from 'vs/workbench/services/textfile/electron-browser/textFileService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
J
Joao Moreno 已提交
72 73
import { ISCMService } from 'vs/workbench/services/scm/common/scm';
import { SCMService } from 'vs/workbench/services/scm/common/scmService';
74 75
import { IProgressService2 } from 'vs/platform/progress/common/progress';
import { ProgressService2 } from 'vs/workbench/services/progress/browser/progressService2';
76
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
77
import { ITextModelService } from 'vs/editor/common/services/resolverService';
J
Johannes Rieken 已提交
78
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
B
Benjamin Pasero 已提交
79
import { ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle';
80
import { LifecycleService } from 'vs/platform/lifecycle/electron-browser/lifecycleService';
B
Benjamin Pasero 已提交
81
import { IWindowService, IWindowConfiguration as IWindowSettings, IWindowConfiguration, IPath } from 'vs/platform/windows/common/windows';
J
Johannes Rieken 已提交
82
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
83
import { IMenuService, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
84
import { MenuService } from 'vs/workbench/services/actions/common/menuService';
J
Johannes Rieken 已提交
85 86
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
B
Benjamin Pasero 已提交
87
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
88
import { OpenRecentAction, ToggleDevToolsAction, ReloadWindowAction, ShowPreviousWindowTab, MoveWindowTabToNewWindow, MergeAllWindowTabs, ShowNextWindowTab, ToggleWindowTabsBar, ReloadWindowWithExtensionsDisabledAction } from 'vs/workbench/electron-browser/actions';
89
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
90
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
B
Benjamin Pasero 已提交
91
import { WorkspaceEditingService } from 'vs/workbench/services/workspace/node/workspaceEditingService';
92
import { FileDecorationsService } from 'vs/workbench/services/decorations/browser/decorationsService';
J
Johannes Rieken 已提交
93
import { IDecorationsService } from 'vs/workbench/services/decorations/browser/decorations';
I
isidor 已提交
94
import { ActivityService } from 'vs/workbench/services/activity/browser/activityService';
B
Benjamin Pasero 已提交
95
import URI from 'vs/base/common/uri';
J
Joao Moreno 已提交
96
import { IListService, ListService } from 'vs/platform/list/browser/listService';
J
Joao Moreno 已提交
97
import { InputFocusedContext } from 'vs/platform/workbench/common/contextkeys';
98
import { IViewsService } from 'vs/workbench/common/views';
S
Sandeep Somavarapu 已提交
99
import { CustomViewsService } from 'vs/workbench/browser/parts/views/customView';
100 101
import { INotificationService } from 'vs/platform/notification/common/notification';
import { NotificationService } from 'vs/workbench/services/notification/common/notificationService';
102 103
import { NotificationsCenter } from 'vs/workbench/browser/parts/notifications/notificationsCenter';
import { NotificationsAlerts } from 'vs/workbench/browser/parts/notifications/notificationsAlerts';
104
import { NotificationsStatus } from 'vs/workbench/browser/parts/notifications/notificationsStatus';
105
import { registerNotificationCommands } from 'vs/workbench/browser/parts/notifications/notificationsCommands';
106
import { NotificationsToasts } from 'vs/workbench/browser/parts/notifications/notificationsToasts';
J
Joao Moreno 已提交
107 108
import { IPCClient } from 'vs/base/parts/ipc/common/ipc';
import { registerWindowDriver } from 'vs/platform/driver/electron-browser/driver';
S
Sandeep Somavarapu 已提交
109 110
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { PreferencesService } from 'vs/workbench/services/preferences/browser/preferencesService';
111
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
112
import { NextEditorPart } from 'vs/workbench/browser/parts/editor2/nextEditorPart';
113
import { INextEditorGroupsService } from 'vs/workbench/services/editor/common/nextEditorGroupsService';
114
import { NextEditorService } from 'vs/workbench/services/editor/browser/nextEditorService';
J
Joao Moreno 已提交
115
import { IExtensionUrlHandler, ExtensionUrlHandler } from 'vs/platform/url/electron-browser/inactiveExtensionUrlHandler';
116

E
Erich Gamma 已提交
117
interface WorkbenchParams {
118
	configuration: IWindowConfiguration;
119
	serviceCollection: ServiceCollection;
E
Erich Gamma 已提交
120 121
}

I
isidor 已提交
122 123
interface IZenModeSettings {
	fullScreen: boolean;
124
	centerLayout: boolean;
I
isidor 已提交
125
	hideTabs: boolean;
126
	hideActivityBar: boolean;
I
isidor 已提交
127
	hideStatusBar: boolean;
I
isidor 已提交
128
	restore: boolean;
I
isidor 已提交
129 130
}

131 132 133
export interface IWorkbenchStartedInfo {
	customKeybindingsCount: number;
	pinnedViewlets: string[];
134 135
	restoredViewlet: string;
	restoredEditors: string[];
136 137
}

138 139
type FontAliasingOption = 'default' | 'antialiased' | 'none' | 'auto';

B
Benjamin Pasero 已提交
140 141
const fontAliasingValues: FontAliasingOption[] = ['antialiased', 'none', 'auto'];

142 143
const Identifiers = {
	WORKBENCH_CONTAINER: 'workbench.main.container',
B
Benjamin Pasero 已提交
144
	TITLEBAR_PART: 'workbench.parts.titlebar',
145 146 147 148 149 150 151
	ACTIVITYBAR_PART: 'workbench.parts.activitybar',
	SIDEBAR_PART: 'workbench.parts.sidebar',
	PANEL_PART: 'workbench.parts.panel',
	EDITOR_PART: 'workbench.parts.editor',
	STATUSBAR_PART: 'workbench.parts.statusbar'
};

J
Joao Moreno 已提交
152 153 154 155 156 157 158 159
function getWorkbenchStateString(state: WorkbenchState): string {
	switch (state) {
		case WorkbenchState.EMPTY: return 'empty';
		case WorkbenchState.FOLDER: return 'folder';
		case WorkbenchState.WORKSPACE: return 'workspace';
	}
}

160 161 162 163 164 165 166 167 168 169
interface IZenMode {
	active: boolean;
	transitionedToFullScreen: boolean;
	transitionedToCenteredEditorLayout: boolean;
	transitionDisposeables: IDisposable[];
	wasSideBarVisible: boolean;
	wasPanelVisible: boolean;
}

export class Workbench extends Disposable implements IPartService {
E
Erich Gamma 已提交
170

171 172 173 174
	private static readonly sidebarHiddenStorageKey = 'workbench.sidebar.hidden';
	private static readonly sidebarRestoreStorageKey = 'workbench.sidebar.restore';
	private static readonly panelHiddenStorageKey = 'workbench.panel.hidden';
	private static readonly zenModeActiveStorageKey = 'workbench.zenmode.active';
175
	private static readonly centeredEditorLayoutActiveStorageKey = 'workbench.centerededitorlayout.active';
176
	private static readonly panelPositionStorageKey = 'workbench.panel.location';
177
	private static readonly defaultPanelPositionStorageKey = 'workbench.panel.defaultLocation';
178 179 180 181 182
	private static readonly sidebarPositionConfigurationKey = 'workbench.sideBar.location';
	private static readonly statusbarVisibleConfigurationKey = 'workbench.statusBar.visible';
	private static readonly activityBarVisibleConfigurationKey = 'workbench.activityBar.visible';
	private static readonly closeWhenEmptyConfigurationKey = 'window.closeWhenEmpty';
	private static readonly fontAliasingConfigurationKey = 'workbench.fontAliasing';
183

184
	_serviceBrand: any;
E
Erich Gamma 已提交
185 186 187 188 189 190

	private workbenchParams: WorkbenchParams;
	private workbenchContainer: Builder;
	private workbench: Builder;
	private workbenchStarted: boolean;
	private workbenchCreated: boolean;
191 192
	private workbenchShutdown: boolean;

193 194
	private nextEditorService: INextEditorService;
	private nextEditorGroupsService: INextEditorGroupsService;
195 196
	private legacyEditorService: IWorkbenchEditorService;
	private legacyEditorGroupService: IEditorGroupService;
P
Pine Wu 已提交
197
	private viewletService: IViewletService;
198
	private contextKeyService: IContextKeyService;
199
	private keybindingService: IKeybindingService;
200
	private backupFileService: IBackupFileService;
201
	private fileService: IFileService;
202 203 204 205
	private quickInput: QuickInputService;

	private workbenchLayout: WorkbenchLayout;

B
Benjamin Pasero 已提交
206
	private titlebarPart: TitlebarPart;
E
Erich Gamma 已提交
207 208
	private activitybarPart: ActivitybarPart;
	private sidebarPart: SidebarPart;
I
isidor 已提交
209
	private panelPart: PanelPart;
210
	private noOpEditorPart: NoOpEditorPart; // TODO@grid adopt methods in next editor part
211
	private editorPart: NextEditorPart;
E
Erich Gamma 已提交
212 213
	private statusbarPart: StatusbarPart;
	private quickOpen: QuickOpenController;
214
	private notificationsCenter: NotificationsCenter;
215
	private notificationsToasts: NotificationsToasts;
216

E
Erich Gamma 已提交
217
	private sideBarHidden: boolean;
218
	private statusBarHidden: boolean;
S
Sanders Lauture 已提交
219
	private activityBarHidden: boolean;
E
Erich Gamma 已提交
220
	private sideBarPosition: Position;
I
isidor 已提交
221
	private panelPosition: Position;
I
isidor 已提交
222
	private panelHidden: boolean;
223 224 225 226 227 228
	private zenMode: IZenMode;
	private centeredEditorLayoutActive: boolean;
	private fontAliasing: FontAliasingOption;
	private hasFilesToCreateOpenOrDiff: boolean;

	private inZenMode: IContextKey<boolean>;
229
	private sideBarVisibleContext: IContextKey<boolean>;
230 231 232 233 234 235 236

	private closeEmptyWindowScheduler: RunOnceScheduler = new RunOnceScheduler(() => this.onAllEditorsClosed(), 50);

	private _onTitleBarVisibilityChange: Emitter<void> = new Emitter<void>();
	get onTitleBarVisibilityChange(): Event<void> { return this._onTitleBarVisibilityChange.event; }

	get onEditorLayout(): Event<IDimension> { return this.editorPart.onDidLayout; }
E
Erich Gamma 已提交
237

238
	constructor(
239 240
		private parent: HTMLElement,
		private container: HTMLElement,
J
Joao Moreno 已提交
241
		private configuration: IWindowConfiguration,
242
		serviceCollection: ServiceCollection,
243
		private lifecycleService: LifecycleService,
J
Joao Moreno 已提交
244
		private mainProcessClient: IPCClient,
245
		@IInstantiationService private instantiationService: IInstantiationService,
246
		@IWorkspaceContextService private contextService: IWorkspaceContextService,
247
		@IStorageService private storageService: IStorageService,
248
		@IConfigurationService private configurationService: WorkspaceService,
I
isidor 已提交
249
		@IEnvironmentService private environmentService: IEnvironmentService,
250 251
		@IWindowService private windowService: IWindowService,
		@INotificationService private notificationService: NotificationService
252
	) {
253
		super();
E
Erich Gamma 已提交
254 255

		this.workbenchParams = {
256
			configuration,
257
			serviceCollection
E
Erich Gamma 已提交
258 259
		};

260
		this.hasFilesToCreateOpenOrDiff =
B
Benjamin Pasero 已提交
261 262 263
			(configuration.filesToCreate && configuration.filesToCreate.length > 0) ||
			(configuration.filesToOpen && configuration.filesToOpen.length > 0) ||
			(configuration.filesToDiff && configuration.filesToDiff.length > 0);
264 265
	}

266
	startup(): TPromise<IWorkbenchStartedInfo> {
267
		this.workbenchStarted = true;
E
Erich Gamma 已提交
268

B
Benjamin Pasero 已提交
269
		// Create Workbench Container
270
		this.createWorkbench();
E
Erich Gamma 已提交
271

272 273
		// Install some global actions
		this.createGlobalActions();
274

275 276
		// Services
		this.initServices();
E
Erich Gamma 已提交
277

278 279
		// Context Keys
		this.handleContextKeys();
J
Joao Moreno 已提交
280

281 282
		// Register Listeners
		this.registerListeners();
E
Erich Gamma 已提交
283

284 285
		// Settings
		this.initSettings();
E
Erich Gamma 已提交
286

287 288
		// Create Workbench and Parts
		this.renderWorkbench();
289

290 291
		// Workbench Layout
		this.createWorkbenchLayout();
B
polish  
Benjamin Pasero 已提交
292

J
Joao Moreno 已提交
293 294
		// Driver
		if (this.environmentService.driverHandle) {
295
			registerWindowDriver(this.mainProcessClient, this.configuration.windowId, this.instantiationService).then(disposable => this._register(disposable));
J
Joao Moreno 已提交
296 297
		}

298
		// Restore Parts
B
Benjamin Pasero 已提交
299 300
		return this.restoreParts();
	}
301

302
	private handleContextKeys(): void {
303 304 305 306
		this.inZenMode = InEditorZenModeContext.bindTo(this.contextKeyService);

		const sidebarVisibleContextRaw = new RawContextKey<boolean>('sidebarVisible', false);
		this.sideBarVisibleContext = sidebarVisibleContextRaw.bindTo(this.contextKeyService);
307

308 309 310 311 312 313
		const editorsVisibleContext = EditorsVisibleContext.bindTo(this.contextKeyService);
		const textCompareEditorVisible = TextCompareEditorVisibleContext.bindTo(this.contextKeyService);
		const activeEditorGroupEmpty = ActiveEditorGroupEmptyContext.bindTo(this.contextKeyService);
		const multipleEditorGroups = MultipleEditorGroupsContext.bindTo(this.contextKeyService);

		const updateEditorContextKeys = () => {
314 315
			const visibleEditors = this.nextEditorService.visibleControls;

316 317 318 319
			textCompareEditorVisible.set(visibleEditors.some(control => control.getId() === TEXT_DIFF_EDITOR_ID));

			if (visibleEditors.length > 0) {
				editorsVisibleContext.set(true);
320
			} else {
321
				editorsVisibleContext.reset();
322
			}
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340

			if (!this.nextEditorService.activeEditor) {
				activeEditorGroupEmpty.set(true);
			} else {
				activeEditorGroupEmpty.reset();
			}

			if (this.nextEditorGroupsService.count > 1) {
				multipleEditorGroups.set(true);
			} else {
				multipleEditorGroups.reset();
			}
		};

		this._register(this.nextEditorService.onDidActiveEditorChange(() => updateEditorContextKeys()));
		this._register(this.nextEditorService.onDidVisibleEditorsChange(() => updateEditorContextKeys()));
		this._register(this.nextEditorGroupsService.onDidAddGroup(() => updateEditorContextKeys()));
		this._register(this.nextEditorGroupsService.onDidRemoveGroup(() => updateEditorContextKeys()));
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359

		const inputFocused = InputFocusedContext.bindTo(this.contextKeyService);
		this._register(DOM.addDisposableListener(window, 'focusin', () => {
			inputFocused.set(document.activeElement && (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA'));
		}, true));

		const workbenchStateRawContext = new RawContextKey<string>('workbenchState', getWorkbenchStateString(this.configurationService.getWorkbenchState()));
		const workbenchStateContext = workbenchStateRawContext.bindTo(this.contextKeyService);
		this._register(this.configurationService.onDidChangeWorkbenchState(() => {
			workbenchStateContext.set(getWorkbenchStateString(this.configurationService.getWorkbenchState()));
		}));

		const workspaceFolderCountRawContext = new RawContextKey<number>('workspaceFolderCount', this.configurationService.getWorkspace().folders.length);
		const workspaceFolderCountContext = workspaceFolderCountRawContext.bindTo(this.contextKeyService);
		this._register(this.configurationService.onDidChangeWorkspaceFolders(() => {
			workspaceFolderCountContext.set(this.configurationService.getWorkspace().folders.length);
		}));
	}

360 361
	private registerListeners(): void {

362
		// Listen to visible editor changes
363
		this._register(this.nextEditorService.onDidVisibleEditorsChange(() => this.onDidVisibleEditorsChange()));
364 365 366 367 368 369

		// Listen to editor closing (if we run with --wait)
		const filesToWait = this.workbenchParams.configuration.filesToWait;
		if (filesToWait) {
			const resourcesToWaitFor = filesToWait.paths.map(p => URI.file(p.filePath));
			const waitMarkerFile = URI.file(filesToWait.waitMarkerFilePath);
370
			const listenerDispose = this.legacyEditorGroupService.getStacksModel().onEditorClosed(() => this.onEditorClosed(listenerDispose, resourcesToWaitFor, waitMarkerFile));
371

372
			this._register(listenerDispose);
373 374 375
		}

		// Configuration changes
376
		this._register(this.configurationService.onDidChangeConfiguration(() => this.onDidUpdateConfiguration()));
377 378

		// Fullscreen changes
379
		this._register(browser.onDidChangeFullscreen(() => this.onFullscreenChanged()));
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
	}

	private onFullscreenChanged(): void {
		if (!this.isCreated) {
			return; // we need to be ready
		}

		// Apply as CSS class
		const isFullscreen = browser.isFullscreen();
		if (isFullscreen) {
			this.workbench.addClass('fullscreen');
		} else {
			this.workbench.removeClass('fullscreen');
			if (this.zenMode.transitionedToFullScreen && this.zenMode.active) {
				this.toggleZenMode();
			}
		}

		// Changing fullscreen state of the window has an impact on custom title bar visibility, so we need to update
		const hasCustomTitle = this.getCustomTitleBarStyle() === 'custom';
		if (hasCustomTitle) {
			this._onTitleBarVisibilityChange.fire();
			this.layout(); // handle title bar when fullscreen changes
		}
	}

	private onEditorClosed(listenerDispose: IDisposable, resourcesToWaitFor: URI[], waitMarkerFile: URI): void {

		// In wait mode, listen to changes to the editors and wait until the files
		// are closed that the user wants to wait for. When this happens we delete
		// the wait marker file to signal to the outside that editing is done.
411
		const stacks = this.legacyEditorGroupService.getStacksModel();
412 413 414 415 416 417
		if (resourcesToWaitFor.every(r => !stacks.isOpen(r))) {
			listenerDispose.dispose();
			this.fileService.del(waitMarkerFile).done(null, errors.onUnexpectedError);
		}
	}

418 419
	private onDidVisibleEditorsChange(): void {
		const visibleEditors = this.nextEditorService.visibleControls;
420 421 422 423 424 425 426 427 428 429 430 431 432

		// Close when empty: check if we should close the window based on the setting
		// Overruled by: window has a workspace opened or this window is for extension development
		// or setting is disabled. Also enabled when running with --wait from the command line.
		if (visibleEditors.length === 0 && this.contextService.getWorkbenchState() === WorkbenchState.EMPTY && !this.environmentService.isExtensionDevelopment) {
			const closeWhenEmpty = this.configurationService.getValue<boolean>(Workbench.closeWhenEmptyConfigurationKey);
			if (closeWhenEmpty || this.environmentService.args.wait) {
				this.closeEmptyWindowScheduler.schedule();
			}
		}
	}

	private onAllEditorsClosed(): void {
433
		const visibleEditors = this.nextEditorService.visibleControls.length;
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
		if (visibleEditors === 0) {
			this.windowService.closeWindow();
		}
	}

	private onDidUpdateConfiguration(skipLayout?: boolean): void {
		const newSidebarPositionValue = this.configurationService.getValue<string>(Workbench.sidebarPositionConfigurationKey);
		const newSidebarPosition = (newSidebarPositionValue === 'right') ? Position.RIGHT : Position.LEFT;
		if (newSidebarPosition !== this.getSideBarPosition()) {
			this.setSideBarPosition(newSidebarPosition);
		}

		this.setPanelPositionFromStorageOrConfig();

		const fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
		if (fontAliasing !== this.fontAliasing) {
			this.setFontAliasing(fontAliasing);
		}

		if (!this.zenMode.active) {
			const newStatusbarHiddenValue = !this.configurationService.getValue<boolean>(Workbench.statusbarVisibleConfigurationKey);
			if (newStatusbarHiddenValue !== this.statusBarHidden) {
				this.setStatusBarHidden(newStatusbarHiddenValue, skipLayout);
			}

			const newActivityBarHiddenValue = !this.configurationService.getValue<boolean>(Workbench.activityBarVisibleConfigurationKey);
			if (newActivityBarHiddenValue !== this.activityBarHidden) {
				this.setActivityBarHidden(newActivityBarHiddenValue, skipLayout);
			}
		}
	}

B
Benjamin Pasero 已提交
466 467 468 469 470 471
	private createWorkbench(): void {
		this.workbenchContainer = $('.monaco-workbench-container');
		this.workbench = $().div({
			'class': `monaco-workbench ${isWindows ? 'windows' : isLinux ? 'linux' : 'mac'}`,
			id: Identifiers.WORKBENCH_CONTAINER
		}).appendTo(this.workbenchContainer);
472
	}
E
Erich Gamma 已提交
473

474 475 476 477
	private restoreParts(): TPromise<IWorkbenchStartedInfo> {
		const restorePromises: TPromise<any>[] = [];

		// Restore Editors
J
Johannes Rieken 已提交
478
		perf.mark('willRestoreEditors');
479 480 481 482
		const restoredEditors: string[] = [];
		restorePromises.push(this.resolveEditorsToOpen().then(inputs => {
			let editorOpenPromise: TPromise<IEditor[]>;
			if (inputs.length) {
483
				editorOpenPromise = this.legacyEditorService.openEditors(inputs.map(input => { return { input, position: EditorPosition.ONE }; }));
484
			} else {
485
				editorOpenPromise = this.noOpEditorPart.restoreEditors();
486 487
			}

B
Benjamin Pasero 已提交
488
			return editorOpenPromise.then(editors => {
J
Johannes Rieken 已提交
489
				perf.mark('didRestoreEditors');
490

491 492 493 494 495 496
				for (const editor of editors) {
					if (editor) {
						if (editor.input) {
							restoredEditors.push(editor.input.getName());
						} else {
							restoredEditors.push(`other:${editor.getId()}`);
497 498
						}
					}
499
				}
B
Benjamin Pasero 已提交
500
			});
501
		}));
E
Erich Gamma 已提交
502

503 504 505 506
		// Restore Sidebar
		let viewletIdToRestore: string;
		if (!this.sideBarHidden) {
			this.sideBarVisibleContext.set(true);
I
isidor 已提交
507

508 509 510
			if (this.shouldRestoreLastOpenedViewlet()) {
				viewletIdToRestore = this.storageService.get(SidebarPart.activeViewletSettingsKey, StorageScope.WORKSPACE);
			}
511

512 513 514
			if (!viewletIdToRestore) {
				viewletIdToRestore = this.viewletService.getDefaultViewletId();
			}
515

J
Johannes Rieken 已提交
516
			perf.mark('willRestoreViewlet');
517
			restorePromises.push(this.viewletService.openViewlet(viewletIdToRestore).then(() => {
J
Johannes Rieken 已提交
518
				perf.mark('didRestoreViewlet');
519 520
			}));
		}
E
Erich Gamma 已提交
521

522 523 524 525 526 527
		// Restore Panel
		const panelRegistry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
		const panelId = this.storageService.get(PanelPart.activePanelSettingsKey, StorageScope.WORKSPACE, panelRegistry.getDefaultPanelId());
		if (!this.panelHidden && !!panelId) {
			restorePromises.push(this.panelPart.openPanel(panelId, false));
		}
E
Erich Gamma 已提交
528

529
		// Restore Zen Mode if active
I
isidor 已提交
530
		if (this.storageService.getBoolean(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE, false)) {
531
			this.toggleZenMode(true);
E
Erich Gamma 已提交
532
		}
533

B
Benjamin Pasero 已提交
534 535 536
		// Restore Forced Editor Center Mode
		if (this.storageService.getBoolean(Workbench.centeredEditorLayoutActiveStorageKey, StorageScope.GLOBAL, false)) {
			this.centeredEditorLayoutActive = true;
S
SrTobi 已提交
537 538
		}

539
		const onRestored = (error?: Error): IWorkbenchStartedInfo => {
B
Benjamin Pasero 已提交
540 541
			this.workbenchCreated = true;

542 543 544 545 546 547 548 549 550 551 552 553 554
			if (error) {
				errors.onUnexpectedError(error);
			}

			return {
				customKeybindingsCount: this.keybindingService.customKeybindingsCount(),
				pinnedViewlets: this.activitybarPart.getPinned(),
				restoredViewlet: viewletIdToRestore,
				restoredEditors
			};
		};

		return TPromise.join(restorePromises).then(() => onRestored(), error => onRestored(error));
E
Erich Gamma 已提交
555 556
	}

557 558 559 560 561 562 563 564 565 566 567 568 569
	private shouldRestoreLastOpenedViewlet(): boolean {
		if (!this.environmentService.isBuilt) {
			return true; // always restore sidebar when we are in development mode
		}

		const restore = this.storageService.getBoolean(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE);
		if (restore) {
			this.storageService.remove(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE); // only support once
		}

		return restore;
	}

570
	private createGlobalActions(): void {
B
Benjamin Pasero 已提交
571
		const isDeveloping = !this.environmentService.isBuilt || this.environmentService.isExtensionDevelopment;
572

B
Benjamin Pasero 已提交
573
		// Actions registered here to adjust for developing vs built workbench
574 575
		const workbenchActionsRegistry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
		workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ReloadWindowAction, ReloadWindowAction.ID, ReloadWindowAction.LABEL, isDeveloping ? { primary: KeyMod.CtrlCmd | KeyCode.KEY_R } : void 0), 'Reload Window');
B
Benjamin Pasero 已提交
576
		workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleDevToolsAction, ToggleDevToolsAction.ID, ToggleDevToolsAction.LABEL, isDeveloping ? { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_I, mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_I } } : void 0), 'Developer: Toggle Developer Tools', localize('developer', "Developer"));
B
Benjamin Pasero 已提交
577
		workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(OpenRecentAction, OpenRecentAction.ID, OpenRecentAction.LABEL, { primary: isDeveloping ? null : KeyMod.CtrlCmd | KeyCode.KEY_R, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_R } }), 'File: Open Recent...', localize('file', "File"));
578
		workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ReloadWindowWithExtensionsDisabledAction, ReloadWindowWithExtensionsDisabledAction.ID, ReloadWindowWithExtensionsDisabledAction.LABEL), 'Reload Window Without Extensions');
579

580
		// Actions for macOS native tabs management (only when enabled)
581
		const windowConfig = this.configurationService.getValue<IWindowConfiguration>();
582 583 584 585 586 587 588
		if (windowConfig && windowConfig.window && windowConfig.window.nativeTabs) {
			workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ShowPreviousWindowTab, ShowPreviousWindowTab.ID, ShowPreviousWindowTab.LABEL), 'Show Previous Window Tab');
			workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ShowNextWindowTab, ShowNextWindowTab.ID, ShowNextWindowTab.LABEL), 'Show Next Window Tab');
			workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(MoveWindowTabToNewWindow, MoveWindowTabToNewWindow.ID, MoveWindowTabToNewWindow.LABEL), 'Move Window Tab to New Window');
			workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(MergeAllWindowTabs, MergeAllWindowTabs.ID, MergeAllWindowTabs.LABEL), 'Merge All Windows');
			workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleWindowTabsBar, ToggleWindowTabsBar.ID, ToggleWindowTabsBar.LABEL), 'Toggle Window Tabs Bar');
		}
589 590
	}

591
	private resolveEditorsToOpen(): TPromise<IResourceInputType[]> {
592
		const config = this.workbenchParams.configuration;
B
Benjamin Pasero 已提交
593 594

		// Files to open, diff or create
595
		if (this.hasFilesToCreateOpenOrDiff) {
B
Benjamin Pasero 已提交
596 597

			// Files to diff is exclusive
598
			const filesToDiff = this.toInputs(config.filesToDiff, false);
599
			if (filesToDiff && filesToDiff.length === 2) {
600 601 602 603 604
				return TPromise.as([<IResourceDiffInput>{
					leftResource: filesToDiff[0].resource,
					rightResource: filesToDiff[1].resource,
					options: { pinned: true }
				}]);
B
Benjamin Pasero 已提交
605 606
			}

607 608
			const filesToCreate = this.toInputs(config.filesToCreate, true);
			const filesToOpen = this.toInputs(config.filesToOpen, false);
609

610 611
			// Otherwise: Open/Create files
			return TPromise.as([...filesToOpen, ...filesToCreate]);
B
Benjamin Pasero 已提交
612 613
		}

614
		// Empty workbench
615
		else if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY && this.openUntitledFile()) {
616
			if (this.noOpEditorPart.hasEditorsToRestore()) {
617 618 619
				return TPromise.as([]); // do not open any empty untitled file if we have editors to restore
			}

620 621 622 623 624
			return this.backupFileService.hasBackups().then(hasBackups => {
				if (hasBackups) {
					return TPromise.as([]); // do not open any empty untitled file if we have backups to restore
				}

625
				return TPromise.as([<IUntitledResourceInput>{}]);
626
			});
B
Benjamin Pasero 已提交
627 628 629 630 631
		}

		return TPromise.as([]);
	}

632
	private toInputs(paths: IPath[], isNew: boolean): (IResourceInput | IUntitledResourceInput)[] {
B
Benjamin Pasero 已提交
633 634 635 636 637
		if (!paths || !paths.length) {
			return [];
		}

		return paths.map(p => {
638 639 640 641 642 643 644
			const resource = URI.file(p.filePath);
			let input: IResourceInput | IUntitledResourceInput;
			if (isNew) {
				input = { filePath: resource.fsPath, options: { pinned: true } } as IUntitledResourceInput;
			} else {
				input = { resource, options: { pinned: true } } as IResourceInput;
			}
B
Benjamin Pasero 已提交
645

646
			if (!isNew && p.lineNumber) {
B
Benjamin Pasero 已提交
647 648 649 650 651 652 653 654 655 656
				input.options.selection = {
					startLineNumber: p.lineNumber,
					startColumn: p.columnNumber
				};
			}

			return input;
		});
	}

657
	private openUntitledFile() {
658
		const startupEditor = this.configurationService.inspect('workbench.startupEditor');
B
Benjamin Pasero 已提交
659 660

		// Fallback to previous workbench.welcome.enabled setting in case startupEditor is not defined
661
		if (!startupEditor.user && !startupEditor.workspace) {
662 663 664
			const welcomeEnabledValue = this.configurationService.getValue('workbench.welcome.enabled');
			if (typeof welcomeEnabledValue === 'boolean') {
				return !welcomeEnabledValue;
665 666
			}
		}
B
Benjamin Pasero 已提交
667

668
		return startupEditor.value === 'newUntitledFile';
669 670
	}

E
Erich Gamma 已提交
671
	private initServices(): void {
B
Benjamin Pasero 已提交
672
		const { serviceCollection } = this.workbenchParams;
673

E
Erich Gamma 已提交
674
		// Services we contribute
675
		serviceCollection.set(IPartService, this);
E
Erich Gamma 已提交
676

677 678 679
		// Clipboard
		serviceCollection.set(IClipboardService, new ClipboardService());

680 681
		// Status bar
		this.statusbarPart = this.instantiationService.createInstance(StatusbarPart, Identifiers.STATUSBAR_PART);
682
		this._register(toDisposable(() => this.statusbarPart.shutdown()));
683 684
		serviceCollection.set(IStatusbarService, this.statusbarPart);

685 686 687
		// Progress 2
		serviceCollection.set(IProgressService2, new SyncDescriptor(ProgressService2));

688
		// Keybindings
A
Alex Dima 已提交
689
		this.contextKeyService = this.instantiationService.createInstance(ContextKeyService);
690
		serviceCollection.set(IContextKeyService, this.contextKeyService);
691

B
Benjamin Pasero 已提交
692
		this.keybindingService = this.instantiationService.createInstance(WorkbenchKeybindingService, window);
693
		serviceCollection.set(IKeybindingService, this.keybindingService);
A
Alex Dima 已提交
694

695 696 697
		// List
		serviceCollection.set(IListService, this.instantiationService.createInstance(ListService));

698
		// Context Menu
699
		serviceCollection.set(IContextMenuService, new SyncDescriptor(ContextMenuService));
700

701 702
		// Menus/Actions
		serviceCollection.set(IMenuService, new SyncDescriptor(MenuService));
703

P
Pine Wu 已提交
704
		// Sidebar part
705
		this.sidebarPart = this.instantiationService.createInstance(SidebarPart, Identifiers.SIDEBAR_PART);
706
		this._register(toDisposable(() => this.sidebarPart.shutdown()));
P
Pine Wu 已提交
707 708 709 710

		// Viewlet service
		this.viewletService = this.instantiationService.createInstance(ViewletService, this.sidebarPart);
		serviceCollection.set(IViewletService, this.viewletService);
E
Erich Gamma 已提交
711

I
isidor 已提交
712
		// Panel service (panel part)
713
		this.panelPart = this.instantiationService.createInstance(PanelPart, Identifiers.PANEL_PART);
714
		this._register(toDisposable(() => this.panelPart.shutdown()));
715
		serviceCollection.set(IPanelService, this.panelPart);
I
isidor 已提交
716

S
Sandeep Somavarapu 已提交
717 718
		// Custom views service
		const customViewsService = this.instantiationService.createInstance(CustomViewsService);
719
		serviceCollection.set(IViewsService, customViewsService);
S
Sandeep Somavarapu 已提交
720

E
Erich Gamma 已提交
721
		// Activity service (activitybar part)
722
		this.activitybarPart = this.instantiationService.createInstance(ActivitybarPart, Identifiers.ACTIVITYBAR_PART);
723
		this._register(toDisposable(() => this.activitybarPart.shutdown()));
I
isidor 已提交
724 725
		const activityService = this.instantiationService.createInstance(ActivityService, this.activitybarPart, this.panelPart);
		serviceCollection.set(IActivityService, activityService);
E
Erich Gamma 已提交
726

727 728 729
		// File Service
		this.fileService = this.instantiationService.createInstance(RemoteFileService);
		serviceCollection.set(IFileService, this.fileService);
S
#47154  
Sandeep Somavarapu 已提交
730
		this.configurationService.acquireFileService(this.fileService);
731

732 733
		// Editor service (next editor part)
		this.editorPart = this.instantiationService.createInstance(NextEditorPart, Identifiers.EDITOR_PART /*, !this.hasFilesToCreateOpenOrDiff*/);
734
		this._register(toDisposable(() => this.editorPart.shutdown()));
735
		this.nextEditorGroupsService = this.editorPart;
736
		serviceCollection.set(INextEditorGroupsService, this.editorPart);
737 738
		this.nextEditorService = this.instantiationService.createInstance(NextEditorService);
		serviceCollection.set(INextEditorService, this.nextEditorService);
739 740 741

		// Legacy Editor Services
		this.noOpEditorPart = new NoOpEditorPart(this.instantiationService);
742 743 744
		this.legacyEditorService = this.instantiationService.createInstance(WorkbenchEditorService, this.noOpEditorPart);
		this.legacyEditorGroupService = this.noOpEditorPart;
		serviceCollection.set(IWorkbenchEditorService, this.legacyEditorService);
745
		serviceCollection.set(IEditorGroupService, this.noOpEditorPart);
E
Erich Gamma 已提交
746

747 748
		// Title bar
		this.titlebarPart = this.instantiationService.createInstance(TitlebarPart, Identifiers.TITLEBAR_PART);
749
		this._register(toDisposable(() => this.titlebarPart.shutdown()));
750 751
		serviceCollection.set(ITitleService, this.titlebarPart);

752
		// History
753
		serviceCollection.set(IHistoryService, new SyncDescriptor(HistoryService));
754

755
		// Backup File Service
756
		this.backupFileService = this.instantiationService.createInstance(BackupFileService, this.workbenchParams.configuration.backupPath);
757
		serviceCollection.set(IBackupFileService, this.backupFileService);
758

759
		// Text File Service
760
		serviceCollection.set(ITextFileService, new SyncDescriptor(TextFileService));
761

762
		// File Decorations
J
Johannes Rieken 已提交
763
		serviceCollection.set(IDecorationsService, new SyncDescriptor(FileDecorationsService));
764

J
Joao Moreno 已提交
765
		// SCM Service
766
		serviceCollection.set(ISCMService, new SyncDescriptor(SCMService));
767

J
Joao Moreno 已提交
768
		// Inactive extension URL handler
J
Joao Moreno 已提交
769
		serviceCollection.set(IExtensionUrlHandler, new SyncDescriptor(ExtensionUrlHandler));
J
Joao Moreno 已提交
770

B
Benjamin Pasero 已提交
771
		// Text Model Resolver Service
772
		serviceCollection.set(ITextModelService, new SyncDescriptor(TextModelResolverService));
B
Benjamin Pasero 已提交
773

774 775 776 777
		// JSON Editing
		const jsonEditingService = this.instantiationService.createInstance(JSONEditingService);
		serviceCollection.set(IJSONEditingService, jsonEditingService);

778 779 780
		// Workspace Editing
		serviceCollection.set(IWorkspaceEditingService, new SyncDescriptor(WorkspaceEditingService));

781 782 783
		// Keybinding Editing
		serviceCollection.set(IKeybindingEditingService, this.instantiationService.createInstance(KeybindingsEditingService));

784
		// Configuration Resolver
B
Benjamin Pasero 已提交
785
		serviceCollection.set(IConfigurationResolverService, new SyncDescriptor(ConfigurationResolverService, process.env));
786

E
Erich Gamma 已提交
787
		// Quick open service (quick open controller)
788
		this.quickOpen = this.instantiationService.createInstance(QuickOpenController);
789
		this._register(toDisposable(() => this.quickOpen.shutdown()));
790
		serviceCollection.set(IQuickOpenService, this.quickOpen);
791

C
Christof Marti 已提交
792 793
		// Quick input service
		this.quickInput = this.instantiationService.createInstance(QuickInputService);
794
		this._register(toDisposable(() => this.quickInput.shutdown()));
C
Christof Marti 已提交
795 796
		serviceCollection.set(IQuickInputService, this.quickInput);

S
Sandeep Somavarapu 已提交
797 798 799
		// PreferencesService
		serviceCollection.set(IPreferencesService, this.instantiationService.createInstance(PreferencesService));

B
polish  
Benjamin Pasero 已提交
800
		// Contributed services
B
Benjamin Pasero 已提交
801
		const contributedServices = getServices();
E
Erich Gamma 已提交
802
		for (let contributedService of contributedServices) {
803
			serviceCollection.set(contributedService.id, contributedService.descriptor);
E
Erich Gamma 已提交
804 805 806
		}

		// Set the some services to registries that have been created eagerly
807
		Registry.as<IActionBarRegistry>(ActionBarExtensions.Actionbar).setInstantiationService(this.instantiationService);
808
		Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).start(this.instantiationService, this.lifecycleService);
809
		Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).setInstantiationService(this.instantiationService);
810

811
		this.instantiationService.createInstance(DefaultConfigurationExportHelper);
812

S
#47154  
Sandeep Somavarapu 已提交
813
		this.configurationService.acquireInstantiationService(this.getInstantiationService());
E
Erich Gamma 已提交
814 815 816 817 818
	}

	private initSettings(): void {

		// Sidebar visibility
I
isidor 已提交
819
		this.sideBarHidden = this.storageService.getBoolean(Workbench.sidebarHiddenStorageKey, StorageScope.WORKSPACE, this.contextService.getWorkbenchState() === WorkbenchState.EMPTY);
E
Erich Gamma 已提交
820

I
isidor 已提交
821
		// Panel part visibility
822
		const panelRegistry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
I
isidor 已提交
823
		this.panelHidden = this.storageService.getBoolean(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE, true);
824 825
		if (!panelRegistry.getDefaultPanelId()) {
			this.panelHidden = true; // we hide panel part if there is no default panel
I
isidor 已提交
826
		}
I
isidor 已提交
827

E
Erich Gamma 已提交
828
		// Sidebar position
829
		const sideBarPosition = this.configurationService.getValue<string>(Workbench.sidebarPositionConfigurationKey);
830
		this.sideBarPosition = (sideBarPosition === 'right') ? Position.RIGHT : Position.LEFT;
B
Benjamin Pasero 已提交
831

I
isidor 已提交
832
		// Panel position
833
		this.setPanelPositionFromStorageOrConfig();
I
isidor 已提交
834

B
Benjamin Pasero 已提交
835
		// Statusbar visibility
836
		const statusBarVisible = this.configurationService.getValue<string>(Workbench.statusbarVisibleConfigurationKey);
837
		this.statusBarHidden = !statusBarVisible;
S
Sanders Lauture 已提交
838 839

		// Activity bar visibility
840
		const activityBarVisible = this.configurationService.getValue<string>(Workbench.activityBarVisibleConfigurationKey);
S
Sanders Lauture 已提交
841
		this.activityBarHidden = !activityBarVisible;
I
isidor 已提交
842

843
		// Font aliasing
844
		this.fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
845

I
isidor 已提交
846 847
		// Zen mode
		this.zenMode = {
I
isidor 已提交
848
			active: false,
849
			transitionedToFullScreen: false,
850
			transitionedToCenteredEditorLayout: false,
851
			wasSideBarVisible: false,
852 853
			wasPanelVisible: false,
			transitionDisposeables: []
I
isidor 已提交
854
		};
S
SrTobi 已提交
855

B
Benjamin Pasero 已提交
856 857
		// Centered Editor Layout
		this.centeredEditorLayoutActive = false;
E
Erich Gamma 已提交
858 859
	}

860 861 862 863 864 865
	private setPanelPositionFromStorageOrConfig() {
		const defaultPanelPosition = this.configurationService.getValue<string>(Workbench.defaultPanelPositionStorageKey);
		const panelPosition = this.storageService.get(Workbench.panelPositionStorageKey, StorageScope.WORKSPACE, defaultPanelPosition);
		this.panelPosition = (panelPosition === 'right') ? Position.RIGHT : Position.BOTTOM;
	}

E
Erich Gamma 已提交
866 867 868
	/**
	 * Returns whether the workbench has been started.
	 */
869
	isStarted(): boolean {
E
Erich Gamma 已提交
870 871 872 873 874 875
		return this.workbenchStarted && !this.workbenchShutdown;
	}

	/**
	 * Returns whether the workbench has been fully created.
	 */
876
	isCreated(): boolean {
E
Erich Gamma 已提交
877 878 879
		return this.workbenchCreated && this.workbenchStarted;
	}

880
	hasFocus(part: Parts): boolean {
B
Benjamin Pasero 已提交
881
		const activeElement = document.activeElement;
E
Erich Gamma 已提交
882 883 884 885
		if (!activeElement) {
			return false;
		}

886 887 888 889
		const container = this.getContainer(part);
		return DOM.isAncestor(activeElement, container);
	}

890
	getContainer(part: Parts): HTMLElement {
891
		let container: HTMLElement = null;
E
Erich Gamma 已提交
892
		switch (part) {
B
Benjamin Pasero 已提交
893 894 895
			case Parts.TITLEBAR_PART:
				container = this.titlebarPart.getContainer();
				break;
E
Erich Gamma 已提交
896 897 898 899 900 901
			case Parts.ACTIVITYBAR_PART:
				container = this.activitybarPart.getContainer();
				break;
			case Parts.SIDEBAR_PART:
				container = this.sidebarPart.getContainer();
				break;
I
isidor 已提交
902 903 904
			case Parts.PANEL_PART:
				container = this.panelPart.getContainer();
				break;
E
Erich Gamma 已提交
905 906 907 908 909 910 911
			case Parts.EDITOR_PART:
				container = this.editorPart.getContainer();
				break;
			case Parts.STATUSBAR_PART:
				container = this.statusbarPart.getContainer();
				break;
		}
912 913

		return container;
E
Erich Gamma 已提交
914 915
	}

916
	isVisible(part: Parts): boolean {
B
Benjamin Pasero 已提交
917
		switch (part) {
B
Benjamin Pasero 已提交
918
			case Parts.TITLEBAR_PART:
919
				return this.getCustomTitleBarStyle() && !browser.isFullscreen();
B
Benjamin Pasero 已提交
920
			case Parts.SIDEBAR_PART:
921
				return !this.sideBarHidden;
B
Benjamin Pasero 已提交
922
			case Parts.PANEL_PART:
923
				return !this.panelHidden;
B
Benjamin Pasero 已提交
924
			case Parts.STATUSBAR_PART:
925
				return !this.statusBarHidden;
S
Sanders Lauture 已提交
926
			case Parts.ACTIVITYBAR_PART:
927
				return !this.activityBarHidden;
928
		}
E
Erich Gamma 已提交
929 930 931 932

		return true; // any other part cannot be hidden
	}

933
	getTitleBarOffset(): number {
934
		let offset = 0;
935
		if (this.isVisible(Parts.TITLEBAR_PART)) {
936 937 938 939 940 941
			offset = 22 / browser.getZoomFactor(); // adjust the position based on title bar size and zoom factor
		}

		return offset;
	}

942
	private getCustomTitleBarStyle(): 'custom' {
B
Benjamin Pasero 已提交
943
		if (!isMacintosh) {
944
			return null; // custom title bar is only supported on Mac currently
B
Benjamin Pasero 已提交
945 946
		}

947
		const isDev = !this.environmentService.isBuilt || this.environmentService.isExtensionDevelopment;
B
Benjamin Pasero 已提交
948
		if (isDev) {
949
			return null; // not enabled when developing due to https://github.com/electron/electron/issues/3647
B
Benjamin Pasero 已提交
950 951
		}

952
		const windowConfig = this.configurationService.getValue<IWindowSettings>();
953 954 955 956 957
		if (windowConfig && windowConfig.window) {
			const useNativeTabs = windowConfig.window.nativeTabs;
			if (useNativeTabs) {
				return null; // native tabs on sierra do not work with custom title style
			}
B
Benjamin Pasero 已提交
958

959 960 961 962
			const style = windowConfig.window.titleBarStyle;
			if (style === 'custom') {
				return style;
			}
963 964 965
		}

		return null;
B
Benjamin Pasero 已提交
966 967
	}

968
	private setStatusBarHidden(hidden: boolean, skipLayout?: boolean): void {
969 970
		this.statusBarHidden = hidden;

971 972 973 974 975 976
		// Adjust CSS
		if (hidden) {
			this.workbench.addClass('nostatusbar');
		} else {
			this.workbench.removeClass('nostatusbar');
		}
I
isidor 已提交
977

978 979
		// Layout
		if (!skipLayout) {
980
			this.workbenchLayout.layout();
981 982 983
		}
	}

984
	setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void {
S
Sanders Lauture 已提交
985 986 987 988
		this.activityBarHidden = hidden;

		// Layout
		if (!skipLayout) {
989
			this.workbenchLayout.layout();
S
Sanders Lauture 已提交
990 991 992
		}
	}

993
	setSideBarHidden(hidden: boolean, skipLayout?: boolean): TPromise<void> {
E
Erich Gamma 已提交
994
		this.sideBarHidden = hidden;
995
		this.sideBarVisibleContext.set(!hidden);
E
Erich Gamma 已提交
996 997 998 999 1000 1001 1002 1003

		// Adjust CSS
		if (hidden) {
			this.workbench.addClass('nosidebar');
		} else {
			this.workbench.removeClass('nosidebar');
		}

B
Benjamin Pasero 已提交
1004
		// If sidebar becomes hidden, also hide the current active Viewlet if any
1005
		let promise = TPromise.wrap<any>(null);
E
Erich Gamma 已提交
1006
		if (hidden && this.sidebarPart.getActiveViewlet()) {
1007
			promise = this.sidebarPart.hideActiveViewlet().then(() => {
1008
				const activeEditor = this.nextEditorService.activeControl;
1009
				const activePanel = this.panelPart.getActivePanel();
B
Benjamin Pasero 已提交
1010

1011 1012 1013 1014 1015 1016 1017
				// Pass Focus to Editor or Panel if Sidebar is now hidden
				if (this.hasFocus(Parts.PANEL_PART) && activePanel) {
					activePanel.focus();
				} else if (activeEditor) {
					activeEditor.focus();
				}
			});
E
Erich Gamma 已提交
1018 1019
		}

B
Benjamin Pasero 已提交
1020
		// If sidebar becomes visible, show last active Viewlet or default viewlet
E
Erich Gamma 已提交
1021
		else if (!hidden && !this.sidebarPart.getActiveViewlet()) {
1022
			const viewletToOpen = this.sidebarPart.getLastActiveViewletId();
E
Erich Gamma 已提交
1023
			if (viewletToOpen) {
1024
				promise = this.sidebarPart.openViewlet(viewletToOpen, true);
E
Erich Gamma 已提交
1025 1026 1027
			}
		}

1028
		return promise.then(() => {
1029

1030
			// Remember in settings
1031
			const defaultHidden = this.contextService.getWorkbenchState() === WorkbenchState.EMPTY;
1032
			if (hidden !== defaultHidden) {
I
isidor 已提交
1033
				this.storageService.store(Workbench.sidebarHiddenStorageKey, hidden ? 'true' : 'false', StorageScope.WORKSPACE);
1034
			} else {
I
isidor 已提交
1035
				this.storageService.remove(Workbench.sidebarHiddenStorageKey, StorageScope.WORKSPACE);
1036
			}
1037 1038 1039

			// Layout
			if (!skipLayout) {
1040
				this.workbenchLayout.layout();
1041 1042
			}
		});
E
Erich Gamma 已提交
1043 1044
	}

1045
	setPanelHidden(hidden: boolean, skipLayout?: boolean): TPromise<void> {
I
isidor 已提交
1046
		this.panelHidden = hidden;
I
isidor 已提交
1047

1048 1049 1050 1051 1052 1053 1054
		// Adjust CSS
		if (hidden) {
			this.workbench.addClass('nopanel');
		} else {
			this.workbench.removeClass('nopanel');
		}

I
isidor 已提交
1055
		// If panel part becomes hidden, also hide the current active panel if any
1056
		let promise = TPromise.wrap<any>(null);
I
isidor 已提交
1057
		if (hidden && this.panelPart.getActivePanel()) {
1058
			promise = this.panelPart.hideActivePanel().then(() => {
1059

1060
				// Pass Focus to Editor if Panel part is now hidden
1061
				const editor = this.nextEditorService.activeControl;
1062 1063 1064 1065
				if (editor) {
					editor.focus();
				}
			});
I
isidor 已提交
1066 1067 1068 1069
		}

		// If panel part becomes visible, show last active panel or default panel
		else if (!hidden && !this.panelPart.getActivePanel()) {
1070
			const panelToOpen = this.panelPart.getLastActivePanelId();
I
isidor 已提交
1071
			if (panelToOpen) {
1072
				promise = this.panelPart.openPanel(panelToOpen, true);
I
isidor 已提交
1073 1074 1075
			}
		}

1076
		return promise.then(() => {
1077

1078
			// Remember in settings
1079
			if (!hidden) {
I
isidor 已提交
1080
				this.storageService.store(Workbench.panelHiddenStorageKey, 'false', StorageScope.WORKSPACE);
1081
			} else {
I
isidor 已提交
1082
				this.storageService.remove(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE);
1083
			}
1084 1085 1086

			// Layout
			if (!skipLayout) {
1087
				this.workbenchLayout.layout();
1088 1089
			}
		});
I
isidor 已提交
1090 1091
	}

1092
	toggleMaximizedPanel(): void {
I
isidor 已提交
1093
		this.workbenchLayout.layout({ toggleMaximizedPanel: true, source: Parts.PANEL_PART });
1094 1095
	}

1096
	isPanelMaximized(): boolean {
1097 1098 1099
		return this.workbenchLayout.isPanelMaximized();
	}

1100
	getSideBarPosition(): Position {
E
Erich Gamma 已提交
1101 1102 1103
		return this.sideBarPosition;
	}

1104
	setSideBarPosition(position: Position): void {
E
Erich Gamma 已提交
1105
		if (this.sideBarHidden) {
1106
			this.setSideBarHidden(false, true /* Skip Layout */).done(void 0, errors.onUnexpectedError);
E
Erich Gamma 已提交
1107 1108
		}

B
Benjamin Pasero 已提交
1109 1110
		const newPositionValue = (position === Position.LEFT) ? 'left' : 'right';
		const oldPositionValue = (this.sideBarPosition === Position.LEFT) ? 'left' : 'right';
E
Erich Gamma 已提交
1111 1112 1113
		this.sideBarPosition = position;

		// Adjust CSS
1114 1115 1116 1117
		DOM.removeClass(this.activitybarPart.getContainer(), oldPositionValue);
		DOM.removeClass(this.sidebarPart.getContainer(), oldPositionValue);
		DOM.addClass(this.activitybarPart.getContainer(), newPositionValue);
		DOM.addClass(this.sidebarPart.getContainer(), newPositionValue);
E
Erich Gamma 已提交
1118

1119 1120 1121 1122
		// Update Styles
		this.activitybarPart.updateStyles();
		this.sidebarPart.updateStyles();

E
Erich Gamma 已提交
1123
		// Layout
1124
		this.workbenchLayout.layout();
E
Erich Gamma 已提交
1125 1126
	}

1127
	getPanelPosition(): Position {
I
isidor 已提交
1128 1129 1130
		return this.panelPosition;
	}

1131
	setPanelPosition(position: Position): TPromise<void> {
I
isidor 已提交
1132 1133 1134 1135 1136
		return (this.panelHidden ? this.setPanelHidden(false, true /* Skip Layout */) : TPromise.as(undefined)).then(() => {
			const newPositionValue = (position === Position.BOTTOM) ? 'bottom' : 'right';
			const oldPositionValue = (this.panelPosition === Position.BOTTOM) ? 'bottom' : 'right';
			this.panelPosition = position;
			this.storageService.store(Workbench.panelPositionStorageKey, Position[this.panelPosition].toLowerCase(), StorageScope.WORKSPACE);
I
isidor 已提交
1137

I
isidor 已提交
1138
			// Adjust CSS
1139 1140
			DOM.removeClass(this.panelPart.getContainer(), oldPositionValue);
			DOM.addClass(this.panelPart.getContainer(), newPositionValue);
I
isidor 已提交
1141

I
isidor 已提交
1142 1143
			// Update Styles
			this.panelPart.updateStyles();
I
isidor 已提交
1144

I
isidor 已提交
1145 1146 1147
			// Layout
			this.workbenchLayout.layout();
		});
I
isidor 已提交
1148 1149
	}

1150
	private setFontAliasing(aliasing: FontAliasingOption) {
1151
		this.fontAliasing = aliasing;
B
Benjamin Pasero 已提交
1152 1153 1154 1155 1156 1157

		// Remove all
		document.body.classList.remove(...fontAliasingValues.map(value => `monaco-font-aliasing-${value}`));

		// Add specific
		if (fontAliasingValues.some(option => option === aliasing)) {
1158 1159
			document.body.classList.add(`monaco-font-aliasing-${aliasing}`);
		}
1160 1161
	}

1162
	layout(options?: ILayoutOptions): void {
1163 1164 1165
		if (this.isStarted()) {
			this.workbenchLayout.layout(options);
		}
E
Erich Gamma 已提交
1166 1167 1168
	}

	private createWorkbenchLayout(): void {
1169 1170
		this.workbenchLayout = this.instantiationService.createInstance(
			WorkbenchLayout,
1171 1172
			this.container,								// Parent
			this.workbench.getHTMLElement(),			// Workbench Container
I
isidor 已提交
1173
			{
B
Benjamin Pasero 已提交
1174
				titlebar: this.titlebarPart,			// Title Bar
I
isidor 已提交
1175 1176 1177 1178 1179 1180
				activitybar: this.activitybarPart,		// Activity Bar
				editor: this.editorPart,				// Editor
				sidebar: this.sidebarPart,				// Sidebar
				panel: this.panelPart,					// Panel Part
				statusbar: this.statusbarPart,			// Statusbar
			},
1181
			this.quickOpen,								// Quickopen
C
Christof Marti 已提交
1182
			this.quickInput,							// QuickInput
1183 1184
			this.notificationsCenter,					// Notifications Center
			this.notificationsToasts					// Notifications Toasts
E
Erich Gamma 已提交
1185 1186 1187 1188 1189 1190 1191 1192 1193
		);
	}

	private renderWorkbench(): void {

		// Apply sidebar state as CSS class
		if (this.sideBarHidden) {
			this.workbench.addClass('nosidebar');
		}
1194 1195 1196
		if (this.panelHidden) {
			this.workbench.addClass('nopanel');
		}
1197 1198 1199
		if (this.statusBarHidden) {
			this.workbench.addClass('nostatusbar');
		}
E
Erich Gamma 已提交
1200

B
Benjamin Pasero 已提交
1201
		// Apply font aliasing
1202 1203
		this.setFontAliasing(this.fontAliasing);

B
Benjamin Pasero 已提交
1204
		// Apply title style if shown
1205 1206 1207 1208 1209 1210 1211 1212
		const titleStyle = this.getCustomTitleBarStyle();
		if (titleStyle) {
			DOM.addClass(this.parent, `titlebar-style-${titleStyle}`);
		}

		// Apply fullscreen state
		if (browser.isFullscreen()) {
			this.workbench.addClass('fullscreen');
B
Benjamin Pasero 已提交
1213 1214
		}

E
Erich Gamma 已提交
1215
		// Create Parts
B
Benjamin Pasero 已提交
1216
		this.createTitlebarPart();
E
Erich Gamma 已提交
1217 1218 1219
		this.createActivityBarPart();
		this.createSidebarPart();
		this.createEditorPart();
1220
		this.createPanelPart();
E
Erich Gamma 已提交
1221 1222
		this.createStatusbarPart();

1223 1224
		// Notification Handlers
		this.createNotificationsHandlers();
1225

E
Erich Gamma 已提交
1226 1227 1228 1229
		// Add Workbench to DOM
		this.workbenchContainer.build(this.container);
	}

B
Benjamin Pasero 已提交
1230 1231 1232 1233 1234 1235 1236
	private createTitlebarPart(): void {
		const titlebarContainer = $(this.workbench).div({
			'class': ['part', 'titlebar'],
			id: Identifiers.TITLEBAR_PART,
			role: 'contentinfo'
		});

1237
		this.titlebarPart.create(titlebarContainer.getHTMLElement());
B
Benjamin Pasero 已提交
1238 1239
	}

E
Erich Gamma 已提交
1240
	private createActivityBarPart(): void {
B
Benjamin Pasero 已提交
1241
		const activitybarPartContainer = $(this.workbench)
E
Erich Gamma 已提交
1242 1243
			.div({
				'class': ['part', 'activitybar', this.sideBarPosition === Position.LEFT ? 'left' : 'right'],
1244 1245
				id: Identifiers.ACTIVITYBAR_PART,
				role: 'navigation'
E
Erich Gamma 已提交
1246 1247
			});

1248
		this.activitybarPart.create(activitybarPartContainer.getHTMLElement());
E
Erich Gamma 已提交
1249 1250 1251
	}

	private createSidebarPart(): void {
B
Benjamin Pasero 已提交
1252
		const sidebarPartContainer = $(this.workbench)
E
Erich Gamma 已提交
1253 1254
			.div({
				'class': ['part', 'sidebar', this.sideBarPosition === Position.LEFT ? 'left' : 'right'],
1255 1256
				id: Identifiers.SIDEBAR_PART,
				role: 'complementary'
E
Erich Gamma 已提交
1257 1258
			});

1259
		this.sidebarPart.create(sidebarPartContainer.getHTMLElement());
E
Erich Gamma 已提交
1260 1261
	}

I
isidor 已提交
1262
	private createPanelPart(): void {
B
Benjamin Pasero 已提交
1263
		const panelPartContainer = $(this.workbench)
I
isidor 已提交
1264
			.div({
1265
				'class': ['part', 'panel', this.panelPosition === Position.BOTTOM ? 'bottom' : 'right'],
1266 1267
				id: Identifiers.PANEL_PART,
				role: 'complementary'
I
isidor 已提交
1268 1269
			});

1270
		this.panelPart.create(panelPartContainer.getHTMLElement());
I
isidor 已提交
1271 1272
	}

E
Erich Gamma 已提交
1273
	private createEditorPart(): void {
B
Benjamin Pasero 已提交
1274
		const editorContainer = $(this.workbench)
E
Erich Gamma 已提交
1275
			.div({
1276
				'class': ['part', 'editor'],
1277 1278
				id: Identifiers.EDITOR_PART,
				role: 'main'
E
Erich Gamma 已提交
1279 1280
			});

1281
		this.editorPart.create(editorContainer.getHTMLElement());
E
Erich Gamma 已提交
1282 1283 1284
	}

	private createStatusbarPart(): void {
B
Benjamin Pasero 已提交
1285
		const statusbarContainer = $(this.workbench).div({
E
Erich Gamma 已提交
1286
			'class': ['part', 'statusbar'],
1287 1288
			id: Identifiers.STATUSBAR_PART,
			role: 'contentinfo'
E
Erich Gamma 已提交
1289 1290
		});

1291
		this.statusbarPart.create(statusbarContainer.getHTMLElement());
E
Erich Gamma 已提交
1292 1293
	}

1294 1295
	private createNotificationsHandlers(): void {

1296
		// Notifications Center
1297
		this.notificationsCenter = this._register(this.instantiationService.createInstance(NotificationsCenter, this.workbench.getHTMLElement(), this.notificationService.model));
1298

1299
		// Notifications Toasts
1300
		this.notificationsToasts = this._register(this.instantiationService.createInstance(NotificationsToasts, this.workbench.getHTMLElement(), this.notificationService.model));
1301

1302
		// Notifications Alerts
1303
		this._register(this.instantiationService.createInstance(NotificationsAlerts, this.notificationService.model));
1304 1305 1306 1307

		// Notifications Status
		const notificationsStatus = this.instantiationService.createInstance(NotificationsStatus, this.notificationService.model);

1308
		// Eventing
1309
		this._register(this.notificationsCenter.onDidChangeVisibility(() => {
1310 1311 1312 1313 1314 1315 1316 1317

			// Update status
			notificationsStatus.update(this.notificationsCenter.isVisible);

			// Update toasts
			this.notificationsToasts.update(this.notificationsCenter.isVisible);
		}));

1318
		// Register Commands
1319
		registerNotificationCommands(this.notificationsCenter, this.notificationsToasts);
1320 1321
	}

1322
	getInstantiationService(): IInstantiationService {
E
Erich Gamma 已提交
1323 1324 1325
		return this.instantiationService;
	}

1326
	getWorkbenchElementId(): string {
1327 1328
		return Identifiers.WORKBENCH_CONTAINER;
	}
1329

1330
	toggleZenMode(skipLayout?: boolean): void {
I
isidor 已提交
1331
		this.zenMode.active = !this.zenMode.active;
1332
		this.zenMode.transitionDisposeables = dispose(this.zenMode.transitionDisposeables);
1333

1334 1335
		// Check if zen mode transitioned to full screen and if now we are out of zen mode
		// -> we need to go out of full screen (same goes for the centered editor layout)
1336
		let toggleFullScreen = false;
1337 1338

		// Zen Mode Active
I
isidor 已提交
1339
		if (this.zenMode.active) {
1340
			const config = this.configurationService.getValue<IZenModeSettings>('zenMode');
1341

I
isidor 已提交
1342
			toggleFullScreen = !browser.isFullscreen() && config.fullScreen;
I
isidor 已提交
1343
			this.zenMode.transitionedToFullScreen = toggleFullScreen;
1344
			this.zenMode.transitionedToCenteredEditorLayout = !this.isEditorLayoutCentered() && config.centerLayout;
1345 1346
			this.zenMode.wasSideBarVisible = this.isVisible(Parts.SIDEBAR_PART);
			this.zenMode.wasPanelVisible = this.isVisible(Parts.PANEL_PART);
1347

1348 1349
			this.setPanelHidden(true, true).done(void 0, errors.onUnexpectedError);
			this.setSideBarHidden(true, true).done(void 0, errors.onUnexpectedError);
I
isidor 已提交
1350

1351 1352 1353
			if (config.hideActivityBar) {
				this.setActivityBarHidden(true, true);
			}
1354

I
isidor 已提交
1355
			if (config.hideStatusBar) {
I
isidor 已提交
1356 1357
				this.setStatusBarHidden(true, true);
			}
1358

1359 1360
			if (config.hideTabs && this.editorPart.partOptions.showTabs) {
				this.zenMode.transitionDisposeables.push(this.editorPart.enforcePartOptions({ showTabs: false }));
I
isidor 已提交
1361
			}
1362 1363 1364 1365

			if (config.centerLayout) {
				this.centerEditorLayout(true, true);
			}
1366 1367 1368 1369
		}

		// Zen Mode Inactive
		else {
1370
			if (this.zenMode.wasPanelVisible) {
1371
				this.setPanelHidden(false, true).done(void 0, errors.onUnexpectedError);
1372
			}
1373

1374
			if (this.zenMode.wasSideBarVisible) {
1375
				this.setSideBarHidden(false, true).done(void 0, errors.onUnexpectedError);
1376
			}
1377

1378 1379 1380
			if (this.zenMode.transitionedToCenteredEditorLayout) {
				this.centerEditorLayout(false, true);
			}
1381

1382 1383
			// Status bar and activity bar visibility come from settings -> update their visibility.
			this.onDidUpdateConfiguration(true);
1384 1385

			const activeEditor = this.nextEditorService.activeControl;
I
isidor 已提交
1386 1387 1388
			if (activeEditor) {
				activeEditor.focus();
			}
1389

1390
			toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
I
isidor 已提交
1391
		}
1392

1393
		this.inZenMode.set(this.zenMode.active);
I
isidor 已提交
1394

I
isidor 已提交
1395
		if (!skipLayout) {
1396
			this.layout();
I
isidor 已提交
1397
		}
1398

1399
		if (toggleFullScreen) {
1400
			this.windowService.toggleFullScreen().done(void 0, errors.onUnexpectedError);
1401
		}
I
isidor 已提交
1402 1403
	}

1404
	isEditorLayoutCentered(): boolean {
B
Benjamin Pasero 已提交
1405
		return this.centeredEditorLayoutActive;
S
SrTobi 已提交
1406 1407
	}

1408
	centerEditorLayout(active: boolean, skipLayout?: boolean): void {
1409
		this.centeredEditorLayoutActive = active;
B
Benjamin Pasero 已提交
1410 1411
		this.storageService.store(Workbench.centeredEditorLayoutActiveStorageKey, this.centeredEditorLayoutActive, StorageScope.GLOBAL);

1412 1413 1414
		if (!skipLayout) {
			this.layout();
		}
S
SrTobi 已提交
1415 1416
	}

1417
	resizePart(part: Parts, sizeChange: number): void {
1418 1419 1420 1421 1422 1423 1424
		switch (part) {
			case Parts.SIDEBAR_PART:
			case Parts.PANEL_PART:
			case Parts.EDITOR_PART:
				this.workbenchLayout.resizePart(part, sizeChange);
				break;
			default:
B
Benjamin Pasero 已提交
1425
				return; // Cannot resize other parts
1426 1427 1428
		}
	}

1429 1430
	dispose(reason = ShutdownReason.QUIT): void {
		super.dispose();
1431

1432 1433 1434
		// Restore sidebar if we are being shutdown as a matter of a reload
		if (reason === ShutdownReason.RELOAD) {
			this.storageService.store(Workbench.sidebarRestoreStorageKey, 'true', StorageScope.WORKSPACE);
1435 1436
		}

1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
		// Preserve zen mode only on reload. Real quit gets out of zen mode so novice users do not get stuck in zen mode.
		const zenConfig = this.configurationService.getValue<IZenModeSettings>('zenMode');
		const restoreZenMode = this.zenMode.active && (zenConfig.restore || reason === ShutdownReason.RELOAD);
		if (restoreZenMode) {
			this.storageService.store(Workbench.zenModeActiveStorageKey, true, StorageScope.WORKSPACE);
		} else {
			if (this.zenMode.active) {
				this.toggleZenMode(true);
			}
			this.storageService.remove(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE);
1447 1448
		}

1449 1450
		// Pass shutdown on to each participant
		this.workbenchShutdown = true;
1451
	}
J
Johannes Rieken 已提交
1452
}