workbench.ts 57.1 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';
J
Johannes Rieken 已提交
12
import { IDisposable, dispose } 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';
S
Sandeep Somavarapu 已提交
99 100
import { ICustomViewsService } from 'vs/workbench/common/views';
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 113 114
import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService';
import { NextEditorPart } from 'vs/workbench/browser/parts/nexteditor/nextEditorPart';
import { INextEditorGroupService } from 'vs/workbench/services/group/common/nextGroupService';
115

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

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

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

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

142 143
type FontAliasingOption = 'default' | 'antialiased' | 'none' | 'auto';

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

146 147
const Identifiers = {
	WORKBENCH_CONTAINER: 'workbench.main.container',
B
Benjamin Pasero 已提交
148
	TITLEBAR_PART: 'workbench.parts.titlebar',
149 150 151 152 153 154 155
	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 已提交
156 157 158 159 160 161 162 163
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 已提交
164
/**
B
Benjamin Pasero 已提交
165
 * The workbench creates and lays out all parts that make up the workbench.
E
Erich Gamma 已提交
166 167 168
 */
export class Workbench implements IPartService {

169 170 171 172
	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';
173
	private static readonly centeredEditorLayoutActiveStorageKey = 'workbench.centerededitorlayout.active';
174
	private static readonly panelPositionStorageKey = 'workbench.panel.location';
175
	private static readonly defaultPanelPositionStorageKey = 'workbench.panel.defaultLocation';
E
Erich Gamma 已提交
176

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

181
	private static readonly closeWhenEmptyConfigurationKey = 'window.closeWhenEmpty';
182

183
	private static readonly fontAliasingConfigurationKey = 'workbench.fontAliasing';
184

M
Matt Bierner 已提交
185
	private readonly _onTitleBarVisibilityChange: Emitter<void>;
186

187
	public _serviceBrand: any;
E
Erich Gamma 已提交
188

B
Benjamin Pasero 已提交
189
	private parent: HTMLElement;
E
Erich Gamma 已提交
190 191 192 193 194 195
	private container: HTMLElement;
	private workbenchParams: WorkbenchParams;
	private workbenchContainer: Builder;
	private workbench: Builder;
	private workbenchStarted: boolean;
	private workbenchCreated: boolean;
196 197
	private editorService: IWorkbenchEditorService;
	private editorGroupService: IEditorGroupService;
E
Erich Gamma 已提交
198
	private workbenchShutdown: boolean;
P
Pine Wu 已提交
199
	private viewletService: IViewletService;
200
	private contextKeyService: IContextKeyService;
201
	private keybindingService: IKeybindingService;
202
	private backupFileService: IBackupFileService;
203
	private fileService: IFileService;
B
Benjamin Pasero 已提交
204
	private titlebarPart: TitlebarPart;
E
Erich Gamma 已提交
205 206
	private activitybarPart: ActivitybarPart;
	private sidebarPart: SidebarPart;
I
isidor 已提交
207
	private panelPart: PanelPart;
208 209
	private noOpEditorPart: NoOpEditorPart; // TODO@next adopt methods in next editor part
	private editorPart: NextEditorPart;
E
Erich Gamma 已提交
210 211
	private statusbarPart: StatusbarPart;
	private quickOpen: QuickOpenController;
C
Christof Marti 已提交
212
	private quickInput: QuickInputService;
213
	private notificationsCenter: NotificationsCenter;
214
	private notificationsToasts: NotificationsToasts;
E
Erich Gamma 已提交
215
	private workbenchLayout: WorkbenchLayout;
216
	private toUnbind: IDisposable[];
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
	private editorBackgroundDelayer: Delayer<any>;
224
	private closeEmptyWindowScheduler: RunOnceScheduler;
A
Alex Dima 已提交
225
	private editorsVisibleContext: IContextKey<boolean>;
I
isidor 已提交
226
	private inZenMode: IContextKey<boolean>;
227
	private sideBarVisibleContext: IContextKey<boolean>;
228
	private hasFilesToCreateOpenOrDiff: boolean;
229
	private fontAliasing: FontAliasingOption;
B
Benjamin Pasero 已提交
230
	private centeredEditorLayoutActive: boolean;
I
isidor 已提交
231
	private zenMode: {
I
isidor 已提交
232 233
		active: boolean;
		transitionedToFullScreen: boolean;
234
		transitionedToCenteredEditorLayout: boolean;
235 236
		wasSideBarVisible: boolean;
		wasPanelVisible: boolean;
I
isidor 已提交
237
	};
E
Erich Gamma 已提交
238

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

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

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

267
		this.toUnbind = [];
268

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

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

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

279
	public get onEditorLayout(): Event<IDimension> {
280
		return this.editorPart.onLayout;
281 282
	}

E
Erich Gamma 已提交
283 284 285 286
	/**
	 * 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 已提交
287
	public startup(): TPromise<IWorkbenchStartedInfo> {
288
		this.workbenchStarted = true;
E
Erich Gamma 已提交
289

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

293 294
		// Install some global actions
		this.createGlobalActions();
295

296 297
		// Services
		this.initServices();
E
Erich Gamma 已提交
298

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

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

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

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

315 316
		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 已提交
317

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

321 322
		// Settings
		this.initSettings();
E
Erich Gamma 已提交
323

324 325
		// Create Workbench and Parts
		this.renderWorkbench();
326

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

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

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

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

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

		// Restore Editors
J
Johannes Rieken 已提交
352
		perf.mark('willRestoreEditors');
353 354 355 356 357 358
		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 {
359
				editorOpenPromise = this.noOpEditorPart.restoreEditors();
360 361
			}

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

J
Johannes Rieken 已提交
365
				perf.mark('didRestoreEditors');
366

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

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

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

388 389 390
			if (!viewletIdToRestore) {
				viewletIdToRestore = this.viewletService.getDefaultViewletId();
			}
391

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

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

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

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

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

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

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

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

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

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

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

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

470 471
			const filesToCreate = this.toInputs(config.filesToCreate, true);
			const filesToOpen = this.toInputs(config.filesToOpen, false);
472

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

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

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

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

		return TPromise.as([]);
	}

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

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

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

			return input;
		});
	}

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

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

531
		return startupEditor.value === 'newUntitledFile';
532 533
	}

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

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

540 541 542
		// Clipboard
		serviceCollection.set(IClipboardService, new ClipboardService());

543 544
		// Status bar
		this.statusbarPart = this.instantiationService.createInstance(StatusbarPart, Identifiers.STATUSBAR_PART);
545
		this.toUnbind.push({ dispose: () => this.statusbarPart.shutdown() });
546 547
		serviceCollection.set(IStatusbarService, this.statusbarPart);

548 549 550
		// Progress 2
		serviceCollection.set(IProgressService2, new SyncDescriptor(ProgressService2));

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

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

558 559 560
		// List
		serviceCollection.set(IListService, this.instantiationService.createInstance(ListService));

561
		// Context Menu
562
		serviceCollection.set(IContextMenuService, new SyncDescriptor(ContextMenuService));
563

564 565
		// Menus/Actions
		serviceCollection.set(IMenuService, new SyncDescriptor(MenuService));
566

P
Pine Wu 已提交
567
		// Sidebar part
568
		this.sidebarPart = this.instantiationService.createInstance(SidebarPart, Identifiers.SIDEBAR_PART);
569
		this.toUnbind.push({ dispose: () => this.sidebarPart.shutdown() });
P
Pine Wu 已提交
570 571 572 573

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

I
isidor 已提交
575
		// Panel service (panel part)
576
		this.panelPart = this.instantiationService.createInstance(PanelPart, Identifiers.PANEL_PART);
577
		this.toUnbind.push({ dispose: () => this.panelPart.shutdown() });
578
		serviceCollection.set(IPanelService, this.panelPart);
I
isidor 已提交
579

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

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

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

595 596
		// Editor service (next editor part)
		this.editorPart = this.instantiationService.createInstance(NextEditorPart, Identifiers.EDITOR_PART /*, !this.hasFilesToCreateOpenOrDiff*/);
597
		this.toUnbind.push({ dispose: () => this.editorPart.shutdown() });
598 599 600 601 602 603 604
		serviceCollection.set(INextEditorService, this.editorPart);
		serviceCollection.set(INextEditorGroupService, this.editorPart);

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

608 609
		// Title bar
		this.titlebarPart = this.instantiationService.createInstance(TitlebarPart, Identifiers.TITLEBAR_PART);
610
		this.toUnbind.push({ dispose: () => this.titlebarPart.shutdown() });
611 612
		serviceCollection.set(ITitleService, this.titlebarPart);

613
		// History
614
		serviceCollection.set(IHistoryService, new SyncDescriptor(HistoryService));
615

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

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

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

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

B
Benjamin Pasero 已提交
629
		// Text Model Resolver Service
630
		serviceCollection.set(ITextModelService, new SyncDescriptor(TextModelResolverService));
B
Benjamin Pasero 已提交
631

632 633 634 635
		// JSON Editing
		const jsonEditingService = this.instantiationService.createInstance(JSONEditingService);
		serviceCollection.set(IJSONEditingService, jsonEditingService);

636 637 638
		// Workspace Editing
		serviceCollection.set(IWorkspaceEditingService, new SyncDescriptor(WorkspaceEditingService));

639 640 641
		// Keybinding Editing
		serviceCollection.set(IKeybindingEditingService, this.instantiationService.createInstance(KeybindingsEditingService));

642
		// Configuration Resolver
B
Benjamin Pasero 已提交
643
		serviceCollection.set(IConfigurationResolverService, new SyncDescriptor(ConfigurationResolverService, process.env));
644

E
Erich Gamma 已提交
645
		// Quick open service (quick open controller)
646
		this.quickOpen = this.instantiationService.createInstance(QuickOpenController);
647
		this.toUnbind.push({ dispose: () => this.quickOpen.shutdown() });
648
		serviceCollection.set(IQuickOpenService, this.quickOpen);
649

C
Christof Marti 已提交
650 651 652 653 654
		// Quick input service
		this.quickInput = this.instantiationService.createInstance(QuickInputService);
		this.toUnbind.push({ dispose: () => this.quickInput.shutdown() });
		serviceCollection.set(IQuickInputService, this.quickInput);

S
Sandeep Somavarapu 已提交
655 656 657
		// PreferencesService
		serviceCollection.set(IPreferencesService, this.instantiationService.createInstance(PreferencesService));

B
polish  
Benjamin Pasero 已提交
658
		// Contributed services
B
Benjamin Pasero 已提交
659
		const contributedServices = getServices();
E
Erich Gamma 已提交
660
		for (let contributedService of contributedServices) {
661
			serviceCollection.set(contributedService.id, contributedService.descriptor);
E
Erich Gamma 已提交
662 663 664
		}

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

669
		this.instantiationService.createInstance(DefaultConfigurationExportHelper);
670

S
#47154  
Sandeep Somavarapu 已提交
671
		this.configurationService.acquireInstantiationService(this.getInstantiationService());
E
Erich Gamma 已提交
672 673 674 675 676
	}

	private initSettings(): void {

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

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

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

I
isidor 已提交
690
		// Panel position
691
		this.setPanelPositionFromStorageOrConfig();
I
isidor 已提交
692

B
Benjamin Pasero 已提交
693
		// Statusbar visibility
694
		const statusBarVisible = this.configurationService.getValue<string>(Workbench.statusbarVisibleConfigurationKey);
695
		this.statusBarHidden = !statusBarVisible;
S
Sanders Lauture 已提交
696 697

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

701
		// Font aliasing
702
		this.fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
703

I
isidor 已提交
704 705
		// Zen mode
		this.zenMode = {
I
isidor 已提交
706
			active: false,
707
			transitionedToFullScreen: false,
708
			transitionedToCenteredEditorLayout: false,
709 710
			wasSideBarVisible: false,
			wasPanelVisible: false
I
isidor 已提交
711
		};
S
SrTobi 已提交
712

B
Benjamin Pasero 已提交
713 714
		// Centered Editor Layout
		this.centeredEditorLayoutActive = false;
E
Erich Gamma 已提交
715 716
	}

717 718 719 720 721 722
	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 已提交
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
	/**
	 * 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 已提交
738
		const activeElement = document.activeElement;
E
Erich Gamma 已提交
739 740 741 742
		if (!activeElement) {
			return false;
		}

743 744 745 746 747
		const container = this.getContainer(part);
		return DOM.isAncestor(activeElement, container);
	}

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

		return container;
E
Erich Gamma 已提交
771 772 773
	}

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

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

790 791
	public getTitleBarOffset(): number {
		let offset = 0;
792
		if (this.isVisible(Parts.TITLEBAR_PART)) {
793 794 795 796 797 798
			offset = 22 / browser.getZoomFactor(); // adjust the position based on title bar size and zoom factor
		}

		return offset;
	}

799
	private getCustomTitleBarStyle(): 'custom' {
B
Benjamin Pasero 已提交
800
		if (!isMacintosh) {
801
			return null; // custom title bar is only supported on Mac currently
B
Benjamin Pasero 已提交
802 803
		}

804
		const isDev = !this.environmentService.isBuilt || this.environmentService.isExtensionDevelopment;
B
Benjamin Pasero 已提交
805
		if (isDev) {
806
			return null; // not enabled when developing due to https://github.com/electron/electron/issues/3647
B
Benjamin Pasero 已提交
807 808
		}

809
		const windowConfig = this.configurationService.getValue<IWindowSettings>();
810 811 812 813 814
		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 已提交
815

816 817 818 819
			const style = windowConfig.window.titleBarStyle;
			if (style === 'custom') {
				return style;
			}
820 821 822
		}

		return null;
B
Benjamin Pasero 已提交
823 824
	}

825
	private setStatusBarHidden(hidden: boolean, skipLayout?: boolean): void {
826 827
		this.statusBarHidden = hidden;

828 829 830 831 832 833
		// Adjust CSS
		if (hidden) {
			this.workbench.addClass('nostatusbar');
		} else {
			this.workbench.removeClass('nostatusbar');
		}
I
isidor 已提交
834

835 836
		// Layout
		if (!skipLayout) {
837
			this.workbenchLayout.layout();
838 839 840
		}
	}

S
Sanders Lauture 已提交
841 842 843 844 845
	public setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.activityBarHidden = hidden;

		// Layout
		if (!skipLayout) {
846
			this.workbenchLayout.layout();
S
Sanders Lauture 已提交
847 848 849
		}
	}

850
	public setSideBarHidden(hidden: boolean, skipLayout?: boolean): TPromise<void> {
E
Erich Gamma 已提交
851
		this.sideBarHidden = hidden;
852
		this.sideBarVisibleContext.set(!hidden);
E
Erich Gamma 已提交
853 854 855 856 857 858 859 860

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

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

868 869 870 871 872 873 874
				// 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 已提交
875 876
		}

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

885
		return promise.then(() => {
886

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

			// Layout
			if (!skipLayout) {
897
				this.workbenchLayout.layout();
898 899
			}
		});
E
Erich Gamma 已提交
900 901
	}

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

905 906 907 908 909 910 911
		// Adjust CSS
		if (hidden) {
			this.workbench.addClass('nopanel');
		} else {
			this.workbench.removeClass('nopanel');
		}

I
isidor 已提交
912
		// If panel part becomes hidden, also hide the current active panel if any
913
		let promise = TPromise.wrap<any>(null);
I
isidor 已提交
914
		if (hidden && this.panelPart.getActivePanel()) {
915
			promise = this.panelPart.hideActivePanel().then(() => {
916

917
				// Pass Focus to Editor if Panel part is now hidden
918
				const editor = this.editorService.getActiveEditor();
919 920 921 922
				if (editor) {
					editor.focus();
				}
			});
I
isidor 已提交
923 924 925 926
		}

		// If panel part becomes visible, show last active panel or default panel
		else if (!hidden && !this.panelPart.getActivePanel()) {
927
			const panelToOpen = this.panelPart.getLastActivePanelId();
I
isidor 已提交
928
			if (panelToOpen) {
929
				promise = this.panelPart.openPanel(panelToOpen, true);
I
isidor 已提交
930 931 932
			}
		}

933
		return promise.then(() => {
934

935
			// Remember in settings
936
			if (!hidden) {
I
isidor 已提交
937
				this.storageService.store(Workbench.panelHiddenStorageKey, 'false', StorageScope.WORKSPACE);
938
			} else {
I
isidor 已提交
939
				this.storageService.remove(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE);
940
			}
941 942 943

			// Layout
			if (!skipLayout) {
944
				this.workbenchLayout.layout();
945 946
			}
		});
I
isidor 已提交
947 948
	}

949
	public toggleMaximizedPanel(): void {
I
isidor 已提交
950
		this.workbenchLayout.layout({ toggleMaximizedPanel: true, source: Parts.PANEL_PART });
951 952 953 954 955 956
	}

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

E
Erich Gamma 已提交
957 958 959 960
	public getSideBarPosition(): Position {
		return this.sideBarPosition;
	}

I
isidor 已提交
961
	public setSideBarPosition(position: Position): void {
E
Erich Gamma 已提交
962
		if (this.sideBarHidden) {
963
			this.setSideBarHidden(false, true /* Skip Layout */).done(void 0, errors.onUnexpectedError);
E
Erich Gamma 已提交
964 965
		}

B
Benjamin Pasero 已提交
966 967
		const newPositionValue = (position === Position.LEFT) ? 'left' : 'right';
		const oldPositionValue = (this.sideBarPosition === Position.LEFT) ? 'left' : 'right';
E
Erich Gamma 已提交
968 969 970
		this.sideBarPosition = position;

		// Adjust CSS
971 972 973 974
		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 已提交
975

976 977 978 979
		// Update Styles
		this.activitybarPart.updateStyles();
		this.sidebarPart.updateStyles();

E
Erich Gamma 已提交
980
		// Layout
981
		this.workbenchLayout.layout();
E
Erich Gamma 已提交
982 983
	}

I
isidor 已提交
984 985 986 987
	public getPanelPosition(): Position {
		return this.panelPosition;
	}

I
isidor 已提交
988 989 990 991 992 993
	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 已提交
994

I
isidor 已提交
995
			// Adjust CSS
996 997
			DOM.removeClass(this.panelPart.getContainer(), oldPositionValue);
			DOM.addClass(this.panelPart.getContainer(), newPositionValue);
I
isidor 已提交
998

I
isidor 已提交
999 1000
			// Update Styles
			this.panelPart.updateStyles();
I
isidor 已提交
1001

I
isidor 已提交
1002 1003 1004
			// Layout
			this.workbenchLayout.layout();
		});
I
isidor 已提交
1005 1006
	}

1007
	private setFontAliasing(aliasing: FontAliasingOption) {
1008
		this.fontAliasing = aliasing;
B
Benjamin Pasero 已提交
1009 1010 1011 1012 1013 1014

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

		// Add specific
		if (fontAliasingValues.some(option => option === aliasing)) {
1015 1016
			document.body.classList.add(`monaco-font-aliasing-${aliasing}`);
		}
1017 1018
	}

1019
	public dispose(reason = ShutdownReason.QUIT): void {
1020 1021 1022

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

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

1038 1039 1040
		// Dispose bindings
		this.toUnbind = dispose(this.toUnbind);

E
Erich Gamma 已提交
1041
		// Pass shutdown on to each participant
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
		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 已提交
1053 1054 1055 1056 1057
	}

	private registerListeners(): void {

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

1060 1061 1062 1063 1064
		// 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);
1065
			const listenerDispose = this.editorGroupService.getStacksModel().onEditorClosed(() => this.onEditorClosed(listenerDispose, resourcesToWaitFor, waitMarkerFile));
1066

1067
			this.toUnbind.push(listenerDispose);
1068 1069
		}

1070
		// Configuration changes
1071
		this.toUnbind.push(this.configurationService.onDidChangeConfiguration(() => this.onDidUpdateConfiguration()));
1072 1073

		// Fullscreen changes
1074
		this.toUnbind.push(browser.onDidChangeFullscreen(() => this.onFullscreenChanged()));
1075 1076 1077 1078 1079 1080 1081
	}

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

1082
		// Apply as CSS class
1083 1084 1085 1086 1087
		const isFullscreen = browser.isFullscreen();
		if (isFullscreen) {
			this.addClass('fullscreen');
		} else {
			this.removeClass('fullscreen');
I
isidor 已提交
1088 1089
			if (this.zenMode.transitionedToFullScreen && this.zenMode.active) {
				this.toggleZenMode();
I
isidor 已提交
1090
			}
1091
		}
1092

1093 1094 1095 1096 1097
		// 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
1098
		}
E
Erich Gamma 已提交
1099 1100
	}

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

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

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

E
Erich Gamma 已提交
1126 1127
		// 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 已提交
1128 1129 1130 1131 1132 1133
		this.handleEditorBackground();
	}

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

1134
		const editorContainer = this.editorPart.getContainer();
E
Erich Gamma 已提交
1135
		if (visibleEditors === 0) {
1136
			this.editorsVisibleContext.reset();
1137
			this.editorBackgroundDelayer.trigger(() => DOM.addClass(editorContainer, 'empty'));
E
Erich Gamma 已提交
1138
		} else {
1139
			this.editorsVisibleContext.set(true);
1140
			this.editorBackgroundDelayer.trigger(() => DOM.removeClass(editorContainer, 'empty'));
E
Erich Gamma 已提交
1141 1142 1143
		}
	}

1144 1145 1146 1147 1148 1149 1150
	private onAllEditorsClosed(): void {
		const visibleEditors = this.editorService.getVisibleEditors().length;
		if (visibleEditors === 0) {
			this.windowService.closeWindow();
		}
	}

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

1158 1159
		this.setPanelPositionFromStorageOrConfig();

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

1165
		if (!this.zenMode.active) {
1166
			const newStatusbarHiddenValue = !this.configurationService.getValue<boolean>(Workbench.statusbarVisibleConfigurationKey);
1167 1168 1169
			if (newStatusbarHiddenValue !== this.statusBarHidden) {
				this.setStatusBarHidden(newStatusbarHiddenValue, skipLayout);
			}
S
Sanders Lauture 已提交
1170

1171
			const newActivityBarHiddenValue = !this.configurationService.getValue<boolean>(Workbench.activityBarVisibleConfigurationKey);
1172 1173 1174
			if (newActivityBarHiddenValue !== this.activityBarHidden) {
				this.setActivityBarHidden(newActivityBarHiddenValue, skipLayout);
			}
S
Sanders Lauture 已提交
1175
		}
1176 1177
	}

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

	private renderWorkbench(): void {

		// Apply sidebar state as CSS class
		if (this.sideBarHidden) {
			this.workbench.addClass('nosidebar');
		}
1204 1205 1206
		if (this.panelHidden) {
			this.workbench.addClass('nopanel');
		}
1207 1208 1209
		if (this.statusBarHidden) {
			this.workbench.addClass('nostatusbar');
		}
E
Erich Gamma 已提交
1210

B
Benjamin Pasero 已提交
1211
		// Apply font aliasing
1212 1213
		this.setFontAliasing(this.fontAliasing);

B
Benjamin Pasero 已提交
1214
		// Apply title style if shown
1215 1216 1217 1218 1219 1220 1221 1222
		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 已提交
1223 1224
		}

E
Erich Gamma 已提交
1225
		// Create Parts
B
Benjamin Pasero 已提交
1226
		this.createTitlebarPart();
E
Erich Gamma 已提交
1227 1228 1229
		this.createActivityBarPart();
		this.createSidebarPart();
		this.createEditorPart();
1230
		this.createPanelPart();
E
Erich Gamma 已提交
1231 1232
		this.createStatusbarPart();

1233 1234
		// Notification Handlers
		this.createNotificationsHandlers();
1235

E
Erich Gamma 已提交
1236 1237 1238 1239
		// Add Workbench to DOM
		this.workbenchContainer.build(this.container);
	}

B
Benjamin Pasero 已提交
1240 1241 1242 1243 1244 1245 1246
	private createTitlebarPart(): void {
		const titlebarContainer = $(this.workbench).div({
			'class': ['part', 'titlebar'],
			id: Identifiers.TITLEBAR_PART,
			role: 'contentinfo'
		});

1247
		this.titlebarPart.create(titlebarContainer.getHTMLElement());
B
Benjamin Pasero 已提交
1248 1249
	}

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

1258
		this.activitybarPart.create(activitybarPartContainer.getHTMLElement());
E
Erich Gamma 已提交
1259 1260 1261
	}

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

1269
		this.sidebarPart.create(sidebarPartContainer.getHTMLElement());
E
Erich Gamma 已提交
1270 1271
	}

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

1280
		this.panelPart.create(panelPartContainer.getHTMLElement());
I
isidor 已提交
1281 1282
	}

E
Erich Gamma 已提交
1283
	private createEditorPart(): void {
B
Benjamin Pasero 已提交
1284
		const editorContainer = $(this.workbench)
E
Erich Gamma 已提交
1285
			.div({
1286
				'class': ['part', 'editor', 'empty'],
1287 1288
				id: Identifiers.EDITOR_PART,
				role: 'main'
E
Erich Gamma 已提交
1289 1290
			});

1291
		this.editorPart.create(editorContainer.getHTMLElement());
E
Erich Gamma 已提交
1292 1293 1294
	}

	private createStatusbarPart(): void {
B
Benjamin Pasero 已提交
1295
		const statusbarContainer = $(this.workbench).div({
E
Erich Gamma 已提交
1296
			'class': ['part', 'statusbar'],
1297 1298
			id: Identifiers.STATUSBAR_PART,
			role: 'contentinfo'
E
Erich Gamma 已提交
1299 1300
		});

1301
		this.statusbarPart.create(statusbarContainer.getHTMLElement());
E
Erich Gamma 已提交
1302 1303
	}

1304 1305
	private createNotificationsHandlers(): void {

1306 1307 1308
		// Notifications Center
		this.notificationsCenter = this.instantiationService.createInstance(NotificationsCenter, this.workbench.getHTMLElement(), this.notificationService.model);
		this.toUnbind.push(this.notificationsCenter);
1309

1310 1311 1312 1313
		// Notifications Toasts
		this.notificationsToasts = this.instantiationService.createInstance(NotificationsToasts, this.workbench.getHTMLElement(), this.notificationService.model);
		this.toUnbind.push(this.notificationsToasts);

1314
		// Notifications Alerts
1315 1316
		const notificationsAlerts = this.instantiationService.createInstance(NotificationsAlerts, this.notificationService.model);
		this.toUnbind.push(notificationsAlerts);
1317 1318 1319 1320

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

1321 1322 1323 1324 1325 1326 1327 1328 1329 1330
		// Eventing
		this.toUnbind.push(this.notificationsCenter.onDidChangeVisibility(() => {

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

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

1331
		// Register Commands
1332
		registerNotificationCommands(this.notificationsCenter, this.notificationsToasts);
1333 1334
	}

E
Erich Gamma 已提交
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349
	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);
		}
	}
1350 1351 1352 1353

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

I
isidor 已提交
1355
	public toggleZenMode(skipLayout?: boolean): void {
I
isidor 已提交
1356
		this.zenMode.active = !this.zenMode.active;
1357

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

1371 1372 1373
			if (config.hideActivityBar) {
				this.setActivityBarHidden(true, true);
			}
1374

I
isidor 已提交
1375
			if (config.hideStatusBar) {
I
isidor 已提交
1376 1377
				this.setStatusBarHidden(true, true);
			}
1378

I
isidor 已提交
1379
			if (config.hideTabs) {
1380
				this.noOpEditorPart.hideTabs(true);
I
isidor 已提交
1381
			}
1382 1383 1384 1385

			if (config.centerLayout) {
				this.centerEditorLayout(true, true);
			}
1386
		} else {
1387
			if (this.zenMode.wasPanelVisible) {
1388
				this.setPanelHidden(false, true).done(void 0, errors.onUnexpectedError);
1389
			}
1390
			if (this.zenMode.wasSideBarVisible) {
1391
				this.setSideBarHidden(false, true).done(void 0, errors.onUnexpectedError);
1392
			}
1393 1394 1395
			if (this.zenMode.transitionedToCenteredEditorLayout) {
				this.centerEditorLayout(false, true);
			}
1396

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

1405
			toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
I
isidor 已提交
1406
		}
1407

1408
		this.inZenMode.set(this.zenMode.active);
I
isidor 已提交
1409

I
isidor 已提交
1410
		if (!skipLayout) {
1411
			this.layout();
I
isidor 已提交
1412
		}
1413

1414
		if (toggleFullScreen) {
1415
			this.windowService.toggleFullScreen().done(void 0, errors.onUnexpectedError);
1416
		}
I
isidor 已提交
1417 1418
	}

B
Benjamin Pasero 已提交
1419 1420
	public isEditorLayoutCentered(): boolean {
		return this.centeredEditorLayoutActive;
S
SrTobi 已提交
1421 1422
	}

1423 1424
	public centerEditorLayout(active: boolean, skipLayout?: boolean): void {
		this.centeredEditorLayoutActive = active;
B
Benjamin Pasero 已提交
1425 1426
		this.storageService.store(Workbench.centeredEditorLayoutActiveStorageKey, this.centeredEditorLayoutActive, StorageScope.GLOBAL);

1427 1428 1429
		if (!skipLayout) {
			this.layout();
		}
S
SrTobi 已提交
1430 1431
	}

1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
	// 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 已提交
1442
				return; // Cannot resize other parts
1443 1444 1445 1446
		}
	}


1447
	private shouldRestoreLastOpenedViewlet(): boolean {
1448 1449 1450 1451
		if (!this.environmentService.isBuilt) {
			return true; // always restore sidebar when we are in development mode
		}

I
isidor 已提交
1452
		const restore = this.storageService.getBoolean(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE);
1453
		if (restore) {
I
isidor 已提交
1454
			this.storageService.remove(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE); // only support once
1455 1456 1457 1458
		}

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