workbench.ts 60.0 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';
P
Pine Wu 已提交
53
import { ViewletService } from 'vs/workbench/services/viewlet/browser/viewletService';
54
import { RemoteFileService } from 'vs/workbench/services/files/electron-browser/remoteFileService';
J
Johannes Rieken 已提交
55 56
import { IFileService } from 'vs/platform/files/common/files';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
57
import { ConfigurationResolverService } from 'vs/workbench/services/configurationResolver/electron-browser/configurationResolverService';
J
Johannes Rieken 已提交
58
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
B
Benjamin Pasero 已提交
59
import { ITitleService } from 'vs/workbench/services/title/common/titleService';
J
Johannes Rieken 已提交
60
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
61 62
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { ClipboardService } from 'vs/platform/clipboard/electron-browser/clipboardService';
J
Johannes Rieken 已提交
63 64 65 66 67
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 已提交
68 69
import { ISCMService } from 'vs/workbench/services/scm/common/scm';
import { SCMService } from 'vs/workbench/services/scm/common/scmService';
70
import { IProgressService2 } from 'vs/platform/progress/common/progress';
71
import { ProgressService2 } from 'vs/workbench/services/progress/browser/progressService2';
72
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
73
import { ITextModelService } from 'vs/editor/common/services/resolverService';
J
Johannes Rieken 已提交
74
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
75
import { LifecyclePhase, StartupKind } from 'vs/platform/lifecycle/common/lifecycle';
76
import { LifecycleService } from 'vs/platform/lifecycle/electron-browser/lifecycleService';
B
Benjamin Pasero 已提交
77
import { IWindowService, IWindowConfiguration, IPath, MenuBarVisibility, getTitleBarStyle } from 'vs/platform/windows/common/windows';
J
Johannes Rieken 已提交
78
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
79
import { IMenuService, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
80
import { MenuService } from 'vs/platform/actions/common/menuService';
S
SteVen Batten 已提交
81
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
J
Johannes Rieken 已提交
82
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
B
Benjamin Pasero 已提交
83
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
84
import { OpenRecentAction, ToggleDevToolsAction, ReloadWindowAction, ShowPreviousWindowTab, MoveWindowTabToNewWindow, MergeAllWindowTabs, ShowNextWindowTab, ToggleWindowTabsBar, ReloadWindowWithExtensionsDisabledAction, NewWindowTab } from 'vs/workbench/electron-browser/actions';
85
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
86
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
B
Benjamin Pasero 已提交
87
import { WorkspaceEditingService } from 'vs/workbench/services/workspace/node/workspaceEditingService';
88
import { FileDecorationsService } from 'vs/workbench/services/decorations/browser/decorationsService';
J
Johannes Rieken 已提交
89
import { IDecorationsService } from 'vs/workbench/services/decorations/browser/decorations';
I
isidor 已提交
90
import { ActivityService } from 'vs/workbench/services/activity/browser/activityService';
91
import { URI } from 'vs/base/common/uri';
J
Joao Moreno 已提交
92
import { IListService, ListService } from 'vs/platform/list/browser/listService';
M
Martin Aeschlimann 已提交
93
import { InputFocusedContext, IsMacContext, IsLinuxContext, IsWindowsContext } from 'vs/platform/workbench/common/contextkeys';
94
import { IViewsService } from 'vs/workbench/common/views';
S
Sandeep Somavarapu 已提交
95
import { ViewsService } from 'vs/workbench/browser/parts/views/views';
96 97
import { INotificationService } from 'vs/platform/notification/common/notification';
import { NotificationService } from 'vs/workbench/services/notification/common/notificationService';
98 99
import { NotificationsCenter } from 'vs/workbench/browser/parts/notifications/notificationsCenter';
import { NotificationsAlerts } from 'vs/workbench/browser/parts/notifications/notificationsAlerts';
100
import { NotificationsStatus } from 'vs/workbench/browser/parts/notifications/notificationsStatus';
101
import { registerNotificationCommands } from 'vs/workbench/browser/parts/notifications/notificationsCommands';
102
import { NotificationsToasts } from 'vs/workbench/browser/parts/notifications/notificationsToasts';
J
Joao Moreno 已提交
103
import { IPCClient } from 'vs/base/parts/ipc/node/ipc';
J
Joao Moreno 已提交
104
import { registerWindowDriver } from 'vs/platform/driver/electron-browser/driver';
S
Sandeep Somavarapu 已提交
105 106
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { PreferencesService } from 'vs/workbench/services/preferences/browser/preferencesService';
107
import { IEditorService, IResourceEditor } from 'vs/workbench/services/editor/common/editorService';
I
isidor 已提交
108
import { IEditorGroupsService, GroupDirection, preferredSideBySideGroupDirection } from 'vs/workbench/services/group/common/editorGroupsService';
109
import { EditorService } from 'vs/workbench/services/editor/browser/editorService';
J
Joao Moreno 已提交
110
import { IExtensionUrlHandler, ExtensionUrlHandler } from 'vs/workbench/services/extensions/electron-browser/inactiveExtensionUrlHandler';
S
SteVen Batten 已提交
111
import { ContextViewService } from 'vs/platform/contextview/browser/contextViewService';
A
Alex Dima 已提交
112 113
import { WorkbenchThemeService } from 'vs/workbench/services/themes/electron-browser/workbenchThemeService';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
M
Martin Aeschlimann 已提交
114 115
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { FileDialogService } from 'vs/workbench/services/dialogs/electron-browser/dialogService';
116
import { LogStorageAction } from 'vs/platform/storage/node/storageService';
117

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

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

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

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

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

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

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

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

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

172
	private static readonly sidebarHiddenStorageKey = 'workbench.sidebar.hidden';
173
	private static readonly menubarVisibilityConfigurationKey = 'window.menuBarVisibility';
174 175
	private static readonly panelHiddenStorageKey = 'workbench.panel.hidden';
	private static readonly zenModeActiveStorageKey = 'workbench.zenmode.active';
176
	private static readonly centeredEditorLayoutActiveStorageKey = 'workbench.centerededitorlayout.active';
177
	private static readonly panelPositionStorageKey = 'workbench.panel.location';
178
	private static readonly defaultPanelPositionStorageKey = 'workbench.panel.defaultLocation';
179 180 181 182 183
	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';
184

185
	_serviceBrand: any;
186

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

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

	private workbenchLayout: WorkbenchLayout;

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

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

I
isidor 已提交
228
	private inZenMode: IContextKey<boolean>;
229
	private sideBarVisibleContext: IContextKey<boolean>;
230

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

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

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

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

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

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

264 265
		// Install some global actions
		this.createGlobalActions();
266

267 268
		// Services
		this.initServices();
E
Erich Gamma 已提交
269

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

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

276 277
		// Settings
		this.initSettings();
E
Erich Gamma 已提交
278

279 280
		// Create Workbench and Parts
		this.renderWorkbench();
281

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

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

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

B
Benjamin Pasero 已提交
294
	private createWorkbench(): void {
B
Benjamin Pasero 已提交
295 296 297
		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 已提交
298

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

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

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

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

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

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

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

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

340 341 342
		// Progress 2
		serviceCollection.set(IProgressService2, new SyncDescriptor(ProgressService2));

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

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

350 351 352
		// List
		serviceCollection.set(IListService, this.instantiationService.createInstance(ListService));

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

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

364 365
		// Menus/Actions
		serviceCollection.set(IMenuService, new SyncDescriptor(MenuService));
366

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

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

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

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

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

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

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

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

405
		// History
406
		serviceCollection.set(IHistoryService, new SyncDescriptor(HistoryService));
407

M
Martin Aeschlimann 已提交
408 409 410
		// File Dialogs
		serviceCollection.set(IFileDialogService, new SyncDescriptor(FileDialogService));

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

419
		// Text File Service
420
		serviceCollection.set(ITextFileService, new SyncDescriptor(TextFileService));
421

422
		// File Decorations
J
Johannes Rieken 已提交
423
		serviceCollection.set(IDecorationsService, new SyncDescriptor(FileDecorationsService));
424

J
Joao Moreno 已提交
425
		// SCM Service
426
		serviceCollection.set(ISCMService, new SyncDescriptor(SCMService));
427

J
Joao Moreno 已提交
428
		// Inactive extension URL handler
J
Joao Moreno 已提交
429
		serviceCollection.set(IExtensionUrlHandler, new SyncDescriptor(ExtensionUrlHandler));
J
Joao Moreno 已提交
430

B
Benjamin Pasero 已提交
431
		// Text Model Resolver Service
432
		serviceCollection.set(ITextModelService, new SyncDescriptor(TextModelResolverService));
B
Benjamin Pasero 已提交
433

434 435 436 437
		// JSON Editing
		const jsonEditingService = this.instantiationService.createInstance(JSONEditingService);
		serviceCollection.set(IJSONEditingService, jsonEditingService);

438 439 440
		// Workspace Editing
		serviceCollection.set(IWorkspaceEditingService, new SyncDescriptor(WorkspaceEditingService));

441 442 443
		// Keybinding Editing
		serviceCollection.set(IKeybindingEditingService, this.instantiationService.createInstance(KeybindingsEditingService));

444
		// Configuration Resolver
445
		serviceCollection.set(IConfigurationResolverService, new SyncDescriptor(ConfigurationResolverService, [process.env]));
446

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

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

S
Sandeep Somavarapu 已提交
455 456 457
		// PreferencesService
		serviceCollection.set(IPreferencesService, this.instantiationService.createInstance(PreferencesService));

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

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

469
		this.instantiationService.createInstance(DefaultConfigurationExportHelper);
470

S
#47154  
Sandeep Somavarapu 已提交
471
		this.configurationService.acquireInstantiationService(this.getInstantiationService());
E
Erich Gamma 已提交
472 473
	}

474
	//#region event handling
E
Erich Gamma 已提交
475

476
	private registerListeners(): void {
I
isidor 已提交
477

478
		// Storage
479
		this._register(this.storageService.onWillSaveState(e => this.saveState(e)));
480

481
		// Listen to visible editor changes
482
		this._register(this.editorService.onDidVisibleEditorsChange(() => this.onDidVisibleEditorsChange()));
B
Benjamin Pasero 已提交
483

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

491
			this._register(listenerDispose);
492
		}
S
Sanders Lauture 已提交
493

494
		// Configuration changes
495
		this._register(this.configurationService.onDidChangeConfiguration(() => this.onDidUpdateConfiguration()));
I
isidor 已提交
496

497
		// Fullscreen changes
498
		this._register(browser.onDidChangeFullscreen(() => this.onFullscreenChanged()));
B
Benjamin Pasero 已提交
499 500 501 502

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

505
	private onFullscreenChanged(): void {
S
SrTobi 已提交
506

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

514 515 516 517
			if (this.zenMode.transitionedToFullScreen && this.zenMode.active) {
				this.toggleZenMode();
			}
		}
E
Erich Gamma 已提交
518

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

526 527 528 529
	private onMenubarToggled(visible: boolean) {
		if (visible !== this.menubarToggled) {
			this.menubarToggled = visible;

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

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

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

548
	private onDidVisibleEditorsChange(): void {
549
		const visibleEditors = this.editorService.visibleControls;
E
Erich Gamma 已提交
550

551 552 553 554 555 556 557 558 559
		// 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();
			}
		}
560 561
	}

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

569 570 571 572 573
	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);
574
		}
E
Erich Gamma 已提交
575

576
		this.setPanelPositionFromStorageOrConfig();
E
Erich Gamma 已提交
577

578 579 580
		const fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
		if (fontAliasing !== this.fontAliasing) {
			this.setFontAliasing(fontAliasing);
581 582
		}

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

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

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

599
	//#endregion
B
Benjamin Pasero 已提交
600

601 602
	private handleContextKeys(): void {
		this.inZenMode = InEditorZenModeContext.bindTo(this.contextKeyService);
603

I
isidor 已提交
604 605 606
		IsMacContext.bindTo(this.contextKeyService);
		IsLinuxContext.bindTo(this.contextKeyService);
		IsWindowsContext.bindTo(this.contextKeyService);
607

608 609
		const sidebarVisibleContextRaw = new RawContextKey<boolean>('sidebarVisible', false);
		this.sideBarVisibleContext = sidebarVisibleContextRaw.bindTo(this.contextKeyService);
610

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

618
		const updateEditorContextKeys = () => {
619
			const activeControl = this.editorService.activeControl;
620
			const visibleEditors = this.editorService.visibleControls;
E
Erich Gamma 已提交
621

622
			textCompareEditorActive.set(activeControl && activeControl.getId() === TEXT_DIFF_EDITOR_ID);
623
			textCompareEditorVisible.set(visibleEditors.some(control => control.getId() === TEXT_DIFF_EDITOR_ID));
I
isidor 已提交
624

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

631
			if (!this.editorService.activeEditor) {
632 633 634
				activeEditorGroupEmpty.set(true);
			} else {
				activeEditorGroupEmpty.reset();
635
			}
636

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

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

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

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

		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 已提交
668
				Event.once(tracker.onDidBlur)(() => {
B
Benjamin Pasero 已提交
669 670 671 672 673 674 675 676
					inputFocused.set(activeElementIsInput());

					tracker.dispose();
				});
			}
		}

		this._register(DOM.addDisposableListener(window, 'focusin', () => trackInputFocus(), true));
677 678 679 680 681 682

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

684 685 686 687 688
		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);
		}));
689

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

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

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

703
		updateSplitEditorsVerticallyContext();
704
	}
E
Erich Gamma 已提交
705

B
Benjamin Pasero 已提交
706
	private restoreParts(): Thenable<IWorkbenchStartedInfo> {
707
		const restorePromises: Thenable<any>[] = [];
B
Benjamin Pasero 已提交
708

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

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

B
Benjamin Pasero 已提交
718 719 720 721 722 723 724 725 726 727 728
				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 已提交
729

730 731 732 733
		// Restore Sidebar
		let viewletIdToRestore: string;
		if (!this.sideBarHidden) {
			this.sideBarVisibleContext.set(true);
734

735
			if (this.shouldRestoreLastOpenedViewlet()) {
736
				viewletIdToRestore = this.storageService.get(SidebarPart.activeViewletSettingsKey, StorageScope.WORKSPACE);
737
			}
738

739 740
			if (!viewletIdToRestore) {
				viewletIdToRestore = this.viewletService.getDefaultViewletId();
741
			}
E
Erich Gamma 已提交
742

743
			perf.mark('willRestoreViewlet');
744 745
			restorePromises.push(this.viewletService.openViewlet(viewletIdToRestore)
				.then(viewlet => viewlet || this.viewletService.openViewlet(this.viewletService.getDefaultViewletId()))
B
Benjamin Pasero 已提交
746
				.then(() => perf.mark('didRestoreViewlet')));
747 748
		}

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

760 761 762
		// 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);
763
		if (wasZenActive && zenConfig.restore) {
I
isidor 已提交
764
			this.toggleZenMode(true, true);
I
isidor 已提交
765 766
		}

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

772
		const onRestored = (error?: Error): IWorkbenchStartedInfo => {
B
Benjamin Pasero 已提交
773 774 775 776 777 778 779 780 781 782 783 784
			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);
785

786 787
			if (error) {
				errors.onUnexpectedError(error);
788
			}
I
isidor 已提交
789

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

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

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

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

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

B
Benjamin Pasero 已提交
813
		// Files to open, diff or create
814
		if (this.hasInitialFilesToOpen) {
I
isidor 已提交
815

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

827 828
			const filesToCreate = this.toInputs(config.filesToCreate, true);
			const filesToOpen = this.toInputs(config.filesToOpen, false);
I
isidor 已提交
829

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

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

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

B
Benjamin Pasero 已提交
846
				return [<IUntitledResourceInput>{}];
847
			});
848
		}
849

B
Benjamin Pasero 已提交
850
		return [];
B
Benjamin Pasero 已提交
851
	}
852

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

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

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

B
Benjamin Pasero 已提交
874 875
			return input;
		});
876 877
	}

878
	private openUntitledFile() {
879
		const startupEditor = this.configurationService.inspect('workbench.startupEditor');
B
Benjamin Pasero 已提交
880 881

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

889
		return startupEditor.value === 'newUntitledFile';
890
	}
E
Erich Gamma 已提交
891 892

	private initSettings(): void {
893

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

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

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

I
isidor 已提交
908
		// Panel position
909
		this.setPanelPositionFromStorageOrConfig();
910

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

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

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

923
		// Font aliasing
924
		this.fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
925

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

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

941 942
		this.panelPosition = (panelPosition === 'right') ? Position.RIGHT : Position.BOTTOM;
	}
943

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

948 949
	private setStatusBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.statusBarHidden = hidden;
B
Benjamin Pasero 已提交
950

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

958 959 960
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
961 962 963
		}
	}

964
	private setFontAliasing(aliasing: FontAliasingOption) {
965
		this.fontAliasing = aliasing;
S
Sanders Lauture 已提交
966

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

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

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

	private renderWorkbench(): void {

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

1003
		if (this.panelHidden) {
B
Benjamin Pasero 已提交
1004
			DOM.addClass(this.workbench, 'nopanel');
1005
		}
B
Benjamin Pasero 已提交
1006

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

B
Benjamin Pasero 已提交
1011
		// Apply font aliasing
1012 1013
		this.setFontAliasing(this.fontAliasing);

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

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

1027 1028
		// Notification Handlers
		this.createNotificationsHandlers();
1029

1030 1031

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

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

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

B
Benjamin Pasero 已提交
1043
		this.titlebarPart.create(titlebarContainer);
B
Benjamin Pasero 已提交
1044 1045
	}

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

B
Benjamin Pasero 已提交
1049
		this.activitybarPart.create(activitybarPartContainer);
E
Erich Gamma 已提交
1050 1051 1052
	}

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

B
Benjamin Pasero 已提交
1055
		this.sidebarPart.create(sidebarPartContainer);
E
Erich Gamma 已提交
1056 1057
	}

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

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

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

B
Benjamin Pasero 已提交
1067
		this.editorPart.create(editorContainer);
E
Erich Gamma 已提交
1068 1069 1070
	}

	private createStatusbarPart(): void {
B
Benjamin Pasero 已提交
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
		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 已提交
1082 1083 1084
		// 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 已提交
1085

B
Benjamin Pasero 已提交
1086
		return part;
E
Erich Gamma 已提交
1087 1088
	}

1089 1090
	private createNotificationsHandlers(): void {

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

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

1097
		// Notifications Alerts
1098
		this._register(this.instantiationService.createInstance(NotificationsAlerts, this.notificationService.model));
1099 1100 1101 1102

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

1103
		// Eventing
1104
		this._register(this.notificationsCenter.onDidChangeVisibility(() => {
1105 1106 1107 1108 1109 1110 1111 1112

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

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

1113
		// Register Commands
1114
		registerNotificationCommands(this.notificationsCenter, this.notificationsToasts);
1115 1116
	}

1117
	getInstantiationService(): IInstantiationService {
E
Erich Gamma 已提交
1118 1119 1120
		return this.instantiationService;
	}

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

		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);
			}
		}
1135 1136
	}

1137
	dispose(): void {
1138
		super.dispose();
1139 1140 1141 1142 1143 1144

		this.workbenchShutdown = true;
	}

	//#region IPartService

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

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

B
Benjamin Pasero 已提交
1150 1151
	isRestored(): boolean {
		return !!(this.workbenchRestored && this.workbenchStarted);
1152
	}
1153

1154 1155 1156 1157 1158
	hasFocus(part: Parts): boolean {
		const activeElement = document.activeElement;
		if (!activeElement) {
			return false;
		}
1159

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

1164
	getContainer(part: Parts): HTMLElement {
1165
		let container: HTMLElement | null = null;
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185
		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;
		}
1186

1187 1188
		return container;
	}
1189

1190 1191 1192
	isVisible(part: Parts): boolean {
		switch (part) {
			case Parts.TITLEBAR_PART:
B
Benjamin Pasero 已提交
1193
				if (!this.useCustomTitleBarStyle()) {
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
					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;
1206 1207 1208 1209 1210 1211 1212 1213
			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 已提交
1214
		}
1215

1216
		return true; // any other part cannot be hidden
E
Erich Gamma 已提交
1217 1218
	}

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

		return offset;
E
Erich Gamma 已提交
1229
	}
1230

1231 1232
	getWorkbenchElement(): HTMLElement {
		return this.workbench;
1233
	}
1234

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

1239 1240
		// 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)
1241
		let toggleFullScreen = false;
1242 1243

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

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

1253 1254
			this.setPanelHidden(true, true);
			this.setSideBarHidden(true, true);
I
isidor 已提交
1255

1256 1257 1258
			if (config.hideActivityBar) {
				this.setActivityBarHidden(true, true);
			}
1259

I
isidor 已提交
1260
			if (config.hideStatusBar) {
I
isidor 已提交
1261 1262
				this.setStatusBarHidden(true, true);
			}
1263

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

			if (config.centerLayout) {
				this.centerEditorLayout(true, true);
			}
1271 1272 1273 1274
		}

		// Zen Mode Inactive
		else {
1275
			if (this.zenMode.wasPanelVisible) {
1276
				this.setPanelHidden(false, true);
1277
			}
1278

1279
			if (this.zenMode.wasSideBarVisible) {
1280
				this.setSideBarHidden(false, true);
1281
			}
1282

1283 1284 1285
			if (this.zenMode.transitionedToCenteredEditorLayout) {
				this.centerEditorLayout(false, true);
			}
1286

1287 1288
			// Status bar and activity bar visibility come from settings -> update their visibility.
			this.onDidUpdateConfiguration(true);
1289

B
Benjamin Pasero 已提交
1290
			this.editorGroupService.activeGroup.focus();
1291

1292
			toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
I
isidor 已提交
1293
		}
1294

1295
		this.inZenMode.set(this.zenMode.active);
I
isidor 已提交
1296

I
isidor 已提交
1297
		if (!skipLayout) {
1298
			this.layout();
I
isidor 已提交
1299
		}
1300

1301
		if (toggleFullScreen) {
1302
			this.windowService.toggleFullScreen();
1303
		}
I
isidor 已提交
1304 1305
	}

1306
	layout(options?: ILayoutOptions): void {
J
Joao Moreno 已提交
1307 1308
		this.contextViewService.layout();

1309 1310 1311 1312 1313
		if (this.workbenchStarted && !this.workbenchShutdown) {
			this.workbenchLayout.layout(options);
		}
	}

1314
	isEditorLayoutCentered(): boolean {
1315
		return this.shouldCenterLayout;
S
SrTobi 已提交
1316 1317
	}

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

1326
		// Enter Centered Editor Layout
1327 1328
		if (this.editorPart.isLayoutCentered() !== smartActive) {
			this.editorPart.centerLayout(smartActive);
1329

1330 1331 1332
			if (!skipLayout) {
				this.layout();
			}
1333
		}
S
SrTobi 已提交
1334 1335
	}

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

1348 1349
	setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.activityBarHidden = hidden;
1350

1351 1352 1353
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
1354
		}
1355
	}
1356

1357
	setSideBarHidden(hidden: boolean, skipLayout?: boolean): void {
1358 1359 1360 1361 1362
		this.sideBarHidden = hidden;
		this.sideBarVisibleContext.set(!hidden);

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

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

		// If sidebar becomes visible, show last active Viewlet or default viewlet
		else if (!hidden && !this.sidebarPart.getActiveViewlet()) {
			const viewletToOpen = this.sidebarPart.getLastActiveViewletId();
			if (viewletToOpen) {
1385 1386 1387 1388
				const viewlet = this.viewletService.openViewlet(viewletToOpen, true);
				if (!viewlet) {
					this.viewletService.openViewlet(this.viewletService.getDefaultViewletId(), true);
				}
1389
			}
1390 1391
		}

1392

1393 1394 1395 1396 1397 1398 1399
		// 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);
		}
1400

1401 1402 1403 1404
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
		}
1405
	}
1406

1407
	setPanelHidden(hidden: boolean, skipLayout?: boolean): void {
1408 1409 1410 1411
		this.panelHidden = hidden;

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

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

		// 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) {
1427
				this.panelPart.openPanel(panelToOpen, true);
1428 1429 1430 1431
			}
		}


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

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

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

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

S
SteVen Batten 已提交
1484 1485 1486
			if (!skipLayout) {
				this.workbenchLayout.layout();
			}
1487 1488 1489
		}
	}

S
SteVen Batten 已提交
1490 1491 1492 1493
	getMenubarVisibility(): MenuBarVisibility {
		return this.menubarVisibility;
	}

1494 1495 1496 1497
	getPanelPosition(): Position {
		return this.panelPosition;
	}

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

1503 1504 1505 1506
		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);
1507

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

1512 1513 1514 1515 1516
		// Update Styles
		this.panelPart.updateStyles();

		// Layout
		this.workbenchLayout.layout();
1517
	}
1518 1519

	//#endregion
I
isidor 已提交
1520
}