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

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

I
isidor 已提交
124 125
interface IZenModeSettings {
	fullScreen: boolean;
126
	centerLayout: boolean;
I
isidor 已提交
127
	hideTabs: boolean;
128
	hideActivityBar: boolean;
I
isidor 已提交
129
	hideStatusBar: 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 177
	private static readonly sidebarRestoreStorageKey = 'workbench.sidebar.restore';
	private static readonly panelHiddenStorageKey = 'workbench.panel.hidden';
	private static readonly zenModeActiveStorageKey = 'workbench.zenmode.active';
178
	private static readonly centeredEditorLayoutActiveStorageKey = 'workbench.centerededitorlayout.active';
179
	private static readonly panelPositionStorageKey = 'workbench.panel.location';
180
	private static readonly defaultPanelPositionStorageKey = 'workbench.panel.defaultLocation';
181 182 183 184 185
	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';
186

187
	_serviceBrand: any;
188

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

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

	private workbenchLayout: WorkbenchLayout;

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

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

I
isidor 已提交
230
	private inZenMode: IContextKey<boolean>;
231
	private sideBarVisibleContext: IContextKey<boolean>;
232

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

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

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

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

260
	startup(): TPromise<IWorkbenchStartedInfo> {
261
		this.workbenchStarted = true;
E
Erich Gamma 已提交
262

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

266 267
		// Install some global actions
		this.createGlobalActions();
268

269 270
		// Services
		this.initServices();
E
Erich Gamma 已提交
271

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

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

278 279
		// Settings
		this.initSettings();
E
Erich Gamma 已提交
280

281 282
		// Create Workbench and Parts
		this.renderWorkbench();
283

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

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

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

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

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

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

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

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

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

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

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

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

342 343 344
		// Progress 2
		serviceCollection.set(IProgressService2, new SyncDescriptor(ProgressService2));

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

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

352 353 354
		// List
		serviceCollection.set(IListService, this.instantiationService.createInstance(ListService));

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

S
SteVen Batten 已提交
359
		// Use themable context menus when custom titlebar is enabled to match custom menubar
B
Benjamin Pasero 已提交
360
		if (!isMacintosh && this.getCustomTitleBarStyle() === 'custom') {
361
			serviceCollection.set(IContextMenuService, new SyncDescriptor(HTMLContextMenuService, null));
S
SteVen Batten 已提交
362 363 364
		} else {
			serviceCollection.set(IContextMenuService, new SyncDescriptor(NativeContextMenuService));
		}
365

366 367
		// Menus/Actions
		serviceCollection.set(IMenuService, new SyncDescriptor(MenuService));
368

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

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

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

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

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

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

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

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

407
		// History
408
		serviceCollection.set(IHistoryService, new SyncDescriptor(HistoryService));
409

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

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

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

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

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

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

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

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

440 441 442
		// Workspace Editing
		serviceCollection.set(IWorkspaceEditingService, new SyncDescriptor(WorkspaceEditingService));

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

446
		// Configuration Resolver
B
Benjamin Pasero 已提交
447
		serviceCollection.set(IConfigurationResolverService, new SyncDescriptor(ConfigurationResolverService, process.env));
448

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

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

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

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

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

471
		this.instantiationService.createInstance(DefaultConfigurationExportHelper);
472

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

476
	//#region event handling
E
Erich Gamma 已提交
477

478
	private registerListeners(): void {
I
isidor 已提交
479

480 481
		// Lifecycle
		this._register(this.lifecycleService.onWillShutdown(e => this.saveState(e.reason)));
482

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

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

493
			this._register(listenerDispose);
494
		}
S
Sanders Lauture 已提交
495

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

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

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

507 508 509 510
	private onFullscreenChanged(): void {
		if (!this.isCreated) {
			return; // we need to be ready
		}
S
SrTobi 已提交
511

512 513 514
		// Apply as CSS class
		const isFullscreen = browser.isFullscreen();
		if (isFullscreen) {
B
Benjamin Pasero 已提交
515
			DOM.addClass(this.workbench, 'fullscreen');
516
		} else {
B
Benjamin Pasero 已提交
517 518
			DOM.removeClass(this.workbench, 'fullscreen');

519 520 521 522
			if (this.zenMode.transitionedToFullScreen && this.zenMode.active) {
				this.toggleZenMode();
			}
		}
E
Erich Gamma 已提交
523

524 525 526 527 528 529
		// Changing fullscreen state of the window has an impact on custom title bar visibility, so we need to update
		const hasCustomTitle = this.getCustomTitleBarStyle() === 'custom';
		if (hasCustomTitle) {
			this._onTitleBarVisibilityChange.fire();
			this.layout(); // handle title bar when fullscreen changes
		}
530 531
	}

532 533 534 535 536
	private onMenubarToggled(visible: boolean) {
		if (visible !== this.menubarToggled) {
			this.menubarToggled = visible;

			if (this.menubarVisibility === 'toggle' || (browser.isFullscreen() && this.menubarVisibility === 'default')) {
S
SteVen Batten 已提交
537 538 539 540
				if (browser.isFullscreen() && this.menubarVisibility === 'default') {
					this._onTitleBarVisibilityChange.fire();
				}

541 542 543 544 545
				this.layout();
			}
		}
	}

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

548 549 550
		// 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.
551
		if (resourcesToWaitFor.every(resource => !this.editorService.isOpen({ resource }))) {
552
			listenerDispose.dispose();
553
			this.fileService.del(waitMarkerFile);
554
		}
E
Erich Gamma 已提交
555 556
	}

557
	private onDidVisibleEditorsChange(): void {
558
		const visibleEditors = this.editorService.visibleControls;
E
Erich Gamma 已提交
559

560 561 562 563 564 565 566 567 568
		// 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();
			}
		}
569 570
	}

571
	private onAllEditorsClosed(): void {
572
		const visibleEditors = this.editorService.visibleControls.length;
573 574
		if (visibleEditors === 0) {
			this.windowService.closeWindow();
E
Erich Gamma 已提交
575 576 577
		}
	}

578 579 580 581 582
	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);
583
		}
E
Erich Gamma 已提交
584

585
		this.setPanelPositionFromStorageOrConfig();
E
Erich Gamma 已提交
586

587 588 589
		const fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
		if (fontAliasing !== this.fontAliasing) {
			this.setFontAliasing(fontAliasing);
590 591
		}

592 593 594 595 596
		if (!this.zenMode.active) {
			const newStatusbarHiddenValue = !this.configurationService.getValue<boolean>(Workbench.statusbarVisibleConfigurationKey);
			if (newStatusbarHiddenValue !== this.statusBarHidden) {
				this.setStatusBarHidden(newStatusbarHiddenValue, skipLayout);
			}
597

598 599 600 601
			const newActivityBarHiddenValue = !this.configurationService.getValue<boolean>(Workbench.activityBarVisibleConfigurationKey);
			if (newActivityBarHiddenValue !== this.activityBarHidden) {
				this.setActivityBarHidden(newActivityBarHiddenValue, skipLayout);
			}
B
Benjamin Pasero 已提交
602
		}
S
SteVen Batten 已提交
603

604
		const newMenubarVisibility = this.configurationService.getValue<MenuBarVisibility>(Workbench.menubarVisibilityConfigurationKey);
S
SteVen Batten 已提交
605
		this.setMenubarVisibility(newMenubarVisibility, skipLayout);
606
	}
B
Benjamin Pasero 已提交
607

608
	//#endregion
B
Benjamin Pasero 已提交
609

610 611
	private handleContextKeys(): void {
		this.inZenMode = InEditorZenModeContext.bindTo(this.contextKeyService);
612

I
isidor 已提交
613 614 615
		IsMacContext.bindTo(this.contextKeyService);
		IsLinuxContext.bindTo(this.contextKeyService);
		IsWindowsContext.bindTo(this.contextKeyService);
616

617 618
		const sidebarVisibleContextRaw = new RawContextKey<boolean>('sidebarVisible', false);
		this.sideBarVisibleContext = sidebarVisibleContextRaw.bindTo(this.contextKeyService);
619

620
		const activeEditorContext = ActiveEditorContext.bindTo(this.contextKeyService);
621 622
		const editorsVisibleContext = EditorsVisibleContext.bindTo(this.contextKeyService);
		const textCompareEditorVisible = TextCompareEditorVisibleContext.bindTo(this.contextKeyService);
623
		const textCompareEditorActive = TextCompareEditorActiveContext.bindTo(this.contextKeyService);
624 625
		const activeEditorGroupEmpty = ActiveEditorGroupEmptyContext.bindTo(this.contextKeyService);
		const multipleEditorGroups = MultipleEditorGroupsContext.bindTo(this.contextKeyService);
626

627
		const updateEditorContextKeys = () => {
628
			const activeControl = this.editorService.activeControl;
629
			const visibleEditors = this.editorService.visibleControls;
E
Erich Gamma 已提交
630

631
			textCompareEditorActive.set(activeControl && activeControl.getId() === TEXT_DIFF_EDITOR_ID);
632
			textCompareEditorVisible.set(visibleEditors.some(control => control.getId() === TEXT_DIFF_EDITOR_ID));
I
isidor 已提交
633

634 635 636 637
			if (visibleEditors.length > 0) {
				editorsVisibleContext.set(true);
			} else {
				editorsVisibleContext.reset();
638
			}
B
Benjamin Pasero 已提交
639

640
			if (!this.editorService.activeEditor) {
641 642 643
				activeEditorGroupEmpty.set(true);
			} else {
				activeEditorGroupEmpty.reset();
644
			}
645

B
Benjamin Pasero 已提交
646
			if (this.editorGroupService.count > 1) {
647 648 649 650
				multipleEditorGroups.set(true);
			} else {
				multipleEditorGroups.reset();
			}
651 652 653 654 655 656

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

659
		this.editorPart.whenRestored.then(() => updateEditorContextKeys());
660 661
		this._register(this.editorService.onDidActiveEditorChange(() => updateEditorContextKeys()));
		this._register(this.editorService.onDidVisibleEditorsChange(() => updateEditorContextKeys()));
B
Benjamin Pasero 已提交
662 663
		this._register(this.editorGroupService.onDidAddGroup(() => updateEditorContextKeys()));
		this._register(this.editorGroupService.onDidRemoveGroup(() => updateEditorContextKeys()));
664

665
		const inputFocused = InputFocusedContext.bindTo(this.contextKeyService);
B
Benjamin Pasero 已提交
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685

		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);
				once(tracker.onDidBlur)(() => {
					inputFocused.set(activeElementIsInput());

					tracker.dispose();
				});
			}
		}

		this._register(DOM.addDisposableListener(window, 'focusin', () => trackInputFocus(), true));
686 687 688 689 690 691

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

693 694 695 696 697
		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);
		}));
698

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

701 702 703 704
		const updateSplitEditorsVerticallyContext = () => {
			const direction = preferredSideBySideGroupDirection(this.configurationService);
			splitEditorsVerticallyContext.set(direction === GroupDirection.DOWN);
		};
S
Sanders Lauture 已提交
705

706 707 708 709 710
		this._register(this.configurationService.onDidChangeConfiguration(e => {
			if (e.affectsConfiguration('workbench.editor.openSideBySideDirection')) {
				updateSplitEditorsVerticallyContext();
			}
		}));
E
Erich Gamma 已提交
711

712
		updateSplitEditorsVerticallyContext();
713
	}
E
Erich Gamma 已提交
714

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

718 719
		// Restore Editorpart
		perf.mark('willRestoreEditors');
720
		restorePromises.push(this.editorPart.whenRestored.then(() => {
721 722
			return this.resolveEditorsToOpen().then(inputs => {
				if (inputs.length) {
723
					return this.editorService.openEditors(inputs);
724
				}
E
Erich Gamma 已提交
725

726 727 728 729 730
				return TPromise.as(void 0);
			});
		}).then(() => {
			perf.mark('didRestoreEditors');
		}));
E
Erich Gamma 已提交
731

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

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

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

745
			perf.mark('willRestoreViewlet');
746 747 748 749 750
			restorePromises.push(this.viewletService.openViewlet(viewletIdToRestore)
				.then(viewlet => viewlet || this.viewletService.openViewlet(this.viewletService.getDefaultViewletId()))
				.then(() => {
					perf.mark('didRestoreViewlet');
				}));
751 752
		}

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

763
		// Restore Zen Mode if active
764
		if (this.storageService.getBoolean(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE, false)) {
I
isidor 已提交
765
			this.toggleZenMode(true, true);
I
isidor 已提交
766 767
		}

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

773
		const onRestored = (error?: Error): IWorkbenchStartedInfo => {
B
Benjamin Pasero 已提交
774
			this.workbenchCreated = true;
775

776 777
			if (error) {
				errors.onUnexpectedError(error);
778
			}
I
isidor 已提交
779

780 781
			return {
				customKeybindingsCount: this.keybindingService.customKeybindingsCount(),
P
Pine Wu 已提交
782
				pinnedViewlets: this.activitybarPart.getPinnedViewletIds(),
783
				restoredViewlet: viewletIdToRestore,
784
				restoredEditorsCount: this.editorService.visibleEditors.length
785 786
			};
		};
787

788
		return TPromise.join(restorePromises).then(() => onRestored(), error => onRestored(error));
E
Erich Gamma 已提交
789 790
	}

791 792 793
	private shouldRestoreLastOpenedViewlet(): boolean {
		if (!this.environmentService.isBuilt) {
			return true; // always restore sidebar when we are in development mode
E
Erich Gamma 已提交
794 795
		}

796
		const restore = this.storageService.getBoolean(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE);
797
		if (restore) {
B
Benjamin Pasero 已提交
798
			this.storageService.remove(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE); // only support once
799
		}
800

801
		return restore;
E
Erich Gamma 已提交
802 803
	}

804
	private resolveEditorsToOpen(): TPromise<IResourceEditor[]> {
805
		const config = this.workbenchParams.configuration;
I
isidor 已提交
806

B
Benjamin Pasero 已提交
807
		// Files to open, diff or create
808
		if (this.hasInitialFilesToOpen) {
I
isidor 已提交
809

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

821 822
			const filesToCreate = this.toInputs(config.filesToCreate, true);
			const filesToOpen = this.toInputs(config.filesToOpen, false);
I
isidor 已提交
823

824 825
			// Otherwise: Open/Create files
			return TPromise.as([...filesToOpen, ...filesToCreate]);
B
Benjamin Pasero 已提交
826
		}
I
isidor 已提交
827

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

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

840
				return TPromise.as([<IUntitledResourceInput>{}]);
841
			});
842
		}
843

B
Benjamin Pasero 已提交
844 845
		return TPromise.as([]);
	}
846

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

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

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

B
Benjamin Pasero 已提交
868 869
			return input;
		});
870 871
	}

872
	private openUntitledFile() {
873
		const startupEditor = this.configurationService.inspect('workbench.startupEditor');
B
Benjamin Pasero 已提交
874 875

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

883
		return startupEditor.value === 'newUntitledFile';
884
	}
E
Erich Gamma 已提交
885 886

	private initSettings(): void {
887

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

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

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

I
isidor 已提交
902
		// Panel position
903
		this.setPanelPositionFromStorageOrConfig();
904

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

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

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

917
		// Font aliasing
918
		this.fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
919

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

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

935 936
		this.panelPosition = (panelPosition === 'right') ? Position.RIGHT : Position.BOTTOM;
	}
937

938 939
	private getCustomTitleBarStyle(): 'custom' {
		const isDev = !this.environmentService.isBuilt || this.environmentService.isExtensionDevelopment;
B
Benjamin Pasero 已提交
940
		if (isMacintosh && isDev) {
941 942
			return null; // not enabled when developing due to https://github.com/electron/electron/issues/3647
		}
E
Erich Gamma 已提交
943

944 945 946 947 948 949 950 951 952 953
		const windowConfig = this.configurationService.getValue<IWindowSettings>();
		if (windowConfig && windowConfig.window) {
			const useNativeTabs = windowConfig.window.nativeTabs;
			if (useNativeTabs) {
				return null; // native tabs on sierra do not work with custom title style
			}

			const style = windowConfig.window.titleBarStyle;
			if (style === 'custom') {
				return style;
954 955 956
			}
		}

957
		return null;
B
Benjamin Pasero 已提交
958 959
	}

960 961
	private setStatusBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.statusBarHidden = hidden;
B
Benjamin Pasero 已提交
962

963 964
		// Adjust CSS
		if (hidden) {
B
Benjamin Pasero 已提交
965
			DOM.addClass(this.workbench, 'nostatusbar');
E
Erich Gamma 已提交
966
		} else {
B
Benjamin Pasero 已提交
967
			DOM.removeClass(this.workbench, 'nostatusbar');
E
Erich Gamma 已提交
968 969
		}

970 971 972
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
973 974 975
		}
	}

976
	private setFontAliasing(aliasing: FontAliasingOption) {
977
		this.fontAliasing = aliasing;
S
Sanders Lauture 已提交
978

B
Benjamin Pasero 已提交
979 980 981 982 983
		// Remove all
		document.body.classList.remove(...fontAliasingValues.map(value => `monaco-font-aliasing-${value}`));

		// Add specific
		if (fontAliasingValues.some(option => option === aliasing)) {
984
			document.body.classList.add(`monaco-font-aliasing-${aliasing}`);
S
Sanders Lauture 已提交
985
		}
986 987
	}

E
Erich Gamma 已提交
988
	private createWorkbenchLayout(): void {
989 990
		this.workbenchLayout = this.instantiationService.createInstance(
			WorkbenchLayout,
991
			this.container,
B
Benjamin Pasero 已提交
992
			this.workbench,
I
isidor 已提交
993
			{
994 995 996 997 998 999
				titlebar: this.titlebarPart,
				activitybar: this.activitybarPart,
				editor: this.editorPart,
				sidebar: this.sidebarPart,
				panel: this.panelPart,
				statusbar: this.statusbarPart,
I
isidor 已提交
1000
			},
1001 1002 1003 1004
			this.quickOpen,
			this.quickInput,
			this.notificationsCenter,
			this.notificationsToasts
E
Erich Gamma 已提交
1005 1006 1007 1008 1009 1010 1011
		);
	}

	private renderWorkbench(): void {

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

1015
		if (this.panelHidden) {
B
Benjamin Pasero 已提交
1016
			DOM.addClass(this.workbench, 'nopanel');
1017
		}
B
Benjamin Pasero 已提交
1018

1019
		if (this.statusBarHidden) {
B
Benjamin Pasero 已提交
1020
			DOM.addClass(this.workbench, 'nostatusbar');
1021
		}
E
Erich Gamma 已提交
1022

B
Benjamin Pasero 已提交
1023
		// Apply font aliasing
1024 1025
		this.setFontAliasing(this.fontAliasing);

1026 1027
		// Apply fullscreen state
		if (browser.isFullscreen()) {
B
Benjamin Pasero 已提交
1028
			DOM.addClass(this.workbench, 'fullscreen');
B
Benjamin Pasero 已提交
1029 1030
		}

E
Erich Gamma 已提交
1031
		// Create Parts
B
Benjamin Pasero 已提交
1032
		this.createTitlebarPart();
E
Erich Gamma 已提交
1033 1034 1035
		this.createActivityBarPart();
		this.createSidebarPart();
		this.createEditorPart();
1036
		this.createPanelPart();
E
Erich Gamma 已提交
1037 1038
		this.createStatusbarPart();

1039 1040
		// Notification Handlers
		this.createNotificationsHandlers();
1041

1042 1043 1044 1045 1046 1047

		// Menubar visibility changes
		if ((isWindows || isLinux) && this.getCustomTitleBarStyle() === 'custom') {
			this.titlebarPart.onMenubarVisibilityChange()(e => this.onMenubarToggled(e));
		}

E
Erich Gamma 已提交
1048
		// Add Workbench to DOM
B
Benjamin Pasero 已提交
1049
		this.container.appendChild(this.workbench);
E
Erich Gamma 已提交
1050 1051
	}

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

B
Benjamin Pasero 已提交
1055
		this.titlebarPart.create(titlebarContainer);
B
Benjamin Pasero 已提交
1056 1057
	}

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

B
Benjamin Pasero 已提交
1061
		this.activitybarPart.create(activitybarPartContainer);
E
Erich Gamma 已提交
1062 1063 1064
	}

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

B
Benjamin Pasero 已提交
1067
		this.sidebarPart.create(sidebarPartContainer);
E
Erich Gamma 已提交
1068 1069
	}

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

B
Benjamin Pasero 已提交
1073
		this.panelPart.create(panelPartContainer);
I
isidor 已提交
1074 1075
	}

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

B
Benjamin Pasero 已提交
1079
		this.editorPart.create(editorContainer);
E
Erich Gamma 已提交
1080 1081 1082
	}

	private createStatusbarPart(): void {
B
Benjamin Pasero 已提交
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
		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 已提交
1094 1095 1096
		// 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 已提交
1097

B
Benjamin Pasero 已提交
1098
		return part;
E
Erich Gamma 已提交
1099 1100
	}

1101 1102
	private createNotificationsHandlers(): void {

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

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

1109
		// Notifications Alerts
1110
		this._register(this.instantiationService.createInstance(NotificationsAlerts, this.notificationService.model));
1111 1112 1113 1114

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

1115
		// Eventing
1116
		this._register(this.notificationsCenter.onDidChangeVisibility(() => {
1117 1118 1119 1120 1121 1122 1123 1124

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

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

1125
		// Register Commands
1126
		registerNotificationCommands(this.notificationsCenter, this.notificationsToasts);
1127 1128
	}

1129
	getInstantiationService(): IInstantiationService {
E
Erich Gamma 已提交
1130 1131 1132
		return this.instantiationService;
	}

1133
	private saveState(reason: ShutdownReason): void {
1134 1135 1136

		// Restore sidebar if we are being shutdown as a matter of a reload
		if (reason === ShutdownReason.RELOAD) {
B
Benjamin Pasero 已提交
1137
			this.storageService.store(Workbench.sidebarRestoreStorageKey, true, StorageScope.WORKSPACE);
1138 1139 1140 1141 1142 1143
		}

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

B
Benjamin Pasero 已提交
1150
			this.storageService.remove(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE);
1151
		}
1152 1153 1154 1155
	}

	dispose(reason = ShutdownReason.QUIT): void {
		super.dispose();
1156 1157 1158 1159 1160 1161

		this.workbenchShutdown = true;
	}

	//#region IPartService

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

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

1167
	isCreated(): boolean {
1168
		return !!(this.workbenchCreated && this.workbenchStarted);
1169
	}
1170

1171 1172 1173 1174 1175
	hasFocus(part: Parts): boolean {
		const activeElement = document.activeElement;
		if (!activeElement) {
			return false;
		}
1176

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

1181
	getContainer(part: Parts): HTMLElement {
1182
		let container: HTMLElement | null = null;
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
		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;
		}
1203

1204 1205
		return container;
	}
1206

1207 1208 1209
	isVisible(part: Parts): boolean {
		switch (part) {
			case Parts.TITLEBAR_PART:
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222
				if (this.getCustomTitleBarStyle() !== 'custom') {
					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;
1223 1224 1225 1226 1227 1228 1229 1230
			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 已提交
1231
		}
1232

1233
		return true; // any other part cannot be hidden
E
Erich Gamma 已提交
1234 1235
	}

1236 1237 1238
	getTitleBarOffset(): number {
		let offset = 0;
		if (this.isVisible(Parts.TITLEBAR_PART)) {
S
SteVen Batten 已提交
1239
			offset = this.workbenchLayout.partLayoutInfo.titlebar.height;
1240 1241 1242
			if (isMacintosh || this.menubarVisibility === 'hidden') {
				offset /= browser.getZoomFactor();
			}
E
Erich Gamma 已提交
1243
		}
1244 1245

		return offset;
E
Erich Gamma 已提交
1246
	}
1247

1248 1249
	getWorkbenchElement(): HTMLElement {
		return this.workbench;
1250
	}
1251

I
isidor 已提交
1252
	toggleZenMode(skipLayout?: boolean, restoring = false): void {
I
isidor 已提交
1253
		this.zenMode.active = !this.zenMode.active;
1254
		this.zenMode.transitionDisposeables = dispose(this.zenMode.transitionDisposeables);
1255

1256 1257
		// 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)
1258
		let toggleFullScreen = false;
1259 1260

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

I
isidor 已提交
1264
			toggleFullScreen = !browser.isFullscreen() && config.fullScreen;
I
isidor 已提交
1265
			this.zenMode.transitionedToFullScreen = restoring ? config.fullScreen : toggleFullScreen;
1266
			this.zenMode.transitionedToCenteredEditorLayout = !this.isEditorLayoutCentered() && config.centerLayout;
1267 1268
			this.zenMode.wasSideBarVisible = this.isVisible(Parts.SIDEBAR_PART);
			this.zenMode.wasPanelVisible = this.isVisible(Parts.PANEL_PART);
1269

1270 1271
			this.setPanelHidden(true, true);
			this.setSideBarHidden(true, true);
I
isidor 已提交
1272

1273 1274 1275
			if (config.hideActivityBar) {
				this.setActivityBarHidden(true, true);
			}
1276

I
isidor 已提交
1277
			if (config.hideStatusBar) {
I
isidor 已提交
1278 1279
				this.setStatusBarHidden(true, true);
			}
1280

1281 1282
			if (config.hideTabs && this.editorPart.partOptions.showTabs) {
				this.zenMode.transitionDisposeables.push(this.editorPart.enforcePartOptions({ showTabs: false }));
I
isidor 已提交
1283
			}
1284 1285 1286 1287

			if (config.centerLayout) {
				this.centerEditorLayout(true, true);
			}
1288 1289 1290 1291
		}

		// Zen Mode Inactive
		else {
1292
			if (this.zenMode.wasPanelVisible) {
1293
				this.setPanelHidden(false, true);
1294
			}
1295

1296
			if (this.zenMode.wasSideBarVisible) {
1297
				this.setSideBarHidden(false, true);
1298
			}
1299

1300 1301 1302
			if (this.zenMode.transitionedToCenteredEditorLayout) {
				this.centerEditorLayout(false, true);
			}
1303

1304 1305
			// Status bar and activity bar visibility come from settings -> update their visibility.
			this.onDidUpdateConfiguration(true);
1306

B
Benjamin Pasero 已提交
1307
			this.editorGroupService.activeGroup.focus();
1308

1309
			toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
I
isidor 已提交
1310
		}
1311

1312
		this.inZenMode.set(this.zenMode.active);
I
isidor 已提交
1313

I
isidor 已提交
1314
		if (!skipLayout) {
1315
			this.layout();
I
isidor 已提交
1316
		}
1317

1318
		if (toggleFullScreen) {
1319
			this.windowService.toggleFullScreen();
1320
		}
I
isidor 已提交
1321 1322
	}

1323
	layout(options?: ILayoutOptions): void {
J
Joao Moreno 已提交
1324 1325
		this.contextViewService.layout();

1326 1327 1328 1329 1330
		if (this.workbenchStarted && !this.workbenchShutdown) {
			this.workbenchLayout.layout(options);
		}
	}

1331
	isEditorLayoutCentered(): boolean {
1332
		return this.shouldCenterLayout;
S
SrTobi 已提交
1333 1334
	}

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

1343
		// Enter Centered Editor Layout
1344 1345
		if (this.editorPart.isLayoutCentered() !== smartActive) {
			this.editorPart.centerLayout(smartActive);
1346

1347 1348 1349
			if (!skipLayout) {
				this.layout();
			}
1350
		}
S
SrTobi 已提交
1351 1352
	}

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

1365 1366
	setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.activityBarHidden = hidden;
1367

1368 1369 1370
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
1371
		}
1372
	}
1373

1374 1375 1376 1377 1378 1379
	setSideBarHidden(hidden: boolean, skipLayout?: boolean): TPromise<void> {
		this.sideBarHidden = hidden;
		this.sideBarVisibleContext.set(!hidden);

		// Adjust CSS
		if (hidden) {
B
Benjamin Pasero 已提交
1380
			DOM.addClass(this.workbench, 'nosidebar');
1381
		} else {
B
Benjamin Pasero 已提交
1382
			DOM.removeClass(this.workbench, 'nosidebar');
1383 1384
		}

1385 1386 1387 1388 1389 1390 1391 1392 1393
		// If sidebar becomes hidden, also hide the current active Viewlet if any
		let promise = TPromise.wrap<any>(null);
		if (hidden && this.sidebarPart.getActiveViewlet()) {
			promise = this.sidebarPart.hideActiveViewlet().then(() => {
				const activePanel = this.panelPart.getActivePanel();

				// Pass Focus to Editor or Panel if Sidebar is now hidden
				if (this.hasFocus(Parts.PANEL_PART) && activePanel) {
					activePanel.focus();
B
Benjamin Pasero 已提交
1394 1395
				} else {
					this.editorGroupService.activeGroup.focus();
1396 1397 1398 1399 1400 1401 1402 1403
				}
			});
		}

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

1409 1410 1411 1412 1413
		return promise.then(() => {

			// Remember in settings
			const defaultHidden = this.contextService.getWorkbenchState() === WorkbenchState.EMPTY;
			if (hidden !== defaultHidden) {
B
Benjamin Pasero 已提交
1414
				this.storageService.store(Workbench.sidebarHiddenStorageKey, hidden ? 'true' : 'false', StorageScope.WORKSPACE);
1415
			} else {
B
Benjamin Pasero 已提交
1416
				this.storageService.remove(Workbench.sidebarHiddenStorageKey, StorageScope.WORKSPACE);
1417 1418 1419 1420 1421 1422 1423
			}

			// Layout
			if (!skipLayout) {
				this.workbenchLayout.layout();
			}
		});
1424
	}
1425 1426 1427 1428 1429 1430

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

		// Adjust CSS
		if (hidden) {
B
Benjamin Pasero 已提交
1431
			DOM.addClass(this.workbench, 'nopanel');
1432
		} else {
B
Benjamin Pasero 已提交
1433
			DOM.removeClass(this.workbench, 'nopanel');
1434 1435 1436 1437 1438 1439
		}

		// If panel part becomes hidden, also hide the current active panel if any
		let promise = TPromise.wrap<any>(null);
		if (hidden && this.panelPart.getActivePanel()) {
			promise = this.panelPart.hideActivePanel().then(() => {
B
Benjamin Pasero 已提交
1440
				this.editorGroupService.activeGroup.focus(); // Pass focus to editor group if panel part is now hidden
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
			});
		}

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

		return promise.then(() => {

			// Remember in settings
			if (!hidden) {
B
Benjamin Pasero 已提交
1456
				this.storageService.store(Workbench.panelHiddenStorageKey, 'false', StorageScope.WORKSPACE);
1457
			} else {
B
Benjamin Pasero 已提交
1458
				this.storageService.remove(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE);
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
			}

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

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

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

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

	setSideBarPosition(position: Position): void {
		if (this.sideBarHidden) {
1482
			this.setSideBarHidden(false, true /* Skip Layout */);
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
		}

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

S
SteVen Batten 已提交
1507 1508 1509
			if (!skipLayout) {
				this.workbenchLayout.layout();
			}
1510 1511 1512
		}
	}

S
SteVen Batten 已提交
1513 1514 1515 1516
	getMenubarVisibility(): MenuBarVisibility {
		return this.menubarVisibility;
	}

1517 1518 1519 1520 1521 1522 1523 1524 1525
	getPanelPosition(): Position {
		return this.panelPosition;
	}

	setPanelPosition(position: Position): TPromise<void> {
		return (this.panelHidden ? this.setPanelHidden(false, true /* Skip Layout */) : TPromise.as(undefined)).then(() => {
			const newPositionValue = (position === Position.BOTTOM) ? 'bottom' : 'right';
			const oldPositionValue = (this.panelPosition === Position.BOTTOM) ? 'bottom' : 'right';
			this.panelPosition = position;
B
Benjamin Pasero 已提交
1526
			this.storageService.store(Workbench.panelPositionStorageKey, PositionToString(this.panelPosition).toLowerCase(), StorageScope.WORKSPACE);
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537

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

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

			// Layout
			this.workbenchLayout.layout();
		});
1538
	}
1539 1540

	//#endregion
I
isidor 已提交
1541
}