workbench.ts 56.9 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 32
import { ActivitybarPart } from 'vs/workbench/browser/parts/activitybar/activitybarPart';
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
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 已提交
33 34
import { TitlebarPart } from 'vs/workbench/browser/parts/titlebar/titlebarPart';
import { WorkbenchLayout } from 'vs/workbench/browser/layout';
35
import { IActionBarRegistry, Extensions as ActionBarExtensions } from 'vs/workbench/browser/actions';
J
Johannes Rieken 已提交
36 37
import { PanelRegistry, Extensions as PanelExtensions } from 'vs/workbench/browser/panel';
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
C
Christof Marti 已提交
38 39
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickInput';
J
Johannes Rieken 已提交
40
import { getServices } from 'vs/platform/instantiation/common/extensions';
41
import { Position, Parts, IPartService, ILayoutOptions, IDimension } from 'vs/workbench/services/part/common/partService';
42
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
J
Johannes Rieken 已提交
43 44 45 46
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';
47
import { WorkspaceService, DefaultConfigurationExportHelper } from 'vs/workbench/services/configuration/node/configurationService';
48 49
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
import { JSONEditingService } from 'vs/workbench/services/configuration/node/jsonEditingService';
J
Johannes Rieken 已提交
50 51
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
52
import { IKeybindingEditingService, KeybindingsEditingService } from 'vs/workbench/services/keybinding/common/keybindingEditing';
J
Johannes Rieken 已提交
53
import { ContextKeyExpr, RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
I
isidor 已提交
54
import { IActivityService } from 'vs/workbench/services/activity/common/activity';
B
Benjamin Pasero 已提交
55
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
P
Pine Wu 已提交
56
import { ViewletService } from 'vs/workbench/services/viewlet/browser/viewletService';
57
import { RemoteFileService } from 'vs/workbench/services/files/electron-browser/remoteFileService';
J
Johannes Rieken 已提交
58 59
import { IFileService } from 'vs/platform/files/common/files';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
60
import { ConfigurationResolverService } from 'vs/workbench/services/configurationResolver/electron-browser/configurationResolverService';
J
Johannes Rieken 已提交
61
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
B
Benjamin Pasero 已提交
62
import { ITitleService } from 'vs/workbench/services/title/common/titleService';
B
Benjamin Pasero 已提交
63
import { IWorkbenchEditorService, IResourceInputType, WorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
J
Johannes Rieken 已提交
64
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
65 66
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { ClipboardService } from 'vs/platform/clipboard/electron-browser/clipboardService';
J
Johannes Rieken 已提交
67 68 69 70 71 72
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 已提交
73 74
import { ISCMService } from 'vs/workbench/services/scm/common/scm';
import { SCMService } from 'vs/workbench/services/scm/common/scmService';
75 76
import { IProgressService2 } from 'vs/platform/progress/common/progress';
import { ProgressService2 } from 'vs/workbench/services/progress/browser/progressService2';
77
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
78
import { ITextModelService } from 'vs/editor/common/services/resolverService';
J
Johannes Rieken 已提交
79
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
B
Benjamin Pasero 已提交
80
import { ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle';
81
import { LifecycleService } from 'vs/platform/lifecycle/electron-browser/lifecycleService';
B
Benjamin Pasero 已提交
82
import { IWindowService, IWindowConfiguration as IWindowSettings, IWindowConfiguration, IPath } from 'vs/platform/windows/common/windows';
J
Johannes Rieken 已提交
83
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
84
import { IMenuService, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
85
import { MenuService } from 'vs/workbench/services/actions/common/menuService';
J
Johannes Rieken 已提交
86 87
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
B
Benjamin Pasero 已提交
88
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
89
import { OpenRecentAction, ToggleDevToolsAction, ReloadWindowAction, ShowPreviousWindowTab, MoveWindowTabToNewWindow, MergeAllWindowTabs, ShowNextWindowTab, ToggleWindowTabsBar, ReloadWindowWithExtensionsDisabledAction } from 'vs/workbench/electron-browser/actions';
90
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
91
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
B
Benjamin Pasero 已提交
92
import { WorkspaceEditingService } from 'vs/workbench/services/workspace/node/workspaceEditingService';
93
import { FileDecorationsService } from 'vs/workbench/services/decorations/browser/decorationsService';
J
Johannes Rieken 已提交
94
import { IDecorationsService } from 'vs/workbench/services/decorations/browser/decorations';
I
isidor 已提交
95
import { ActivityService } from 'vs/workbench/services/activity/browser/activityService';
B
Benjamin Pasero 已提交
96
import URI from 'vs/base/common/uri';
J
Joao Moreno 已提交
97
import { IListService, ListService } from 'vs/platform/list/browser/listService';
J
Joao Moreno 已提交
98 99
import { domEvent } from 'vs/base/browser/event';
import { InputFocusedContext } from 'vs/platform/workbench/common/contextkeys';
100
import { IViewsService } from 'vs/workbench/common/views';
S
Sandeep Somavarapu 已提交
101
import { ViewsService } from 'vs/workbench/browser/parts/views/views';
102 103
import { INotificationService } from 'vs/platform/notification/common/notification';
import { NotificationService } from 'vs/workbench/services/notification/common/notificationService';
104 105
import { NotificationsCenter } from 'vs/workbench/browser/parts/notifications/notificationsCenter';
import { NotificationsAlerts } from 'vs/workbench/browser/parts/notifications/notificationsAlerts';
106
import { NotificationsStatus } from 'vs/workbench/browser/parts/notifications/notificationsStatus';
107
import { registerNotificationCommands } from 'vs/workbench/browser/parts/notifications/notificationsCommands';
108
import { NotificationsToasts } from 'vs/workbench/browser/parts/notifications/notificationsToasts';
J
Joao Moreno 已提交
109 110
import { IPCClient } from 'vs/base/parts/ipc/common/ipc';
import { registerWindowDriver } from 'vs/platform/driver/electron-browser/driver';
S
Sandeep Somavarapu 已提交
111 112
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { PreferencesService } from 'vs/workbench/services/preferences/browser/preferencesService';
J
Joao Moreno 已提交
113
import { IExtensionUrlHandler, ExtensionUrlHandler } from 'vs/platform/url/electron-browser/inactiveExtensionUrlHandler';
114

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

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

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

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

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

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

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

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

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

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

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

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

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

B
Benjamin Pasero 已提交
188
	private parent: HTMLElement;
E
Erich Gamma 已提交
189 190 191 192 193 194 195
	private container: HTMLElement;
	private workbenchParams: WorkbenchParams;
	private workbenchContainer: Builder;
	private workbench: Builder;
	private workbenchStarted: boolean;
	private workbenchCreated: boolean;
	private workbenchShutdown: boolean;
196
	private editorService: WorkbenchEditorService;
P
Pine Wu 已提交
197
	private viewletService: IViewletService;
198
	private contextKeyService: IContextKeyService;
199
	private keybindingService: IKeybindingService;
200
	private backupFileService: IBackupFileService;
201
	private fileService: IFileService;
B
Benjamin Pasero 已提交
202
	private titlebarPart: TitlebarPart;
E
Erich Gamma 已提交
203 204
	private activitybarPart: ActivitybarPart;
	private sidebarPart: SidebarPart;
I
isidor 已提交
205
	private panelPart: PanelPart;
E
Erich Gamma 已提交
206 207 208
	private editorPart: EditorPart;
	private statusbarPart: StatusbarPart;
	private quickOpen: QuickOpenController;
C
Christof Marti 已提交
209
	private quickInput: QuickInputService;
210
	private notificationsCenter: NotificationsCenter;
211
	private notificationsToasts: NotificationsToasts;
E
Erich Gamma 已提交
212
	private workbenchLayout: WorkbenchLayout;
213
	private toUnbind: IDisposable[];
E
Erich Gamma 已提交
214
	private sideBarHidden: boolean;
215
	private statusBarHidden: boolean;
S
Sanders Lauture 已提交
216
	private activityBarHidden: boolean;
E
Erich Gamma 已提交
217
	private sideBarPosition: Position;
I
isidor 已提交
218
	private panelPosition: Position;
I
isidor 已提交
219
	private panelHidden: boolean;
220
	private editorBackgroundDelayer: Delayer<any>;
221
	private closeEmptyWindowScheduler: RunOnceScheduler;
A
Alex Dima 已提交
222
	private editorsVisibleContext: IContextKey<boolean>;
I
isidor 已提交
223
	private inZenMode: IContextKey<boolean>;
224
	private sideBarVisibleContext: IContextKey<boolean>;
225
	private hasFilesToCreateOpenOrDiff: boolean;
226
	private fontAliasing: FontAliasingOption;
B
Benjamin Pasero 已提交
227
	private centeredEditorLayoutActive: boolean;
I
isidor 已提交
228
	private zenMode: {
I
isidor 已提交
229 230
		active: boolean;
		transitionedToFullScreen: boolean;
231
		transitionedToCenteredEditorLayout: boolean;
232 233
		wasSideBarVisible: boolean;
		wasPanelVisible: boolean;
I
isidor 已提交
234
	};
E
Erich Gamma 已提交
235

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

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

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

264
		this.toUnbind = [];
265

E
Erich Gamma 已提交
266
		this.editorBackgroundDelayer = new Delayer<void>(50);
267
		this.closeEmptyWindowScheduler = new RunOnceScheduler(() => this.onAllEditorsClosed(), 50);
E
Erich Gamma 已提交
268

269
		this._onTitleBarVisibilityChange = new Emitter<void>();
E
Erich Gamma 已提交
270 271
	}

272 273 274 275
	public get onTitleBarVisibilityChange(): Event<void> {
		return this._onTitleBarVisibilityChange.event;
	}

276
	public get onEditorLayout(): Event<IDimension> {
277
		return this.editorPart.onLayout;
278 279
	}

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

B
Benjamin Pasero 已提交
287
		// Create Workbench Container
288
		this.createWorkbench();
E
Erich Gamma 已提交
289

290 291
		// Install some global actions
		this.createGlobalActions();
292

293 294
		// Services
		this.initServices();
E
Erich Gamma 已提交
295

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

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

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

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

312 313
		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 已提交
314

315 316
		// Register Listeners
		this.registerListeners();
E
Erich Gamma 已提交
317

318 319
		// Settings
		this.initSettings();
E
Erich Gamma 已提交
320

321 322
		// Create Workbench and Parts
		this.renderWorkbench();
323

324 325
		// Workbench Layout
		this.createWorkbenchLayout();
B
polish  
Benjamin Pasero 已提交
326

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

333
		// Restore Parts
B
Benjamin Pasero 已提交
334 335
		return this.restoreParts();
	}
336

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

345 346 347 348
	private restoreParts(): TPromise<IWorkbenchStartedInfo> {
		const restorePromises: TPromise<any>[] = [];

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

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

J
Johannes Rieken 已提交
362
				perf.mark('didRestoreEditors');
363

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

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

381 382 383
			if (this.shouldRestoreLastOpenedViewlet()) {
				viewletIdToRestore = this.storageService.get(SidebarPart.activeViewletSettingsKey, StorageScope.WORKSPACE);
			}
384

385 386 387
			if (!viewletIdToRestore) {
				viewletIdToRestore = this.viewletService.getDefaultViewletId();
			}
388

J
Johannes Rieken 已提交
389
			perf.mark('willRestoreViewlet');
S
Sandeep Somavarapu 已提交
390 391 392 393 394
			restorePromises.push(this.viewletService.openViewlet(viewletIdToRestore)
				.then(viewlet => viewlet || this.viewletService.openViewlet(this.viewletService.getDefaultViewletId()))
				.then(() => {
					perf.mark('didRestoreViewlet');
				}));
395
		}
E
Erich Gamma 已提交
396

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		return TPromise.as([]);
	}

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

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

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

			return input;
		});
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

E
Erich Gamma 已提交
594
		// Editor service (editor part)
595
		this.editorPart = this.instantiationService.createInstance(EditorPart, Identifiers.EDITOR_PART, !this.hasFilesToCreateOpenOrDiff);
596
		this.toUnbind.push({ dispose: () => this.editorPart.shutdown() });
597
		this.editorService = this.instantiationService.createInstance(WorkbenchEditorService, this.editorPart);
598
		serviceCollection.set(IWorkbenchEditorService, this.editorService);
599
		serviceCollection.set(IEditorGroupService, this.editorPart);
E
Erich Gamma 已提交
600

601 602
		// Title bar
		this.titlebarPart = this.instantiationService.createInstance(TitlebarPart, Identifiers.TITLEBAR_PART);
603
		this.toUnbind.push({ dispose: () => this.titlebarPart.shutdown() });
604 605
		serviceCollection.set(ITitleService, this.titlebarPart);

606
		// History
607
		serviceCollection.set(IHistoryService, new SyncDescriptor(HistoryService));
608

609
		// Backup File Service
610
		this.backupFileService = this.instantiationService.createInstance(BackupFileService, this.workbenchParams.configuration.backupPath);
611
		serviceCollection.set(IBackupFileService, this.backupFileService);
612

613
		// Text File Service
614
		serviceCollection.set(ITextFileService, new SyncDescriptor(TextFileService));
615

616
		// File Decorations
J
Johannes Rieken 已提交
617
		serviceCollection.set(IDecorationsService, new SyncDescriptor(FileDecorationsService));
618

J
Joao Moreno 已提交
619
		// SCM Service
620
		serviceCollection.set(ISCMService, new SyncDescriptor(SCMService));
621

J
Joao Moreno 已提交
622
		// Inactive extension URL handler
J
Joao Moreno 已提交
623
		serviceCollection.set(IExtensionUrlHandler, new SyncDescriptor(ExtensionUrlHandler));
J
Joao Moreno 已提交
624

B
Benjamin Pasero 已提交
625
		// Text Model Resolver Service
626
		serviceCollection.set(ITextModelService, new SyncDescriptor(TextModelResolverService));
B
Benjamin Pasero 已提交
627

628 629 630 631
		// JSON Editing
		const jsonEditingService = this.instantiationService.createInstance(JSONEditingService);
		serviceCollection.set(IJSONEditingService, jsonEditingService);

632 633 634
		// Workspace Editing
		serviceCollection.set(IWorkspaceEditingService, new SyncDescriptor(WorkspaceEditingService));

635 636 637
		// Keybinding Editing
		serviceCollection.set(IKeybindingEditingService, this.instantiationService.createInstance(KeybindingsEditingService));

638
		// Configuration Resolver
B
Benjamin Pasero 已提交
639
		serviceCollection.set(IConfigurationResolverService, new SyncDescriptor(ConfigurationResolverService, process.env));
640

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

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

S
Sandeep Somavarapu 已提交
651 652 653
		// PreferencesService
		serviceCollection.set(IPreferencesService, this.instantiationService.createInstance(PreferencesService));

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

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

665
		this.instantiationService.createInstance(DefaultConfigurationExportHelper);
666

S
#47154  
Sandeep Somavarapu 已提交
667
		this.configurationService.acquireInstantiationService(this.getInstantiationService());
E
Erich Gamma 已提交
668 669 670 671 672
	}

	private initSettings(): void {

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

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

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

I
isidor 已提交
686
		// Panel position
687
		this.setPanelPositionFromStorageOrConfig();
I
isidor 已提交
688

B
Benjamin Pasero 已提交
689
		// Statusbar visibility
690
		const statusBarVisible = this.configurationService.getValue<string>(Workbench.statusbarVisibleConfigurationKey);
691
		this.statusBarHidden = !statusBarVisible;
S
Sanders Lauture 已提交
692 693

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

697
		// Font aliasing
698
		this.fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
699

I
isidor 已提交
700 701
		// Zen mode
		this.zenMode = {
I
isidor 已提交
702
			active: false,
703
			transitionedToFullScreen: false,
704
			transitionedToCenteredEditorLayout: false,
705 706
			wasSideBarVisible: false,
			wasPanelVisible: false
I
isidor 已提交
707
		};
S
SrTobi 已提交
708

B
Benjamin Pasero 已提交
709 710
		// Centered Editor Layout
		this.centeredEditorLayoutActive = false;
E
Erich Gamma 已提交
711 712
	}

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

739 740 741 742 743
		const container = this.getContainer(part);
		return DOM.isAncestor(activeElement, container);
	}

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

		return container;
E
Erich Gamma 已提交
767 768 769
	}

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

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

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

		return offset;
	}

795
	private getCustomTitleBarStyle(): 'custom' {
B
Benjamin Pasero 已提交
796
		if (!isMacintosh) {
797
			return null; // custom title bar is only supported on Mac currently
B
Benjamin Pasero 已提交
798 799
		}

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

805
		const windowConfig = this.configurationService.getValue<IWindowSettings>();
806 807 808 809 810
		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 已提交
811

812 813 814 815
			const style = windowConfig.window.titleBarStyle;
			if (style === 'custom') {
				return style;
			}
816 817 818
		}

		return null;
B
Benjamin Pasero 已提交
819 820
	}

821
	private setStatusBarHidden(hidden: boolean, skipLayout?: boolean): void {
822 823
		this.statusBarHidden = hidden;

824 825 826 827 828 829
		// Adjust CSS
		if (hidden) {
			this.workbench.addClass('nostatusbar');
		} else {
			this.workbench.removeClass('nostatusbar');
		}
I
isidor 已提交
830

831 832
		// Layout
		if (!skipLayout) {
833
			this.workbenchLayout.layout();
834 835 836
		}
	}

S
Sanders Lauture 已提交
837 838 839 840 841
	public setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.activityBarHidden = hidden;

		// Layout
		if (!skipLayout) {
842
			this.workbenchLayout.layout();
S
Sanders Lauture 已提交
843 844 845
		}
	}

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

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

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

864 865 866 867 868 869 870
				// 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 已提交
871 872
		}

B
Benjamin Pasero 已提交
873
		// If sidebar becomes visible, show last active Viewlet or default viewlet
E
Erich Gamma 已提交
874
		else if (!hidden && !this.sidebarPart.getActiveViewlet()) {
875
			const viewletToOpen = this.sidebarPart.getLastActiveViewletId();
E
Erich Gamma 已提交
876
			if (viewletToOpen) {
S
Sandeep Somavarapu 已提交
877 878
				promise = this.viewletService.openViewlet(viewletToOpen, true)
					.then(viewlet => viewlet || this.viewletService.openViewlet(this.viewletService.getDefaultViewletId(), true));
E
Erich Gamma 已提交
879 880 881
			}
		}

882
		return promise.then(() => {
883

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

			// Layout
			if (!skipLayout) {
894
				this.workbenchLayout.layout();
895 896
			}
		});
E
Erich Gamma 已提交
897 898
	}

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

902 903 904 905 906 907 908
		// Adjust CSS
		if (hidden) {
			this.workbench.addClass('nopanel');
		} else {
			this.workbench.removeClass('nopanel');
		}

I
isidor 已提交
909
		// If panel part becomes hidden, also hide the current active panel if any
910
		let promise = TPromise.wrap<any>(null);
I
isidor 已提交
911
		if (hidden && this.panelPart.getActivePanel()) {
912 913 914 915 916 917 918
			promise = this.panelPart.hideActivePanel().then(() => {
				// Pass Focus to Editor if Panel part is now hidden
				const editor = this.editorPart.getActiveEditor();
				if (editor) {
					editor.focus();
				}
			});
I
isidor 已提交
919 920 921 922
		}

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

929
		return promise.then(() => {
930

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

			// Layout
			if (!skipLayout) {
940
				this.workbenchLayout.layout();
941 942
			}
		});
I
isidor 已提交
943 944
	}

945
	public toggleMaximizedPanel(): void {
I
isidor 已提交
946
		this.workbenchLayout.layout({ toggleMaximizedPanel: true, source: Parts.PANEL_PART });
947 948 949 950 951 952
	}

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

E
Erich Gamma 已提交
953 954 955 956
	public getSideBarPosition(): Position {
		return this.sideBarPosition;
	}

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

B
Benjamin Pasero 已提交
962 963
		const newPositionValue = (position === Position.LEFT) ? 'left' : 'right';
		const oldPositionValue = (this.sideBarPosition === Position.LEFT) ? 'left' : 'right';
E
Erich Gamma 已提交
964 965 966
		this.sideBarPosition = position;

		// Adjust CSS
967 968 969 970
		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 已提交
971

972 973 974 975
		// Update Styles
		this.activitybarPart.updateStyles();
		this.sidebarPart.updateStyles();

E
Erich Gamma 已提交
976
		// Layout
977
		this.workbenchLayout.layout();
E
Erich Gamma 已提交
978 979
	}

I
isidor 已提交
980 981 982 983
	public getPanelPosition(): Position {
		return this.panelPosition;
	}

I
isidor 已提交
984 985 986 987 988 989
	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 已提交
990

I
isidor 已提交
991
			// Adjust CSS
992 993
			DOM.removeClass(this.panelPart.getContainer(), oldPositionValue);
			DOM.addClass(this.panelPart.getContainer(), newPositionValue);
I
isidor 已提交
994

I
isidor 已提交
995 996
			// Update Styles
			this.panelPart.updateStyles();
I
isidor 已提交
997

I
isidor 已提交
998 999 1000
			// Layout
			this.workbenchLayout.layout();
		});
I
isidor 已提交
1001 1002
	}

1003
	private setFontAliasing(aliasing: FontAliasingOption) {
1004
		this.fontAliasing = aliasing;
B
Benjamin Pasero 已提交
1005 1006 1007 1008 1009 1010

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

		// Add specific
		if (fontAliasingValues.some(option => option === aliasing)) {
1011 1012
			document.body.classList.add(`monaco-font-aliasing-${aliasing}`);
		}
1013 1014
	}

1015
	public dispose(reason = ShutdownReason.QUIT): void {
1016 1017 1018

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

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

1034 1035 1036
		// Dispose bindings
		this.toUnbind = dispose(this.toUnbind);

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

	private registerListeners(): void {

		// Listen to editor changes
1054
		this.toUnbind.push(this.editorPart.onEditorsChanged(() => this.onEditorsChanged()));
1055

1056 1057 1058 1059 1060 1061 1062
		// 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);
			const listenerDispose = this.editorPart.getStacksModel().onEditorClosed(() => this.onEditorClosed(listenerDispose, resourcesToWaitFor, waitMarkerFile));

1063
			this.toUnbind.push(listenerDispose);
1064 1065
		}

1066
		// Configuration changes
1067
		this.toUnbind.push(this.configurationService.onDidChangeConfiguration(() => this.onDidUpdateConfiguration()));
1068 1069

		// Fullscreen changes
1070
		this.toUnbind.push(browser.onDidChangeFullscreen(() => this.onFullscreenChanged()));
1071 1072 1073 1074 1075 1076 1077
	}

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

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

1089 1090 1091 1092 1093
		// 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
1094
		}
E
Erich Gamma 已提交
1095 1096
	}

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

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

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

E
Erich Gamma 已提交
1122 1123
		// 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 已提交
1124 1125 1126 1127 1128 1129
		this.handleEditorBackground();
	}

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

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

1140 1141 1142 1143 1144 1145 1146
	private onAllEditorsClosed(): void {
		const visibleEditors = this.editorService.getVisibleEditors().length;
		if (visibleEditors === 0) {
			this.windowService.closeWindow();
		}
	}

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

1154 1155
		this.setPanelPositionFromStorageOrConfig();

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

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

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

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

	private renderWorkbench(): void {

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

B
Benjamin Pasero 已提交
1207
		// Apply font aliasing
1208 1209
		this.setFontAliasing(this.fontAliasing);

B
Benjamin Pasero 已提交
1210
		// Apply title style if shown
1211 1212 1213 1214 1215 1216 1217 1218
		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 已提交
1219 1220
		}

E
Erich Gamma 已提交
1221
		// Create Parts
B
Benjamin Pasero 已提交
1222
		this.createTitlebarPart();
E
Erich Gamma 已提交
1223 1224 1225
		this.createActivityBarPart();
		this.createSidebarPart();
		this.createEditorPart();
1226
		this.createPanelPart();
E
Erich Gamma 已提交
1227 1228
		this.createStatusbarPart();

1229 1230
		// Notification Handlers
		this.createNotificationsHandlers();
1231

E
Erich Gamma 已提交
1232 1233 1234 1235
		// Add Workbench to DOM
		this.workbenchContainer.build(this.container);
	}

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

1243
		this.titlebarPart.create(titlebarContainer.getHTMLElement());
B
Benjamin Pasero 已提交
1244 1245
	}

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

1254
		this.activitybarPart.create(activitybarPartContainer.getHTMLElement());
E
Erich Gamma 已提交
1255 1256 1257
	}

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

1265
		this.sidebarPart.create(sidebarPartContainer.getHTMLElement());
E
Erich Gamma 已提交
1266 1267
	}

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

1276
		this.panelPart.create(panelPartContainer.getHTMLElement());
I
isidor 已提交
1277 1278
	}

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

1287
		this.editorPart.create(editorContainer.getHTMLElement());
E
Erich Gamma 已提交
1288 1289 1290
	}

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

1297
		this.statusbarPart.create(statusbarContainer.getHTMLElement());
E
Erich Gamma 已提交
1298 1299
	}

1300 1301
	private createNotificationsHandlers(): void {

1302 1303 1304
		// Notifications Center
		this.notificationsCenter = this.instantiationService.createInstance(NotificationsCenter, this.workbench.getHTMLElement(), this.notificationService.model);
		this.toUnbind.push(this.notificationsCenter);
1305

1306 1307 1308 1309
		// Notifications Toasts
		this.notificationsToasts = this.instantiationService.createInstance(NotificationsToasts, this.workbench.getHTMLElement(), this.notificationService.model);
		this.toUnbind.push(this.notificationsToasts);

1310
		// Notifications Alerts
1311 1312
		const notificationsAlerts = this.instantiationService.createInstance(NotificationsAlerts, this.notificationService.model);
		this.toUnbind.push(notificationsAlerts);
1313 1314 1315 1316

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

1317 1318 1319 1320 1321 1322 1323 1324 1325 1326
		// Eventing
		this.toUnbind.push(this.notificationsCenter.onDidChangeVisibility(() => {

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

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

1327
		// Register Commands
1328
		registerNotificationCommands(this.notificationsCenter, this.notificationsToasts);
1329 1330
	}

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

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

I
isidor 已提交
1351
	public toggleZenMode(skipLayout?: boolean): void {
I
isidor 已提交
1352
		this.zenMode.active = !this.zenMode.active;
1353

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

1367 1368 1369
			if (config.hideActivityBar) {
				this.setActivityBarHidden(true, true);
			}
1370

I
isidor 已提交
1371
			if (config.hideStatusBar) {
I
isidor 已提交
1372 1373
				this.setStatusBarHidden(true, true);
			}
1374

I
isidor 已提交
1375
			if (config.hideTabs) {
I
isidor 已提交
1376 1377
				this.editorPart.hideTabs(true);
			}
1378 1379 1380 1381

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

1393 1394
			// Status bar and activity bar visibility come from settings -> update their visibility.
			this.onDidUpdateConfiguration(true);
I
isidor 已提交
1395
			this.editorPart.hideTabs(false);
I
isidor 已提交
1396 1397 1398 1399
			const activeEditor = this.editorPart.getActiveEditor();
			if (activeEditor) {
				activeEditor.focus();
			}
1400

1401
			toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
I
isidor 已提交
1402
		}
1403

1404
		this.inZenMode.set(this.zenMode.active);
I
isidor 已提交
1405

I
isidor 已提交
1406
		if (!skipLayout) {
1407
			this.layout();
I
isidor 已提交
1408
		}
1409

1410
		if (toggleFullScreen) {
1411
			this.windowService.toggleFullScreen().done(void 0, errors.onUnexpectedError);
1412
		}
I
isidor 已提交
1413 1414
	}

B
Benjamin Pasero 已提交
1415 1416
	public isEditorLayoutCentered(): boolean {
		return this.centeredEditorLayoutActive;
S
SrTobi 已提交
1417 1418
	}

1419 1420
	public centerEditorLayout(active: boolean, skipLayout?: boolean): void {
		this.centeredEditorLayoutActive = active;
1421
		this.storageService.store(Workbench.centeredEditorLayoutActiveStorageKey, this.centeredEditorLayoutActive, StorageScope.WORKSPACE);
B
Benjamin Pasero 已提交
1422

1423 1424 1425
		if (!skipLayout) {
			this.layout();
		}
S
SrTobi 已提交
1426 1427
	}

1428 1429 1430 1431 1432 1433 1434 1435 1436 1437
	// 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 已提交
1438
				return; // Cannot resize other parts
1439 1440 1441 1442
		}
	}


1443
	private shouldRestoreLastOpenedViewlet(): boolean {
1444 1445 1446 1447
		if (!this.environmentService.isBuilt) {
			return true; // always restore sidebar when we are in development mode
		}

I
isidor 已提交
1448
		const restore = this.storageService.getBoolean(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE);
1449
		if (restore) {
I
isidor 已提交
1450
			this.storageService.remove(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE); // only support once
1451 1452 1453 1454
		}

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