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

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

8
import { localize } from 'vs/nls';
B
Benjamin Pasero 已提交
9
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
J
Joao Moreno 已提交
10
import { Event, Emitter } from 'vs/base/common/event';
11
import * as DOM from 'vs/base/browser/dom';
B
Benjamin Pasero 已提交
12
import { RunOnceScheduler, runWhenIdle } from 'vs/base/common/async';
13
import * as browser from 'vs/base/browser/browser';
J
Johannes Rieken 已提交
14
import * as perf from 'vs/base/common/performance';
15
import * as errors from 'vs/base/common/errors';
B
Benjamin Pasero 已提交
16
import { BackupFileService, InMemoryBackupFileService } from 'vs/workbench/services/backup/node/backupFileService';
17
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
18
import { Registry } from 'vs/platform/registry/common/platform';
B
Benjamin Pasero 已提交
19
import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform';
20
import { IResourceInput } from 'vs/platform/editor/common/editor';
J
Johannes Rieken 已提交
21
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
22
import { IEditorInputFactoryRegistry, Extensions as EditorExtensions, TextCompareEditorVisibleContext, TEXT_DIFF_EDITOR_ID, EditorsVisibleContext, InEditorZenModeContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, IUntitledResourceInput, IResourceDiffInput, SplitEditorsVertically, TextCompareEditorActiveContext, ActiveEditorContext } from 'vs/workbench/common/editor';
23
import { HistoryService } from 'vs/workbench/services/history/electron-browser/history';
J
Johannes Rieken 已提交
24 25 26 27
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 已提交
28
import { TitlebarPart } from 'vs/workbench/browser/parts/titlebar/titlebarPart';
29
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
B
Benjamin Pasero 已提交
30
import { WorkbenchLayout } from 'vs/workbench/browser/layout';
31
import { IActionBarRegistry, Extensions as ActionBarExtensions } from 'vs/workbench/browser/actions';
J
Johannes Rieken 已提交
32 33
import { PanelRegistry, Extensions as PanelExtensions } from 'vs/workbench/browser/panel';
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
C
Christof Marti 已提交
34 35
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickInput';
J
Johannes Rieken 已提交
36
import { getServices } from 'vs/platform/instantiation/common/extensions';
A
Alex Dima 已提交
37
import { Position, Parts, IPartService, ILayoutOptions, IDimension, PositionToString } from 'vs/workbench/services/part/common/partService';
38
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
39
import { IStorageService, StorageScope, IWillSaveStateEvent, WillSaveStateReason } from 'vs/platform/storage/common/storage';
S
SteVen Batten 已提交
40 41
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 已提交
42 43
import { WorkbenchKeybindingService } from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
44
import { WorkspaceService, DefaultConfigurationExportHelper } from 'vs/workbench/services/configuration/node/configurationService';
45 46
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
import { JSONEditingService } from 'vs/workbench/services/configuration/node/jsonEditingService';
J
Johannes Rieken 已提交
47
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
48 49
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IKeybindingEditingService, KeybindingsEditingService } from 'vs/workbench/services/keybinding/common/keybindingEditing';
50
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
I
isidor 已提交
51
import { IActivityService } from 'vs/workbench/services/activity/common/activity';
B
Benjamin Pasero 已提交
52
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
53
import { RemoteFileService } from 'vs/workbench/services/files/electron-browser/remoteFileService';
J
Johannes Rieken 已提交
54 55
import { IFileService } from 'vs/platform/files/common/files';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
56
import { ConfigurationResolverService } from 'vs/workbench/services/configurationResolver/electron-browser/configurationResolverService';
J
Johannes Rieken 已提交
57
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
B
Benjamin Pasero 已提交
58
import { ITitleService } from 'vs/workbench/services/title/common/titleService';
J
Johannes Rieken 已提交
59
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
60 61
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { ClipboardService } from 'vs/platform/clipboard/electron-browser/clipboardService';
J
Johannes Rieken 已提交
62 63 64 65 66
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 已提交
67 68
import { ISCMService } from 'vs/workbench/services/scm/common/scm';
import { SCMService } from 'vs/workbench/services/scm/common/scmService';
69
import { IProgressService2 } from 'vs/platform/progress/common/progress';
70
import { ProgressService2 } from 'vs/workbench/services/progress/browser/progressService2';
71
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
72
import { ITextModelService } from 'vs/editor/common/services/resolverService';
J
Johannes Rieken 已提交
73
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
74
import { LifecyclePhase, StartupKind } from 'vs/platform/lifecycle/common/lifecycle';
75
import { LifecycleService } from 'vs/platform/lifecycle/electron-browser/lifecycleService';
B
Benjamin Pasero 已提交
76
import { IWindowService, IWindowConfiguration, IPath, MenuBarVisibility, getTitleBarStyle } from 'vs/platform/windows/common/windows';
J
Johannes Rieken 已提交
77
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
78
import { IMenuService, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
79
import { MenuService } from 'vs/platform/actions/common/menuService';
S
SteVen Batten 已提交
80
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
J
Johannes Rieken 已提交
81
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
B
Benjamin Pasero 已提交
82
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
83
import { OpenRecentAction, ToggleDevToolsAction, ReloadWindowAction, ShowPreviousWindowTab, MoveWindowTabToNewWindow, MergeAllWindowTabs, ShowNextWindowTab, ToggleWindowTabsBar, ReloadWindowWithExtensionsDisabledAction, NewWindowTab } from 'vs/workbench/electron-browser/actions';
84
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
85
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
B
Benjamin Pasero 已提交
86
import { WorkspaceEditingService } from 'vs/workbench/services/workspace/node/workspaceEditingService';
87
import { FileDecorationsService } from 'vs/workbench/services/decorations/browser/decorationsService';
J
Johannes Rieken 已提交
88
import { IDecorationsService } from 'vs/workbench/services/decorations/browser/decorations';
I
isidor 已提交
89
import { ActivityService } from 'vs/workbench/services/activity/browser/activityService';
90
import { URI } from 'vs/base/common/uri';
J
Joao Moreno 已提交
91
import { IListService, ListService } from 'vs/platform/list/browser/listService';
M
Martin Aeschlimann 已提交
92
import { InputFocusedContext, IsMacContext, IsLinuxContext, IsWindowsContext } from 'vs/platform/workbench/common/contextkeys';
93
import { IViewsService } from 'vs/workbench/common/views';
S
Sandeep Somavarapu 已提交
94
import { ViewsService } from 'vs/workbench/browser/parts/views/views';
95 96
import { INotificationService } from 'vs/platform/notification/common/notification';
import { NotificationService } from 'vs/workbench/services/notification/common/notificationService';
97 98
import { NotificationsCenter } from 'vs/workbench/browser/parts/notifications/notificationsCenter';
import { NotificationsAlerts } from 'vs/workbench/browser/parts/notifications/notificationsAlerts';
99
import { NotificationsStatus } from 'vs/workbench/browser/parts/notifications/notificationsStatus';
100
import { registerNotificationCommands } from 'vs/workbench/browser/parts/notifications/notificationsCommands';
101
import { NotificationsToasts } from 'vs/workbench/browser/parts/notifications/notificationsToasts';
J
Joao Moreno 已提交
102
import { IPCClient } from 'vs/base/parts/ipc/node/ipc';
J
Joao Moreno 已提交
103
import { registerWindowDriver } from 'vs/platform/driver/electron-browser/driver';
S
Sandeep Somavarapu 已提交
104 105
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { PreferencesService } from 'vs/workbench/services/preferences/browser/preferencesService';
106
import { IEditorService, IResourceEditor } from 'vs/workbench/services/editor/common/editorService';
I
isidor 已提交
107
import { IEditorGroupsService, GroupDirection, preferredSideBySideGroupDirection } from 'vs/workbench/services/group/common/editorGroupsService';
108
import { EditorService } from 'vs/workbench/services/editor/browser/editorService';
J
Joao Moreno 已提交
109
import { IExtensionUrlHandler, ExtensionUrlHandler } from 'vs/workbench/services/extensions/electron-browser/inactiveExtensionUrlHandler';
S
SteVen Batten 已提交
110
import { ContextViewService } from 'vs/platform/contextview/browser/contextViewService';
A
Alex Dima 已提交
111 112
import { WorkbenchThemeService } from 'vs/workbench/services/themes/electron-browser/workbenchThemeService';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
M
Martin Aeschlimann 已提交
113 114
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { FileDialogService } from 'vs/workbench/services/dialogs/electron-browser/dialogService';
115
import { LogStorageAction } from 'vs/platform/storage/node/storageService';
116

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

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

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

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

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

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

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

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

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

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

184
	_serviceBrand: any;
185

E
Erich Gamma 已提交
186
	private workbenchParams: WorkbenchParams;
B
Benjamin Pasero 已提交
187
	private workbench: HTMLElement;
E
Erich Gamma 已提交
188
	private workbenchStarted: boolean;
B
Benjamin Pasero 已提交
189
	private workbenchRestored: boolean;
E
Erich Gamma 已提交
190
	private workbenchShutdown: boolean;
191

192 193
	private editorService: EditorService;
	private editorGroupService: IEditorGroupsService;
J
Joao Moreno 已提交
194
	private contextViewService: ContextViewService;
195
	private contextKeyService: IContextKeyService;
196
	private keybindingService: IKeybindingService;
197
	private backupFileService: IBackupFileService;
198
	private fileService: IFileService;
199 200 201 202
	private quickInput: QuickInputService;

	private workbenchLayout: WorkbenchLayout;

B
Benjamin Pasero 已提交
203
	private titlebarPart: TitlebarPart;
E
Erich Gamma 已提交
204 205
	private activitybarPart: ActivitybarPart;
	private sidebarPart: SidebarPart;
I
isidor 已提交
206
	private panelPart: PanelPart;
E
Erich Gamma 已提交
207 208 209
	private editorPart: EditorPart;
	private statusbarPart: StatusbarPart;
	private quickOpen: QuickOpenController;
210
	private notificationsCenter: NotificationsCenter;
211
	private notificationsToasts: NotificationsToasts;
212

E
Erich Gamma 已提交
213
	private sideBarHidden: boolean;
214
	private statusBarHidden: boolean;
S
Sanders Lauture 已提交
215
	private activityBarHidden: boolean;
216
	private menubarToggled: boolean;
E
Erich Gamma 已提交
217
	private sideBarPosition: Position;
I
isidor 已提交
218
	private panelPosition: Position;
I
isidor 已提交
219
	private panelHidden: boolean;
S
SteVen Batten 已提交
220
	private menubarVisibility: MenuBarVisibility;
221 222
	private zenMode: IZenMode;
	private fontAliasing: FontAliasingOption;
223
	private hasInitialFilesToOpen: boolean;
224
	private shouldCenterLayout = false;
225

I
isidor 已提交
226
	private inZenMode: IContextKey<boolean>;
227
	private sideBarVisibleContext: IContextKey<boolean>;
228

B
Benjamin Pasero 已提交
229
	private closeEmptyWindowScheduler: RunOnceScheduler = this._register(new RunOnceScheduler(() => this.onAllEditorsClosed(), 50));
E
Erich Gamma 已提交
230

231
	constructor(
232
		private container: HTMLElement,
J
Joao Moreno 已提交
233
		private configuration: IWindowConfiguration,
234
		serviceCollection: ServiceCollection,
235
		private lifecycleService: LifecycleService,
J
Joao Moreno 已提交
236
		private mainProcessClient: IPCClient,
237
		@IInstantiationService private instantiationService: IInstantiationService,
238
		@IWorkspaceContextService private contextService: IWorkspaceContextService,
239
		@IStorageService private storageService: IStorageService,
240
		@IConfigurationService private configurationService: WorkspaceService,
A
Alex Dima 已提交
241
		@IWorkbenchThemeService private themeService: WorkbenchThemeService,
I
isidor 已提交
242
		@IEnvironmentService private environmentService: IEnvironmentService,
243
		@IWindowService private windowService: IWindowService,
B
Benjamin Pasero 已提交
244
		@INotificationService private notificationService: NotificationService
245
	) {
246
		super();
E
Erich Gamma 已提交
247

248
		this.workbenchParams = { configuration, serviceCollection };
E
Erich Gamma 已提交
249

250
		this.hasInitialFilesToOpen =
B
Benjamin Pasero 已提交
251 252 253
			(configuration.filesToCreate && configuration.filesToCreate.length > 0) ||
			(configuration.filesToOpen && configuration.filesToOpen.length > 0) ||
			(configuration.filesToDiff && configuration.filesToDiff.length > 0);
254 255
	}

B
Benjamin Pasero 已提交
256
	startup(): Thenable<IWorkbenchStartedInfo> {
257
		this.workbenchStarted = true;
E
Erich Gamma 已提交
258

B
Benjamin Pasero 已提交
259
		// Create Workbench Container
260
		this.createWorkbench();
E
Erich Gamma 已提交
261

262 263
		// Install some global actions
		this.createGlobalActions();
264

265 266
		// Services
		this.initServices();
E
Erich Gamma 已提交
267

268 269
		// Context Keys
		this.handleContextKeys();
J
Joao Moreno 已提交
270

271 272
		// Register Listeners
		this.registerListeners();
E
Erich Gamma 已提交
273

274 275
		// Settings
		this.initSettings();
E
Erich Gamma 已提交
276

277 278
		// Create Workbench and Parts
		this.renderWorkbench();
279

280 281
		// Workbench Layout
		this.createWorkbenchLayout();
B
polish  
Benjamin Pasero 已提交
282

J
Joao Moreno 已提交
283 284
		// Driver
		if (this.environmentService.driverHandle) {
285
			registerWindowDriver(this.mainProcessClient, this.configuration.windowId, this.instantiationService).then(disposable => this._register(disposable));
J
Joao Moreno 已提交
286 287
		}

288
		// Restore Parts
B
Benjamin Pasero 已提交
289 290
		return this.restoreParts();
	}
291

B
Benjamin Pasero 已提交
292
	private createWorkbench(): void {
B
Benjamin Pasero 已提交
293 294 295
		this.workbench = document.createElement('div');
		this.workbench.id = Identifiers.WORKBENCH_CONTAINER;
		DOM.addClasses(this.workbench, 'monaco-workbench', isWindows ? 'windows' : isLinux ? 'linux' : 'mac');
S
SteVen Batten 已提交
296

B
Benjamin Pasero 已提交
297 298 299
		this._register(DOM.addDisposableListener(this.workbench, DOM.EventType.SCROLL, () => {
			this.workbench.scrollTop = 0; // Prevent workbench from scrolling #55456
		}));
300
	}
E
Erich Gamma 已提交
301

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

B
Benjamin Pasero 已提交
305
		// Actions registered here to adjust for developing vs built workbench
306 307 308 309 310
		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');
311
		registry.registerWorkbenchAction(new SyncActionDescriptor(LogStorageAction, LogStorageAction.ID, LogStorageAction.LABEL), 'Developer: Log Storage', localize('developer', "Developer"));
312

313
		// Actions for macOS native tabs management (only when enabled)
314
		const windowConfig = this.configurationService.getValue<IWindowConfiguration>();
315
		if (windowConfig && windowConfig.window && windowConfig.window.nativeTabs) {
316
			registry.registerWorkbenchAction(new SyncActionDescriptor(NewWindowTab, NewWindowTab.ID, NewWindowTab.LABEL), 'New Window Tab');
317 318 319 320 321
			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');
322
		}
323 324
	}

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

E
Erich Gamma 已提交
328
		// Services we contribute
329
		serviceCollection.set(IPartService, this);
E
Erich Gamma 已提交
330

331
		// Clipboard
J
Johannes Rieken 已提交
332
		serviceCollection.set(IClipboardService, new SyncDescriptor(ClipboardService));
333

334 335 336 337
		// Status bar
		this.statusbarPart = this.instantiationService.createInstance(StatusbarPart, Identifiers.STATUSBAR_PART);
		serviceCollection.set(IStatusbarService, this.statusbarPart);

338 339 340
		// Progress 2
		serviceCollection.set(IProgressService2, new SyncDescriptor(ProgressService2));

341
		// Keybindings
A
Alex Dima 已提交
342
		this.contextKeyService = this.instantiationService.createInstance(ContextKeyService);
343
		serviceCollection.set(IContextKeyService, this.contextKeyService);
344

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

348 349 350
		// List
		serviceCollection.set(IListService, this.instantiationService.createInstance(ListService));

J
Joao Moreno 已提交
351
		// Context view service
B
Benjamin Pasero 已提交
352
		this.contextViewService = this.instantiationService.createInstance(ContextViewService, this.workbench);
J
Joao Moreno 已提交
353 354
		serviceCollection.set(IContextViewService, this.contextViewService);

S
SteVen Batten 已提交
355
		// Use themable context menus when custom titlebar is enabled to match custom menubar
B
Benjamin Pasero 已提交
356
		if (!isMacintosh && this.useCustomTitleBarStyle()) {
J
fix npe  
Johannes Rieken 已提交
357
			serviceCollection.set(IContextMenuService, new SyncDescriptor(HTMLContextMenuService, [null]));
S
SteVen Batten 已提交
358 359 360
		} else {
			serviceCollection.set(IContextMenuService, new SyncDescriptor(NativeContextMenuService));
		}
361

362 363
		// Menus/Actions
		serviceCollection.set(IMenuService, new SyncDescriptor(MenuService));
364

P
Pine Wu 已提交
365
		// Sidebar part
366
		this.sidebarPart = this.instantiationService.createInstance(SidebarPart, Identifiers.SIDEBAR_PART);
P
Pine Wu 已提交
367 368

		// Viewlet service
I
isidor 已提交
369
		serviceCollection.set(IViewletService, this.sidebarPart);
E
Erich Gamma 已提交
370

I
isidor 已提交
371
		// Panel service (panel part)
372 373
		this.panelPart = this.instantiationService.createInstance(PanelPart, Identifiers.PANEL_PART);
		serviceCollection.set(IPanelService, this.panelPart);
I
isidor 已提交
374

375 376 377
		// views service
		const viewsService = this.instantiationService.createInstance(ViewsService);
		serviceCollection.set(IViewsService, viewsService);
S
Sandeep Somavarapu 已提交
378

E
Erich Gamma 已提交
379
		// Activity service (activitybar part)
380
		this.activitybarPart = this.instantiationService.createInstance(ActivitybarPart, Identifiers.ACTIVITYBAR_PART);
I
isidor 已提交
381 382
		const activityService = this.instantiationService.createInstance(ActivityService, this.activitybarPart, this.panelPart);
		serviceCollection.set(IActivityService, activityService);
E
Erich Gamma 已提交
383

384 385 386
		// File Service
		this.fileService = this.instantiationService.createInstance(RemoteFileService);
		serviceCollection.set(IFileService, this.fileService);
S
#47154  
Sandeep Somavarapu 已提交
387
		this.configurationService.acquireFileService(this.fileService);
A
Alex Dima 已提交
388
		this.themeService.acquireFileService(this.fileService);
389

390 391
		// Editor and Group services
		const restorePreviousEditorState = !this.hasInitialFilesToOpen;
392
		this.editorPart = this.instantiationService.createInstance(EditorPart, Identifiers.EDITOR_PART, restorePreviousEditorState);
B
Benjamin Pasero 已提交
393
		this.editorGroupService = this.editorPart;
394 395 396
		serviceCollection.set(IEditorGroupsService, this.editorPart);
		this.editorService = this.instantiationService.createInstance(EditorService);
		serviceCollection.set(IEditorService, this.editorService);
E
Erich Gamma 已提交
397

398 399 400
		// Title bar
		this.titlebarPart = this.instantiationService.createInstance(TitlebarPart, Identifiers.TITLEBAR_PART);
		serviceCollection.set(ITitleService, this.titlebarPart);
B
Benjamin Pasero 已提交
401

402
		// History
403
		serviceCollection.set(IHistoryService, new SyncDescriptor(HistoryService));
404

M
Martin Aeschlimann 已提交
405 406 407
		// File Dialogs
		serviceCollection.set(IFileDialogService, new SyncDescriptor(FileDialogService));

408
		// Backup File Service
B
Benjamin Pasero 已提交
409 410 411 412 413
		if (this.workbenchParams.configuration.backupPath) {
			this.backupFileService = this.instantiationService.createInstance(BackupFileService, this.workbenchParams.configuration.backupPath);
		} else {
			this.backupFileService = new InMemoryBackupFileService();
		}
414
		serviceCollection.set(IBackupFileService, this.backupFileService);
415

416
		// Text File Service
417
		serviceCollection.set(ITextFileService, new SyncDescriptor(TextFileService));
418

419
		// File Decorations
J
Johannes Rieken 已提交
420
		serviceCollection.set(IDecorationsService, new SyncDescriptor(FileDecorationsService));
421

J
Joao Moreno 已提交
422
		// SCM Service
423
		serviceCollection.set(ISCMService, new SyncDescriptor(SCMService));
424

J
Joao Moreno 已提交
425
		// Inactive extension URL handler
J
Joao Moreno 已提交
426
		serviceCollection.set(IExtensionUrlHandler, new SyncDescriptor(ExtensionUrlHandler));
J
Joao Moreno 已提交
427

B
Benjamin Pasero 已提交
428
		// Text Model Resolver Service
429
		serviceCollection.set(ITextModelService, new SyncDescriptor(TextModelResolverService));
B
Benjamin Pasero 已提交
430

431 432 433 434
		// JSON Editing
		const jsonEditingService = this.instantiationService.createInstance(JSONEditingService);
		serviceCollection.set(IJSONEditingService, jsonEditingService);

435 436 437
		// Workspace Editing
		serviceCollection.set(IWorkspaceEditingService, new SyncDescriptor(WorkspaceEditingService));

438 439 440
		// Keybinding Editing
		serviceCollection.set(IKeybindingEditingService, this.instantiationService.createInstance(KeybindingsEditingService));

441
		// Configuration Resolver
442
		serviceCollection.set(IConfigurationResolverService, new SyncDescriptor(ConfigurationResolverService, [process.env]));
443

E
Erich Gamma 已提交
444
		// Quick open service (quick open controller)
445 446
		this.quickOpen = this.instantiationService.createInstance(QuickOpenController);
		serviceCollection.set(IQuickOpenService, this.quickOpen);
447

C
Christof Marti 已提交
448 449 450 451
		// Quick input service
		this.quickInput = this.instantiationService.createInstance(QuickInputService);
		serviceCollection.set(IQuickInputService, this.quickInput);

S
Sandeep Somavarapu 已提交
452 453 454
		// PreferencesService
		serviceCollection.set(IPreferencesService, this.instantiationService.createInstance(PreferencesService));

B
polish  
Benjamin Pasero 已提交
455
		// Contributed services
B
Benjamin Pasero 已提交
456
		const contributedServices = getServices();
E
Erich Gamma 已提交
457
		for (let contributedService of contributedServices) {
458
			serviceCollection.set(contributedService.id, contributedService.descriptor);
E
Erich Gamma 已提交
459 460 461
		}

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

466
		this.instantiationService.createInstance(DefaultConfigurationExportHelper);
467

S
#47154  
Sandeep Somavarapu 已提交
468
		this.configurationService.acquireInstantiationService(this.getInstantiationService());
E
Erich Gamma 已提交
469 470
	}

471
	//#region event handling
E
Erich Gamma 已提交
472

473
	private registerListeners(): void {
I
isidor 已提交
474

475
		// Storage
476
		this._register(this.storageService.onWillSaveState(e => this.saveState(e)));
477

478
		// Listen to visible editor changes
479
		this._register(this.editorService.onDidVisibleEditorsChange(() => this.onDidVisibleEditorsChange()));
B
Benjamin Pasero 已提交
480

481 482 483
		// Listen to editor closing (if we run with --wait)
		const filesToWait = this.workbenchParams.configuration.filesToWait;
		if (filesToWait) {
484
			const resourcesToWaitFor = filesToWait.paths.map(p => p.fileUri);
485
			const waitMarkerFile = URI.file(filesToWait.waitMarkerFilePath);
486
			const listenerDispose = this.editorService.onDidCloseEditor(() => this.onEditorClosed(listenerDispose, resourcesToWaitFor, waitMarkerFile));
I
isidor 已提交
487

488
			this._register(listenerDispose);
489
		}
S
Sanders Lauture 已提交
490

491
		// Configuration changes
492
		this._register(this.configurationService.onDidChangeConfiguration(() => this.onDidUpdateConfiguration()));
I
isidor 已提交
493

494
		// Fullscreen changes
495
		this._register(browser.onDidChangeFullscreen(() => this.onFullscreenChanged()));
B
Benjamin Pasero 已提交
496 497 498 499

		// Group changes
		this._register(this.editorGroupService.onDidAddGroup(() => this.centerEditorLayout(this.shouldCenterLayout)));
		this._register(this.editorGroupService.onDidRemoveGroup(() => this.centerEditorLayout(this.shouldCenterLayout)));
500
	}
501

502
	private onFullscreenChanged(): void {
S
SrTobi 已提交
503

504 505 506
		// Apply as CSS class
		const isFullscreen = browser.isFullscreen();
		if (isFullscreen) {
B
Benjamin Pasero 已提交
507
			DOM.addClass(this.workbench, 'fullscreen');
508
		} else {
B
Benjamin Pasero 已提交
509 510
			DOM.removeClass(this.workbench, 'fullscreen');

511 512 513 514
			if (this.zenMode.transitionedToFullScreen && this.zenMode.active) {
				this.toggleZenMode();
			}
		}
E
Erich Gamma 已提交
515

516
		// Changing fullscreen state of the window has an impact on custom title bar visibility, so we need to update
B
Benjamin Pasero 已提交
517
		if (this.useCustomTitleBarStyle()) {
518 519 520
			this._onTitleBarVisibilityChange.fire();
			this.layout(); // handle title bar when fullscreen changes
		}
521 522
	}

523 524 525 526
	private onMenubarToggled(visible: boolean) {
		if (visible !== this.menubarToggled) {
			this.menubarToggled = visible;

527 528
			if (browser.isFullscreen() && (this.menubarVisibility === 'toggle' || this.menubarVisibility === 'default')) {
				this._onTitleBarVisibilityChange.fire();
529 530 531 532 533
				this.layout();
			}
		}
	}

534
	private onEditorClosed(listenerDispose: IDisposable, resourcesToWaitFor: URI[], waitMarkerFile: URI): void {
E
Erich Gamma 已提交
535

536 537 538
		// 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.
539
		if (resourcesToWaitFor.every(resource => !this.editorService.isOpen({ resource }))) {
540
			listenerDispose.dispose();
541
			this.fileService.del(waitMarkerFile);
542
		}
E
Erich Gamma 已提交
543 544
	}

545
	private onDidVisibleEditorsChange(): void {
546
		const visibleEditors = this.editorService.visibleControls;
E
Erich Gamma 已提交
547

548 549 550 551 552 553 554 555 556
		// 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();
			}
		}
557 558
	}

559
	private onAllEditorsClosed(): void {
560
		const visibleEditors = this.editorService.visibleControls.length;
561 562
		if (visibleEditors === 0) {
			this.windowService.closeWindow();
E
Erich Gamma 已提交
563 564 565
		}
	}

566 567 568 569 570
	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);
571
		}
E
Erich Gamma 已提交
572

573
		this.setPanelPositionFromStorageOrConfig();
E
Erich Gamma 已提交
574

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

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

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

592
		const newMenubarVisibility = this.configurationService.getValue<MenuBarVisibility>(Workbench.menubarVisibilityConfigurationKey);
S
SteVen Batten 已提交
593
		this.setMenubarVisibility(newMenubarVisibility, skipLayout);
594
	}
B
Benjamin Pasero 已提交
595

596
	//#endregion
B
Benjamin Pasero 已提交
597

598 599
	private handleContextKeys(): void {
		this.inZenMode = InEditorZenModeContext.bindTo(this.contextKeyService);
600

I
isidor 已提交
601 602 603
		IsMacContext.bindTo(this.contextKeyService);
		IsLinuxContext.bindTo(this.contextKeyService);
		IsWindowsContext.bindTo(this.contextKeyService);
604

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

608
		const activeEditorContext = ActiveEditorContext.bindTo(this.contextKeyService);
609 610
		const editorsVisibleContext = EditorsVisibleContext.bindTo(this.contextKeyService);
		const textCompareEditorVisible = TextCompareEditorVisibleContext.bindTo(this.contextKeyService);
611
		const textCompareEditorActive = TextCompareEditorActiveContext.bindTo(this.contextKeyService);
612 613
		const activeEditorGroupEmpty = ActiveEditorGroupEmptyContext.bindTo(this.contextKeyService);
		const multipleEditorGroups = MultipleEditorGroupsContext.bindTo(this.contextKeyService);
614

615
		const updateEditorContextKeys = () => {
616
			const activeControl = this.editorService.activeControl;
617
			const visibleEditors = this.editorService.visibleControls;
E
Erich Gamma 已提交
618

619
			textCompareEditorActive.set(activeControl && activeControl.getId() === TEXT_DIFF_EDITOR_ID);
620
			textCompareEditorVisible.set(visibleEditors.some(control => control.getId() === TEXT_DIFF_EDITOR_ID));
I
isidor 已提交
621

622 623 624 625
			if (visibleEditors.length > 0) {
				editorsVisibleContext.set(true);
			} else {
				editorsVisibleContext.reset();
626
			}
B
Benjamin Pasero 已提交
627

628
			if (!this.editorService.activeEditor) {
629 630 631
				activeEditorGroupEmpty.set(true);
			} else {
				activeEditorGroupEmpty.reset();
632
			}
633

B
Benjamin Pasero 已提交
634
			if (this.editorGroupService.count > 1) {
635 636 637 638
				multipleEditorGroups.set(true);
			} else {
				multipleEditorGroups.reset();
			}
639 640 641 642 643 644

			if (activeControl) {
				activeEditorContext.set(activeControl.getId());
			} else {
				activeEditorContext.reset();
			}
645
		};
B
Benjamin Pasero 已提交
646

647
		this.editorPart.whenRestored.then(() => updateEditorContextKeys());
648 649
		this._register(this.editorService.onDidActiveEditorChange(() => updateEditorContextKeys()));
		this._register(this.editorService.onDidVisibleEditorsChange(() => updateEditorContextKeys()));
B
Benjamin Pasero 已提交
650 651
		this._register(this.editorGroupService.onDidAddGroup(() => updateEditorContextKeys()));
		this._register(this.editorGroupService.onDidRemoveGroup(() => updateEditorContextKeys()));
652

653
		const inputFocused = InputFocusedContext.bindTo(this.contextKeyService);
B
Benjamin Pasero 已提交
654 655 656 657 658 659 660 661 662 663 664

		function activeElementIsInput(): boolean {
			return document.activeElement && (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA');
		}

		function trackInputFocus(): void {
			const isInputFocused = activeElementIsInput();
			inputFocused.set(isInputFocused);

			if (isInputFocused) {
				const tracker = DOM.trackFocus(document.activeElement as HTMLElement);
J
Joao Moreno 已提交
665
				Event.once(tracker.onDidBlur)(() => {
B
Benjamin Pasero 已提交
666 667 668 669 670 671 672 673
					inputFocused.set(activeElementIsInput());

					tracker.dispose();
				});
			}
		}

		this._register(DOM.addDisposableListener(window, 'focusin', () => trackInputFocus(), true));
674 675 676 677 678 679

		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 已提交
680

681 682 683 684 685
		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);
		}));
686

687
		const splitEditorsVerticallyContext = SplitEditorsVertically.bindTo(this.contextKeyService);
S
Sanders Lauture 已提交
688

689 690 691 692
		const updateSplitEditorsVerticallyContext = () => {
			const direction = preferredSideBySideGroupDirection(this.configurationService);
			splitEditorsVerticallyContext.set(direction === GroupDirection.DOWN);
		};
S
Sanders Lauture 已提交
693

694 695 696 697 698
		this._register(this.configurationService.onDidChangeConfiguration(e => {
			if (e.affectsConfiguration('workbench.editor.openSideBySideDirection')) {
				updateSplitEditorsVerticallyContext();
			}
		}));
E
Erich Gamma 已提交
699

700
		updateSplitEditorsVerticallyContext();
701
	}
E
Erich Gamma 已提交
702

B
Benjamin Pasero 已提交
703
	private restoreParts(): Thenable<IWorkbenchStartedInfo> {
704
		const restorePromises: Thenable<any>[] = [];
B
Benjamin Pasero 已提交
705

706 707
		// Restore Editorpart
		perf.mark('willRestoreEditors');
708
		restorePromises.push(this.editorPart.whenRestored.then(() => {
B
Benjamin Pasero 已提交
709 710 711 712

			function openEditors(editors: IResourceEditor[], editorService: IEditorService) {
				if (editors.length) {
					return editorService.openEditors(editors);
713
				}
E
Erich Gamma 已提交
714

B
Benjamin Pasero 已提交
715 716 717 718 719 720 721 722 723 724 725
				return Promise.resolve();
			}

			const editorsToOpen = this.resolveEditorsToOpen();

			if (Array.isArray(editorsToOpen)) {
				return openEditors(editorsToOpen, this.editorService);
			}

			return editorsToOpen.then(editors => openEditors(editors, this.editorService));
		}).then(() => perf.mark('didRestoreEditors')));
E
Erich Gamma 已提交
726

727 728 729 730
		// Restore Sidebar
		let viewletIdToRestore: string;
		if (!this.sideBarHidden) {
			this.sideBarVisibleContext.set(true);
731

732
			if (this.shouldRestoreLastOpenedViewlet()) {
733
				viewletIdToRestore = this.storageService.get(SidebarPart.activeViewletSettingsKey, StorageScope.WORKSPACE);
734
			}
735

736
			if (!viewletIdToRestore) {
I
isidor 已提交
737
				viewletIdToRestore = this.sidebarPart.getDefaultViewletId();
738
			}
E
Erich Gamma 已提交
739

740
			perf.mark('willRestoreViewlet');
I
isidor 已提交
741 742
			restorePromises.push(this.sidebarPart.openViewlet(viewletIdToRestore)
				.then(viewlet => viewlet || this.sidebarPart.openViewlet(this.sidebarPart.getDefaultViewletId()))
B
Benjamin Pasero 已提交
743
				.then(() => perf.mark('didRestoreViewlet')));
744 745
		}

746 747
		// Restore Panel
		const panelRegistry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
748
		const panelId = this.storageService.get(PanelPart.activePanelSettingsKey, StorageScope.WORKSPACE, panelRegistry.getDefaultPanelId());
749
		if (!this.panelHidden && !!panelId) {
750
			perf.mark('willRestorePanel');
751
			const isPanelToRestoreEnabled = !!this.panelPart.getPanels().filter(p => p.id === panelId).length;
752
			const panelIdToRestore = isPanelToRestoreEnabled ? panelId : panelRegistry.getDefaultPanelId();
753 754
			this.panelPart.openPanel(panelIdToRestore, false);
			perf.mark('didRestorePanel');
I
isidor 已提交
755 756
		}

757 758 759
		// Restore Zen Mode if active and supported for restore on startup
		const zenConfig = this.configurationService.getValue<IZenModeSettings>('zenMode');
		const wasZenActive = this.storageService.getBoolean(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE, false);
760
		if (wasZenActive && zenConfig.restore) {
I
isidor 已提交
761
			this.toggleZenMode(true, true);
I
isidor 已提交
762 763
		}

B
Benjamin Pasero 已提交
764
		// Restore Forced Editor Center Mode
765
		if (this.storageService.getBoolean(Workbench.centeredEditorLayoutActiveStorageKey, StorageScope.WORKSPACE, false)) {
I
isidor 已提交
766
			this.centerEditorLayout(true);
S
SrTobi 已提交
767
		}
768

769
		const onRestored = (error?: Error): IWorkbenchStartedInfo => {
B
Benjamin Pasero 已提交
770 771 772 773 774 775 776 777 778 779 780 781
			this.workbenchRestored = true;

			// Set lifecycle phase to `Restored`
			this.lifecycleService.phase = LifecyclePhase.Restored;

			// Set lifecycle phase to `Runnning For A Bit` after a short delay
			let eventuallPhaseTimeoutHandle = runWhenIdle(() => {
				eventuallPhaseTimeoutHandle = void 0;
				this.lifecycleService.phase = LifecyclePhase.Eventually;
			}, 5000);

			this._register(eventuallPhaseTimeoutHandle);
782

783 784
			if (error) {
				errors.onUnexpectedError(error);
785
			}
I
isidor 已提交
786

787 788
			return {
				customKeybindingsCount: this.keybindingService.customKeybindingsCount(),
P
Pine Wu 已提交
789
				pinnedViewlets: this.activitybarPart.getPinnedViewletIds(),
790
				restoredViewlet: viewletIdToRestore,
791
				restoredEditorsCount: this.editorService.visibleEditors.length
792 793
			};
		};
794

B
Benjamin Pasero 已提交
795
		return Promise.all(restorePromises).then(() => onRestored(), error => onRestored(error));
E
Erich Gamma 已提交
796 797
	}

798 799 800
	private shouldRestoreLastOpenedViewlet(): boolean {
		if (!this.environmentService.isBuilt) {
			return true; // always restore sidebar when we are in development mode
E
Erich Gamma 已提交
801 802
		}

803 804
		// always restore sidebar when the window was reloaded
		return this.lifecycleService.startupKind === StartupKind.ReloadedWindow;
E
Erich Gamma 已提交
805 806
	}

B
Benjamin Pasero 已提交
807
	private resolveEditorsToOpen(): Thenable<IResourceEditor[]> | IResourceEditor[] {
808
		const config = this.workbenchParams.configuration;
I
isidor 已提交
809

B
Benjamin Pasero 已提交
810
		// Files to open, diff or create
811
		if (this.hasInitialFilesToOpen) {
I
isidor 已提交
812

B
Benjamin Pasero 已提交
813
			// Files to diff is exclusive
814
			const filesToDiff = this.toInputs(config.filesToDiff, false);
815
			if (filesToDiff && filesToDiff.length === 2) {
B
Benjamin Pasero 已提交
816
				return [<IResourceDiffInput>{
817 818
					leftResource: filesToDiff[0].resource,
					rightResource: filesToDiff[1].resource,
B
Benjamin Pasero 已提交
819
					options: { pinned: true },
B
Benjamin Pasero 已提交
820
					forceFile: true
B
Benjamin Pasero 已提交
821
				}];
B
Benjamin Pasero 已提交
822
			}
I
isidor 已提交
823

824 825
			const filesToCreate = this.toInputs(config.filesToCreate, true);
			const filesToOpen = this.toInputs(config.filesToOpen, false);
I
isidor 已提交
826

827
			// Otherwise: Open/Create files
B
Benjamin Pasero 已提交
828
			return [...filesToOpen, ...filesToCreate];
B
Benjamin Pasero 已提交
829
		}
I
isidor 已提交
830

831
		// Empty workbench
832
		else if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY && this.openUntitledFile()) {
B
Benjamin Pasero 已提交
833
			const isEmpty = this.editorGroupService.count === 1 && this.editorGroupService.activeGroup.count === 0;
834
			if (!isEmpty) {
B
Benjamin Pasero 已提交
835
				return []; // do not open any empty untitled file if we restored editors from previous session
836
			}
B
Benjamin Pasero 已提交
837

838 839
			return this.backupFileService.hasBackups().then(hasBackups => {
				if (hasBackups) {
B
Benjamin Pasero 已提交
840
					return []; // do not open any empty untitled file if we have backups to restore
841
				}
B
Benjamin Pasero 已提交
842

B
Benjamin Pasero 已提交
843
				return [<IUntitledResourceInput>{}];
844
			});
845
		}
846

B
Benjamin Pasero 已提交
847
		return [];
B
Benjamin Pasero 已提交
848
	}
849

850
	private toInputs(paths: IPath[], isNew: boolean): (IResourceInput | IUntitledResourceInput)[] {
B
Benjamin Pasero 已提交
851 852
		if (!paths || !paths.length) {
			return [];
853
		}
I
isidor 已提交
854

B
Benjamin Pasero 已提交
855
		return paths.map(p => {
856
			const resource = p.fileUri;
857 858 859 860
			let input: IResourceInput | IUntitledResourceInput;
			if (isNew) {
				input = { filePath: resource.fsPath, options: { pinned: true } } as IUntitledResourceInput;
			} else {
B
Benjamin Pasero 已提交
861
				input = { resource, options: { pinned: true }, forceFile: true } as IResourceInput;
862
			}
E
Erich Gamma 已提交
863

864
			if (!isNew && p.lineNumber) {
B
Benjamin Pasero 已提交
865 866 867 868 869
				input.options.selection = {
					startLineNumber: p.lineNumber,
					startColumn: p.columnNumber
				};
			}
870

B
Benjamin Pasero 已提交
871 872
			return input;
		});
873 874
	}

875
	private openUntitledFile() {
876
		const startupEditor = this.configurationService.inspect('workbench.startupEditor');
B
Benjamin Pasero 已提交
877 878

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

886
		return startupEditor.value === 'newUntitledFile';
887
	}
E
Erich Gamma 已提交
888 889

	private initSettings(): void {
890

E
Erich Gamma 已提交
891
		// Sidebar visibility
892
		this.sideBarHidden = this.storageService.getBoolean(Workbench.sidebarHiddenStorageKey, StorageScope.WORKSPACE, this.contextService.getWorkbenchState() === WorkbenchState.EMPTY);
893

I
isidor 已提交
894
		// Panel part visibility
895
		const panelRegistry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
896
		this.panelHidden = this.storageService.getBoolean(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE, true);
897 898
		if (!panelRegistry.getDefaultPanelId()) {
			this.panelHidden = true; // we hide panel part if there is no default panel
899 900
		}

E
Erich Gamma 已提交
901
		// Sidebar position
902
		const sideBarPosition = this.configurationService.getValue<string>(Workbench.sidebarPositionConfigurationKey);
903
		this.sideBarPosition = (sideBarPosition === 'right') ? Position.RIGHT : Position.LEFT;
904

I
isidor 已提交
905
		// Panel position
906
		this.setPanelPositionFromStorageOrConfig();
907

908
		// Menubar visibility
909
		const menuBarVisibility = this.configurationService.getValue<MenuBarVisibility>(Workbench.menubarVisibilityConfigurationKey);
S
SteVen Batten 已提交
910
		this.setMenubarVisibility(menuBarVisibility, true);
911

B
Benjamin Pasero 已提交
912
		// Statusbar visibility
913
		const statusBarVisible = this.configurationService.getValue<string>(Workbench.statusbarVisibleConfigurationKey);
914
		this.statusBarHidden = !statusBarVisible;
915

S
Sanders Lauture 已提交
916
		// Activity bar visibility
917
		const activityBarVisible = this.configurationService.getValue<string>(Workbench.activityBarVisibleConfigurationKey);
S
Sanders Lauture 已提交
918
		this.activityBarHidden = !activityBarVisible;
919

920
		// Font aliasing
921
		this.fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
922

I
isidor 已提交
923 924
		// Zen mode
		this.zenMode = {
I
isidor 已提交
925
			active: false,
926
			transitionedToFullScreen: false,
927
			transitionedToCenteredEditorLayout: false,
928
			wasSideBarVisible: false,
929 930
			wasPanelVisible: false,
			transitionDisposeables: []
I
isidor 已提交
931
		};
E
Erich Gamma 已提交
932 933
	}

934 935
	private setPanelPositionFromStorageOrConfig() {
		const defaultPanelPosition = this.configurationService.getValue<string>(Workbench.defaultPanelPositionStorageKey);
936
		const panelPosition = this.storageService.get(Workbench.panelPositionStorageKey, StorageScope.WORKSPACE, defaultPanelPosition);
937

938 939
		this.panelPosition = (panelPosition === 'right') ? Position.RIGHT : Position.BOTTOM;
	}
940

B
Benjamin Pasero 已提交
941 942
	private useCustomTitleBarStyle(): boolean {
		return getTitleBarStyle(this.configurationService, this.environmentService) === 'custom';
B
Benjamin Pasero 已提交
943 944
	}

945 946
	private setStatusBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.statusBarHidden = hidden;
B
Benjamin Pasero 已提交
947

948 949
		// Adjust CSS
		if (hidden) {
B
Benjamin Pasero 已提交
950
			DOM.addClass(this.workbench, 'nostatusbar');
E
Erich Gamma 已提交
951
		} else {
B
Benjamin Pasero 已提交
952
			DOM.removeClass(this.workbench, 'nostatusbar');
E
Erich Gamma 已提交
953 954
		}

955 956 957
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
958 959 960
		}
	}

961
	private setFontAliasing(aliasing: FontAliasingOption) {
962
		this.fontAliasing = aliasing;
S
Sanders Lauture 已提交
963

B
Benjamin Pasero 已提交
964 965 966 967 968
		// Remove all
		document.body.classList.remove(...fontAliasingValues.map(value => `monaco-font-aliasing-${value}`));

		// Add specific
		if (fontAliasingValues.some(option => option === aliasing)) {
969
			document.body.classList.add(`monaco-font-aliasing-${aliasing}`);
S
Sanders Lauture 已提交
970
		}
971 972
	}

E
Erich Gamma 已提交
973
	private createWorkbenchLayout(): void {
974 975
		this.workbenchLayout = this.instantiationService.createInstance(
			WorkbenchLayout,
976
			this.container,
B
Benjamin Pasero 已提交
977
			this.workbench,
I
isidor 已提交
978
			{
979 980 981 982 983 984
				titlebar: this.titlebarPart,
				activitybar: this.activitybarPart,
				editor: this.editorPart,
				sidebar: this.sidebarPart,
				panel: this.panelPart,
				statusbar: this.statusbarPart,
I
isidor 已提交
985
			},
986 987 988 989
			this.quickOpen,
			this.quickInput,
			this.notificationsCenter,
			this.notificationsToasts
E
Erich Gamma 已提交
990 991 992 993 994 995 996
		);
	}

	private renderWorkbench(): void {

		// Apply sidebar state as CSS class
		if (this.sideBarHidden) {
B
Benjamin Pasero 已提交
997
			DOM.addClass(this.workbench, 'nosidebar');
E
Erich Gamma 已提交
998
		}
B
Benjamin Pasero 已提交
999

1000
		if (this.panelHidden) {
B
Benjamin Pasero 已提交
1001
			DOM.addClass(this.workbench, 'nopanel');
1002
		}
B
Benjamin Pasero 已提交
1003

1004
		if (this.statusBarHidden) {
B
Benjamin Pasero 已提交
1005
			DOM.addClass(this.workbench, 'nostatusbar');
1006
		}
E
Erich Gamma 已提交
1007

B
Benjamin Pasero 已提交
1008
		// Apply font aliasing
1009 1010
		this.setFontAliasing(this.fontAliasing);

1011 1012
		// Apply fullscreen state
		if (browser.isFullscreen()) {
B
Benjamin Pasero 已提交
1013
			DOM.addClass(this.workbench, 'fullscreen');
B
Benjamin Pasero 已提交
1014 1015
		}

E
Erich Gamma 已提交
1016
		// Create Parts
B
Benjamin Pasero 已提交
1017
		this.createTitlebarPart();
E
Erich Gamma 已提交
1018 1019 1020
		this.createActivityBarPart();
		this.createSidebarPart();
		this.createEditorPart();
1021
		this.createPanelPart();
E
Erich Gamma 已提交
1022 1023
		this.createStatusbarPart();

1024 1025
		// Notification Handlers
		this.createNotificationsHandlers();
1026

1027 1028

		// Menubar visibility changes
B
Benjamin Pasero 已提交
1029
		if ((isWindows || isLinux) && this.useCustomTitleBarStyle()) {
1030 1031 1032
			this.titlebarPart.onMenubarVisibilityChange()(e => this.onMenubarToggled(e));
		}

E
Erich Gamma 已提交
1033
		// Add Workbench to DOM
B
Benjamin Pasero 已提交
1034
		this.container.appendChild(this.workbench);
E
Erich Gamma 已提交
1035 1036
	}

B
Benjamin Pasero 已提交
1037
	private createTitlebarPart(): void {
B
Benjamin Pasero 已提交
1038
		const titlebarContainer = this.createPart(Identifiers.TITLEBAR_PART, ['part', 'titlebar'], 'contentinfo');
B
Benjamin Pasero 已提交
1039

B
Benjamin Pasero 已提交
1040
		this.titlebarPart.create(titlebarContainer);
B
Benjamin Pasero 已提交
1041 1042
	}

E
Erich Gamma 已提交
1043
	private createActivityBarPart(): void {
B
Benjamin Pasero 已提交
1044
		const activitybarPartContainer = this.createPart(Identifiers.ACTIVITYBAR_PART, ['part', 'activitybar', this.sideBarPosition === Position.LEFT ? 'left' : 'right'], 'navigation');
E
Erich Gamma 已提交
1045

B
Benjamin Pasero 已提交
1046
		this.activitybarPart.create(activitybarPartContainer);
E
Erich Gamma 已提交
1047 1048 1049
	}

	private createSidebarPart(): void {
B
Benjamin Pasero 已提交
1050
		const sidebarPartContainer = this.createPart(Identifiers.SIDEBAR_PART, ['part', 'sidebar', this.sideBarPosition === Position.LEFT ? 'left' : 'right'], 'complementary');
E
Erich Gamma 已提交
1051

B
Benjamin Pasero 已提交
1052
		this.sidebarPart.create(sidebarPartContainer);
E
Erich Gamma 已提交
1053 1054
	}

I
isidor 已提交
1055
	private createPanelPart(): void {
B
Benjamin Pasero 已提交
1056
		const panelPartContainer = this.createPart(Identifiers.PANEL_PART, ['part', 'panel', this.panelPosition === Position.BOTTOM ? 'bottom' : 'right'], 'complementary');
I
isidor 已提交
1057

B
Benjamin Pasero 已提交
1058
		this.panelPart.create(panelPartContainer);
I
isidor 已提交
1059 1060
	}

E
Erich Gamma 已提交
1061
	private createEditorPart(): void {
B
Benjamin Pasero 已提交
1062
		const editorContainer = this.createPart(Identifiers.EDITOR_PART, ['part', 'editor'], 'main');
E
Erich Gamma 已提交
1063

B
Benjamin Pasero 已提交
1064
		this.editorPart.create(editorContainer);
E
Erich Gamma 已提交
1065 1066 1067
	}

	private createStatusbarPart(): void {
B
Benjamin Pasero 已提交
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
		const statusbarContainer = this.createPart(Identifiers.STATUSBAR_PART, ['part', 'statusbar'], 'contentinfo');

		this.statusbarPart.create(statusbarContainer);
	}

	private createPart(id: string, classes: string[], role: string): HTMLElement {
		const part = document.createElement('div');
		classes.forEach(clazz => DOM.addClass(part, clazz));
		part.id = id;
		part.setAttribute('role', role);

S
SteVen Batten 已提交
1079 1080 1081
		// Insert all workbench parts at the beginning. Issue #52531
		// This is primarily for the title bar to allow overriding -webkit-app-region
		this.workbench.insertBefore(part, this.workbench.lastChild);
E
Erich Gamma 已提交
1082

B
Benjamin Pasero 已提交
1083
		return part;
E
Erich Gamma 已提交
1084 1085
	}

1086 1087
	private createNotificationsHandlers(): void {

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

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

1094
		// Notifications Alerts
1095
		this._register(this.instantiationService.createInstance(NotificationsAlerts, this.notificationService.model));
1096 1097 1098 1099

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

1100
		// Eventing
1101
		this._register(this.notificationsCenter.onDidChangeVisibility(() => {
1102 1103 1104 1105 1106 1107 1108 1109

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

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

1110
		// Register Commands
1111
		registerNotificationCommands(this.notificationsCenter, this.notificationsToasts);
1112 1113
	}

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

1118
	private saveState(e: IWillSaveStateEvent): void {
1119
		if (this.zenMode.active) {
B
Benjamin Pasero 已提交
1120
			this.storageService.store(Workbench.zenModeActiveStorageKey, true, StorageScope.WORKSPACE);
1121
		} else {
B
Benjamin Pasero 已提交
1122
			this.storageService.remove(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE);
1123
		}
1124 1125 1126 1127 1128 1129 1130 1131

		if (e.reason === WillSaveStateReason.SHUTDOWN && this.zenMode.active) {
			const zenConfig = this.configurationService.getValue<IZenModeSettings>('zenMode');
			if (!zenConfig.restore) {
				// We will not restore zen mode, need to clear all zen mode state changes
				this.toggleZenMode(true);
			}
		}
1132 1133
	}

1134
	dispose(): void {
1135
		super.dispose();
1136 1137 1138 1139 1140 1141

		this.workbenchShutdown = true;
	}

	//#region IPartService

B
Benjamin Pasero 已提交
1142
	private _onTitleBarVisibilityChange: Emitter<void> = this._register(new Emitter<void>());
1143
	get onTitleBarVisibilityChange(): Event<void> { return this._onTitleBarVisibilityChange.event; }
1144

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

B
Benjamin Pasero 已提交
1147 1148
	isRestored(): boolean {
		return !!(this.workbenchRestored && this.workbenchStarted);
1149
	}
1150

1151 1152 1153 1154 1155
	hasFocus(part: Parts): boolean {
		const activeElement = document.activeElement;
		if (!activeElement) {
			return false;
		}
1156

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

1161
	getContainer(part: Parts): HTMLElement {
1162
		let container: HTMLElement | null = null;
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
		switch (part) {
			case Parts.TITLEBAR_PART:
				container = this.titlebarPart.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;
		}
1183

1184 1185
		return container;
	}
1186

1187 1188 1189
	isVisible(part: Parts): boolean {
		switch (part) {
			case Parts.TITLEBAR_PART:
B
Benjamin Pasero 已提交
1190
				if (!this.useCustomTitleBarStyle()) {
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
					return false;
				} else if (!browser.isFullscreen()) {
					return true;
				} else if (isMacintosh) {
					return false;
				} else if (this.menubarVisibility === 'visible') {
					return true;
				} else if (this.menubarVisibility === 'toggle' || this.menubarVisibility === 'default') {
					return this.menubarToggled;
				}

				return false;
1203 1204 1205 1206 1207 1208 1209 1210
			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 已提交
1211
		}
1212

1213
		return true; // any other part cannot be hidden
E
Erich Gamma 已提交
1214 1215
	}

1216 1217 1218
	getTitleBarOffset(): number {
		let offset = 0;
		if (this.isVisible(Parts.TITLEBAR_PART)) {
S
SteVen Batten 已提交
1219
			offset = this.workbenchLayout.partLayoutInfo.titlebar.height;
1220 1221 1222
			if (isMacintosh || this.menubarVisibility === 'hidden') {
				offset /= browser.getZoomFactor();
			}
E
Erich Gamma 已提交
1223
		}
1224 1225

		return offset;
E
Erich Gamma 已提交
1226
	}
1227

1228 1229
	getWorkbenchElement(): HTMLElement {
		return this.workbench;
1230
	}
1231

I
isidor 已提交
1232
	toggleZenMode(skipLayout?: boolean, restoring = false): void {
I
isidor 已提交
1233
		this.zenMode.active = !this.zenMode.active;
1234
		this.zenMode.transitionDisposeables = dispose(this.zenMode.transitionDisposeables);
1235

1236 1237
		// 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)
1238
		let toggleFullScreen = false;
1239 1240

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

I
isidor 已提交
1244
			toggleFullScreen = !browser.isFullscreen() && config.fullScreen;
I
isidor 已提交
1245
			this.zenMode.transitionedToFullScreen = restoring ? config.fullScreen : toggleFullScreen;
1246
			this.zenMode.transitionedToCenteredEditorLayout = !this.isEditorLayoutCentered() && config.centerLayout;
1247 1248
			this.zenMode.wasSideBarVisible = this.isVisible(Parts.SIDEBAR_PART);
			this.zenMode.wasPanelVisible = this.isVisible(Parts.PANEL_PART);
1249

1250 1251
			this.setPanelHidden(true, true);
			this.setSideBarHidden(true, true);
I
isidor 已提交
1252

1253 1254 1255
			if (config.hideActivityBar) {
				this.setActivityBarHidden(true, true);
			}
1256

I
isidor 已提交
1257
			if (config.hideStatusBar) {
I
isidor 已提交
1258 1259
				this.setStatusBarHidden(true, true);
			}
1260

1261 1262
			if (config.hideTabs && this.editorPart.partOptions.showTabs) {
				this.zenMode.transitionDisposeables.push(this.editorPart.enforcePartOptions({ showTabs: false }));
I
isidor 已提交
1263
			}
1264 1265 1266 1267

			if (config.centerLayout) {
				this.centerEditorLayout(true, true);
			}
1268 1269 1270 1271
		}

		// Zen Mode Inactive
		else {
1272
			if (this.zenMode.wasPanelVisible) {
1273
				this.setPanelHidden(false, true);
1274
			}
1275

1276
			if (this.zenMode.wasSideBarVisible) {
1277
				this.setSideBarHidden(false, true);
1278
			}
1279

1280 1281 1282
			if (this.zenMode.transitionedToCenteredEditorLayout) {
				this.centerEditorLayout(false, true);
			}
1283

1284 1285
			// Status bar and activity bar visibility come from settings -> update their visibility.
			this.onDidUpdateConfiguration(true);
1286

B
Benjamin Pasero 已提交
1287
			this.editorGroupService.activeGroup.focus();
1288

1289
			toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
I
isidor 已提交
1290
		}
1291

1292
		this.inZenMode.set(this.zenMode.active);
I
isidor 已提交
1293

I
isidor 已提交
1294
		if (!skipLayout) {
1295
			this.layout();
I
isidor 已提交
1296
		}
1297

1298
		if (toggleFullScreen) {
1299
			this.windowService.toggleFullScreen();
1300
		}
I
isidor 已提交
1301 1302
	}

1303
	layout(options?: ILayoutOptions): void {
J
Joao Moreno 已提交
1304 1305
		this.contextViewService.layout();

1306 1307 1308 1309 1310
		if (this.workbenchStarted && !this.workbenchShutdown) {
			this.workbenchLayout.layout(options);
		}
	}

1311
	isEditorLayoutCentered(): boolean {
1312
		return this.shouldCenterLayout;
S
SrTobi 已提交
1313 1314
	}

1315
	centerEditorLayout(active: boolean, skipLayout?: boolean): void {
B
Benjamin Pasero 已提交
1316
		this.storageService.store(Workbench.centeredEditorLayoutActiveStorageKey, active, StorageScope.WORKSPACE);
1317 1318
		this.shouldCenterLayout = active;
		let smartActive = active;
1319
		if (this.editorPart.groups.length > 1 && this.configurationService.getValue('workbench.editor.centeredLayoutAutoResize')) {
B
Benjamin Pasero 已提交
1320
			smartActive = false; // Respect the auto resize setting - do not go into centered layout if there is more than 1 group.
1321
		}
B
Benjamin Pasero 已提交
1322

1323
		// Enter Centered Editor Layout
1324 1325
		if (this.editorPart.isLayoutCentered() !== smartActive) {
			this.editorPart.centerLayout(smartActive);
1326

1327 1328 1329
			if (!skipLayout) {
				this.layout();
			}
1330
		}
S
SrTobi 已提交
1331 1332
	}

1333
	resizePart(part: Parts, sizeChange: number): void {
1334 1335 1336 1337 1338 1339 1340
		switch (part) {
			case Parts.SIDEBAR_PART:
			case Parts.PANEL_PART:
			case Parts.EDITOR_PART:
				this.workbenchLayout.resizePart(part, sizeChange);
				break;
			default:
B
Benjamin Pasero 已提交
1341
				return; // Cannot resize other parts
1342 1343 1344
		}
	}

1345 1346
	setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.activityBarHidden = hidden;
1347

1348 1349 1350
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
1351
		}
1352
	}
1353

1354
	setSideBarHidden(hidden: boolean, skipLayout?: boolean): void {
1355 1356 1357 1358 1359
		this.sideBarHidden = hidden;
		this.sideBarVisibleContext.set(!hidden);

		// Adjust CSS
		if (hidden) {
B
Benjamin Pasero 已提交
1360
			DOM.addClass(this.workbench, 'nosidebar');
1361
		} else {
B
Benjamin Pasero 已提交
1362
			DOM.removeClass(this.workbench, 'nosidebar');
1363 1364
		}

1365 1366
		// If sidebar becomes hidden, also hide the current active Viewlet if any
		if (hidden && this.sidebarPart.getActiveViewlet()) {
1367 1368 1369 1370 1371 1372 1373 1374 1375
			this.sidebarPart.hideActiveViewlet();
			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();
			}
1376 1377 1378 1379 1380 1381
		}

		// If sidebar becomes visible, show last active Viewlet or default viewlet
		else if (!hidden && !this.sidebarPart.getActiveViewlet()) {
			const viewletToOpen = this.sidebarPart.getLastActiveViewletId();
			if (viewletToOpen) {
I
isidor 已提交
1382
				const viewlet = this.sidebarPart.openViewlet(viewletToOpen, true);
1383
				if (!viewlet) {
I
isidor 已提交
1384
					this.sidebarPart.openViewlet(this.sidebarPart.getDefaultViewletId(), true);
1385
				}
1386
			}
1387 1388
		}

1389

1390 1391 1392 1393 1394 1395 1396
		// 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);
		}
1397

1398 1399 1400 1401
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
		}
1402
	}
1403

1404
	setPanelHidden(hidden: boolean, skipLayout?: boolean): void {
1405 1406 1407 1408
		this.panelHidden = hidden;

		// Adjust CSS
		if (hidden) {
B
Benjamin Pasero 已提交
1409
			DOM.addClass(this.workbench, 'nopanel');
1410
		} else {
B
Benjamin Pasero 已提交
1411
			DOM.removeClass(this.workbench, 'nopanel');
1412 1413 1414 1415
		}

		// If panel part becomes hidden, also hide the current active panel if any
		if (hidden && this.panelPart.getActivePanel()) {
1416 1417
			this.panelPart.hideActivePanel();
			this.editorGroupService.activeGroup.focus(); // Pass focus to editor group if panel part is now hidden
1418 1419 1420 1421 1422 1423
		}

		// 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) {
1424
				this.panelPart.openPanel(panelToOpen, true);
1425 1426 1427 1428
			}
		}


1429 1430 1431 1432 1433 1434
		// Remember in settings
		if (!hidden) {
			this.storageService.store(Workbench.panelHiddenStorageKey, 'false', StorageScope.WORKSPACE);
		} else {
			this.storageService.remove(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE);
		}
1435

1436 1437 1438 1439
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
		}
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
	}

	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) {
1456
			this.setSideBarHidden(false, true /* Skip Layout */);
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476
		}

		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 已提交
1477
	setMenubarVisibility(visibility: MenuBarVisibility, skipLayout: boolean): void {
S
SteVen Batten 已提交
1478 1479
		if (this.menubarVisibility !== visibility) {
			this.menubarVisibility = visibility;
1480

S
SteVen Batten 已提交
1481 1482 1483
			if (!skipLayout) {
				this.workbenchLayout.layout();
			}
1484 1485 1486
		}
	}

S
SteVen Batten 已提交
1487 1488 1489 1490
	getMenubarVisibility(): MenuBarVisibility {
		return this.menubarVisibility;
	}

1491 1492 1493 1494
	getPanelPosition(): Position {
		return this.panelPosition;
	}

1495 1496 1497 1498
	setPanelPosition(position: Position): void {
		if (this.panelHidden) {
			this.setPanelHidden(false, true /* Skip Layout */);
		}
1499

1500 1501 1502 1503
		const newPositionValue = (position === Position.BOTTOM) ? 'bottom' : 'right';
		const oldPositionValue = (this.panelPosition === Position.BOTTOM) ? 'bottom' : 'right';
		this.panelPosition = position;
		this.storageService.store(Workbench.panelPositionStorageKey, PositionToString(this.panelPosition).toLowerCase(), StorageScope.WORKSPACE);
1504

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

1509 1510 1511 1512 1513
		// Update Styles
		this.panelPart.updateStyles();

		// Layout
		this.workbenchLayout.layout();
1514
	}
1515 1516

	//#endregion
I
isidor 已提交
1517
}