workbench.ts 57.5 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 } 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 { Delayer, 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 } 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';
J
Johannes Rieken 已提交
52
import { ContextKeyExpr, 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 98
import { domEvent } from 'vs/base/browser/event';
import { InputFocusedContext } from 'vs/platform/workbench/common/contextkeys';
99
import { IViewsService } from 'vs/workbench/common/views';
S
Sandeep Somavarapu 已提交
100
import { CustomViewsService } from 'vs/workbench/browser/parts/views/customView';
101 102
import { INotificationService } from 'vs/platform/notification/common/notification';
import { NotificationService } from 'vs/workbench/services/notification/common/notificationService';
103 104
import { NotificationsCenter } from 'vs/workbench/browser/parts/notifications/notificationsCenter';
import { NotificationsAlerts } from 'vs/workbench/browser/parts/notifications/notificationsAlerts';
105
import { NotificationsStatus } from 'vs/workbench/browser/parts/notifications/notificationsStatus';
106
import { registerNotificationCommands } from 'vs/workbench/browser/parts/notifications/notificationsCommands';
107
import { NotificationsToasts } from 'vs/workbench/browser/parts/notifications/notificationsToasts';
J
Joao Moreno 已提交
108 109
import { IPCClient } from 'vs/base/parts/ipc/common/ipc';
import { registerWindowDriver } from 'vs/platform/driver/electron-browser/driver';
S
Sandeep Somavarapu 已提交
110 111
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { PreferencesService } from 'vs/workbench/services/preferences/browser/preferencesService';
112
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
113
import { NextEditorPart } from 'vs/workbench/browser/parts/editor2/nextEditorPart';
114
import { INextEditorGroupsService } from 'vs/workbench/services/editor/common/nextEditorGroupsService';
115
import { NextEditorService } from 'vs/workbench/services/editor/browser/nextEditorService';
J
Joao Moreno 已提交
116
import { IExtensionUrlHandler, ExtensionUrlHandler } from 'vs/platform/url/electron-browser/inactiveExtensionUrlHandler';
117

A
Alex Dima 已提交
118
export const EditorsVisibleContext = new RawContextKey<boolean>('editorIsOpen', false);
I
isidor 已提交
119
export const InZenModeContext = new RawContextKey<boolean>('inZenMode', false);
120
export const SidebarVisibleContext = new RawContextKey<boolean>('sidebarVisible', false);
J
Johannes Rieken 已提交
121
export const NoEditorsVisibleContext: ContextKeyExpr = EditorsVisibleContext.toNegated();
A
Alex Dima 已提交
122

E
Erich Gamma 已提交
123
interface WorkbenchParams {
124
	configuration: IWindowConfiguration;
125
	serviceCollection: ServiceCollection;
E
Erich Gamma 已提交
126 127
}

I
isidor 已提交
128 129
interface IZenModeSettings {
	fullScreen: boolean;
130
	centerLayout: boolean;
I
isidor 已提交
131
	hideTabs: boolean;
132
	hideActivityBar: boolean;
I
isidor 已提交
133
	hideStatusBar: boolean;
I
isidor 已提交
134
	restore: boolean;
I
isidor 已提交
135 136
}

137 138 139
export interface IWorkbenchStartedInfo {
	customKeybindingsCount: number;
	pinnedViewlets: string[];
140 141
	restoredViewlet: string;
	restoredEditors: string[];
142 143
}

144 145
type FontAliasingOption = 'default' | 'antialiased' | 'none' | 'auto';

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

148 149
const Identifiers = {
	WORKBENCH_CONTAINER: 'workbench.main.container',
B
Benjamin Pasero 已提交
150
	TITLEBAR_PART: 'workbench.parts.titlebar',
151 152 153 154 155 156 157
	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 已提交
158 159 160 161 162 163 164 165
function getWorkbenchStateString(state: WorkbenchState): string {
	switch (state) {
		case WorkbenchState.EMPTY: return 'empty';
		case WorkbenchState.FOLDER: return 'folder';
		case WorkbenchState.WORKSPACE: return 'workspace';
	}
}

E
Erich Gamma 已提交
166
/**
B
Benjamin Pasero 已提交
167
 * The workbench creates and lays out all parts that make up the workbench.
E
Erich Gamma 已提交
168 169 170
 */
export class Workbench implements IPartService {

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';
E
Erich Gamma 已提交
178

179 180 181
	private static readonly sidebarPositionConfigurationKey = 'workbench.sideBar.location';
	private static readonly statusbarVisibleConfigurationKey = 'workbench.statusBar.visible';
	private static readonly activityBarVisibleConfigurationKey = 'workbench.activityBar.visible';
182

183
	private static readonly closeWhenEmptyConfigurationKey = 'window.closeWhenEmpty';
184

185
	private static readonly fontAliasingConfigurationKey = 'workbench.fontAliasing';
186

M
Matt Bierner 已提交
187
	private readonly _onTitleBarVisibilityChange: Emitter<void>;
188

189
	public _serviceBrand: any;
E
Erich Gamma 已提交
190

B
Benjamin Pasero 已提交
191
	private parent: HTMLElement;
E
Erich Gamma 已提交
192 193 194 195 196 197
	private container: HTMLElement;
	private workbenchParams: WorkbenchParams;
	private workbenchContainer: Builder;
	private workbench: Builder;
	private workbenchStarted: boolean;
	private workbenchCreated: boolean;
198 199
	private editorService: IWorkbenchEditorService;
	private editorGroupService: IEditorGroupService;
E
Erich Gamma 已提交
200
	private workbenchShutdown: boolean;
P
Pine Wu 已提交
201
	private viewletService: IViewletService;
202
	private contextKeyService: IContextKeyService;
203
	private keybindingService: IKeybindingService;
204
	private backupFileService: IBackupFileService;
205
	private fileService: IFileService;
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;
C
Christof Marti 已提交
214
	private quickInput: QuickInputService;
215
	private notificationsCenter: NotificationsCenter;
216
	private notificationsToasts: NotificationsToasts;
E
Erich Gamma 已提交
217
	private workbenchLayout: WorkbenchLayout;
218
	private toUnbind: IDisposable[];
E
Erich Gamma 已提交
219
	private sideBarHidden: boolean;
220
	private statusBarHidden: boolean;
S
Sanders Lauture 已提交
221
	private activityBarHidden: boolean;
E
Erich Gamma 已提交
222
	private sideBarPosition: Position;
I
isidor 已提交
223
	private panelPosition: Position;
I
isidor 已提交
224
	private panelHidden: boolean;
225
	private editorBackgroundDelayer: Delayer<any>;
226
	private closeEmptyWindowScheduler: RunOnceScheduler;
A
Alex Dima 已提交
227
	private editorsVisibleContext: IContextKey<boolean>;
I
isidor 已提交
228
	private inZenMode: IContextKey<boolean>;
229
	private sideBarVisibleContext: IContextKey<boolean>;
230
	private hasFilesToCreateOpenOrDiff: boolean;
231
	private fontAliasing: FontAliasingOption;
B
Benjamin Pasero 已提交
232
	private centeredEditorLayoutActive: boolean;
I
isidor 已提交
233
	private zenMode: {
I
isidor 已提交
234 235
		active: boolean;
		transitionedToFullScreen: boolean;
236
		transitionedToCenteredEditorLayout: boolean;
237 238
		wasSideBarVisible: boolean;
		wasPanelVisible: boolean;
I
isidor 已提交
239
	};
E
Erich Gamma 已提交
240

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

		this.workbenchParams = {
260
			configuration,
261
			serviceCollection
E
Erich Gamma 已提交
262 263
		};

264
		this.hasFilesToCreateOpenOrDiff =
B
Benjamin Pasero 已提交
265 266 267
			(configuration.filesToCreate && configuration.filesToCreate.length > 0) ||
			(configuration.filesToOpen && configuration.filesToOpen.length > 0) ||
			(configuration.filesToDiff && configuration.filesToDiff.length > 0);
268

269
		this.toUnbind = [];
270

E
Erich Gamma 已提交
271
		this.editorBackgroundDelayer = new Delayer<void>(50);
272
		this.closeEmptyWindowScheduler = new RunOnceScheduler(() => this.onAllEditorsClosed(), 50);
E
Erich Gamma 已提交
273

274
		this._onTitleBarVisibilityChange = new Emitter<void>();
E
Erich Gamma 已提交
275 276
	}

277 278 279 280
	public get onTitleBarVisibilityChange(): Event<void> {
		return this._onTitleBarVisibilityChange.event;
	}

281
	public get onEditorLayout(): Event<IDimension> {
282
		return this.editorPart.onDidLayout;
283 284
	}

E
Erich Gamma 已提交
285 286 287 288
	/**
	 * Starts the workbench and creates the HTML elements on the container. A workbench can only be started
	 * once. Use the shutdown function to free up resources created by the workbench on startup.
	 */
B
Benjamin Pasero 已提交
289
	public startup(): TPromise<IWorkbenchStartedInfo> {
290
		this.workbenchStarted = true;
E
Erich Gamma 已提交
291

B
Benjamin Pasero 已提交
292
		// Create Workbench Container
293
		this.createWorkbench();
E
Erich Gamma 已提交
294

295 296
		// Install some global actions
		this.createGlobalActions();
297

298 299
		// Services
		this.initServices();
E
Erich Gamma 已提交
300

301 302 303 304
		// Contexts
		this.editorsVisibleContext = EditorsVisibleContext.bindTo(this.contextKeyService);
		this.inZenMode = InZenModeContext.bindTo(this.contextKeyService);
		this.sideBarVisibleContext = SidebarVisibleContext.bindTo(this.contextKeyService);
E
Erich Gamma 已提交
305

J
Joao Moreno 已提交
306 307
		const inputFocused = InputFocusedContext.bindTo(this.contextKeyService);
		const onWindowsFocusIn = domEvent(window, 'focusin', true);
308
		onWindowsFocusIn(() => inputFocused.set(document.activeElement && (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA')), null, this.toUnbind);
J
Joao Moreno 已提交
309

J
Joao Moreno 已提交
310 311 312
		// Set workbench state context
		const WorkbenchStateContext = new RawContextKey<string>('workbenchState', getWorkbenchStateString(this.configurationService.getWorkbenchState()));
		const workbenchStateContext = WorkbenchStateContext.bindTo(this.contextKeyService);
J
Joao Moreno 已提交
313 314 315 316

		const WorkspaceFolderCountContext = new RawContextKey<number>('workspaceFolderCount', this.configurationService.getWorkspace().folders.length);
		const workspaceFolderCountContext = WorkspaceFolderCountContext.bindTo(this.contextKeyService);

317 318
		this.toUnbind.push(this.configurationService.onDidChangeWorkbenchState(() => workbenchStateContext.set(getWorkbenchStateString(this.configurationService.getWorkbenchState()))));
		this.toUnbind.push(this.configurationService.onDidChangeWorkspaceFolders(() => workspaceFolderCountContext.set(this.configurationService.getWorkspace().folders.length)));
J
Joao Moreno 已提交
319

320 321
		// Register Listeners
		this.registerListeners();
E
Erich Gamma 已提交
322

323 324
		// Settings
		this.initSettings();
E
Erich Gamma 已提交
325

326 327
		// Create Workbench and Parts
		this.renderWorkbench();
328

329 330
		// Workbench Layout
		this.createWorkbenchLayout();
B
polish  
Benjamin Pasero 已提交
331

J
Joao Moreno 已提交
332 333 334 335 336 337
		// Driver
		if (this.environmentService.driverHandle) {
			registerWindowDriver(this.mainProcessClient, this.configuration.windowId, this.instantiationService)
				.then(disposable => this.toUnbind.push(disposable));
		}

338
		// Restore Parts
B
Benjamin Pasero 已提交
339 340
		return this.restoreParts();
	}
341

B
Benjamin Pasero 已提交
342 343 344 345 346 347
	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);
348
	}
E
Erich Gamma 已提交
349

350 351 352 353
	private restoreParts(): TPromise<IWorkbenchStartedInfo> {
		const restorePromises: TPromise<any>[] = [];

		// Restore Editors
J
Johannes Rieken 已提交
354
		perf.mark('willRestoreEditors');
355 356 357 358 359 360
		const restoredEditors: string[] = [];
		restorePromises.push(this.resolveEditorsToOpen().then(inputs => {
			let editorOpenPromise: TPromise<IEditor[]>;
			if (inputs.length) {
				editorOpenPromise = this.editorService.openEditors(inputs.map(input => { return { input, position: EditorPosition.ONE }; }));
			} else {
361
				editorOpenPromise = this.noOpEditorPart.restoreEditors();
362 363
			}

B
Benjamin Pasero 已提交
364
			return editorOpenPromise.then(editors => {
365 366
				this.handleEditorBackground(); // make sure we show the proper background in the editor area

J
Johannes Rieken 已提交
367
				perf.mark('didRestoreEditors');
368

369 370 371 372 373 374
				for (const editor of editors) {
					if (editor) {
						if (editor.input) {
							restoredEditors.push(editor.input.getName());
						} else {
							restoredEditors.push(`other:${editor.getId()}`);
375 376
						}
					}
377
				}
B
Benjamin Pasero 已提交
378
			});
379
		}));
E
Erich Gamma 已提交
380

381 382 383 384
		// Restore Sidebar
		let viewletIdToRestore: string;
		if (!this.sideBarHidden) {
			this.sideBarVisibleContext.set(true);
I
isidor 已提交
385

386 387 388
			if (this.shouldRestoreLastOpenedViewlet()) {
				viewletIdToRestore = this.storageService.get(SidebarPart.activeViewletSettingsKey, StorageScope.WORKSPACE);
			}
389

390 391 392
			if (!viewletIdToRestore) {
				viewletIdToRestore = this.viewletService.getDefaultViewletId();
			}
393

J
Johannes Rieken 已提交
394
			perf.mark('willRestoreViewlet');
395
			restorePromises.push(this.viewletService.openViewlet(viewletIdToRestore).then(() => {
J
Johannes Rieken 已提交
396
				perf.mark('didRestoreViewlet');
397 398
			}));
		}
E
Erich Gamma 已提交
399

400 401 402 403 404 405
		// 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 已提交
406

407
		// Restore Zen Mode if active
I
isidor 已提交
408
		if (this.storageService.getBoolean(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE, false)) {
409
			this.toggleZenMode(true);
E
Erich Gamma 已提交
410
		}
411

B
Benjamin Pasero 已提交
412 413 414
		// Restore Forced Editor Center Mode
		if (this.storageService.getBoolean(Workbench.centeredEditorLayoutActiveStorageKey, StorageScope.GLOBAL, false)) {
			this.centeredEditorLayoutActive = true;
S
SrTobi 已提交
415 416
		}

417
		const onRestored = (error?: Error): IWorkbenchStartedInfo => {
B
Benjamin Pasero 已提交
418 419
			this.workbenchCreated = true;

420 421 422 423 424 425 426 427 428 429 430 431 432
			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 已提交
433 434
	}

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

B
Benjamin Pasero 已提交
438
		// Actions registered here to adjust for developing vs built workbench
439 440
		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 已提交
441
		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 已提交
442
		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"));
443
		workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ReloadWindowWithExtensionsDisabledAction, ReloadWindowWithExtensionsDisabledAction.ID, ReloadWindowWithExtensionsDisabledAction.LABEL), 'Reload Window Without Extensions');
444

445
		// Actions for macOS native tabs management (only when enabled)
446
		const windowConfig = this.configurationService.getValue<IWindowConfiguration>();
447 448 449 450 451 452 453
		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');
		}
454 455
	}

456
	private resolveEditorsToOpen(): TPromise<IResourceInputType[]> {
457
		const config = this.workbenchParams.configuration;
B
Benjamin Pasero 已提交
458 459

		// Files to open, diff or create
460
		if (this.hasFilesToCreateOpenOrDiff) {
B
Benjamin Pasero 已提交
461 462

			// Files to diff is exclusive
463
			const filesToDiff = this.toInputs(config.filesToDiff, false);
464
			if (filesToDiff && filesToDiff.length === 2) {
465 466 467 468 469
				return TPromise.as([<IResourceDiffInput>{
					leftResource: filesToDiff[0].resource,
					rightResource: filesToDiff[1].resource,
					options: { pinned: true }
				}]);
B
Benjamin Pasero 已提交
470 471
			}

472 473
			const filesToCreate = this.toInputs(config.filesToCreate, true);
			const filesToOpen = this.toInputs(config.filesToOpen, false);
474

475 476
			// Otherwise: Open/Create files
			return TPromise.as([...filesToOpen, ...filesToCreate]);
B
Benjamin Pasero 已提交
477 478
		}

479
		// Empty workbench
480
		else if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY && this.openUntitledFile()) {
481
			if (this.noOpEditorPart.hasEditorsToRestore()) {
482 483 484
				return TPromise.as([]); // do not open any empty untitled file if we have editors to restore
			}

485 486 487 488 489
			return this.backupFileService.hasBackups().then(hasBackups => {
				if (hasBackups) {
					return TPromise.as([]); // do not open any empty untitled file if we have backups to restore
				}

490
				return TPromise.as([<IUntitledResourceInput>{}]);
491
			});
B
Benjamin Pasero 已提交
492 493 494 495 496
		}

		return TPromise.as([]);
	}

497
	private toInputs(paths: IPath[], isNew: boolean): (IResourceInput | IUntitledResourceInput)[] {
B
Benjamin Pasero 已提交
498 499 500 501 502
		if (!paths || !paths.length) {
			return [];
		}

		return paths.map(p => {
503 504 505 506 507 508 509
			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 已提交
510

511
			if (!isNew && p.lineNumber) {
B
Benjamin Pasero 已提交
512 513 514 515 516 517 518 519 520 521
				input.options.selection = {
					startLineNumber: p.lineNumber,
					startColumn: p.columnNumber
				};
			}

			return input;
		});
	}

522
	private openUntitledFile() {
523
		const startupEditor = this.configurationService.inspect('workbench.startupEditor');
B
Benjamin Pasero 已提交
524 525

		// Fallback to previous workbench.welcome.enabled setting in case startupEditor is not defined
526
		if (!startupEditor.user && !startupEditor.workspace) {
527 528 529
			const welcomeEnabledValue = this.configurationService.getValue('workbench.welcome.enabled');
			if (typeof welcomeEnabledValue === 'boolean') {
				return !welcomeEnabledValue;
530 531
			}
		}
B
Benjamin Pasero 已提交
532

533
		return startupEditor.value === 'newUntitledFile';
534 535
	}

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

E
Erich Gamma 已提交
539
		// Services we contribute
540
		serviceCollection.set(IPartService, this);
E
Erich Gamma 已提交
541

542 543 544
		// Clipboard
		serviceCollection.set(IClipboardService, new ClipboardService());

545 546
		// Status bar
		this.statusbarPart = this.instantiationService.createInstance(StatusbarPart, Identifiers.STATUSBAR_PART);
547
		this.toUnbind.push(toDisposable(() => this.statusbarPart.shutdown()));
548 549
		serviceCollection.set(IStatusbarService, this.statusbarPart);

550 551 552
		// Progress 2
		serviceCollection.set(IProgressService2, new SyncDescriptor(ProgressService2));

553
		// Keybindings
A
Alex Dima 已提交
554
		this.contextKeyService = this.instantiationService.createInstance(ContextKeyService);
555
		serviceCollection.set(IContextKeyService, this.contextKeyService);
556

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

560 561 562
		// List
		serviceCollection.set(IListService, this.instantiationService.createInstance(ListService));

563
		// Context Menu
564
		serviceCollection.set(IContextMenuService, new SyncDescriptor(ContextMenuService));
565

566 567
		// Menus/Actions
		serviceCollection.set(IMenuService, new SyncDescriptor(MenuService));
568

P
Pine Wu 已提交
569
		// Sidebar part
570
		this.sidebarPart = this.instantiationService.createInstance(SidebarPart, Identifiers.SIDEBAR_PART);
571
		this.toUnbind.push(toDisposable(() => this.sidebarPart.shutdown()));
P
Pine Wu 已提交
572 573 574 575

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

I
isidor 已提交
577
		// Panel service (panel part)
578
		this.panelPart = this.instantiationService.createInstance(PanelPart, Identifiers.PANEL_PART);
579
		this.toUnbind.push(toDisposable(() => this.panelPart.shutdown()));
580
		serviceCollection.set(IPanelService, this.panelPart);
I
isidor 已提交
581

S
Sandeep Somavarapu 已提交
582 583
		// Custom views service
		const customViewsService = this.instantiationService.createInstance(CustomViewsService);
584
		serviceCollection.set(IViewsService, customViewsService);
S
Sandeep Somavarapu 已提交
585

E
Erich Gamma 已提交
586
		// Activity service (activitybar part)
587
		this.activitybarPart = this.instantiationService.createInstance(ActivitybarPart, Identifiers.ACTIVITYBAR_PART);
588
		this.toUnbind.push(toDisposable(() => this.activitybarPart.shutdown()));
I
isidor 已提交
589 590
		const activityService = this.instantiationService.createInstance(ActivityService, this.activitybarPart, this.panelPart);
		serviceCollection.set(IActivityService, activityService);
E
Erich Gamma 已提交
591

592 593 594
		// File Service
		this.fileService = this.instantiationService.createInstance(RemoteFileService);
		serviceCollection.set(IFileService, this.fileService);
S
#47154  
Sandeep Somavarapu 已提交
595
		this.configurationService.acquireFileService(this.fileService);
596

597 598
		// Editor service (next editor part)
		this.editorPart = this.instantiationService.createInstance(NextEditorPart, Identifiers.EDITOR_PART /*, !this.hasFilesToCreateOpenOrDiff*/);
599
		this.toUnbind.push(toDisposable(() => this.editorPart.shutdown()));
600
		serviceCollection.set(INextEditorGroupsService, this.editorPart);
601
		serviceCollection.set(INextEditorService, new SyncDescriptor(NextEditorService));
602 603 604 605 606

		// Legacy Editor Services
		this.noOpEditorPart = new NoOpEditorPart(this.instantiationService);
		this.editorService = this.instantiationService.createInstance(WorkbenchEditorService, this.noOpEditorPart);
		this.editorGroupService = this.noOpEditorPart;
607
		serviceCollection.set(IWorkbenchEditorService, this.editorService);
608
		serviceCollection.set(IEditorGroupService, this.noOpEditorPart);
E
Erich Gamma 已提交
609

610 611
		// Title bar
		this.titlebarPart = this.instantiationService.createInstance(TitlebarPart, Identifiers.TITLEBAR_PART);
612
		this.toUnbind.push(toDisposable(() => this.titlebarPart.shutdown()));
613 614
		serviceCollection.set(ITitleService, this.titlebarPart);

615
		// History
616
		serviceCollection.set(IHistoryService, new SyncDescriptor(HistoryService));
617

618
		// Backup File Service
619
		this.backupFileService = this.instantiationService.createInstance(BackupFileService, this.workbenchParams.configuration.backupPath);
620
		serviceCollection.set(IBackupFileService, this.backupFileService);
621

622
		// Text File Service
623
		serviceCollection.set(ITextFileService, new SyncDescriptor(TextFileService));
624

625
		// File Decorations
J
Johannes Rieken 已提交
626
		serviceCollection.set(IDecorationsService, new SyncDescriptor(FileDecorationsService));
627

J
Joao Moreno 已提交
628
		// SCM Service
629
		serviceCollection.set(ISCMService, new SyncDescriptor(SCMService));
630

J
Joao Moreno 已提交
631
		// Inactive extension URL handler
J
Joao Moreno 已提交
632
		serviceCollection.set(IExtensionUrlHandler, new SyncDescriptor(ExtensionUrlHandler));
J
Joao Moreno 已提交
633

B
Benjamin Pasero 已提交
634
		// Text Model Resolver Service
635
		serviceCollection.set(ITextModelService, new SyncDescriptor(TextModelResolverService));
B
Benjamin Pasero 已提交
636

637 638 639 640
		// JSON Editing
		const jsonEditingService = this.instantiationService.createInstance(JSONEditingService);
		serviceCollection.set(IJSONEditingService, jsonEditingService);

641 642 643
		// Workspace Editing
		serviceCollection.set(IWorkspaceEditingService, new SyncDescriptor(WorkspaceEditingService));

644 645 646
		// Keybinding Editing
		serviceCollection.set(IKeybindingEditingService, this.instantiationService.createInstance(KeybindingsEditingService));

647
		// Configuration Resolver
B
Benjamin Pasero 已提交
648
		serviceCollection.set(IConfigurationResolverService, new SyncDescriptor(ConfigurationResolverService, process.env));
649

E
Erich Gamma 已提交
650
		// Quick open service (quick open controller)
651
		this.quickOpen = this.instantiationService.createInstance(QuickOpenController);
652
		this.toUnbind.push(toDisposable(() => this.quickOpen.shutdown()));
653
		serviceCollection.set(IQuickOpenService, this.quickOpen);
654

C
Christof Marti 已提交
655 656
		// Quick input service
		this.quickInput = this.instantiationService.createInstance(QuickInputService);
657
		this.toUnbind.push(toDisposable(() => this.quickInput.shutdown()));
C
Christof Marti 已提交
658 659
		serviceCollection.set(IQuickInputService, this.quickInput);

S
Sandeep Somavarapu 已提交
660 661 662
		// PreferencesService
		serviceCollection.set(IPreferencesService, this.instantiationService.createInstance(PreferencesService));

B
polish  
Benjamin Pasero 已提交
663
		// Contributed services
B
Benjamin Pasero 已提交
664
		const contributedServices = getServices();
E
Erich Gamma 已提交
665
		for (let contributedService of contributedServices) {
666
			serviceCollection.set(contributedService.id, contributedService.descriptor);
E
Erich Gamma 已提交
667 668 669
		}

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

674
		this.instantiationService.createInstance(DefaultConfigurationExportHelper);
675

S
#47154  
Sandeep Somavarapu 已提交
676
		this.configurationService.acquireInstantiationService(this.getInstantiationService());
E
Erich Gamma 已提交
677 678 679 680 681
	}

	private initSettings(): void {

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

I
isidor 已提交
684
		// Panel part visibility
685
		const panelRegistry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
I
isidor 已提交
686
		this.panelHidden = this.storageService.getBoolean(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE, true);
687 688
		if (!panelRegistry.getDefaultPanelId()) {
			this.panelHidden = true; // we hide panel part if there is no default panel
I
isidor 已提交
689
		}
I
isidor 已提交
690

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

I
isidor 已提交
695
		// Panel position
696
		this.setPanelPositionFromStorageOrConfig();
I
isidor 已提交
697

B
Benjamin Pasero 已提交
698
		// Statusbar visibility
699
		const statusBarVisible = this.configurationService.getValue<string>(Workbench.statusbarVisibleConfigurationKey);
700
		this.statusBarHidden = !statusBarVisible;
S
Sanders Lauture 已提交
701 702

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

706
		// Font aliasing
707
		this.fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
708

I
isidor 已提交
709 710
		// Zen mode
		this.zenMode = {
I
isidor 已提交
711
			active: false,
712
			transitionedToFullScreen: false,
713
			transitionedToCenteredEditorLayout: false,
714 715
			wasSideBarVisible: false,
			wasPanelVisible: false
I
isidor 已提交
716
		};
S
SrTobi 已提交
717

B
Benjamin Pasero 已提交
718 719
		// Centered Editor Layout
		this.centeredEditorLayoutActive = false;
E
Erich Gamma 已提交
720 721
	}

722 723 724 725 726 727
	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 已提交
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
	/**
	 * Returns whether the workbench has been started.
	 */
	public isStarted(): boolean {
		return this.workbenchStarted && !this.workbenchShutdown;
	}

	/**
	 * Returns whether the workbench has been fully created.
	 */
	public isCreated(): boolean {
		return this.workbenchCreated && this.workbenchStarted;
	}

	public hasFocus(part: Parts): boolean {
B
Benjamin Pasero 已提交
743
		const activeElement = document.activeElement;
E
Erich Gamma 已提交
744 745 746 747
		if (!activeElement) {
			return false;
		}

748 749 750 751 752
		const container = this.getContainer(part);
		return DOM.isAncestor(activeElement, container);
	}

	public getContainer(part: Parts): HTMLElement {
753
		let container: HTMLElement = null;
E
Erich Gamma 已提交
754
		switch (part) {
B
Benjamin Pasero 已提交
755 756 757
			case Parts.TITLEBAR_PART:
				container = this.titlebarPart.getContainer();
				break;
E
Erich Gamma 已提交
758 759 760 761 762 763
			case Parts.ACTIVITYBAR_PART:
				container = this.activitybarPart.getContainer();
				break;
			case Parts.SIDEBAR_PART:
				container = this.sidebarPart.getContainer();
				break;
I
isidor 已提交
764 765 766
			case Parts.PANEL_PART:
				container = this.panelPart.getContainer();
				break;
E
Erich Gamma 已提交
767 768 769 770 771 772 773
			case Parts.EDITOR_PART:
				container = this.editorPart.getContainer();
				break;
			case Parts.STATUSBAR_PART:
				container = this.statusbarPart.getContainer();
				break;
		}
774 775

		return container;
E
Erich Gamma 已提交
776 777 778
	}

	public isVisible(part: Parts): boolean {
B
Benjamin Pasero 已提交
779
		switch (part) {
B
Benjamin Pasero 已提交
780
			case Parts.TITLEBAR_PART:
781
				return this.getCustomTitleBarStyle() && !browser.isFullscreen();
B
Benjamin Pasero 已提交
782
			case Parts.SIDEBAR_PART:
783
				return !this.sideBarHidden;
B
Benjamin Pasero 已提交
784
			case Parts.PANEL_PART:
785
				return !this.panelHidden;
B
Benjamin Pasero 已提交
786
			case Parts.STATUSBAR_PART:
787
				return !this.statusBarHidden;
S
Sanders Lauture 已提交
788
			case Parts.ACTIVITYBAR_PART:
789
				return !this.activityBarHidden;
790
		}
E
Erich Gamma 已提交
791 792 793 794

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

795 796
	public getTitleBarOffset(): number {
		let offset = 0;
797
		if (this.isVisible(Parts.TITLEBAR_PART)) {
798 799 800 801 802 803
			offset = 22 / browser.getZoomFactor(); // adjust the position based on title bar size and zoom factor
		}

		return offset;
	}

804
	private getCustomTitleBarStyle(): 'custom' {
B
Benjamin Pasero 已提交
805
		if (!isMacintosh) {
806
			return null; // custom title bar is only supported on Mac currently
B
Benjamin Pasero 已提交
807 808
		}

809
		const isDev = !this.environmentService.isBuilt || this.environmentService.isExtensionDevelopment;
B
Benjamin Pasero 已提交
810
		if (isDev) {
811
			return null; // not enabled when developing due to https://github.com/electron/electron/issues/3647
B
Benjamin Pasero 已提交
812 813
		}

814
		const windowConfig = this.configurationService.getValue<IWindowSettings>();
815 816 817 818 819
		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 已提交
820

821 822 823 824
			const style = windowConfig.window.titleBarStyle;
			if (style === 'custom') {
				return style;
			}
825 826 827
		}

		return null;
B
Benjamin Pasero 已提交
828 829
	}

830
	private setStatusBarHidden(hidden: boolean, skipLayout?: boolean): void {
831 832
		this.statusBarHidden = hidden;

833 834 835 836 837 838
		// Adjust CSS
		if (hidden) {
			this.workbench.addClass('nostatusbar');
		} else {
			this.workbench.removeClass('nostatusbar');
		}
I
isidor 已提交
839

840 841
		// Layout
		if (!skipLayout) {
842
			this.workbenchLayout.layout();
843 844 845
		}
	}

S
Sanders Lauture 已提交
846 847 848 849 850
	public setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.activityBarHidden = hidden;

		// Layout
		if (!skipLayout) {
851
			this.workbenchLayout.layout();
S
Sanders Lauture 已提交
852 853 854
		}
	}

855
	public setSideBarHidden(hidden: boolean, skipLayout?: boolean): TPromise<void> {
E
Erich Gamma 已提交
856
		this.sideBarHidden = hidden;
857
		this.sideBarVisibleContext.set(!hidden);
E
Erich Gamma 已提交
858 859 860 861 862 863 864 865

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

B
Benjamin Pasero 已提交
866
		// If sidebar becomes hidden, also hide the current active Viewlet if any
867
		let promise = TPromise.wrap<any>(null);
E
Erich Gamma 已提交
868
		if (hidden && this.sidebarPart.getActiveViewlet()) {
869
			promise = this.sidebarPart.hideActiveViewlet().then(() => {
870
				const activeEditor = this.editorService.getActiveEditor();
871
				const activePanel = this.panelPart.getActivePanel();
B
Benjamin Pasero 已提交
872

873 874 875 876 877 878 879
				// 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 已提交
880 881
		}

B
Benjamin Pasero 已提交
882
		// If sidebar becomes visible, show last active Viewlet or default viewlet
E
Erich Gamma 已提交
883
		else if (!hidden && !this.sidebarPart.getActiveViewlet()) {
884
			const viewletToOpen = this.sidebarPart.getLastActiveViewletId();
E
Erich Gamma 已提交
885
			if (viewletToOpen) {
886
				promise = this.sidebarPart.openViewlet(viewletToOpen, true);
E
Erich Gamma 已提交
887 888 889
			}
		}

890
		return promise.then(() => {
891

892
			// Remember in settings
893
			const defaultHidden = this.contextService.getWorkbenchState() === WorkbenchState.EMPTY;
894
			if (hidden !== defaultHidden) {
I
isidor 已提交
895
				this.storageService.store(Workbench.sidebarHiddenStorageKey, hidden ? 'true' : 'false', StorageScope.WORKSPACE);
896
			} else {
I
isidor 已提交
897
				this.storageService.remove(Workbench.sidebarHiddenStorageKey, StorageScope.WORKSPACE);
898
			}
899 900 901

			// Layout
			if (!skipLayout) {
902
				this.workbenchLayout.layout();
903 904
			}
		});
E
Erich Gamma 已提交
905 906
	}

907
	public setPanelHidden(hidden: boolean, skipLayout?: boolean): TPromise<void> {
I
isidor 已提交
908
		this.panelHidden = hidden;
I
isidor 已提交
909

910 911 912 913 914 915 916
		// Adjust CSS
		if (hidden) {
			this.workbench.addClass('nopanel');
		} else {
			this.workbench.removeClass('nopanel');
		}

I
isidor 已提交
917
		// If panel part becomes hidden, also hide the current active panel if any
918
		let promise = TPromise.wrap<any>(null);
I
isidor 已提交
919
		if (hidden && this.panelPart.getActivePanel()) {
920
			promise = this.panelPart.hideActivePanel().then(() => {
921

922
				// Pass Focus to Editor if Panel part is now hidden
923
				const editor = this.editorService.getActiveEditor();
924 925 926 927
				if (editor) {
					editor.focus();
				}
			});
I
isidor 已提交
928 929 930 931
		}

		// If panel part becomes visible, show last active panel or default panel
		else if (!hidden && !this.panelPart.getActivePanel()) {
932
			const panelToOpen = this.panelPart.getLastActivePanelId();
I
isidor 已提交
933
			if (panelToOpen) {
934
				promise = this.panelPart.openPanel(panelToOpen, true);
I
isidor 已提交
935 936 937
			}
		}

938
		return promise.then(() => {
939

940
			// Remember in settings
941
			if (!hidden) {
I
isidor 已提交
942
				this.storageService.store(Workbench.panelHiddenStorageKey, 'false', StorageScope.WORKSPACE);
943
			} else {
I
isidor 已提交
944
				this.storageService.remove(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE);
945
			}
946 947 948

			// Layout
			if (!skipLayout) {
949
				this.workbenchLayout.layout();
950 951
			}
		});
I
isidor 已提交
952 953
	}

954
	public toggleMaximizedPanel(): void {
I
isidor 已提交
955
		this.workbenchLayout.layout({ toggleMaximizedPanel: true, source: Parts.PANEL_PART });
956 957 958 959 960 961
	}

	public isPanelMaximized(): boolean {
		return this.workbenchLayout.isPanelMaximized();
	}

E
Erich Gamma 已提交
962 963 964 965
	public getSideBarPosition(): Position {
		return this.sideBarPosition;
	}

I
isidor 已提交
966
	public setSideBarPosition(position: Position): void {
E
Erich Gamma 已提交
967
		if (this.sideBarHidden) {
968
			this.setSideBarHidden(false, true /* Skip Layout */).done(void 0, errors.onUnexpectedError);
E
Erich Gamma 已提交
969 970
		}

B
Benjamin Pasero 已提交
971 972
		const newPositionValue = (position === Position.LEFT) ? 'left' : 'right';
		const oldPositionValue = (this.sideBarPosition === Position.LEFT) ? 'left' : 'right';
E
Erich Gamma 已提交
973 974 975
		this.sideBarPosition = position;

		// Adjust CSS
976 977 978 979
		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 已提交
980

981 982 983 984
		// Update Styles
		this.activitybarPart.updateStyles();
		this.sidebarPart.updateStyles();

E
Erich Gamma 已提交
985
		// Layout
986
		this.workbenchLayout.layout();
E
Erich Gamma 已提交
987 988
	}

I
isidor 已提交
989 990 991 992
	public getPanelPosition(): Position {
		return this.panelPosition;
	}

I
isidor 已提交
993 994 995 996 997 998
	public setPanelPosition(position: Position): TPromise<void> {
		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 已提交
999

I
isidor 已提交
1000
			// Adjust CSS
1001 1002
			DOM.removeClass(this.panelPart.getContainer(), oldPositionValue);
			DOM.addClass(this.panelPart.getContainer(), newPositionValue);
I
isidor 已提交
1003

I
isidor 已提交
1004 1005
			// Update Styles
			this.panelPart.updateStyles();
I
isidor 已提交
1006

I
isidor 已提交
1007 1008 1009
			// Layout
			this.workbenchLayout.layout();
		});
I
isidor 已提交
1010 1011
	}

1012
	private setFontAliasing(aliasing: FontAliasingOption) {
1013
		this.fontAliasing = aliasing;
B
Benjamin Pasero 已提交
1014 1015 1016 1017 1018 1019

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

		// Add specific
		if (fontAliasingValues.some(option => option === aliasing)) {
1020 1021
			document.body.classList.add(`monaco-font-aliasing-${aliasing}`);
		}
1022 1023
	}

1024
	public dispose(reason = ShutdownReason.QUIT): void {
1025 1026 1027

		// Restore sidebar if we are being shutdown as a matter of a reload
		if (reason === ShutdownReason.RELOAD) {
I
isidor 已提交
1028
			this.storageService.store(Workbench.sidebarRestoreStorageKey, 'true', StorageScope.WORKSPACE);
1029
		}
I
isidor 已提交
1030

I
isidor 已提交
1031
		// Preserve zen mode only on reload. Real quit gets out of zen mode so novice users do not get stuck in zen mode.
1032
		const zenConfig = this.configurationService.getValue<IZenModeSettings>('zenMode');
1033 1034
		const restoreZenMode = this.zenMode.active && (zenConfig.restore || reason === ShutdownReason.RELOAD);
		if (restoreZenMode) {
I
isidor 已提交
1035
			this.storageService.store(Workbench.zenModeActiveStorageKey, true, StorageScope.WORKSPACE);
1036
		} else {
1037 1038 1039
			if (this.zenMode.active) {
				this.toggleZenMode(true);
			}
I
isidor 已提交
1040
			this.storageService.remove(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE);
1041
		}
E
Erich Gamma 已提交
1042

1043 1044 1045
		// Dispose bindings
		this.toUnbind = dispose(this.toUnbind);

E
Erich Gamma 已提交
1046
		// Pass shutdown on to each participant
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
		this.workbenchShutdown = true;
	}

	/**
	 * Asks the workbench and all its UI components inside to lay out according to
	 * the containers dimension the workbench is living in.
	 */
	public layout(options?: ILayoutOptions): void {
		if (this.isStarted()) {
			this.workbenchLayout.layout(options);
		}
E
Erich Gamma 已提交
1058 1059 1060 1061 1062
	}

	private registerListeners(): void {

		// Listen to editor changes
1063
		this.toUnbind.push(this.editorGroupService.onEditorsChanged(() => this.onEditorsChanged()));
1064

1065 1066 1067 1068 1069
		// 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);
1070
			const listenerDispose = this.editorGroupService.getStacksModel().onEditorClosed(() => this.onEditorClosed(listenerDispose, resourcesToWaitFor, waitMarkerFile));
1071

1072
			this.toUnbind.push(listenerDispose);
1073 1074
		}

1075
		// Configuration changes
1076
		this.toUnbind.push(this.configurationService.onDidChangeConfiguration(() => this.onDidUpdateConfiguration()));
1077 1078

		// Fullscreen changes
1079
		this.toUnbind.push(browser.onDidChangeFullscreen(() => this.onFullscreenChanged()));
1080 1081 1082 1083 1084 1085 1086
	}

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

1087
		// Apply as CSS class
1088 1089 1090 1091 1092
		const isFullscreen = browser.isFullscreen();
		if (isFullscreen) {
			this.addClass('fullscreen');
		} else {
			this.removeClass('fullscreen');
I
isidor 已提交
1093 1094
			if (this.zenMode.transitionedToFullScreen && this.zenMode.active) {
				this.toggleZenMode();
I
isidor 已提交
1095
			}
1096
		}
1097

1098 1099 1100 1101 1102
		// 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
1103
		}
E
Erich Gamma 已提交
1104 1105
	}

1106 1107 1108 1109 1110
	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.
1111
		const stacks = this.editorGroupService.getStacksModel();
1112 1113 1114 1115 1116 1117
		if (resourcesToWaitFor.every(r => !stacks.isOpen(r))) {
			listenerDispose.dispose();
			this.fileService.del(waitMarkerFile).done(null, errors.onUnexpectedError);
		}
	}

1118
	private onEditorsChanged(): void {
B
Benjamin Pasero 已提交
1119
		const visibleEditors = this.editorService.getVisibleEditors().length;
E
Erich Gamma 已提交
1120

1121 1122
		// 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
1123
		// or setting is disabled. Also enabled when running with --wait from the command line.
1124
		if (visibleEditors === 0 && this.contextService.getWorkbenchState() === WorkbenchState.EMPTY && !this.environmentService.isExtensionDevelopment) {
1125
			const closeWhenEmpty = this.configurationService.getValue<boolean>(Workbench.closeWhenEmptyConfigurationKey);
1126
			if (closeWhenEmpty || this.environmentService.args.wait) {
1127 1128 1129 1130
				this.closeEmptyWindowScheduler.schedule();
			}
		}

E
Erich Gamma 已提交
1131 1132
		// We update the editorpart class to indicate if an editor is opened or not
		// through a delay to accomodate for fast editor switching
B
Benjamin Pasero 已提交
1133 1134 1135 1136 1137 1138
		this.handleEditorBackground();
	}

	private handleEditorBackground(): void {
		const visibleEditors = this.editorService.getVisibleEditors().length;

1139
		const editorContainer = this.editorPart.getContainer();
E
Erich Gamma 已提交
1140
		if (visibleEditors === 0) {
1141
			this.editorsVisibleContext.reset();
1142
			this.editorBackgroundDelayer.trigger(() => DOM.addClass(editorContainer, 'empty2')); // TODO@grid reenable (find "empty2") and move this into editorPart.ts!
E
Erich Gamma 已提交
1143
		} else {
1144
			this.editorsVisibleContext.set(true);
1145
			this.editorBackgroundDelayer.trigger(() => DOM.removeClass(editorContainer, 'empty2'));
E
Erich Gamma 已提交
1146 1147 1148
		}
	}

1149 1150 1151 1152 1153 1154 1155
	private onAllEditorsClosed(): void {
		const visibleEditors = this.editorService.getVisibleEditors().length;
		if (visibleEditors === 0) {
			this.windowService.closeWindow();
		}
	}

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

1163 1164
		this.setPanelPositionFromStorageOrConfig();

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

1170
		if (!this.zenMode.active) {
1171
			const newStatusbarHiddenValue = !this.configurationService.getValue<boolean>(Workbench.statusbarVisibleConfigurationKey);
1172 1173 1174
			if (newStatusbarHiddenValue !== this.statusBarHidden) {
				this.setStatusBarHidden(newStatusbarHiddenValue, skipLayout);
			}
S
Sanders Lauture 已提交
1175

1176
			const newActivityBarHiddenValue = !this.configurationService.getValue<boolean>(Workbench.activityBarVisibleConfigurationKey);
1177 1178 1179
			if (newActivityBarHiddenValue !== this.activityBarHidden) {
				this.setActivityBarHidden(newActivityBarHiddenValue, skipLayout);
			}
S
Sanders Lauture 已提交
1180
		}
1181 1182
	}

E
Erich Gamma 已提交
1183
	private createWorkbenchLayout(): void {
1184 1185
		this.workbenchLayout = this.instantiationService.createInstance(
			WorkbenchLayout,
1186 1187
			this.container,								// Parent
			this.workbench.getHTMLElement(),			// Workbench Container
I
isidor 已提交
1188
			{
B
Benjamin Pasero 已提交
1189
				titlebar: this.titlebarPart,			// Title Bar
I
isidor 已提交
1190 1191 1192 1193 1194 1195
				activitybar: this.activitybarPart,		// Activity Bar
				editor: this.editorPart,				// Editor
				sidebar: this.sidebarPart,				// Sidebar
				panel: this.panelPart,					// Panel Part
				statusbar: this.statusbarPart,			// Statusbar
			},
1196
			this.quickOpen,								// Quickopen
C
Christof Marti 已提交
1197
			this.quickInput,							// QuickInput
1198 1199
			this.notificationsCenter,					// Notifications Center
			this.notificationsToasts					// Notifications Toasts
E
Erich Gamma 已提交
1200 1201 1202 1203 1204 1205 1206 1207 1208
		);
	}

	private renderWorkbench(): void {

		// Apply sidebar state as CSS class
		if (this.sideBarHidden) {
			this.workbench.addClass('nosidebar');
		}
1209 1210 1211
		if (this.panelHidden) {
			this.workbench.addClass('nopanel');
		}
1212 1213 1214
		if (this.statusBarHidden) {
			this.workbench.addClass('nostatusbar');
		}
E
Erich Gamma 已提交
1215

B
Benjamin Pasero 已提交
1216
		// Apply font aliasing
1217 1218
		this.setFontAliasing(this.fontAliasing);

B
Benjamin Pasero 已提交
1219
		// Apply title style if shown
1220 1221 1222 1223 1224 1225 1226 1227
		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 已提交
1228 1229
		}

E
Erich Gamma 已提交
1230
		// Create Parts
B
Benjamin Pasero 已提交
1231
		this.createTitlebarPart();
E
Erich Gamma 已提交
1232 1233 1234
		this.createActivityBarPart();
		this.createSidebarPart();
		this.createEditorPart();
1235
		this.createPanelPart();
E
Erich Gamma 已提交
1236 1237
		this.createStatusbarPart();

1238 1239
		// Notification Handlers
		this.createNotificationsHandlers();
1240

E
Erich Gamma 已提交
1241 1242 1243 1244
		// Add Workbench to DOM
		this.workbenchContainer.build(this.container);
	}

B
Benjamin Pasero 已提交
1245 1246 1247 1248 1249 1250 1251
	private createTitlebarPart(): void {
		const titlebarContainer = $(this.workbench).div({
			'class': ['part', 'titlebar'],
			id: Identifiers.TITLEBAR_PART,
			role: 'contentinfo'
		});

1252
		this.titlebarPart.create(titlebarContainer.getHTMLElement());
B
Benjamin Pasero 已提交
1253 1254
	}

E
Erich Gamma 已提交
1255
	private createActivityBarPart(): void {
B
Benjamin Pasero 已提交
1256
		const activitybarPartContainer = $(this.workbench)
E
Erich Gamma 已提交
1257 1258
			.div({
				'class': ['part', 'activitybar', this.sideBarPosition === Position.LEFT ? 'left' : 'right'],
1259 1260
				id: Identifiers.ACTIVITYBAR_PART,
				role: 'navigation'
E
Erich Gamma 已提交
1261 1262
			});

1263
		this.activitybarPart.create(activitybarPartContainer.getHTMLElement());
E
Erich Gamma 已提交
1264 1265 1266
	}

	private createSidebarPart(): void {
B
Benjamin Pasero 已提交
1267
		const sidebarPartContainer = $(this.workbench)
E
Erich Gamma 已提交
1268 1269
			.div({
				'class': ['part', 'sidebar', this.sideBarPosition === Position.LEFT ? 'left' : 'right'],
1270 1271
				id: Identifiers.SIDEBAR_PART,
				role: 'complementary'
E
Erich Gamma 已提交
1272 1273
			});

1274
		this.sidebarPart.create(sidebarPartContainer.getHTMLElement());
E
Erich Gamma 已提交
1275 1276
	}

I
isidor 已提交
1277
	private createPanelPart(): void {
B
Benjamin Pasero 已提交
1278
		const panelPartContainer = $(this.workbench)
I
isidor 已提交
1279
			.div({
1280
				'class': ['part', 'panel', this.panelPosition === Position.BOTTOM ? 'bottom' : 'right'],
1281 1282
				id: Identifiers.PANEL_PART,
				role: 'complementary'
I
isidor 已提交
1283 1284
			});

1285
		this.panelPart.create(panelPartContainer.getHTMLElement());
I
isidor 已提交
1286 1287
	}

E
Erich Gamma 已提交
1288
	private createEditorPart(): void {
B
Benjamin Pasero 已提交
1289
		const editorContainer = $(this.workbench)
E
Erich Gamma 已提交
1290
			.div({
1291
				'class': ['part', 'editor', 'empty2'],
1292 1293
				id: Identifiers.EDITOR_PART,
				role: 'main'
E
Erich Gamma 已提交
1294 1295
			});

1296
		this.editorPart.create(editorContainer.getHTMLElement());
E
Erich Gamma 已提交
1297 1298 1299
	}

	private createStatusbarPart(): void {
B
Benjamin Pasero 已提交
1300
		const statusbarContainer = $(this.workbench).div({
E
Erich Gamma 已提交
1301
			'class': ['part', 'statusbar'],
1302 1303
			id: Identifiers.STATUSBAR_PART,
			role: 'contentinfo'
E
Erich Gamma 已提交
1304 1305
		});

1306
		this.statusbarPart.create(statusbarContainer.getHTMLElement());
E
Erich Gamma 已提交
1307 1308
	}

1309 1310
	private createNotificationsHandlers(): void {

1311 1312 1313
		// Notifications Center
		this.notificationsCenter = this.instantiationService.createInstance(NotificationsCenter, this.workbench.getHTMLElement(), this.notificationService.model);
		this.toUnbind.push(this.notificationsCenter);
1314

1315 1316 1317 1318
		// Notifications Toasts
		this.notificationsToasts = this.instantiationService.createInstance(NotificationsToasts, this.workbench.getHTMLElement(), this.notificationService.model);
		this.toUnbind.push(this.notificationsToasts);

1319
		// Notifications Alerts
1320 1321
		const notificationsAlerts = this.instantiationService.createInstance(NotificationsAlerts, this.notificationService.model);
		this.toUnbind.push(notificationsAlerts);
1322 1323 1324 1325

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

1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
		// Eventing
		this.toUnbind.push(this.notificationsCenter.onDidChangeVisibility(() => {

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

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

1336
		// Register Commands
1337
		registerNotificationCommands(this.notificationsCenter, this.notificationsToasts);
1338 1339
	}

E
Erich Gamma 已提交
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
	public getInstantiationService(): IInstantiationService {
		return this.instantiationService;
	}

	public addClass(clazz: string): void {
		if (this.workbench) {
			this.workbench.addClass(clazz);
		}
	}

	public removeClass(clazz: string): void {
		if (this.workbench) {
			this.workbench.removeClass(clazz);
		}
	}
1355 1356 1357 1358

	public getWorkbenchElementId(): string {
		return Identifiers.WORKBENCH_CONTAINER;
	}
1359

I
isidor 已提交
1360
	public toggleZenMode(skipLayout?: boolean): void {
I
isidor 已提交
1361
		this.zenMode.active = !this.zenMode.active;
1362

1363 1364
		// 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)
1365
		let toggleFullScreen = false;
I
isidor 已提交
1366
		if (this.zenMode.active) {
1367
			const config = this.configurationService.getValue<IZenModeSettings>('zenMode');
I
isidor 已提交
1368
			toggleFullScreen = !browser.isFullscreen() && config.fullScreen;
I
isidor 已提交
1369
			this.zenMode.transitionedToFullScreen = toggleFullScreen;
1370
			this.zenMode.transitionedToCenteredEditorLayout = !this.isEditorLayoutCentered() && config.centerLayout;
1371 1372
			this.zenMode.wasSideBarVisible = this.isVisible(Parts.SIDEBAR_PART);
			this.zenMode.wasPanelVisible = this.isVisible(Parts.PANEL_PART);
1373 1374
			this.setPanelHidden(true, true).done(void 0, errors.onUnexpectedError);
			this.setSideBarHidden(true, true).done(void 0, errors.onUnexpectedError);
I
isidor 已提交
1375

1376 1377 1378
			if (config.hideActivityBar) {
				this.setActivityBarHidden(true, true);
			}
1379

I
isidor 已提交
1380
			if (config.hideStatusBar) {
I
isidor 已提交
1381 1382
				this.setStatusBarHidden(true, true);
			}
1383

I
isidor 已提交
1384
			if (config.hideTabs) {
1385
				this.noOpEditorPart.hideTabs(true);
I
isidor 已提交
1386
			}
1387 1388 1389 1390

			if (config.centerLayout) {
				this.centerEditorLayout(true, true);
			}
1391
		} else {
1392
			if (this.zenMode.wasPanelVisible) {
1393
				this.setPanelHidden(false, true).done(void 0, errors.onUnexpectedError);
1394
			}
1395
			if (this.zenMode.wasSideBarVisible) {
1396
				this.setSideBarHidden(false, true).done(void 0, errors.onUnexpectedError);
1397
			}
1398 1399 1400
			if (this.zenMode.transitionedToCenteredEditorLayout) {
				this.centerEditorLayout(false, true);
			}
1401

1402 1403
			// Status bar and activity bar visibility come from settings -> update their visibility.
			this.onDidUpdateConfiguration(true);
1404 1405
			this.noOpEditorPart.hideTabs(false);
			const activeEditor = this.editorService.getActiveEditor();
I
isidor 已提交
1406 1407 1408
			if (activeEditor) {
				activeEditor.focus();
			}
1409

1410
			toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
I
isidor 已提交
1411
		}
1412

1413
		this.inZenMode.set(this.zenMode.active);
I
isidor 已提交
1414

I
isidor 已提交
1415
		if (!skipLayout) {
1416
			this.layout();
I
isidor 已提交
1417
		}
1418

1419
		if (toggleFullScreen) {
1420
			this.windowService.toggleFullScreen().done(void 0, errors.onUnexpectedError);
1421
		}
I
isidor 已提交
1422 1423
	}

B
Benjamin Pasero 已提交
1424 1425
	public isEditorLayoutCentered(): boolean {
		return this.centeredEditorLayoutActive;
S
SrTobi 已提交
1426 1427
	}

1428 1429
	public centerEditorLayout(active: boolean, skipLayout?: boolean): void {
		this.centeredEditorLayoutActive = active;
B
Benjamin Pasero 已提交
1430 1431
		this.storageService.store(Workbench.centeredEditorLayoutActiveStorageKey, this.centeredEditorLayoutActive, StorageScope.GLOBAL);

1432 1433 1434
		if (!skipLayout) {
			this.layout();
		}
S
SrTobi 已提交
1435 1436
	}

1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
	// Resize requested part along the main axis
	// layout will do all the math for us and adjusts the other Parts
	public resizePart(part: Parts, sizeChange: number): void {
		switch (part) {
			case Parts.SIDEBAR_PART:
			case Parts.PANEL_PART:
			case Parts.EDITOR_PART:
				this.workbenchLayout.resizePart(part, sizeChange);
				break;
			default:
B
Benjamin Pasero 已提交
1447
				return; // Cannot resize other parts
1448 1449 1450 1451
		}
	}


1452
	private shouldRestoreLastOpenedViewlet(): boolean {
1453 1454 1455 1456
		if (!this.environmentService.isBuilt) {
			return true; // always restore sidebar when we are in development mode
		}

I
isidor 已提交
1457
		const restore = this.storageService.getBoolean(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE);
1458
		if (restore) {
I
isidor 已提交
1459
			this.storageService.remove(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE); // only support once
1460 1461 1462 1463
		}

		return restore;
	}
J
Johannes Rieken 已提交
1464
}