workbench.ts 60.4 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';
I
isidor 已提交
116
import { IEditor } from 'vs/editor/common/editorCommon';
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
	hideLineNumbers: boolean;
I
isidor 已提交
130
	restore: boolean;
I
isidor 已提交
131 132
}

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

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

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

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

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

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

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

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

186
	_serviceBrand: any;
187

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

194 195
	private editorService: EditorService;
	private editorGroupService: IEditorGroupsService;
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 240 241 242 243 244 245 246
		@IInstantiationService private readonly instantiationService: IInstantiationService,
		@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
		@IStorageService private readonly storageService: IStorageService,
		@IConfigurationService private readonly configurationService: WorkspaceService,
		@IWorkbenchThemeService private readonly themeService: WorkbenchThemeService,
		@IEnvironmentService private readonly environmentService: IEnvironmentService,
		@IWindowService private readonly windowService: IWindowService,
		@INotificationService private readonly 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
	}

J
Johannes Rieken 已提交
258
	startup(): Promise<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
		this.workbench = document.createElement('div');
		this.workbench.id = Identifiers.WORKBENCH_CONTAINER;
297
		DOM.addClass(this.workbench, 'monaco-workbench');
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
		const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
R
Rob Lourens 已提交
309 310
		registry.registerWorkbenchAction(new SyncActionDescriptor(ReloadWindowAction, ReloadWindowAction.ID, ReloadWindowAction.LABEL, isDeveloping ? { primary: KeyMod.CtrlCmd | KeyCode.KEY_R } : undefined), '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 } } : undefined), 'Developer: Toggle Developer Tools', localize('developer', "Developer"));
311 312
		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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

468
		this.instantiationService.createInstance(DefaultConfigurationExportHelper);
469

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

					tracker.dispose();
				});
			}
		}

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

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

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

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

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

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

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

J
Johannes Rieken 已提交
705 706
	private restoreParts(): Promise<IWorkbenchStartedInfo> {
		const restorePromises: Promise<any>[] = [];
B
Benjamin Pasero 已提交
707

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

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

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

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

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

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

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

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

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

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

771
		const onRestored = (error?: Error): IWorkbenchStartedInfo => {
B
Benjamin Pasero 已提交
772 773 774 775 776 777 778
			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(() => {
R
Rob Lourens 已提交
779
				eventuallPhaseTimeoutHandle = undefined;
B
Benjamin Pasero 已提交
780 781 782 783
				this.lifecycleService.phase = LifecyclePhase.Eventually;
			}, 5000);

			this._register(eventuallPhaseTimeoutHandle);
784

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

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

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

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

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

J
Johannes Rieken 已提交
809
	private resolveEditorsToOpen(): Promise<IResourceEditor[]> | IResourceEditor[] {
810
		const config = this.workbenchParams.configuration;
I
isidor 已提交
811

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	private initSettings(): void {
892

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	private renderWorkbench(): void {

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

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

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

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

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

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

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

1029 1030

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1088 1089
	private createNotificationsHandlers(): void {

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

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

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

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

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

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

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

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

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

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

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

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

		this.workbenchShutdown = true;
	}

	//#region IPartService

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

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

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

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

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

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

1186 1187
		return container;
	}
1188

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

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

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

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

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

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

1238 1239
		// 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)
1240
		let toggleFullScreen = false;
I
isidor 已提交
1241 1242 1243 1244 1245 1246 1247 1248
		const setLineNumbers = (lineNumbers: any) => {
			this.editorService.visibleControls.forEach(editor => {
				const control = <IEditor>editor.getControl();
				if (control) {
					control.updateOptions({ lineNumbers });
				}
			});
		};
1249 1250

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

I
isidor 已提交
1254
			toggleFullScreen = !browser.isFullscreen() && config.fullScreen;
I
isidor 已提交
1255
			this.zenMode.transitionedToFullScreen = restoring ? config.fullScreen : toggleFullScreen;
1256
			this.zenMode.transitionedToCenteredEditorLayout = !this.isEditorLayoutCentered() && config.centerLayout;
1257 1258
			this.zenMode.wasSideBarVisible = this.isVisible(Parts.SIDEBAR_PART);
			this.zenMode.wasPanelVisible = this.isVisible(Parts.PANEL_PART);
1259

1260 1261
			this.setPanelHidden(true, true);
			this.setSideBarHidden(true, true);
I
isidor 已提交
1262

1263 1264 1265
			if (config.hideActivityBar) {
				this.setActivityBarHidden(true, true);
			}
1266

I
isidor 已提交
1267
			if (config.hideStatusBar) {
I
isidor 已提交
1268 1269
				this.setStatusBarHidden(true, true);
			}
1270

I
isidor 已提交
1271 1272 1273 1274 1275
			if (config.hideLineNumbers) {
				setLineNumbers('off');
				this.zenMode.transitionDisposeables.push(this.editorService.onDidVisibleEditorsChange(() => setLineNumbers('off')));
			}

1276 1277
			if (config.hideTabs && this.editorPart.partOptions.showTabs) {
				this.zenMode.transitionDisposeables.push(this.editorPart.enforcePartOptions({ showTabs: false }));
I
isidor 已提交
1278
			}
1279 1280 1281 1282

			if (config.centerLayout) {
				this.centerEditorLayout(true, true);
			}
1283 1284 1285 1286
		}

		// Zen Mode Inactive
		else {
1287
			if (this.zenMode.wasPanelVisible) {
1288
				this.setPanelHidden(false, true);
1289
			}
1290

1291
			if (this.zenMode.wasSideBarVisible) {
1292
				this.setSideBarHidden(false, true);
1293
			}
1294

1295 1296 1297
			if (this.zenMode.transitionedToCenteredEditorLayout) {
				this.centerEditorLayout(false, true);
			}
I
isidor 已提交
1298
			setLineNumbers(this.configurationService.getValue('editor.lineNumbers'));
1299

1300 1301
			// Status bar and activity bar visibility come from settings -> update their visibility.
			this.onDidUpdateConfiguration(true);
1302

B
Benjamin Pasero 已提交
1303
			this.editorGroupService.activeGroup.focus();
1304

1305
			toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
I
isidor 已提交
1306
		}
1307

1308
		this.inZenMode.set(this.zenMode.active);
I
isidor 已提交
1309

I
isidor 已提交
1310
		if (!skipLayout) {
1311
			this.layout();
I
isidor 已提交
1312
		}
1313

1314
		if (toggleFullScreen) {
1315
			this.windowService.toggleFullScreen();
1316
		}
I
isidor 已提交
1317 1318
	}

1319
	layout(options?: ILayoutOptions): void {
J
Joao Moreno 已提交
1320 1321
		this.contextViewService.layout();

1322 1323 1324 1325 1326
		if (this.workbenchStarted && !this.workbenchShutdown) {
			this.workbenchLayout.layout(options);
		}
	}

1327
	isEditorLayoutCentered(): boolean {
1328
		return this.shouldCenterLayout;
S
SrTobi 已提交
1329 1330
	}

1331
	centerEditorLayout(active: boolean, skipLayout?: boolean): void {
B
Benjamin Pasero 已提交
1332
		this.storageService.store(Workbench.centeredEditorLayoutActiveStorageKey, active, StorageScope.WORKSPACE);
1333 1334
		this.shouldCenterLayout = active;
		let smartActive = active;
1335
		if (this.editorPart.groups.length > 1 && this.configurationService.getValue('workbench.editor.centeredLayoutAutoResize')) {
B
Benjamin Pasero 已提交
1336
			smartActive = false; // Respect the auto resize setting - do not go into centered layout if there is more than 1 group.
1337
		}
B
Benjamin Pasero 已提交
1338

1339
		// Enter Centered Editor Layout
1340 1341
		if (this.editorPart.isLayoutCentered() !== smartActive) {
			this.editorPart.centerLayout(smartActive);
1342

1343 1344 1345
			if (!skipLayout) {
				this.layout();
			}
1346
		}
S
SrTobi 已提交
1347 1348
	}

1349
	resizePart(part: Parts, sizeChange: number): void {
1350 1351 1352 1353 1354 1355 1356
		switch (part) {
			case Parts.SIDEBAR_PART:
			case Parts.PANEL_PART:
			case Parts.EDITOR_PART:
				this.workbenchLayout.resizePart(part, sizeChange);
				break;
			default:
B
Benjamin Pasero 已提交
1357
				return; // Cannot resize other parts
1358 1359 1360
		}
	}

1361 1362
	setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.activityBarHidden = hidden;
1363

1364 1365 1366
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
1367
		}
1368
	}
1369

1370
	setSideBarHidden(hidden: boolean, skipLayout?: boolean): void {
1371 1372 1373 1374 1375
		this.sideBarHidden = hidden;
		this.sideBarVisibleContext.set(!hidden);

		// Adjust CSS
		if (hidden) {
B
Benjamin Pasero 已提交
1376
			DOM.addClass(this.workbench, 'nosidebar');
1377
		} else {
B
Benjamin Pasero 已提交
1378
			DOM.removeClass(this.workbench, 'nosidebar');
1379 1380
		}

1381 1382
		// If sidebar becomes hidden, also hide the current active Viewlet if any
		if (hidden && this.sidebarPart.getActiveViewlet()) {
1383 1384 1385 1386 1387 1388 1389 1390 1391
			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();
			}
1392 1393 1394 1395 1396 1397
		}

		// 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 已提交
1398
				const viewlet = this.sidebarPart.openViewlet(viewletToOpen, true);
1399
				if (!viewlet) {
I
isidor 已提交
1400
					this.sidebarPart.openViewlet(this.sidebarPart.getDefaultViewletId(), true);
1401
				}
1402
			}
1403 1404
		}

1405

1406 1407 1408 1409 1410 1411 1412
		// 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);
		}
1413

1414 1415 1416 1417
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
		}
1418
	}
1419

1420
	setPanelHidden(hidden: boolean, skipLayout?: boolean): void {
1421 1422 1423 1424
		this.panelHidden = hidden;

		// Adjust CSS
		if (hidden) {
B
Benjamin Pasero 已提交
1425
			DOM.addClass(this.workbench, 'nopanel');
1426
		} else {
B
Benjamin Pasero 已提交
1427
			DOM.removeClass(this.workbench, 'nopanel');
1428 1429 1430 1431
		}

		// If panel part becomes hidden, also hide the current active panel if any
		if (hidden && this.panelPart.getActivePanel()) {
1432 1433
			this.panelPart.hideActivePanel();
			this.editorGroupService.activeGroup.focus(); // Pass focus to editor group if panel part is now hidden
1434 1435 1436 1437 1438 1439
		}

		// 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) {
1440
				this.panelPart.openPanel(panelToOpen, true);
1441 1442 1443 1444
			}
		}


1445 1446 1447 1448 1449 1450
		// Remember in settings
		if (!hidden) {
			this.storageService.store(Workbench.panelHiddenStorageKey, 'false', StorageScope.WORKSPACE);
		} else {
			this.storageService.remove(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE);
		}
1451

1452 1453 1454 1455
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
		}
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471
	}

	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) {
1472
			this.setSideBarHidden(false, true /* Skip Layout */);
1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492
		}

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

S
SteVen Batten 已提交
1497 1498 1499
			if (!skipLayout) {
				this.workbenchLayout.layout();
			}
1500 1501 1502
		}
	}

S
SteVen Batten 已提交
1503 1504 1505 1506
	getMenubarVisibility(): MenuBarVisibility {
		return this.menubarVisibility;
	}

1507 1508 1509 1510
	getPanelPosition(): Position {
		return this.panelPosition;
	}

1511 1512 1513 1514
	setPanelPosition(position: Position): void {
		if (this.panelHidden) {
			this.setPanelHidden(false, true /* Skip Layout */);
		}
1515

1516 1517 1518 1519
		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);
1520

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

1525 1526 1527 1528 1529
		// Update Styles
		this.panelPart.updateStyles();

		// Layout
		this.workbenchLayout.layout();
1530
	}
1531 1532

	//#endregion
I
isidor 已提交
1533
}