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

'use strict';

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

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

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

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

136 137 138
export interface IWorkbenchStartedInfo {
	customKeybindingsCount: number;
	pinnedViewlets: string[];
139
	restoredViewlet: string;
140
	restoredEditorsCount: number;
141 142
}

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

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

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

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

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

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

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

191
	_serviceBrand: any;
192

E
Erich Gamma 已提交
193 194 195 196 197
	private workbenchParams: WorkbenchParams;
	private workbench: Builder;
	private workbenchStarted: boolean;
	private workbenchCreated: boolean;
	private workbenchShutdown: boolean;
198

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

	private workbenchLayout: WorkbenchLayout;

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

E
Erich Gamma 已提交
222
	private sideBarHidden: boolean;
223
	private statusBarHidden: boolean;
S
Sanders Lauture 已提交
224
	private activityBarHidden: boolean;
E
Erich Gamma 已提交
225
	private sideBarPosition: Position;
I
isidor 已提交
226
	private panelPosition: Position;
I
isidor 已提交
227
	private panelHidden: boolean;
S
SteVen Batten 已提交
228
	private menubarVisibility: MenuBarVisibility;
229 230
	private zenMode: IZenMode;
	private fontAliasing: FontAliasingOption;
231
	private hasInitialFilesToOpen: boolean;
232

I
isidor 已提交
233
	private inZenMode: IContextKey<boolean>;
234
	private sideBarVisibleContext: IContextKey<boolean>;
235

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

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

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

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

264
	startup(): TPromise<IWorkbenchStartedInfo> {
265
		this.workbenchStarted = true;
E
Erich Gamma 已提交
266

B
Benjamin Pasero 已提交
267
		// Create Workbench Container
268
		this.createWorkbench();
E
Erich Gamma 已提交
269

270 271
		// Install some global actions
		this.createGlobalActions();
272

273 274
		// Services
		this.initServices();
E
Erich Gamma 已提交
275

276 277
		// Context Keys
		this.handleContextKeys();
J
Joao Moreno 已提交
278

279 280
		// Register Listeners
		this.registerListeners();
E
Erich Gamma 已提交
281

282 283
		// Settings
		this.initSettings();
E
Erich Gamma 已提交
284

285 286
		// Create Workbench and Parts
		this.renderWorkbench();
287

288 289
		// Workbench Layout
		this.createWorkbenchLayout();
B
polish  
Benjamin Pasero 已提交
290

J
Joao Moreno 已提交
291 292
		// Driver
		if (this.environmentService.driverHandle) {
293
			registerWindowDriver(this.mainProcessClient, this.configuration.windowId, this.instantiationService).then(disposable => this._register(disposable));
J
Joao Moreno 已提交
294 295
		}

296
		// Restore Parts
B
Benjamin Pasero 已提交
297 298
		return this.restoreParts();
	}
299

B
Benjamin Pasero 已提交
300 301 302 303
	private createWorkbench(): void {
		this.workbench = $().div({
			'class': `monaco-workbench ${isWindows ? 'windows' : isLinux ? 'linux' : 'mac'}`,
			id: Identifiers.WORKBENCH_CONTAINER
J
Joao Moreno 已提交
304
		});
305
	}
E
Erich Gamma 已提交
306

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

B
Benjamin Pasero 已提交
310
		// Actions registered here to adjust for developing vs built workbench
311 312 313 314 315
		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');
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 321 322 323 324
			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');
325
		}
326 327
	}

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

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

334 335 336
		// Clipboard
		serviceCollection.set(IClipboardService, new ClipboardService());

337 338
		// Status bar
		this.statusbarPart = this.instantiationService.createInstance(StatusbarPart, Identifiers.STATUSBAR_PART);
339
		this._register(toDisposable(() => this.statusbarPart.shutdown()));
340 341
		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 356 357 358
		// Context view service
		this.contextViewService = this.instantiationService.createInstance(ContextViewService, this.workbench.getHTMLElement());
		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') {
S
SteVen Batten 已提交
361
			serviceCollection.set(IContextMenuService, new SyncDescriptor(HTMLContextMenuService, null, this.telemetryService, this.notificationService, this.contextViewService));
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);
371
		this._register(toDisposable(() => this.sidebarPart.shutdown()));
P
Pine Wu 已提交
372 373 374 375

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

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

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

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

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

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

407 408
		// Title bar
		this.titlebarPart = this.instantiationService.createInstance(TitlebarPart, Identifiers.TITLEBAR_PART);
409
		this._register(toDisposable(() => this.titlebarPart.shutdown()));
410
		serviceCollection.set(ITitleService, this.titlebarPart);
B
Benjamin Pasero 已提交
411

412
		// History
413
		serviceCollection.set(IHistoryService, new SyncDescriptor(HistoryService));
414

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

418
		// Backup File Service
B
Benjamin Pasero 已提交
419 420 421 422 423
		if (this.workbenchParams.configuration.backupPath) {
			this.backupFileService = this.instantiationService.createInstance(BackupFileService, this.workbenchParams.configuration.backupPath);
		} else {
			this.backupFileService = new InMemoryBackupFileService();
		}
424
		serviceCollection.set(IBackupFileService, this.backupFileService);
425

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

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

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

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

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

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

445 446 447
		// Workspace Editing
		serviceCollection.set(IWorkspaceEditingService, new SyncDescriptor(WorkspaceEditingService));

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

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

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

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

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

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

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

478
		this.instantiationService.createInstance(DefaultConfigurationExportHelper);
479

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

483
	//#region event handling
E
Erich Gamma 已提交
484

485
	private registerListeners(): void {
I
isidor 已提交
486

487
		// Listen to visible editor changes
488
		this._register(this.editorService.onDidVisibleEditorsChange(() => this.onDidVisibleEditorsChange()));
B
Benjamin Pasero 已提交
489

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

497
			this._register(listenerDispose);
498
		}
S
Sanders Lauture 已提交
499

500
		// Configuration changes
501
		this._register(this.configurationService.onDidChangeConfiguration(() => this.onDidUpdateConfiguration()));
I
isidor 已提交
502

503
		// Fullscreen changes
504
		this._register(browser.onDidChangeFullscreen(() => this.onFullscreenChanged()));
505
	}
506

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

512 513 514 515 516 517 518 519 520 521
		// Apply as CSS class
		const isFullscreen = browser.isFullscreen();
		if (isFullscreen) {
			this.workbench.addClass('fullscreen');
		} else {
			this.workbench.removeClass('fullscreen');
			if (this.zenMode.transitionedToFullScreen && this.zenMode.active) {
				this.toggleZenMode();
			}
		}
E
Erich Gamma 已提交
522

523 524 525 526 527 528
		// 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
		}
529 530
	}

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

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

542
	private onDidVisibleEditorsChange(): void {
543
		const visibleEditors = this.editorService.visibleControls;
E
Erich Gamma 已提交
544

545 546 547 548 549 550 551 552 553
		// 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();
			}
		}
554 555
	}

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

563 564 565 566 567
	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);
568
		}
E
Erich Gamma 已提交
569

570
		this.setPanelPositionFromStorageOrConfig();
E
Erich Gamma 已提交
571

572 573 574
		const fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
		if (fontAliasing !== this.fontAliasing) {
			this.setFontAliasing(fontAliasing);
575 576
		}

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

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

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

593
	//#endregion
B
Benjamin Pasero 已提交
594

595 596
	private handleContextKeys(): void {
		this.inZenMode = InEditorZenModeContext.bindTo(this.contextKeyService);
597

598 599
		const sidebarVisibleContextRaw = new RawContextKey<boolean>('sidebarVisible', false);
		this.sideBarVisibleContext = sidebarVisibleContextRaw.bindTo(this.contextKeyService);
600

601 602 603 604
		const editorsVisibleContext = EditorsVisibleContext.bindTo(this.contextKeyService);
		const textCompareEditorVisible = TextCompareEditorVisibleContext.bindTo(this.contextKeyService);
		const activeEditorGroupEmpty = ActiveEditorGroupEmptyContext.bindTo(this.contextKeyService);
		const multipleEditorGroups = MultipleEditorGroupsContext.bindTo(this.contextKeyService);
605

606
		const updateEditorContextKeys = () => {
607
			const visibleEditors = this.editorService.visibleControls;
E
Erich Gamma 已提交
608

609
			textCompareEditorVisible.set(visibleEditors.some(control => control.getId() === TEXT_DIFF_EDITOR_ID));
I
isidor 已提交
610

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

617
			if (!this.editorService.activeEditor) {
618 619 620
				activeEditorGroupEmpty.set(true);
			} else {
				activeEditorGroupEmpty.reset();
621
			}
622

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

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

636 637 638 639 640 641 642 643 644 645
		const inputFocused = InputFocusedContext.bindTo(this.contextKeyService);
		this._register(DOM.addDisposableListener(window, 'focusin', () => {
			inputFocused.set(document.activeElement && (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA'));
		}, true));

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

647 648 649 650 651
		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);
		}));
652

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

655 656 657 658
		const updateSplitEditorsVerticallyContext = () => {
			const direction = preferredSideBySideGroupDirection(this.configurationService);
			splitEditorsVerticallyContext.set(direction === GroupDirection.DOWN);
		};
S
Sanders Lauture 已提交
659

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

666
		updateSplitEditorsVerticallyContext();
667
	}
E
Erich Gamma 已提交
668

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

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

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

686 687 688 689
		// Restore Sidebar
		let viewletIdToRestore: string;
		if (!this.sideBarHidden) {
			this.sideBarVisibleContext.set(true);
690

691 692
			if (this.shouldRestoreLastOpenedViewlet()) {
				viewletIdToRestore = this.storageService.get(SidebarPart.activeViewletSettingsKey, StorageScope.WORKSPACE);
693
			}
694

695 696
			if (!viewletIdToRestore) {
				viewletIdToRestore = this.viewletService.getDefaultViewletId();
697
			}
E
Erich Gamma 已提交
698

699
			perf.mark('willRestoreViewlet');
700 701 702 703 704
			restorePromises.push(this.viewletService.openViewlet(viewletIdToRestore)
				.then(viewlet => viewlet || this.viewletService.openViewlet(this.viewletService.getDefaultViewletId()))
				.then(() => {
					perf.mark('didRestoreViewlet');
				}));
705 706
		}

707 708 709 710
		// Restore Panel
		const panelRegistry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
		const panelId = this.storageService.get(PanelPart.activePanelSettingsKey, StorageScope.WORKSPACE, panelRegistry.getDefaultPanelId());
		if (!this.panelHidden && !!panelId) {
711 712 713 714 715 716
			const isPanelToRestoreEnabled = !!this.panelPart.getPanels().filter(p => p.id === panelId).length;
			if (isPanelToRestoreEnabled) {
				restorePromises.push(this.panelPart.openPanel(panelId, false));
			} else {
				restorePromises.push(this.panelPart.openPanel(panelRegistry.getDefaultPanelId(), false));
			}
I
isidor 已提交
717 718
		}

719
		// Restore Zen Mode if active
I
isidor 已提交
720
		if (this.storageService.getBoolean(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE, false)) {
I
isidor 已提交
721
			this.toggleZenMode(true, true);
I
isidor 已提交
722 723
		}

B
Benjamin Pasero 已提交
724
		// Restore Forced Editor Center Mode
725
		if (this.storageService.getBoolean(Workbench.centeredEditorLayoutActiveStorageKey, StorageScope.WORKSPACE, false)) {
I
isidor 已提交
726
			this.centerEditorLayout(true);
S
SrTobi 已提交
727
		}
728

729
		const onRestored = (error?: Error): IWorkbenchStartedInfo => {
B
Benjamin Pasero 已提交
730
			this.workbenchCreated = true;
731

732 733
			if (error) {
				errors.onUnexpectedError(error);
734
			}
I
isidor 已提交
735

736 737 738 739
			return {
				customKeybindingsCount: this.keybindingService.customKeybindingsCount(),
				pinnedViewlets: this.activitybarPart.getPinned(),
				restoredViewlet: viewletIdToRestore,
740
				restoredEditorsCount: this.editorService.visibleEditors.length
741 742
			};
		};
743

744
		return TPromise.join(restorePromises).then(() => onRestored(), error => onRestored(error));
E
Erich Gamma 已提交
745 746
	}

747 748 749
	private shouldRestoreLastOpenedViewlet(): boolean {
		if (!this.environmentService.isBuilt) {
			return true; // always restore sidebar when we are in development mode
E
Erich Gamma 已提交
750 751
		}

752 753 754 755
		const restore = this.storageService.getBoolean(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE);
		if (restore) {
			this.storageService.remove(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE); // only support once
		}
756

757
		return restore;
E
Erich Gamma 已提交
758 759
	}

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

B
Benjamin Pasero 已提交
763
		// Files to open, diff or create
764
		if (this.hasInitialFilesToOpen) {
I
isidor 已提交
765

B
Benjamin Pasero 已提交
766
			// Files to diff is exclusive
767
			const filesToDiff = this.toInputs(config.filesToDiff, false);
768
			if (filesToDiff && filesToDiff.length === 2) {
769 770 771 772 773
				return TPromise.as([<IResourceDiffInput>{
					leftResource: filesToDiff[0].resource,
					rightResource: filesToDiff[1].resource,
					options: { pinned: true }
				}]);
B
Benjamin Pasero 已提交
774
			}
I
isidor 已提交
775

776 777
			const filesToCreate = this.toInputs(config.filesToCreate, true);
			const filesToOpen = this.toInputs(config.filesToOpen, false);
I
isidor 已提交
778

779 780
			// Otherwise: Open/Create files
			return TPromise.as([...filesToOpen, ...filesToCreate]);
B
Benjamin Pasero 已提交
781
		}
I
isidor 已提交
782

783
		// Empty workbench
784
		else if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY && this.openUntitledFile()) {
B
Benjamin Pasero 已提交
785
			const isEmpty = this.editorGroupService.count === 1 && this.editorGroupService.activeGroup.count === 0;
786 787
			if (!isEmpty) {
				return TPromise.as([]); // do not open any empty untitled file if we restored editors from previous session
788
			}
B
Benjamin Pasero 已提交
789

790 791 792 793
			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 已提交
794

795
				return TPromise.as([<IUntitledResourceInput>{}]);
796
			});
797
		}
798

B
Benjamin Pasero 已提交
799 800
		return TPromise.as([]);
	}
801

802
	private toInputs(paths: IPath[], isNew: boolean): (IResourceInput | IUntitledResourceInput)[] {
B
Benjamin Pasero 已提交
803 804
		if (!paths || !paths.length) {
			return [];
805
		}
I
isidor 已提交
806

B
Benjamin Pasero 已提交
807
		return paths.map(p => {
808 809 810 811 812 813
			const resource = URI.file(p.filePath);
			let input: IResourceInput | IUntitledResourceInput;
			if (isNew) {
				input = { filePath: resource.fsPath, options: { pinned: true } } as IUntitledResourceInput;
			} else {
				input = { resource, options: { pinned: true } } as IResourceInput;
814
			}
E
Erich Gamma 已提交
815

816
			if (!isNew && p.lineNumber) {
B
Benjamin Pasero 已提交
817 818 819 820 821
				input.options.selection = {
					startLineNumber: p.lineNumber,
					startColumn: p.columnNumber
				};
			}
822

B
Benjamin Pasero 已提交
823 824
			return input;
		});
825 826
	}

827
	private openUntitledFile() {
828
		const startupEditor = this.configurationService.inspect('workbench.startupEditor');
B
Benjamin Pasero 已提交
829 830

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

838
		return startupEditor.value === 'newUntitledFile';
839
	}
E
Erich Gamma 已提交
840 841

	private initSettings(): void {
842

E
Erich Gamma 已提交
843
		// Sidebar visibility
I
isidor 已提交
844
		this.sideBarHidden = this.storageService.getBoolean(Workbench.sidebarHiddenStorageKey, StorageScope.WORKSPACE, this.contextService.getWorkbenchState() === WorkbenchState.EMPTY);
845

I
isidor 已提交
846
		// Panel part visibility
847
		const panelRegistry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
I
isidor 已提交
848
		this.panelHidden = this.storageService.getBoolean(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE, true);
849 850
		if (!panelRegistry.getDefaultPanelId()) {
			this.panelHidden = true; // we hide panel part if there is no default panel
851 852
		}

E
Erich Gamma 已提交
853
		// Sidebar position
854
		const sideBarPosition = this.configurationService.getValue<string>(Workbench.sidebarPositionConfigurationKey);
855
		this.sideBarPosition = (sideBarPosition === 'right') ? Position.RIGHT : Position.LEFT;
856

I
isidor 已提交
857
		// Panel position
858
		this.setPanelPositionFromStorageOrConfig();
859

860
		// Menubar visibility
861
		const menuBarVisibility = this.configurationService.getValue<MenuBarVisibility>(Workbench.menubarVisibilityConfigurationKey);
S
SteVen Batten 已提交
862
		this.setMenubarVisibility(menuBarVisibility, true);
863

B
Benjamin Pasero 已提交
864
		// Statusbar visibility
865
		const statusBarVisible = this.configurationService.getValue<string>(Workbench.statusbarVisibleConfigurationKey);
866
		this.statusBarHidden = !statusBarVisible;
867

S
Sanders Lauture 已提交
868
		// Activity bar visibility
869
		const activityBarVisible = this.configurationService.getValue<string>(Workbench.activityBarVisibleConfigurationKey);
S
Sanders Lauture 已提交
870
		this.activityBarHidden = !activityBarVisible;
871

872
		// Font aliasing
873
		this.fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
874

I
isidor 已提交
875 876
		// Zen mode
		this.zenMode = {
I
isidor 已提交
877
			active: false,
878
			transitionedToFullScreen: false,
879
			transitionedToCenteredEditorLayout: false,
880
			wasSideBarVisible: false,
881 882
			wasPanelVisible: false,
			transitionDisposeables: []
I
isidor 已提交
883
		};
E
Erich Gamma 已提交
884 885
	}

886 887 888 889 890
	private setPanelPositionFromStorageOrConfig() {
		const defaultPanelPosition = this.configurationService.getValue<string>(Workbench.defaultPanelPositionStorageKey);
		const panelPosition = this.storageService.get(Workbench.panelPositionStorageKey, StorageScope.WORKSPACE, defaultPanelPosition);
		this.panelPosition = (panelPosition === 'right') ? Position.RIGHT : Position.BOTTOM;
	}
891

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

898 899 900 901 902 903 904 905 906 907
		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;
908 909 910
			}
		}

911
		return null;
B
Benjamin Pasero 已提交
912 913
	}

914 915
	private setStatusBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.statusBarHidden = hidden;
B
Benjamin Pasero 已提交
916

917 918 919
		// Adjust CSS
		if (hidden) {
			this.workbench.addClass('nostatusbar');
E
Erich Gamma 已提交
920
		} else {
921
			this.workbench.removeClass('nostatusbar');
E
Erich Gamma 已提交
922 923
		}

924 925 926
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
927 928 929
		}
	}

930
	private setFontAliasing(aliasing: FontAliasingOption) {
931
		this.fontAliasing = aliasing;
S
Sanders Lauture 已提交
932

B
Benjamin Pasero 已提交
933 934 935 936 937
		// Remove all
		document.body.classList.remove(...fontAliasingValues.map(value => `monaco-font-aliasing-${value}`));

		// Add specific
		if (fontAliasingValues.some(option => option === aliasing)) {
938
			document.body.classList.add(`monaco-font-aliasing-${aliasing}`);
S
Sanders Lauture 已提交
939
		}
940 941
	}

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

	private renderWorkbench(): void {

		// Apply sidebar state as CSS class
		if (this.sideBarHidden) {
			this.workbench.addClass('nosidebar');
		}
969 970 971
		if (this.panelHidden) {
			this.workbench.addClass('nopanel');
		}
972 973 974
		if (this.statusBarHidden) {
			this.workbench.addClass('nostatusbar');
		}
E
Erich Gamma 已提交
975

B
Benjamin Pasero 已提交
976
		// Apply font aliasing
977 978
		this.setFontAliasing(this.fontAliasing);

979 980 981
		// Apply fullscreen state
		if (browser.isFullscreen()) {
			this.workbench.addClass('fullscreen');
B
Benjamin Pasero 已提交
982 983
		}

E
Erich Gamma 已提交
984
		// Create Parts
B
Benjamin Pasero 已提交
985
		this.createTitlebarPart();
986
		this.createMenubarPart();
E
Erich Gamma 已提交
987 988 989
		this.createActivityBarPart();
		this.createSidebarPart();
		this.createEditorPart();
990
		this.createPanelPart();
E
Erich Gamma 已提交
991 992
		this.createStatusbarPart();

993 994
		// Notification Handlers
		this.createNotificationsHandlers();
995

E
Erich Gamma 已提交
996
		// Add Workbench to DOM
J
Joao Moreno 已提交
997
		this.workbench.appendTo(this.container);
E
Erich Gamma 已提交
998 999
	}

B
Benjamin Pasero 已提交
1000 1001 1002 1003 1004 1005 1006
	private createTitlebarPart(): void {
		const titlebarContainer = $(this.workbench).div({
			'class': ['part', 'titlebar'],
			id: Identifiers.TITLEBAR_PART,
			role: 'contentinfo'
		});

1007
		this.titlebarPart.create(titlebarContainer.getHTMLElement());
B
Benjamin Pasero 已提交
1008 1009
	}

1010
	private createMenubarPart(): void {
1011 1012 1013 1014 1015
		const menubarContainer = $(this.workbench).div({
			'class': ['part', 'menubar'],
			id: Identifiers.MENUBAR_PART,
			role: 'menubar'
		});
B
Benjamin Pasero 已提交
1016

1017
		this.menubarPart.create(menubarContainer.getHTMLElement());
B
Benjamin Pasero 已提交
1018 1019

		this._register(this.menubarPart.onVisibilityChange((dimension => {
1020
			this._onMenubarVisibilityChange.fire(dimension);
B
Benjamin Pasero 已提交
1021
		})));
1022 1023
	}

E
Erich Gamma 已提交
1024
	private createActivityBarPart(): void {
B
Benjamin Pasero 已提交
1025
		const activitybarPartContainer = $(this.workbench)
E
Erich Gamma 已提交
1026 1027
			.div({
				'class': ['part', 'activitybar', this.sideBarPosition === Position.LEFT ? 'left' : 'right'],
1028 1029
				id: Identifiers.ACTIVITYBAR_PART,
				role: 'navigation'
E
Erich Gamma 已提交
1030 1031
			});

1032
		this.activitybarPart.create(activitybarPartContainer.getHTMLElement());
E
Erich Gamma 已提交
1033 1034 1035
	}

	private createSidebarPart(): void {
B
Benjamin Pasero 已提交
1036
		const sidebarPartContainer = $(this.workbench)
E
Erich Gamma 已提交
1037 1038
			.div({
				'class': ['part', 'sidebar', this.sideBarPosition === Position.LEFT ? 'left' : 'right'],
1039 1040
				id: Identifiers.SIDEBAR_PART,
				role: 'complementary'
E
Erich Gamma 已提交
1041 1042
			});

1043
		this.sidebarPart.create(sidebarPartContainer.getHTMLElement());
E
Erich Gamma 已提交
1044 1045
	}

I
isidor 已提交
1046
	private createPanelPart(): void {
B
Benjamin Pasero 已提交
1047
		const panelPartContainer = $(this.workbench)
I
isidor 已提交
1048
			.div({
1049
				'class': ['part', 'panel', this.panelPosition === Position.BOTTOM ? 'bottom' : 'right'],
1050 1051
				id: Identifiers.PANEL_PART,
				role: 'complementary'
I
isidor 已提交
1052 1053
			});

1054
		this.panelPart.create(panelPartContainer.getHTMLElement());
I
isidor 已提交
1055 1056
	}

E
Erich Gamma 已提交
1057
	private createEditorPart(): void {
B
Benjamin Pasero 已提交
1058
		const editorContainer = $(this.workbench)
E
Erich Gamma 已提交
1059
			.div({
1060
				'class': ['part', 'editor'],
1061 1062
				id: Identifiers.EDITOR_PART,
				role: 'main'
E
Erich Gamma 已提交
1063 1064
			});

1065
		this.editorPart.create(editorContainer.getHTMLElement());
E
Erich Gamma 已提交
1066 1067 1068
	}

	private createStatusbarPart(): void {
B
Benjamin Pasero 已提交
1069
		const statusbarContainer = $(this.workbench).div({
E
Erich Gamma 已提交
1070
			'class': ['part', 'statusbar'],
1071 1072
			id: Identifiers.STATUSBAR_PART,
			role: 'contentinfo'
E
Erich Gamma 已提交
1073 1074
		});

1075
		this.statusbarPart.create(statusbarContainer.getHTMLElement());
E
Erich Gamma 已提交
1076 1077
	}

1078 1079
	private createNotificationsHandlers(): void {

1080
		// Notifications Center
1081
		this.notificationsCenter = this._register(this.instantiationService.createInstance(NotificationsCenter, this.workbench.getHTMLElement(), this.notificationService.model));
1082

1083
		// Notifications Toasts
1084
		this.notificationsToasts = this._register(this.instantiationService.createInstance(NotificationsToasts, this.workbench.getHTMLElement(), this.notificationService.model));
1085

1086
		// Notifications Alerts
1087
		this._register(this.instantiationService.createInstance(NotificationsAlerts, this.notificationService.model));
1088 1089 1090 1091

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

1092
		// Eventing
1093
		this._register(this.notificationsCenter.onDidChangeVisibility(() => {
1094 1095 1096 1097 1098 1099 1100 1101

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

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

1102
		// Register Commands
1103
		registerNotificationCommands(this.notificationsCenter, this.notificationsToasts);
1104 1105
	}

1106
	getInstantiationService(): IInstantiationService {
E
Erich Gamma 已提交
1107 1108 1109
		return this.instantiationService;
	}

1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
	dispose(reason = ShutdownReason.QUIT): void {
		super.dispose();

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

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

		this.workbenchShutdown = true;
	}

	//#region IPartService

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

B
Benjamin Pasero 已提交
1138
	private _onMenubarVisibilityChange: Emitter<DOM.Dimension> = this._register(new Emitter<DOM.Dimension>());
1139 1140
	get onMenubarVisibilityChange(): Event<DOM.Dimension> { return this._onMenubarVisibilityChange.event; }

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

1143 1144 1145
	isCreated(): boolean {
		return this.workbenchCreated && this.workbenchStarted;
	}
1146

1147 1148 1149 1150 1151
	hasFocus(part: Parts): boolean {
		const activeElement = document.activeElement;
		if (!activeElement) {
			return false;
		}
1152

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

1157 1158 1159 1160 1161 1162
	getContainer(part: Parts): HTMLElement {
		let container: HTMLElement = null;
		switch (part) {
			case Parts.TITLEBAR_PART:
				container = this.titlebarPart.getContainer();
				break;
B
Benjamin Pasero 已提交
1163 1164 1165
			case Parts.MENUBAR_PART:
				container = this.menubarPart.getContainer();
				break;
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
			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;
		}
1182

1183 1184
		return container;
	}
1185

1186 1187 1188
	isVisible(part: Parts): boolean {
		switch (part) {
			case Parts.TITLEBAR_PART:
B
Benjamin Pasero 已提交
1189
				return this.getCustomTitleBarStyle() === 'custom' && !browser.isFullscreen();
B
Benjamin Pasero 已提交
1190
			case Parts.MENUBAR_PART:
S
SteVen Batten 已提交
1191
				return !isMacintosh && this.isVisible(Parts.TITLEBAR_PART) && !(this.menubarVisibility === 'hidden' || (this.menubarVisibility === 'default' && browser.isFullscreen()));
1192 1193 1194 1195 1196 1197 1198 1199
			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 已提交
1200
		}
1201

1202
		return true; // any other part cannot be hidden
E
Erich Gamma 已提交
1203 1204
	}

1205 1206 1207
	getTitleBarOffset(): number {
		let offset = 0;
		if (this.isVisible(Parts.TITLEBAR_PART)) {
S
SteVen Batten 已提交
1208
			offset = this.workbenchLayout.partLayoutInfo.titlebar.height;
E
Erich Gamma 已提交
1209
		}
1210 1211

		return offset;
E
Erich Gamma 已提交
1212
	}
1213

1214
	getWorkbenchElementId(): string {
1215 1216
		return Identifiers.WORKBENCH_CONTAINER;
	}
1217

I
isidor 已提交
1218
	toggleZenMode(skipLayout?: boolean, restoring = false): void {
I
isidor 已提交
1219
		this.zenMode.active = !this.zenMode.active;
1220
		this.zenMode.transitionDisposeables = dispose(this.zenMode.transitionDisposeables);
1221

1222 1223
		// 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)
1224
		let toggleFullScreen = false;
1225 1226

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

I
isidor 已提交
1230
			toggleFullScreen = !browser.isFullscreen() && config.fullScreen;
I
isidor 已提交
1231
			this.zenMode.transitionedToFullScreen = restoring ? config.fullScreen : toggleFullScreen;
1232
			this.zenMode.transitionedToCenteredEditorLayout = !this.isEditorLayoutCentered() && config.centerLayout;
1233 1234
			this.zenMode.wasSideBarVisible = this.isVisible(Parts.SIDEBAR_PART);
			this.zenMode.wasPanelVisible = this.isVisible(Parts.PANEL_PART);
1235

1236 1237
			this.setPanelHidden(true, true).done(void 0, errors.onUnexpectedError);
			this.setSideBarHidden(true, true).done(void 0, errors.onUnexpectedError);
I
isidor 已提交
1238

1239 1240 1241
			if (config.hideActivityBar) {
				this.setActivityBarHidden(true, true);
			}
1242

I
isidor 已提交
1243
			if (config.hideStatusBar) {
I
isidor 已提交
1244 1245
				this.setStatusBarHidden(true, true);
			}
1246

1247 1248
			if (config.hideTabs && this.editorPart.partOptions.showTabs) {
				this.zenMode.transitionDisposeables.push(this.editorPart.enforcePartOptions({ showTabs: false }));
I
isidor 已提交
1249
			}
1250 1251 1252 1253

			if (config.centerLayout) {
				this.centerEditorLayout(true, true);
			}
1254 1255 1256 1257
		}

		// Zen Mode Inactive
		else {
1258
			if (this.zenMode.wasPanelVisible) {
1259
				this.setPanelHidden(false, true).done(void 0, errors.onUnexpectedError);
1260
			}
1261

1262
			if (this.zenMode.wasSideBarVisible) {
1263
				this.setSideBarHidden(false, true).done(void 0, errors.onUnexpectedError);
1264
			}
1265

1266 1267 1268
			if (this.zenMode.transitionedToCenteredEditorLayout) {
				this.centerEditorLayout(false, true);
			}
1269

1270 1271
			// Status bar and activity bar visibility come from settings -> update their visibility.
			this.onDidUpdateConfiguration(true);
1272

B
Benjamin Pasero 已提交
1273
			this.editorGroupService.activeGroup.focus();
1274

1275
			toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
I
isidor 已提交
1276
		}
1277

1278
		this.inZenMode.set(this.zenMode.active);
I
isidor 已提交
1279

I
isidor 已提交
1280
		if (!skipLayout) {
1281
			this.layout();
I
isidor 已提交
1282
		}
1283

1284
		if (toggleFullScreen) {
1285
			this.windowService.toggleFullScreen().done(void 0, errors.onUnexpectedError);
1286
		}
I
isidor 已提交
1287 1288
	}

1289
	layout(options?: ILayoutOptions): void {
J
Joao Moreno 已提交
1290 1291
		this.contextViewService.layout();

1292 1293 1294 1295 1296
		if (this.workbenchStarted && !this.workbenchShutdown) {
			this.workbenchLayout.layout(options);
		}
	}

1297
	isEditorLayoutCentered(): boolean {
I
isidor 已提交
1298
		return this.editorPart.isLayoutCentered();
S
SrTobi 已提交
1299 1300
	}

1301
	centerEditorLayout(active: boolean, skipLayout?: boolean): void {
I
isidor 已提交
1302
		this.storageService.store(Workbench.centeredEditorLayoutActiveStorageKey, active, StorageScope.WORKSPACE);
B
Benjamin Pasero 已提交
1303

1304
		// Enter Centered Editor Layout
I
isidor 已提交
1305
		this.editorPart.centerLayout(active);
1306

1307 1308 1309
		if (!skipLayout) {
			this.layout();
		}
S
SrTobi 已提交
1310 1311
	}

1312
	resizePart(part: Parts, sizeChange: number): void {
1313 1314 1315 1316 1317 1318 1319
		switch (part) {
			case Parts.SIDEBAR_PART:
			case Parts.PANEL_PART:
			case Parts.EDITOR_PART:
				this.workbenchLayout.resizePart(part, sizeChange);
				break;
			default:
B
Benjamin Pasero 已提交
1320
				return; // Cannot resize other parts
1321 1322 1323
		}
	}

1324 1325
	setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.activityBarHidden = hidden;
1326

1327 1328 1329
		// Layout
		if (!skipLayout) {
			this.workbenchLayout.layout();
1330
		}
1331
	}
1332

1333 1334 1335 1336 1337 1338 1339
	setSideBarHidden(hidden: boolean, skipLayout?: boolean): TPromise<void> {
		this.sideBarHidden = hidden;
		this.sideBarVisibleContext.set(!hidden);

		// Adjust CSS
		if (hidden) {
			this.workbench.addClass('nosidebar');
1340
		} else {
1341
			this.workbench.removeClass('nosidebar');
1342 1343
		}

1344 1345 1346 1347 1348 1349 1350 1351 1352
		// 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 已提交
1353 1354
				} else {
					this.editorGroupService.activeGroup.focus();
1355 1356 1357 1358 1359 1360 1361 1362
				}
			});
		}

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

1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382
		return promise.then(() => {

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

			// Layout
			if (!skipLayout) {
				this.workbenchLayout.layout();
			}
		});
1383
	}
1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398

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

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

		// If panel part becomes hidden, also hide the current active panel if any
		let promise = TPromise.wrap<any>(null);
		if (hidden && this.panelPart.getActivePanel()) {
			promise = this.panelPart.hideActivePanel().then(() => {
B
Benjamin Pasero 已提交
1399
				this.editorGroupService.activeGroup.focus(); // Pass focus to editor group if panel part is now hidden
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461
			});
		}

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

		return promise.then(() => {

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

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

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

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

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

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

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

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

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

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

S
SteVen Batten 已提交
1462 1463
	setMenubarVisibility(visibility: MenuBarVisibility, skipLayout: boolean): void {
		this.menubarVisibility = visibility;
1464 1465 1466 1467 1468 1469

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

1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
	getPanelPosition(): Position {
		return this.panelPosition;
	}

	setPanelPosition(position: Position): TPromise<void> {
		return (this.panelHidden ? this.setPanelHidden(false, true /* Skip Layout */) : TPromise.as(undefined)).then(() => {
			const newPositionValue = (position === Position.BOTTOM) ? 'bottom' : 'right';
			const oldPositionValue = (this.panelPosition === Position.BOTTOM) ? 'bottom' : 'right';
			this.panelPosition = position;
			this.storageService.store(Workbench.panelPositionStorageKey, Position[this.panelPosition].toLowerCase(), StorageScope.WORKSPACE);

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

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

			// Layout
			this.workbenchLayout.layout();
		});
1491
	}
1492 1493

	//#endregion
I
isidor 已提交
1494
}