workbench.ts 59.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';
B
Benjamin Pasero 已提交
12
import { IDisposable, dispose, toDisposable, Disposable } from 'vs/base/common/lifecycle';
M
Matt Bierner 已提交
13
import { Event, Emitter } from 'vs/base/common/event';
14
import * as DOM from 'vs/base/browser/dom';
B
Benjamin Pasero 已提交
15
import { Builder, $ } from 'vs/base/browser/builder';
B
Benjamin Pasero 已提交
16
import { RunOnceScheduler } from 'vs/base/common/async';
17
import * as browser from 'vs/base/browser/browser';
J
Johannes Rieken 已提交
18
import * as perf from 'vs/base/common/performance';
19
import * as errors from 'vs/base/common/errors';
20
import { BackupFileService } from 'vs/workbench/services/backup/node/backupFileService';
21
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
22
import { Registry } from 'vs/platform/registry/common/platform';
B
Benjamin Pasero 已提交
23
import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform';
B
Benjamin Pasero 已提交
24
import { IResourceInput } from 'vs/platform/editor/common/editor';
J
Johannes Rieken 已提交
25
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
B
Benjamin Pasero 已提交
26
import { IEditorInputFactoryRegistry, Extensions as EditorExtensions, TextCompareEditorVisibleContext, TEXT_DIFF_EDITOR_ID, EditorsVisibleContext, InEditorZenModeContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, IUntitledResourceInput, IResourceDiffInput, SplitEditorsVertically } 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
import { TitlebarPart } from 'vs/workbench/browser/parts/titlebar/titlebarPart';
33
import { MenubarPart } from 'vs/workbench/browser/parts/menubar/menubarPart';
B
Benjamin Pasero 已提交
34
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
B
Benjamin Pasero 已提交
35
import { WorkbenchLayout } from 'vs/workbench/browser/layout';
36
import { IActionBarRegistry, Extensions as ActionBarExtensions } from 'vs/workbench/browser/actions';
J
Johannes Rieken 已提交
37 38
import { PanelRegistry, Extensions as PanelExtensions } from 'vs/workbench/browser/panel';
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
C
Christof Marti 已提交
39 40
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickInput';
J
Johannes Rieken 已提交
41
import { getServices } from 'vs/platform/instantiation/common/extensions';
42
import { Position, Parts, IPartService, ILayoutOptions, IDimension } from 'vs/workbench/services/part/common/partService';
43
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
J
Johannes Rieken 已提交
44
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
S
SteVen Batten 已提交
45 46
import { ContextMenuService as NativeContextMenuService } from 'vs/workbench/services/contextview/electron-browser/contextmenuService';
import { ContextMenuService as HTMLContextMenuService } from 'vs/platform/contextview/browser/contextMenuService';
J
Johannes Rieken 已提交
47 48
import { WorkbenchKeybindingService } from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
49
import { WorkspaceService, DefaultConfigurationExportHelper } from 'vs/workbench/services/configuration/node/configurationService';
50 51
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
import { JSONEditingService } from 'vs/workbench/services/configuration/node/jsonEditingService';
J
Johannes Rieken 已提交
52 53
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
54
import { IKeybindingEditingService, KeybindingsEditingService } from 'vs/workbench/services/keybinding/common/keybindingEditing';
B
Benjamin Pasero 已提交
55
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
I
isidor 已提交
56
import { IActivityService } from 'vs/workbench/services/activity/common/activity';
B
Benjamin Pasero 已提交
57
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
P
Pine Wu 已提交
58
import { ViewletService } from 'vs/workbench/services/viewlet/browser/viewletService';
59
import { RemoteFileService } from 'vs/workbench/services/files/electron-browser/remoteFileService';
J
Johannes Rieken 已提交
60 61
import { IFileService } from 'vs/platform/files/common/files';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
62
import { ConfigurationResolverService } from 'vs/workbench/services/configurationResolver/electron-browser/configurationResolverService';
J
Johannes Rieken 已提交
63
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
B
Benjamin Pasero 已提交
64
import { ITitleService } from 'vs/workbench/services/title/common/titleService';
J
Johannes Rieken 已提交
65
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
66 67
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { ClipboardService } from 'vs/platform/clipboard/electron-browser/clipboardService';
J
Johannes Rieken 已提交
68 69 70 71 72
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
import { IProgressService2 } from 'vs/workbench/services/progress/common/progress';
76
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';
S
SteVen Batten 已提交
86
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
J
Johannes Rieken 已提交
87
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';
B
Benjamin Pasero 已提交
91 92
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
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
import { InputFocusedContext } from 'vs/platform/workbench/common/contextkeys';
99
import { IViewsService } from 'vs/workbench/common/views';
B
Benjamin Pasero 已提交
100
import { ViewsService } from 'vs/workbench/browser/parts/views/views';
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';
B
Benjamin Pasero 已提交
112 113 114
import { IEditorService, IResourceEditor } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupsService, GroupDirection, preferredSideBySideGroupDirection, GroupOrientation } from 'vs/workbench/services/group/common/editorGroupsService';
import { EditorService } from 'vs/workbench/services/editor/browser/editorService';
J
Joao Moreno 已提交
115
import { IExtensionUrlHandler, ExtensionUrlHandler } from 'vs/platform/url/electron-browser/inactiveExtensionUrlHandler';
S
SteVen Batten 已提交
116
import { ContextViewService } from 'vs/platform/contextview/browser/contextViewService';
S
SteVen Batten 已提交
117 118
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
A
Alex Dima 已提交
119 120
import { WorkbenchThemeService } from 'vs/workbench/services/themes/electron-browser/workbenchThemeService';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
E
Erich Gamma 已提交
121 122

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

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

136 137 138
export interface IWorkbenchStartedInfo {
	customKeybindingsCount: number;
	pinnedViewlets: string[];
139
	restoredViewlet: string;
B
Benjamin Pasero 已提交
140
	restoredEditorsCount: number;
141 142
}

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

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

147 148
const Identifiers = {
	WORKBENCH_CONTAINER: 'workbench.main.container',
B
Benjamin Pasero 已提交
149
	TITLEBAR_PART: 'workbench.parts.titlebar',
150 151 152 153
	ACTIVITYBAR_PART: 'workbench.parts.activitybar',
	SIDEBAR_PART: 'workbench.parts.sidebar',
	PANEL_PART: 'workbench.parts.panel',
	EDITOR_PART: 'workbench.parts.editor',
154 155
	STATUSBAR_PART: 'workbench.parts.statusbar',
	MENUBAR_PART: 'workbench.parts.menubar'
156 157
};

J
Joao Moreno 已提交
158 159 160 161 162 163 164 165
function getWorkbenchStateString(state: WorkbenchState): string {
	switch (state) {
		case WorkbenchState.EMPTY: return 'empty';
		case WorkbenchState.FOLDER: return 'folder';
		case WorkbenchState.WORKSPACE: return 'workspace';
	}
}

B
Benjamin Pasero 已提交
166 167 168 169 170 171 172 173 174 175
interface IZenMode {
	active: boolean;
	transitionedToFullScreen: boolean;
	transitionedToCenteredEditorLayout: boolean;
	transitionDisposeables: IDisposable[];
	wasSideBarVisible: boolean;
	wasPanelVisible: boolean;
}

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

177
	private static readonly sidebarHiddenStorageKey = 'workbench.sidebar.hidden';
178
	private static readonly menubarVisibilityConfigurationKey = 'window.menuBarVisibility';
179 180 181
	private static readonly sidebarRestoreStorageKey = 'workbench.sidebar.restore';
	private static readonly panelHiddenStorageKey = 'workbench.panel.hidden';
	private static readonly zenModeActiveStorageKey = 'workbench.zenmode.active';
182
	private static readonly centeredEditorLayoutActiveStorageKey = 'workbench.centerededitorlayout.active';
183
	private static readonly panelPositionStorageKey = 'workbench.panel.location';
184
	private static readonly defaultPanelPositionStorageKey = 'workbench.panel.defaultLocation';
185 186 187 188 189
	private static readonly sidebarPositionConfigurationKey = 'workbench.sideBar.location';
	private static readonly statusbarVisibleConfigurationKey = 'workbench.statusBar.visible';
	private static readonly activityBarVisibleConfigurationKey = 'workbench.activityBar.visible';
	private static readonly closeWhenEmptyConfigurationKey = 'window.closeWhenEmpty';
	private static readonly fontAliasingConfigurationKey = 'workbench.fontAliasing';
190

B
Benjamin Pasero 已提交
191
	_serviceBrand: any;
192

E
Erich Gamma 已提交
193 194 195 196 197 198
	private workbenchParams: WorkbenchParams;
	private workbenchContainer: Builder;
	private workbench: Builder;
	private workbenchStarted: boolean;
	private workbenchCreated: boolean;
	private workbenchShutdown: boolean;
B
Benjamin Pasero 已提交
199 200 201

	private editorService: EditorService;
	private editorGroupService: IEditorGroupsService;
P
Pine Wu 已提交
202
	private viewletService: IViewletService;
203
	private contextKeyService: IContextKeyService;
204
	private keybindingService: IKeybindingService;
205
	private backupFileService: IBackupFileService;
206
	private fileService: IFileService;
B
Benjamin Pasero 已提交
207 208 209 210
	private quickInput: QuickInputService;

	private workbenchLayout: WorkbenchLayout;

B
Benjamin Pasero 已提交
211
	private titlebarPart: TitlebarPart;
212
	private menubarPart: MenubarPart;
E
Erich Gamma 已提交
213 214
	private activitybarPart: ActivitybarPart;
	private sidebarPart: SidebarPart;
I
isidor 已提交
215
	private panelPart: PanelPart;
E
Erich Gamma 已提交
216 217 218
	private editorPart: EditorPart;
	private statusbarPart: StatusbarPart;
	private quickOpen: QuickOpenController;
219
	private notificationsCenter: NotificationsCenter;
220
	private notificationsToasts: NotificationsToasts;
B
Benjamin Pasero 已提交
221

E
Erich Gamma 已提交
222
	private sideBarHidden: boolean;
223
	private statusBarHidden: boolean;
S
Sanders Lauture 已提交
224
	private activityBarHidden: boolean;
E
Erich Gamma 已提交
225
	private sideBarPosition: Position;
I
isidor 已提交
226
	private panelPosition: Position;
I
isidor 已提交
227
	private panelHidden: boolean;
228
	private menubarHidden: boolean;
B
Benjamin Pasero 已提交
229 230 231 232 233
	private zenMode: IZenMode;
	private centeredEditorLayoutActive: boolean;
	private fontAliasing: FontAliasingOption;
	private hasInitialFilesToOpen: boolean;

I
isidor 已提交
234
	private inZenMode: IContextKey<boolean>;
235
	private sideBarVisibleContext: IContextKey<boolean>;
B
Benjamin Pasero 已提交
236 237

	private closeEmptyWindowScheduler: RunOnceScheduler = new RunOnceScheduler(() => this.onAllEditorsClosed(), 50);
E
Erich Gamma 已提交
238

239
	constructor(
B
Benjamin Pasero 已提交
240 241
		private parent: HTMLElement,
		private 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,
A
Alex Dima 已提交
250
		@IWorkbenchThemeService private themeService: WorkbenchThemeService,
I
isidor 已提交
251
		@IEnvironmentService private environmentService: IEnvironmentService,
252
		@IWindowService private windowService: IWindowService,
S
SteVen Batten 已提交
253
		@INotificationService private notificationService: NotificationService,
S
SteVen Batten 已提交
254 255
		@IContextViewService private contextViewService: ContextViewService,
		@ITelemetryService private telemetryService: TelemetryService
256
	) {
B
Benjamin Pasero 已提交
257
		super();
E
Erich Gamma 已提交
258

B
Benjamin Pasero 已提交
259
		this.workbenchParams = { configuration, serviceCollection };
E
Erich Gamma 已提交
260

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

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

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

273 274
		// Install some global actions
		this.createGlobalActions();
E
Erich Gamma 已提交
275

276 277
		// Services
		this.initServices();
278

B
Benjamin Pasero 已提交
279 280
		// Context Keys
		this.handleContextKeys();
E
Erich Gamma 已提交
281

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

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

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

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

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

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

B
Benjamin Pasero 已提交
303 304 305 306 307 308
	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);
309
	}
E
Erich Gamma 已提交
310

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

B
Benjamin Pasero 已提交
314
		// Actions registered here to adjust for developing vs built workbench
B
Benjamin Pasero 已提交
315 316 317 318 319
		const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
		registry.registerWorkbenchAction(new SyncActionDescriptor(ReloadWindowAction, ReloadWindowAction.ID, ReloadWindowAction.LABEL, isDeveloping ? { primary: KeyMod.CtrlCmd | KeyCode.KEY_R } : void 0), 'Reload Window');
		registry.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"));
		registry.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"));
		registry.registerWorkbenchAction(new SyncActionDescriptor(ReloadWindowWithExtensionsDisabledAction, ReloadWindowWithExtensionsDisabledAction.ID, ReloadWindowWithExtensionsDisabledAction.LABEL), 'Reload Window Without Extensions');
320

321
		// Actions for macOS native tabs management (only when enabled)
322
		const windowConfig = this.configurationService.getValue<IWindowConfiguration>();
323
		if (windowConfig && windowConfig.window && windowConfig.window.nativeTabs) {
B
Benjamin Pasero 已提交
324 325 326 327 328
			registry.registerWorkbenchAction(new SyncActionDescriptor(ShowPreviousWindowTab, ShowPreviousWindowTab.ID, ShowPreviousWindowTab.LABEL), 'Show Previous Window Tab');
			registry.registerWorkbenchAction(new SyncActionDescriptor(ShowNextWindowTab, ShowNextWindowTab.ID, ShowNextWindowTab.LABEL), 'Show Next Window Tab');
			registry.registerWorkbenchAction(new SyncActionDescriptor(MoveWindowTabToNewWindow, MoveWindowTabToNewWindow.ID, MoveWindowTabToNewWindow.LABEL), 'Move Window Tab to New Window');
			registry.registerWorkbenchAction(new SyncActionDescriptor(MergeAllWindowTabs, MergeAllWindowTabs.ID, MergeAllWindowTabs.LABEL), 'Merge All Windows');
			registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleWindowTabsBar, ToggleWindowTabsBar.ID, ToggleWindowTabsBar.LABEL), 'Toggle Window Tabs Bar');
329
		}
330 331
	}

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

E
Erich Gamma 已提交
335
		// Services we contribute
336
		serviceCollection.set(IPartService, this);
E
Erich Gamma 已提交
337

338 339 340
		// Clipboard
		serviceCollection.set(IClipboardService, new ClipboardService());

341 342
		// Status bar
		this.statusbarPart = this.instantiationService.createInstance(StatusbarPart, Identifiers.STATUSBAR_PART);
B
Benjamin Pasero 已提交
343
		this._register(toDisposable(() => this.statusbarPart.shutdown()));
344 345
		serviceCollection.set(IStatusbarService, this.statusbarPart);

346 347 348
		// Progress 2
		serviceCollection.set(IProgressService2, new SyncDescriptor(ProgressService2));

349
		// Keybindings
A
Alex Dima 已提交
350
		this.contextKeyService = this.instantiationService.createInstance(ContextKeyService);
351
		serviceCollection.set(IContextKeyService, this.contextKeyService);
352

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

356 357 358
		// List
		serviceCollection.set(IListService, this.instantiationService.createInstance(ListService));

359
		// Context Menu
S
SteVen Batten 已提交
360 361 362
		const hasCustomTitle = this.getCustomTitleBarStyle() === 'custom';

		// Use themable context menus when custom titlebar is enabled to match custom menubar
S
SteVen Batten 已提交
363 364
		if (!isMacintosh && hasCustomTitle) {
			serviceCollection.set(IContextMenuService, new SyncDescriptor(HTMLContextMenuService, null, this.telemetryService, this.notificationService, this.contextViewService));
S
SteVen Batten 已提交
365 366 367
		} else {
			serviceCollection.set(IContextMenuService, new SyncDescriptor(NativeContextMenuService));
		}
368

369 370
		// Menus/Actions
		serviceCollection.set(IMenuService, new SyncDescriptor(MenuService));
371

P
Pine Wu 已提交
372
		// Sidebar part
373
		this.sidebarPart = this.instantiationService.createInstance(SidebarPart, Identifiers.SIDEBAR_PART);
B
Benjamin Pasero 已提交
374
		this._register(toDisposable(() => this.sidebarPart.shutdown()));
P
Pine Wu 已提交
375 376 377 378

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

I
isidor 已提交
380
		// Panel service (panel part)
381
		this.panelPart = this.instantiationService.createInstance(PanelPart, Identifiers.PANEL_PART);
B
Benjamin Pasero 已提交
382
		this._register(toDisposable(() => this.panelPart.shutdown()));
383
		serviceCollection.set(IPanelService, this.panelPart);
I
isidor 已提交
384

385 386 387
		// views service
		const viewsService = this.instantiationService.createInstance(ViewsService);
		serviceCollection.set(IViewsService, viewsService);
S
Sandeep Somavarapu 已提交
388

E
Erich Gamma 已提交
389
		// Activity service (activitybar part)
390
		this.activitybarPart = this.instantiationService.createInstance(ActivitybarPart, Identifiers.ACTIVITYBAR_PART);
B
Benjamin Pasero 已提交
391
		this._register(toDisposable(() => this.activitybarPart.shutdown()));
I
isidor 已提交
392 393
		const activityService = this.instantiationService.createInstance(ActivityService, this.activitybarPart, this.panelPart);
		serviceCollection.set(IActivityService, activityService);
E
Erich Gamma 已提交
394

395 396 397
		// File Service
		this.fileService = this.instantiationService.createInstance(RemoteFileService);
		serviceCollection.set(IFileService, this.fileService);
S
#47154  
Sandeep Somavarapu 已提交
398
		this.configurationService.acquireFileService(this.fileService);
A
Alex Dima 已提交
399
		this.themeService.acquireFileService(this.fileService);
E
Erich Gamma 已提交
400

B
Benjamin Pasero 已提交
401 402 403 404 405 406 407 408
		// Editor and Group services
		const restorePreviousEditorState = !this.hasInitialFilesToOpen;
		this.editorPart = this.instantiationService.createInstance(EditorPart, Identifiers.EDITOR_PART, restorePreviousEditorState);
		this._register(toDisposable(() => this.editorPart.shutdown()));
		this.editorGroupService = this.editorPart;
		serviceCollection.set(IEditorGroupsService, this.editorPart);
		this.editorService = this.instantiationService.createInstance(EditorService);
		serviceCollection.set(IEditorService, this.editorService);
E
Erich Gamma 已提交
409

410 411
		// Title bar
		this.titlebarPart = this.instantiationService.createInstance(TitlebarPart, Identifiers.TITLEBAR_PART);
B
Benjamin Pasero 已提交
412
		this._register(toDisposable(() => this.titlebarPart.shutdown()));
413
		serviceCollection.set(ITitleService, this.titlebarPart);
414
		// History
415
		serviceCollection.set(IHistoryService, new SyncDescriptor(HistoryService));
416

B
Benjamin Pasero 已提交
417 418 419
		// Menubar
		this.menubarPart = this.instantiationService.createInstance(MenubarPart, Identifiers.MENUBAR_PART);

420
		// Backup File Service
421
		this.backupFileService = this.instantiationService.createInstance(BackupFileService, this.workbenchParams.configuration.backupPath);
422
		serviceCollection.set(IBackupFileService, this.backupFileService);
423

424
		// Text File Service
425
		serviceCollection.set(ITextFileService, new SyncDescriptor(TextFileService));
426

427
		// File Decorations
J
Johannes Rieken 已提交
428
		serviceCollection.set(IDecorationsService, new SyncDescriptor(FileDecorationsService));
429

J
Joao Moreno 已提交
430
		// SCM Service
431
		serviceCollection.set(ISCMService, new SyncDescriptor(SCMService));
432

J
Joao Moreno 已提交
433
		// Inactive extension URL handler
J
Joao Moreno 已提交
434
		serviceCollection.set(IExtensionUrlHandler, new SyncDescriptor(ExtensionUrlHandler));
J
Joao Moreno 已提交
435

B
Benjamin Pasero 已提交
436
		// Text Model Resolver Service
437
		serviceCollection.set(ITextModelService, new SyncDescriptor(TextModelResolverService));
B
Benjamin Pasero 已提交
438

439 440 441 442
		// JSON Editing
		const jsonEditingService = this.instantiationService.createInstance(JSONEditingService);
		serviceCollection.set(IJSONEditingService, jsonEditingService);

443 444 445
		// Workspace Editing
		serviceCollection.set(IWorkspaceEditingService, new SyncDescriptor(WorkspaceEditingService));

446 447 448
		// Keybinding Editing
		serviceCollection.set(IKeybindingEditingService, this.instantiationService.createInstance(KeybindingsEditingService));

449
		// Configuration Resolver
B
Benjamin Pasero 已提交
450
		serviceCollection.set(IConfigurationResolverService, new SyncDescriptor(ConfigurationResolverService, process.env));
451

E
Erich Gamma 已提交
452
		// Quick open service (quick open controller)
453
		this.quickOpen = this.instantiationService.createInstance(QuickOpenController);
B
Benjamin Pasero 已提交
454
		this._register(toDisposable(() => this.quickOpen.shutdown()));
455
		serviceCollection.set(IQuickOpenService, this.quickOpen);
E
Erich Gamma 已提交
456

C
Christof Marti 已提交
457 458
		// Quick input service
		this.quickInput = this.instantiationService.createInstance(QuickInputService);
B
Benjamin Pasero 已提交
459
		this._register(toDisposable(() => this.quickInput.shutdown()));
C
Christof Marti 已提交
460 461
		serviceCollection.set(IQuickInputService, this.quickInput);

S
Sandeep Somavarapu 已提交
462 463 464
		// PreferencesService
		serviceCollection.set(IPreferencesService, this.instantiationService.createInstance(PreferencesService));

B
polish  
Benjamin Pasero 已提交
465
		// Contributed services
B
Benjamin Pasero 已提交
466
		const contributedServices = getServices();
E
Erich Gamma 已提交
467
		for (let contributedService of contributedServices) {
468
			serviceCollection.set(contributedService.id, contributedService.descriptor);
E
Erich Gamma 已提交
469 470 471
		}

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

476
		this.instantiationService.createInstance(DefaultConfigurationExportHelper);
477

S
#47154  
Sandeep Somavarapu 已提交
478
		this.configurationService.acquireInstantiationService(this.getInstantiationService());
E
Erich Gamma 已提交
479 480
	}

B
Benjamin Pasero 已提交
481
	//#region event handling
E
Erich Gamma 已提交
482

B
Benjamin Pasero 已提交
483
	private registerListeners(): void {
E
Erich Gamma 已提交
484

B
Benjamin Pasero 已提交
485 486
		// Listen to visible editor changes
		this._register(this.editorService.onDidVisibleEditorsChange(() => this.onDidVisibleEditorsChange()));
I
isidor 已提交
487

B
Benjamin Pasero 已提交
488 489 490 491 492 493
		// 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.editorService.onDidCloseEditor(() => this.onEditorClosed(listenerDispose, resourcesToWaitFor, waitMarkerFile));
B
Benjamin Pasero 已提交
494

B
Benjamin Pasero 已提交
495 496
			this._register(listenerDispose);
		}
I
isidor 已提交
497

B
Benjamin Pasero 已提交
498 499
		// Configuration changes
		this._register(this.configurationService.onDidChangeConfiguration(() => this.onDidUpdateConfiguration()));
S
Sanders Lauture 已提交
500

B
Benjamin Pasero 已提交
501 502 503
		// Fullscreen changes
		this._register(browser.onDidChangeFullscreen(() => this.onFullscreenChanged()));
	}
I
isidor 已提交
504

B
Benjamin Pasero 已提交
505 506 507 508
	private onFullscreenChanged(): void {
		if (!this.isCreated) {
			return; // we need to be ready
		}
509

B
Benjamin Pasero 已提交
510 511 512 513 514 515 516 517 518 519
		// Apply as CSS class
		const isFullscreen = browser.isFullscreen();
		if (isFullscreen) {
			this.workbench.addClass('fullscreen');
		} else {
			this.workbench.removeClass('fullscreen');
			if (this.zenMode.transitionedToFullScreen && this.zenMode.active) {
				this.toggleZenMode();
			}
		}
S
SrTobi 已提交
520

B
Benjamin Pasero 已提交
521 522 523 524 525 526
		// 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
		}
E
Erich Gamma 已提交
527 528
	}

B
Benjamin Pasero 已提交
529
	private onEditorClosed(listenerDispose: IDisposable, resourcesToWaitFor: URI[], waitMarkerFile: URI): void {
E
Erich Gamma 已提交
530

B
Benjamin Pasero 已提交
531 532 533 534 535 536 537
		// 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.
		if (resourcesToWaitFor.every(resource => !this.editorService.isOpen({ resource }))) {
			listenerDispose.dispose();
			this.fileService.del(waitMarkerFile).done(null, errors.onUnexpectedError);
		}
E
Erich Gamma 已提交
538 539
	}

B
Benjamin Pasero 已提交
540 541
	private onDidVisibleEditorsChange(): void {
		const visibleEditors = this.editorService.visibleControls;
E
Erich Gamma 已提交
542

B
Benjamin Pasero 已提交
543 544 545 546 547 548 549 550
		// Close when empty: check if we should close the window based on the setting
		// Overruled by: window has a workspace opened or this window is for extension development
		// or setting is disabled. Also enabled when running with --wait from the command line.
		if (visibleEditors.length === 0 && this.contextService.getWorkbenchState() === WorkbenchState.EMPTY && !this.environmentService.isExtensionDevelopment) {
			const closeWhenEmpty = this.configurationService.getValue<boolean>(Workbench.closeWhenEmptyConfigurationKey);
			if (closeWhenEmpty || this.environmentService.args.wait) {
				this.closeEmptyWindowScheduler.schedule();
			}
E
Erich Gamma 已提交
551
		}
552 553
	}

B
Benjamin Pasero 已提交
554 555 556 557
	private onAllEditorsClosed(): void {
		const visibleEditors = this.editorService.visibleControls.length;
		if (visibleEditors === 0) {
			this.windowService.closeWindow();
E
Erich Gamma 已提交
558 559 560
		}
	}

B
Benjamin Pasero 已提交
561 562 563 564 565
	private onDidUpdateConfiguration(skipLayout?: boolean): void {
		const newSidebarPositionValue = this.configurationService.getValue<string>(Workbench.sidebarPositionConfigurationKey);
		const newSidebarPosition = (newSidebarPositionValue === 'right') ? Position.RIGHT : Position.LEFT;
		if (newSidebarPosition !== this.getSideBarPosition()) {
			this.setSideBarPosition(newSidebarPosition);
566
		}
E
Erich Gamma 已提交
567

B
Benjamin Pasero 已提交
568
		this.setPanelPositionFromStorageOrConfig();
E
Erich Gamma 已提交
569

B
Benjamin Pasero 已提交
570 571 572
		const fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
		if (fontAliasing !== this.fontAliasing) {
			this.setFontAliasing(fontAliasing);
573 574
		}

B
Benjamin Pasero 已提交
575 576 577 578 579 580 581 582 583 584 585
		if (!this.zenMode.active) {
			const newStatusbarHiddenValue = !this.configurationService.getValue<boolean>(Workbench.statusbarVisibleConfigurationKey);
			if (newStatusbarHiddenValue !== this.statusBarHidden) {
				this.setStatusBarHidden(newStatusbarHiddenValue, skipLayout);
			}

			const newActivityBarHiddenValue = !this.configurationService.getValue<boolean>(Workbench.activityBarVisibleConfigurationKey);
			if (newActivityBarHiddenValue !== this.activityBarHidden) {
				this.setActivityBarHidden(newActivityBarHiddenValue, skipLayout);
			}
		}
S
SteVen Batten 已提交
586 587 588

		const newMenubarVisibility = this.configurationService.getValue<string>(Workbench.menubarVisibilityConfigurationKey);
		this.setMenubarHidden(newMenubarVisibility, skipLayout);
589 590
	}

B
Benjamin Pasero 已提交
591
	//#endregion
B
Benjamin Pasero 已提交
592

B
Benjamin Pasero 已提交
593 594
	private handleContextKeys(): void {
		this.inZenMode = InEditorZenModeContext.bindTo(this.contextKeyService);
B
Benjamin Pasero 已提交
595

B
Benjamin Pasero 已提交
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
		const sidebarVisibleContextRaw = new RawContextKey<boolean>('sidebarVisible', false);
		this.sideBarVisibleContext = sidebarVisibleContextRaw.bindTo(this.contextKeyService);

		const editorsVisibleContext = EditorsVisibleContext.bindTo(this.contextKeyService);
		const textCompareEditorVisible = TextCompareEditorVisibleContext.bindTo(this.contextKeyService);
		const activeEditorGroupEmpty = ActiveEditorGroupEmptyContext.bindTo(this.contextKeyService);
		const multipleEditorGroups = MultipleEditorGroupsContext.bindTo(this.contextKeyService);

		const updateEditorContextKeys = () => {
			const visibleEditors = this.editorService.visibleControls;

			textCompareEditorVisible.set(visibleEditors.some(control => control.getId() === TEXT_DIFF_EDITOR_ID));

			if (visibleEditors.length > 0) {
				editorsVisibleContext.set(true);
			} else {
				editorsVisibleContext.reset();
613
			}
B
Benjamin Pasero 已提交
614

B
Benjamin Pasero 已提交
615 616 617 618
			if (!this.editorService.activeEditor) {
				activeEditorGroupEmpty.set(true);
			} else {
				activeEditorGroupEmpty.reset();
R
Ryan Adolf 已提交
619
			}
620

B
Benjamin Pasero 已提交
621 622 623 624 625 626
			if (this.editorGroupService.count > 1) {
				multipleEditorGroups.set(true);
			} else {
				multipleEditorGroups.reset();
			}
		};
B
Benjamin Pasero 已提交
627

B
Benjamin Pasero 已提交
628 629 630 631 632
		this.editorPart.whenRestored.then(() => updateEditorContextKeys());
		this._register(this.editorService.onDidActiveEditorChange(() => updateEditorContextKeys()));
		this._register(this.editorService.onDidVisibleEditorsChange(() => updateEditorContextKeys()));
		this._register(this.editorGroupService.onDidAddGroup(() => updateEditorContextKeys()));
		this._register(this.editorGroupService.onDidRemoveGroup(() => updateEditorContextKeys()));
633

B
Benjamin Pasero 已提交
634 635 636 637 638 639 640 641 642 643
		const inputFocused = InputFocusedContext.bindTo(this.contextKeyService);
		this._register(DOM.addDisposableListener(window, 'focusin', () => {
			inputFocused.set(document.activeElement && (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA'));
		}, true));

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

B
Benjamin Pasero 已提交
645 646 647 648 649
		const workspaceFolderCountRawContext = new RawContextKey<number>('workspaceFolderCount', this.configurationService.getWorkspace().folders.length);
		const workspaceFolderCountContext = workspaceFolderCountRawContext.bindTo(this.contextKeyService);
		this._register(this.configurationService.onDidChangeWorkspaceFolders(() => {
			workspaceFolderCountContext.set(this.configurationService.getWorkspace().folders.length);
		}));
650

B
Benjamin Pasero 已提交
651
		const splitEditorsVerticallyContext = SplitEditorsVertically.bindTo(this.contextKeyService);
S
Sanders Lauture 已提交
652

B
Benjamin Pasero 已提交
653 654 655 656
		const updateSplitEditorsVerticallyContext = () => {
			const direction = preferredSideBySideGroupDirection(this.configurationService);
			splitEditorsVerticallyContext.set(direction === GroupDirection.DOWN);
		};
S
Sanders Lauture 已提交
657

B
Benjamin Pasero 已提交
658 659 660 661 662
		this._register(this.configurationService.onDidChangeConfiguration(e => {
			if (e.affectsConfiguration('workbench.editor.openSideBySideDirection')) {
				updateSplitEditorsVerticallyContext();
			}
		}));
E
Erich Gamma 已提交
663

B
Benjamin Pasero 已提交
664 665
		updateSplitEditorsVerticallyContext();
	}
E
Erich Gamma 已提交
666

B
Benjamin Pasero 已提交
667 668
	private restoreParts(): TPromise<IWorkbenchStartedInfo> {
		const restorePromises: Thenable<any>[] = [];
B
Benjamin Pasero 已提交
669

B
Benjamin Pasero 已提交
670 671 672 673 674 675
		// Restore Editorpart
		perf.mark('willRestoreEditors');
		restorePromises.push(this.editorPart.whenRestored.then(() => {
			return this.resolveEditorsToOpen().then(inputs => {
				if (inputs.length) {
					return this.editorService.openEditors(inputs);
676
				}
E
Erich Gamma 已提交
677

B
Benjamin Pasero 已提交
678 679 680 681 682
				return TPromise.as(void 0);
			});
		}).then(() => {
			perf.mark('didRestoreEditors');
		}));
E
Erich Gamma 已提交
683

B
Benjamin Pasero 已提交
684 685 686 687
		// Restore Sidebar
		let viewletIdToRestore: string;
		if (!this.sideBarHidden) {
			this.sideBarVisibleContext.set(true);
688

B
Benjamin Pasero 已提交
689 690
			if (this.shouldRestoreLastOpenedViewlet()) {
				viewletIdToRestore = this.storageService.get(SidebarPart.activeViewletSettingsKey, StorageScope.WORKSPACE);
691
			}
692

B
Benjamin Pasero 已提交
693 694
			if (!viewletIdToRestore) {
				viewletIdToRestore = this.viewletService.getDefaultViewletId();
695
			}
E
Erich Gamma 已提交
696

B
Benjamin Pasero 已提交
697 698 699 700 701 702
			perf.mark('willRestoreViewlet');
			restorePromises.push(this.viewletService.openViewlet(viewletIdToRestore)
				.then(viewlet => viewlet || this.viewletService.openViewlet(this.viewletService.getDefaultViewletId()))
				.then(() => {
					perf.mark('didRestoreViewlet');
				}));
703 704
		}

B
Benjamin Pasero 已提交
705 706 707 708 709
		// 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));
I
isidor 已提交
710 711
		}

B
Benjamin Pasero 已提交
712 713 714
		// Restore Zen Mode if active
		if (this.storageService.getBoolean(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE, false)) {
			this.toggleZenMode(true);
I
isidor 已提交
715 716
		}

B
Benjamin Pasero 已提交
717 718 719 720
		// Restore Forced Editor Center Mode
		if (this.storageService.getBoolean(Workbench.centeredEditorLayoutActiveStorageKey, StorageScope.WORKSPACE, false)) {
			this.centeredEditorLayoutActive = true;
		}
721

B
Benjamin Pasero 已提交
722 723
		const onRestored = (error?: Error): IWorkbenchStartedInfo => {
			this.workbenchCreated = true;
724

B
Benjamin Pasero 已提交
725 726
			if (error) {
				errors.onUnexpectedError(error);
727
			}
I
isidor 已提交
728

B
Benjamin Pasero 已提交
729 730 731 732 733 734 735
			return {
				customKeybindingsCount: this.keybindingService.customKeybindingsCount(),
				pinnedViewlets: this.activitybarPart.getPinned(),
				restoredViewlet: viewletIdToRestore,
				restoredEditorsCount: this.editorService.visibleEditors.length
			};
		};
I
isidor 已提交
736

B
Benjamin Pasero 已提交
737
		return TPromise.join(restorePromises).then(() => onRestored(), error => onRestored(error));
E
Erich Gamma 已提交
738 739
	}

B
Benjamin Pasero 已提交
740 741 742
	private shouldRestoreLastOpenedViewlet(): boolean {
		if (!this.environmentService.isBuilt) {
			return true; // always restore sidebar when we are in development mode
E
Erich Gamma 已提交
743 744
		}

B
Benjamin Pasero 已提交
745 746 747 748
		const restore = this.storageService.getBoolean(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE);
		if (restore) {
			this.storageService.remove(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE); // only support once
		}
749

B
Benjamin Pasero 已提交
750
		return restore;
E
Erich Gamma 已提交
751 752
	}

B
Benjamin Pasero 已提交
753 754
	private resolveEditorsToOpen(): TPromise<IResourceEditor[]> {
		const config = this.workbenchParams.configuration;
I
isidor 已提交
755

B
Benjamin Pasero 已提交
756 757
		// Files to open, diff or create
		if (this.hasInitialFilesToOpen) {
I
isidor 已提交
758

B
Benjamin Pasero 已提交
759 760 761 762 763 764 765 766 767
			// Files to diff is exclusive
			const filesToDiff = this.toInputs(config.filesToDiff, false);
			if (filesToDiff && filesToDiff.length === 2) {
				return TPromise.as([<IResourceDiffInput>{
					leftResource: filesToDiff[0].resource,
					rightResource: filesToDiff[1].resource,
					options: { pinned: true }
				}]);
			}
I
isidor 已提交
768

B
Benjamin Pasero 已提交
769 770
			const filesToCreate = this.toInputs(config.filesToCreate, true);
			const filesToOpen = this.toInputs(config.filesToOpen, false);
I
isidor 已提交
771

B
Benjamin Pasero 已提交
772 773 774
			// Otherwise: Open/Create files
			return TPromise.as([...filesToOpen, ...filesToCreate]);
		}
I
isidor 已提交
775

B
Benjamin Pasero 已提交
776 777 778 779 780 781
		// Empty workbench
		else if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY && this.openUntitledFile()) {
			const isEmpty = this.editorGroupService.count === 1 && this.editorGroupService.activeGroup.count === 0;
			if (!isEmpty) {
				return TPromise.as([]); // do not open any empty untitled file if we restored editors from previous session
			}
B
Benjamin Pasero 已提交
782

B
Benjamin Pasero 已提交
783 784 785 786
			return this.backupFileService.hasBackups().then(hasBackups => {
				if (hasBackups) {
					return TPromise.as([]); // do not open any empty untitled file if we have backups to restore
				}
B
Benjamin Pasero 已提交
787

B
Benjamin Pasero 已提交
788 789
				return TPromise.as([<IUntitledResourceInput>{}]);
			});
790
		}
791

B
Benjamin Pasero 已提交
792 793
		return TPromise.as([]);
	}
794

B
Benjamin Pasero 已提交
795 796 797
	private toInputs(paths: IPath[], isNew: boolean): (IResourceInput | IUntitledResourceInput)[] {
		if (!paths || !paths.length) {
			return [];
798
		}
I
isidor 已提交
799

B
Benjamin Pasero 已提交
800 801 802 803 804 805 806
		return paths.map(p => {
			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;
807
			}
E
Erich Gamma 已提交
808

B
Benjamin Pasero 已提交
809 810 811 812 813 814
			if (!isNew && p.lineNumber) {
				input.options.selection = {
					startLineNumber: p.lineNumber,
					startColumn: p.columnNumber
				};
			}
815

B
Benjamin Pasero 已提交
816 817
			return input;
		});
818 819
	}

B
Benjamin Pasero 已提交
820 821 822 823 824 825 826 827 828
	private openUntitledFile() {
		const startupEditor = this.configurationService.inspect('workbench.startupEditor');

		// Fallback to previous workbench.welcome.enabled setting in case startupEditor is not defined
		if (!startupEditor.user && !startupEditor.workspace) {
			const welcomeEnabledValue = this.configurationService.getValue('workbench.welcome.enabled');
			if (typeof welcomeEnabledValue === 'boolean') {
				return !welcomeEnabledValue;
			}
829
		}
E
Erich Gamma 已提交
830

B
Benjamin Pasero 已提交
831 832
		return startupEditor.value === 'newUntitledFile';
	}
E
Erich Gamma 已提交
833

B
Benjamin Pasero 已提交
834
	private initSettings(): void {
835

B
Benjamin Pasero 已提交
836 837
		// Sidebar visibility
		this.sideBarHidden = this.storageService.getBoolean(Workbench.sidebarHiddenStorageKey, StorageScope.WORKSPACE, this.contextService.getWorkbenchState() === WorkbenchState.EMPTY);
838

B
Benjamin Pasero 已提交
839 840 841 842 843
		// Panel part visibility
		const panelRegistry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
		this.panelHidden = this.storageService.getBoolean(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE, true);
		if (!panelRegistry.getDefaultPanelId()) {
			this.panelHidden = true; // we hide panel part if there is no default panel
844 845
		}

B
Benjamin Pasero 已提交
846 847 848
		// Sidebar position
		const sideBarPosition = this.configurationService.getValue<string>(Workbench.sidebarPositionConfigurationKey);
		this.sideBarPosition = (sideBarPosition === 'right') ? Position.RIGHT : Position.LEFT;
849

B
Benjamin Pasero 已提交
850 851
		// Panel position
		this.setPanelPositionFromStorageOrConfig();
852

853 854 855 856
		// Menubar visibility
		const menuBarVisibility = this.configurationService.getValue<string>(Workbench.menubarVisibilityConfigurationKey);
		this.setMenubarHidden(menuBarVisibility, true);

B
Benjamin Pasero 已提交
857 858 859
		// Statusbar visibility
		const statusBarVisible = this.configurationService.getValue<string>(Workbench.statusbarVisibleConfigurationKey);
		this.statusBarHidden = !statusBarVisible;
860

B
Benjamin Pasero 已提交
861 862 863
		// Activity bar visibility
		const activityBarVisible = this.configurationService.getValue<string>(Workbench.activityBarVisibleConfigurationKey);
		this.activityBarHidden = !activityBarVisible;
864

B
Benjamin Pasero 已提交
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
		// Font aliasing
		this.fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);

		// Zen mode
		this.zenMode = {
			active: false,
			transitionedToFullScreen: false,
			transitionedToCenteredEditorLayout: false,
			wasSideBarVisible: false,
			wasPanelVisible: false,
			transitionDisposeables: []
		};

		// Centered Editor Layout
		this.centeredEditorLayoutActive = false;
E
Erich Gamma 已提交
880 881
	}

B
Benjamin Pasero 已提交
882 883 884 885 886
	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;
	}
887

B
Benjamin Pasero 已提交
888 889 890 891
	private getCustomTitleBarStyle(): 'custom' {
		const isDev = !this.environmentService.isBuilt || this.environmentService.isExtensionDevelopment;
		if (isMacintosh && isDev) {
			return null; // not enabled when developing due to https://github.com/electron/electron/issues/3647
892 893
		}

B
Benjamin Pasero 已提交
894 895 896 897 898 899
		const windowConfig = this.configurationService.getValue<IWindowSettings>();
		if (windowConfig && windowConfig.window) {
			const useNativeTabs = windowConfig.window.nativeTabs;
			if (useNativeTabs) {
				return null; // native tabs on sierra do not work with custom title style
			}
E
Erich Gamma 已提交
900

B
Benjamin Pasero 已提交
901 902 903
			const style = windowConfig.window.titleBarStyle;
			if (style === 'custom') {
				return style;
904 905 906
			}
		}

B
Benjamin Pasero 已提交
907
		return null;
B
Benjamin Pasero 已提交
908 909
	}

B
Benjamin Pasero 已提交
910 911
	private setStatusBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.statusBarHidden = hidden;
B
Benjamin Pasero 已提交
912

B
Benjamin Pasero 已提交
913 914 915
		// Adjust CSS
		if (hidden) {
			this.workbench.addClass('nostatusbar');
E
Erich Gamma 已提交
916
		} else {
B
Benjamin Pasero 已提交
917
			this.workbench.removeClass('nostatusbar');
E
Erich Gamma 已提交
918 919
		}

B
Benjamin Pasero 已提交
920 921 922
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
923 924 925
		}
	}

B
Benjamin Pasero 已提交
926 927
	private setFontAliasing(aliasing: FontAliasingOption) {
		this.fontAliasing = aliasing;
928

B
Benjamin Pasero 已提交
929 930
		// Remove all
		document.body.classList.remove(...fontAliasingValues.map(value => `monaco-font-aliasing-${value}`));
S
Sanders Lauture 已提交
931

B
Benjamin Pasero 已提交
932 933 934
		// Add specific
		if (fontAliasingValues.some(option => option === aliasing)) {
			document.body.classList.add(`monaco-font-aliasing-${aliasing}`);
S
Sanders Lauture 已提交
935
		}
936 937
	}

E
Erich Gamma 已提交
938
	private createWorkbenchLayout(): void {
939 940
		this.workbenchLayout = this.instantiationService.createInstance(
			WorkbenchLayout,
B
Benjamin Pasero 已提交
941 942
			this.container,
			this.workbench.getHTMLElement(),
I
isidor 已提交
943
			{
B
Benjamin Pasero 已提交
944 945 946 947 948 949 950
				titlebar: this.titlebarPart,
				menubar: this.menubarPart,
				activitybar: this.activitybarPart,
				editor: this.editorPart,
				sidebar: this.sidebarPart,
				panel: this.panelPart,
				statusbar: this.statusbarPart,
I
isidor 已提交
951
			},
B
Benjamin Pasero 已提交
952 953 954 955
			this.quickOpen,
			this.quickInput,
			this.notificationsCenter,
			this.notificationsToasts
E
Erich Gamma 已提交
956 957
		);

958 959 960 961 962
		if (!isMacintosh && this.getCustomTitleBarStyle()) {
			this.windowService.isMaximized().then((max) => {
				this.workbenchLayout.onMaximizeChange(max);
				this.workbenchLayout.layout();
			});
B
Benjamin Pasero 已提交
963

964 965
			this.windowService.onDidChangeMaximize(this.workbenchLayout.onMaximizeChange, this.workbenchLayout);
		}
E
Erich Gamma 已提交
966 967 968 969 970 971 972 973
	}

	private renderWorkbench(): void {

		// Apply sidebar state as CSS class
		if (this.sideBarHidden) {
			this.workbench.addClass('nosidebar');
		}
974 975 976
		if (this.panelHidden) {
			this.workbench.addClass('nopanel');
		}
977 978 979
		if (this.statusBarHidden) {
			this.workbench.addClass('nostatusbar');
		}
E
Erich Gamma 已提交
980

B
Benjamin Pasero 已提交
981
		// Apply font aliasing
982 983
		this.setFontAliasing(this.fontAliasing);

B
Benjamin Pasero 已提交
984
		// Apply title style if shown
985 986 987 988 989 990 991 992
		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 已提交
993 994
		}

E
Erich Gamma 已提交
995
		// Create Parts
B
Benjamin Pasero 已提交
996
		this.createTitlebarPart();
997
		this.createMenubarPart();
E
Erich Gamma 已提交
998 999 1000
		this.createActivityBarPart();
		this.createSidebarPart();
		this.createEditorPart();
1001
		this.createPanelPart();
E
Erich Gamma 已提交
1002 1003
		this.createStatusbarPart();

1004 1005
		// Notification Handlers
		this.createNotificationsHandlers();
1006

E
Erich Gamma 已提交
1007 1008 1009 1010
		// Add Workbench to DOM
		this.workbenchContainer.build(this.container);
	}

B
Benjamin Pasero 已提交
1011 1012 1013 1014 1015 1016 1017
	private createTitlebarPart(): void {
		const titlebarContainer = $(this.workbench).div({
			'class': ['part', 'titlebar'],
			id: Identifiers.TITLEBAR_PART,
			role: 'contentinfo'
		});

1018
		this.titlebarPart.create(titlebarContainer.getHTMLElement());
B
Benjamin Pasero 已提交
1019 1020
	}

1021
	private createMenubarPart(): void {
1022 1023 1024 1025 1026
		const menubarContainer = $(this.workbench).div({
			'class': ['part', 'menubar'],
			id: Identifiers.MENUBAR_PART,
			role: 'menubar'
		});
B
Benjamin Pasero 已提交
1027

1028 1029 1030
		this.menubarPart.create(menubarContainer.getHTMLElement());
	}

E
Erich Gamma 已提交
1031
	private createActivityBarPart(): void {
B
Benjamin Pasero 已提交
1032
		const activitybarPartContainer = $(this.workbench)
E
Erich Gamma 已提交
1033 1034
			.div({
				'class': ['part', 'activitybar', this.sideBarPosition === Position.LEFT ? 'left' : 'right'],
1035 1036
				id: Identifiers.ACTIVITYBAR_PART,
				role: 'navigation'
E
Erich Gamma 已提交
1037 1038
			});

1039
		this.activitybarPart.create(activitybarPartContainer.getHTMLElement());
E
Erich Gamma 已提交
1040 1041 1042
	}

	private createSidebarPart(): void {
B
Benjamin Pasero 已提交
1043
		const sidebarPartContainer = $(this.workbench)
E
Erich Gamma 已提交
1044 1045
			.div({
				'class': ['part', 'sidebar', this.sideBarPosition === Position.LEFT ? 'left' : 'right'],
1046 1047
				id: Identifiers.SIDEBAR_PART,
				role: 'complementary'
E
Erich Gamma 已提交
1048 1049
			});

1050
		this.sidebarPart.create(sidebarPartContainer.getHTMLElement());
E
Erich Gamma 已提交
1051 1052
	}

I
isidor 已提交
1053
	private createPanelPart(): void {
B
Benjamin Pasero 已提交
1054
		const panelPartContainer = $(this.workbench)
I
isidor 已提交
1055
			.div({
1056
				'class': ['part', 'panel', this.panelPosition === Position.BOTTOM ? 'bottom' : 'right'],
1057 1058
				id: Identifiers.PANEL_PART,
				role: 'complementary'
I
isidor 已提交
1059 1060
			});

1061
		this.panelPart.create(panelPartContainer.getHTMLElement());
I
isidor 已提交
1062 1063
	}

E
Erich Gamma 已提交
1064
	private createEditorPart(): void {
B
Benjamin Pasero 已提交
1065
		const editorContainer = $(this.workbench)
E
Erich Gamma 已提交
1066
			.div({
B
Benjamin Pasero 已提交
1067
				'class': ['part', 'editor'],
1068 1069
				id: Identifiers.EDITOR_PART,
				role: 'main'
E
Erich Gamma 已提交
1070 1071
			});

1072
		this.editorPart.create(editorContainer.getHTMLElement());
E
Erich Gamma 已提交
1073 1074 1075
	}

	private createStatusbarPart(): void {
B
Benjamin Pasero 已提交
1076
		const statusbarContainer = $(this.workbench).div({
E
Erich Gamma 已提交
1077
			'class': ['part', 'statusbar'],
1078 1079
			id: Identifiers.STATUSBAR_PART,
			role: 'contentinfo'
E
Erich Gamma 已提交
1080 1081
		});

1082
		this.statusbarPart.create(statusbarContainer.getHTMLElement());
E
Erich Gamma 已提交
1083 1084
	}

1085 1086
	private createNotificationsHandlers(): void {

1087
		// Notifications Center
B
Benjamin Pasero 已提交
1088
		this.notificationsCenter = this._register(this.instantiationService.createInstance(NotificationsCenter, this.workbench.getHTMLElement(), this.notificationService.model));
1089

1090
		// Notifications Toasts
B
Benjamin Pasero 已提交
1091
		this.notificationsToasts = this._register(this.instantiationService.createInstance(NotificationsToasts, this.workbench.getHTMLElement(), this.notificationService.model));
1092

1093
		// Notifications Alerts
B
Benjamin Pasero 已提交
1094
		this._register(this.instantiationService.createInstance(NotificationsAlerts, this.notificationService.model));
S
SteVen Batten 已提交
1095 1096 1097 1098 1099 1100

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

		// Eventing
		this._register(this.notificationsCenter.onDidChangeVisibility(() => {
S
SteVen Batten 已提交
1101

S
SteVen Batten 已提交
1102 1103 1104 1105 1106 1107
			// Update status
			notificationsStatus.update(this.notificationsCenter.isVisible);

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

S
SteVen Batten 已提交
1109
		// Register Commands
S
SteVen Batten 已提交
1110
		registerNotificationCommands(this.notificationsCenter, this.notificationsToasts);
1111 1112
	}

B
Benjamin Pasero 已提交
1113
	getInstantiationService(): IInstantiationService {
E
Erich Gamma 已提交
1114 1115 1116
		return this.instantiationService;
	}

B
Benjamin Pasero 已提交
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140
	dispose(reason = ShutdownReason.QUIT): void {
		super.dispose();

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

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

		this.workbenchShutdown = true;
	}

	//#region IPartService
S
SteVen Batten 已提交
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160

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

	get onEditorLayout(): Event<IDimension> { return this.editorPart.onDidLayout; }

	isCreated(): boolean {
		return this.workbenchCreated && this.workbenchStarted;
	}

	hasFocus(part: Parts): boolean {
		const activeElement = document.activeElement;
		if (!activeElement) {
			return false;
		}

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

B
Benjamin Pasero 已提交
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
	getContainer(part: Parts): HTMLElement {
		let container: HTMLElement = null;
		switch (part) {
			case Parts.TITLEBAR_PART:
				container = this.titlebarPart.getContainer();
				break;
			case Parts.MENUBAR_PART:
				container = this.menubarPart.getContainer();
				break;
			case Parts.ACTIVITYBAR_PART:
				container = this.activitybarPart.getContainer();
				break;
			case Parts.SIDEBAR_PART:
				container = this.sidebarPart.getContainer();
				break;
			case Parts.PANEL_PART:
				container = this.panelPart.getContainer();
				break;
			case Parts.EDITOR_PART:
				container = this.editorPart.getContainer();
				break;
			case Parts.STATUSBAR_PART:
				container = this.statusbarPart.getContainer();
				break;
		}

		return container;
	}

	isVisible(part: Parts): boolean {
		switch (part) {
			case Parts.TITLEBAR_PART:
				return this.getCustomTitleBarStyle() && !browser.isFullscreen();
			case Parts.MENUBAR_PART:
S
SteVen Batten 已提交
1195
				return this.getCustomTitleBarStyle() && !this.menubarHidden;
B
Benjamin Pasero 已提交
1196 1197 1198 1199 1200 1201 1202 1203
			case Parts.SIDEBAR_PART:
				return !this.sideBarHidden;
			case Parts.PANEL_PART:
				return !this.panelHidden;
			case Parts.STATUSBAR_PART:
				return !this.statusBarHidden;
			case Parts.ACTIVITYBAR_PART:
				return !this.activityBarHidden;
E
Erich Gamma 已提交
1204
		}
B
Benjamin Pasero 已提交
1205 1206

		return true; // any other part cannot be hidden
E
Erich Gamma 已提交
1207 1208
	}

B
Benjamin Pasero 已提交
1209 1210 1211 1212
	getTitleBarOffset(): number {
		let offset = 0;
		if (this.isVisible(Parts.TITLEBAR_PART)) {
			offset = 22 / browser.getZoomFactor(); // adjust the position based on title bar size and zoom factor
E
Erich Gamma 已提交
1213
		}
B
Benjamin Pasero 已提交
1214 1215

		return offset;
E
Erich Gamma 已提交
1216
	}
1217

B
Benjamin Pasero 已提交
1218
	getWorkbenchElementId(): string {
1219 1220
		return Identifiers.WORKBENCH_CONTAINER;
	}
1221

B
Benjamin Pasero 已提交
1222
	toggleZenMode(skipLayout?: boolean): void {
I
isidor 已提交
1223
		this.zenMode.active = !this.zenMode.active;
B
Benjamin Pasero 已提交
1224
		this.zenMode.transitionDisposeables = dispose(this.zenMode.transitionDisposeables);
1225

B
Benjamin Pasero 已提交
1226 1227
		// 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)
1228
		let toggleFullScreen = false;
B
Benjamin Pasero 已提交
1229 1230

		// Zen Mode Active
I
isidor 已提交
1231
		if (this.zenMode.active) {
1232
			const config = this.configurationService.getValue<IZenModeSettings>('zenMode');
B
Benjamin Pasero 已提交
1233

I
isidor 已提交
1234
			toggleFullScreen = !browser.isFullscreen() && config.fullScreen;
I
isidor 已提交
1235
			this.zenMode.transitionedToFullScreen = toggleFullScreen;
1236
			this.zenMode.transitionedToCenteredEditorLayout = !this.isEditorLayoutCentered() && config.centerLayout;
1237 1238
			this.zenMode.wasSideBarVisible = this.isVisible(Parts.SIDEBAR_PART);
			this.zenMode.wasPanelVisible = this.isVisible(Parts.PANEL_PART);
B
Benjamin Pasero 已提交
1239

1240 1241
			this.setPanelHidden(true, true).done(void 0, errors.onUnexpectedError);
			this.setSideBarHidden(true, true).done(void 0, errors.onUnexpectedError);
I
isidor 已提交
1242

1243 1244 1245
			if (config.hideActivityBar) {
				this.setActivityBarHidden(true, true);
			}
1246

I
isidor 已提交
1247
			if (config.hideStatusBar) {
I
isidor 已提交
1248 1249
				this.setStatusBarHidden(true, true);
			}
1250

B
Benjamin Pasero 已提交
1251 1252
			if (config.hideTabs && this.editorPart.partOptions.showTabs) {
				this.zenMode.transitionDisposeables.push(this.editorPart.enforcePartOptions({ showTabs: false }));
I
isidor 已提交
1253
			}
1254 1255 1256 1257

			if (config.centerLayout) {
				this.centerEditorLayout(true, true);
			}
B
Benjamin Pasero 已提交
1258 1259 1260 1261
		}

		// Zen Mode Inactive
		else {
1262
			if (this.zenMode.wasPanelVisible) {
1263
				this.setPanelHidden(false, true).done(void 0, errors.onUnexpectedError);
1264
			}
B
Benjamin Pasero 已提交
1265

1266
			if (this.zenMode.wasSideBarVisible) {
1267
				this.setSideBarHidden(false, true).done(void 0, errors.onUnexpectedError);
1268
			}
B
Benjamin Pasero 已提交
1269

1270 1271 1272
			if (this.zenMode.transitionedToCenteredEditorLayout) {
				this.centerEditorLayout(false, true);
			}
1273

1274 1275
			// Status bar and activity bar visibility come from settings -> update their visibility.
			this.onDidUpdateConfiguration(true);
B
Benjamin Pasero 已提交
1276 1277

			this.editorGroupService.activeGroup.focus();
1278

1279
			toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
I
isidor 已提交
1280
		}
1281

1282
		this.inZenMode.set(this.zenMode.active);
I
isidor 已提交
1283

I
isidor 已提交
1284
		if (!skipLayout) {
1285
			this.layout();
I
isidor 已提交
1286
		}
1287

1288
		if (toggleFullScreen) {
1289
			this.windowService.toggleFullScreen().done(void 0, errors.onUnexpectedError);
1290
		}
I
isidor 已提交
1291 1292
	}

B
Benjamin Pasero 已提交
1293 1294 1295 1296 1297 1298 1299
	layout(options?: ILayoutOptions): void {
		if (this.workbenchStarted && !this.workbenchShutdown) {
			this.workbenchLayout.layout(options);
		}
	}

	isEditorLayoutCentered(): boolean {
B
Benjamin Pasero 已提交
1300
		return this.centeredEditorLayoutActive;
S
SrTobi 已提交
1301 1302
	}

B
Benjamin Pasero 已提交
1303 1304 1305 1306 1307 1308
	// TODO@ben support centered editor layout using empty groups or not? functionality missing:
	// - resize sashes left and right in sync
	// - IEditorInput.supportsCenteredEditorLayout() no longer supported
	// - should we just allow to enter layout even if groups > 1? what does it then mean to be
	//   actively in centered editor layout though?
	centerEditorLayout(active: boolean, skipLayout?: boolean): void {
1309
		this.centeredEditorLayoutActive = active;
1310
		this.storageService.store(Workbench.centeredEditorLayoutActiveStorageKey, this.centeredEditorLayoutActive, StorageScope.WORKSPACE);
B
Benjamin Pasero 已提交
1311

B
Benjamin Pasero 已提交
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
		// Enter Centered Editor Layout
		if (active) {
			if (this.editorGroupService.count === 1) {
				const activeGroup = this.editorGroupService.activeGroup;
				this.editorGroupService.addGroup(activeGroup, GroupDirection.LEFT);
				this.editorGroupService.addGroup(activeGroup, GroupDirection.RIGHT);

				this.editorGroupService.applyLayout({ groups: [{ size: 0.2 }, { size: 0.6 }, { size: 0.2 }], orientation: GroupOrientation.HORIZONTAL });
			}
		}

		// Leave Centered Editor Layout
		else {
			if (this.editorGroupService.count === 3) {
				this.editorGroupService.groups.forEach(group => {
					if (group.count === 0) {
						this.editorGroupService.removeGroup(group);
					}
				});
			}
		}

1334 1335 1336
		if (!skipLayout) {
			this.layout();
		}
S
SrTobi 已提交
1337 1338
	}

B
Benjamin Pasero 已提交
1339
	resizePart(part: Parts, sizeChange: number): void {
1340 1341 1342 1343 1344 1345 1346
		switch (part) {
			case Parts.SIDEBAR_PART:
			case Parts.PANEL_PART:
			case Parts.EDITOR_PART:
				this.workbenchLayout.resizePart(part, sizeChange);
				break;
			default:
B
Benjamin Pasero 已提交
1347
				return; // Cannot resize other parts
1348 1349 1350
		}
	}

B
Benjamin Pasero 已提交
1351 1352
	setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.activityBarHidden = hidden;
1353

B
Benjamin Pasero 已提交
1354 1355 1356
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
1357
		}
B
Benjamin Pasero 已提交
1358
	}
1359

B
Benjamin Pasero 已提交
1360 1361 1362 1363 1364 1365 1366 1367 1368
	setSideBarHidden(hidden: boolean, skipLayout?: boolean): TPromise<void> {
		this.sideBarHidden = hidden;
		this.sideBarVisibleContext.set(!hidden);

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

B
Benjamin Pasero 已提交
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409
		// If sidebar becomes hidden, also hide the current active Viewlet if any
		let promise = TPromise.wrap<any>(null);
		if (hidden && this.sidebarPart.getActiveViewlet()) {
			promise = this.sidebarPart.hideActiveViewlet().then(() => {
				const activePanel = this.panelPart.getActivePanel();

				// Pass Focus to Editor or Panel if Sidebar is now hidden
				if (this.hasFocus(Parts.PANEL_PART) && activePanel) {
					activePanel.focus();
				} else {
					this.editorGroupService.activeGroup.focus();
				}
			});
		}

		// If sidebar becomes visible, show last active Viewlet or default viewlet
		else if (!hidden && !this.sidebarPart.getActiveViewlet()) {
			const viewletToOpen = this.sidebarPart.getLastActiveViewletId();
			if (viewletToOpen) {
				promise = this.viewletService.openViewlet(viewletToOpen, true)
					.then(viewlet => viewlet || this.viewletService.openViewlet(this.viewletService.getDefaultViewletId(), true));
			}
		}

		return promise.then(() => {

			// Remember in settings
			const defaultHidden = this.contextService.getWorkbenchState() === WorkbenchState.EMPTY;
			if (hidden !== defaultHidden) {
				this.storageService.store(Workbench.sidebarHiddenStorageKey, hidden ? 'true' : 'false', StorageScope.WORKSPACE);
			} else {
				this.storageService.remove(Workbench.sidebarHiddenStorageKey, StorageScope.WORKSPACE);
			}

			// Layout
			if (!skipLayout) {
				this.workbenchLayout.layout();
			}
		});
1410
	}
B
Benjamin Pasero 已提交
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488

	setPanelHidden(hidden: boolean, skipLayout?: boolean): TPromise<void> {
		this.panelHidden = hidden;

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

		// If panel part becomes hidden, also hide the current active panel if any
		let promise = TPromise.wrap<any>(null);
		if (hidden && this.panelPart.getActivePanel()) {
			promise = this.panelPart.hideActivePanel().then(() => {
				this.editorGroupService.activeGroup.focus(); // Pass focus to editor group if panel part is now hidden
			});
		}

		// If panel part becomes visible, show last active panel or default panel
		else if (!hidden && !this.panelPart.getActivePanel()) {
			const panelToOpen = this.panelPart.getLastActivePanelId();
			if (panelToOpen) {
				promise = this.panelPart.openPanel(panelToOpen, true);
			}
		}

		return promise.then(() => {

			// Remember in settings
			if (!hidden) {
				this.storageService.store(Workbench.panelHiddenStorageKey, 'false', StorageScope.WORKSPACE);
			} else {
				this.storageService.remove(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE);
			}

			// Layout
			if (!skipLayout) {
				this.workbenchLayout.layout();
			}
		});
	}

	toggleMaximizedPanel(): void {
		this.workbenchLayout.layout({ toggleMaximizedPanel: true, source: Parts.PANEL_PART });
	}

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

	getSideBarPosition(): Position {
		return this.sideBarPosition;
	}

	setSideBarPosition(position: Position): void {
		if (this.sideBarHidden) {
			this.setSideBarHidden(false, true /* Skip Layout */).done(void 0, errors.onUnexpectedError);
		}

		const newPositionValue = (position === Position.LEFT) ? 'left' : 'right';
		const oldPositionValue = (this.sideBarPosition === Position.LEFT) ? 'left' : 'right';
		this.sideBarPosition = position;

		// Adjust CSS
		DOM.removeClass(this.activitybarPart.getContainer(), oldPositionValue);
		DOM.removeClass(this.sidebarPart.getContainer(), oldPositionValue);
		DOM.addClass(this.activitybarPart.getContainer(), newPositionValue);
		DOM.addClass(this.sidebarPart.getContainer(), newPositionValue);

		// Update Styles
		this.activitybarPart.updateStyles();
		this.sidebarPart.updateStyles();

		// Layout
		this.workbenchLayout.layout();
	}

S
SteVen Batten 已提交
1489
	setMenubarHidden(visibility: 'default' | 'visible' | 'toggle' | 'hidden' | string, skipLayout: boolean): void {
1490 1491 1492 1493 1494 1495 1496
		this.menubarHidden = !(visibility === 'visible' || (visibility === 'default' && !browser.isFullscreen()));

		if (!skipLayout) {
			this.workbenchLayout.layout();
		}
	}

B
Benjamin Pasero 已提交
1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521
	getPanelPosition(): Position {
		return this.panelPosition;
	}

	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);

			// Adjust CSS
			DOM.removeClass(this.panelPart.getContainer(), oldPositionValue);
			DOM.addClass(this.panelPart.getContainer(), newPositionValue);

			// Update Styles
			this.panelPart.updateStyles();

			// Layout
			this.workbenchLayout.layout();
		});
	}

	//#endregion
}