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

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

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

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

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

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

145 146
type WorkbenchView = StatusbarPart | TitlebarPart | SidebarPart | EditorPart | ActivitybarPart | PanelPart;

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',
S
SteVen Batten 已提交
154
	STATUSBAR_PART: 'workbench.parts.statusbar'
155 156
};

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

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

174 175 176 177 178 179
interface IWorkbenchUIState {
	lastPanelHeight?: number;
	lastPanelWidth?: number;
	lastSidebarDimension?: number;
}

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

182
	private static readonly workbenchGridUIStateStorageKey = 'workbench.layout.state';
183
	private static readonly sidebarHiddenStorageKey = 'workbench.sidebar.hidden';
184
	private static readonly menubarVisibilityConfigurationKey = 'window.menuBarVisibility';
185 186
	private static readonly panelHiddenStorageKey = 'workbench.panel.hidden';
	private static readonly zenModeActiveStorageKey = 'workbench.zenmode.active';
187
	private static readonly centeredEditorLayoutActiveStorageKey = 'workbench.centerededitorlayout.active';
188
	private static readonly panelPositionStorageKey = 'workbench.panel.location';
189
	private static readonly defaultPanelPositionStorageKey = 'workbench.panel.defaultLocation';
190 191 192 193 194
	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';
195

196
	_serviceBrand: any;
197

E
Erich Gamma 已提交
198
	private workbenchParams: WorkbenchParams;
B
Benjamin Pasero 已提交
199
	private workbench: HTMLElement;
E
Erich Gamma 已提交
200
	private workbenchStarted: boolean;
B
Benjamin Pasero 已提交
201
	private workbenchRestored: boolean;
E
Erich Gamma 已提交
202
	private workbenchShutdown: boolean;
203

204 205
	private editorService: EditorService;
	private editorGroupService: IEditorGroupsService;
J
Joao Moreno 已提交
206
	private contextViewService: ContextViewService;
207
	private contextKeyService: IContextKeyService;
208
	private keybindingService: IKeybindingService;
209
	private backupFileService: IBackupFileService;
210
	private fileService: IFileService;
211 212
	private quickInput: QuickInputService;

213
	private workbenchGrid: SerializableGrid<WorkbenchView> | WorkbenchLayout;
214

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

E
Erich Gamma 已提交
225
	private sideBarHidden: boolean;
S
SteVen Batten 已提交
226
	private titleBarHidden: boolean;
227
	private statusBarHidden: boolean;
S
Sanders Lauture 已提交
228
	private activityBarHidden: boolean;
229
	private menubarToggled: boolean;
E
Erich Gamma 已提交
230
	private sideBarPosition: Position;
I
isidor 已提交
231
	private panelPosition: Position;
I
isidor 已提交
232
	private panelHidden: boolean;
S
SteVen Batten 已提交
233
	private menubarVisibility: MenuBarVisibility;
234 235
	private zenMode: IZenMode;
	private fontAliasing: FontAliasingOption;
236
	private hasInitialFilesToOpen: boolean;
237
	private shouldCenterLayout = false;
238
	private uiState: IWorkbenchUIState = {};
239

I
isidor 已提交
240
	private inZenMode: IContextKey<boolean>;
241
	private sideBarVisibleContext: IContextKey<boolean>;
242

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

245
	constructor(
246
		private container: HTMLElement,
J
Joao Moreno 已提交
247
		private configuration: IWindowConfiguration,
248
		serviceCollection: ServiceCollection,
249
		private lifecycleService: LifecycleService,
J
Joao Moreno 已提交
250
		private mainProcessClient: IPCClient,
251 252 253 254 255 256 257 258
		@IInstantiationService private readonly instantiationService: IInstantiationService,
		@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
		@IStorageService private readonly storageService: IStorageService,
		@IConfigurationService private readonly configurationService: WorkspaceService,
		@IWorkbenchThemeService private readonly themeService: WorkbenchThemeService,
		@IEnvironmentService private readonly environmentService: IEnvironmentService,
		@IWindowService private readonly windowService: IWindowService,
		@INotificationService private readonly notificationService: NotificationService
259
	) {
260
		super();
E
Erich Gamma 已提交
261

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

264
		this.hasInitialFilesToOpen =
B
Benjamin Pasero 已提交
265 266 267
			(configuration.filesToCreate && configuration.filesToCreate.length > 0) ||
			(configuration.filesToOpen && configuration.filesToOpen.length > 0) ||
			(configuration.filesToDiff && configuration.filesToDiff.length > 0);
268 269
	}

J
Johannes Rieken 已提交
270
	startup(): Promise<IWorkbenchStartedInfo> {
271
		this.workbenchStarted = true;
E
Erich Gamma 已提交
272

B
Benjamin Pasero 已提交
273
		// Create Workbench Container
274
		this.createWorkbench();
E
Erich Gamma 已提交
275

276 277
		// Install some global actions
		this.createGlobalActions();
278

279 280
		// Services
		this.initServices();
E
Erich Gamma 已提交
281

282 283
		// Context Keys
		this.handleContextKeys();
J
Joao Moreno 已提交
284

285 286
		// Register Listeners
		this.registerListeners();
E
Erich Gamma 已提交
287

288 289
		// Settings
		this.initSettings();
E
Erich Gamma 已提交
290

291 292
		// Create Workbench and Parts
		this.renderWorkbench();
293

294 295
		// Workbench Layout
		this.createWorkbenchLayout();
B
polish  
Benjamin Pasero 已提交
296

J
Joao Moreno 已提交
297 298
		// Driver
		if (this.environmentService.driverHandle) {
299
			registerWindowDriver(this.mainProcessClient, this.configuration.windowId, this.instantiationService).then(disposable => this._register(disposable));
J
Joao Moreno 已提交
300 301
		}

302
		// Restore Parts
B
Benjamin Pasero 已提交
303 304
		return this.restoreParts();
	}
305

B
Benjamin Pasero 已提交
306
	private createWorkbench(): void {
B
Benjamin Pasero 已提交
307 308
		this.workbench = document.createElement('div');
		this.workbench.id = Identifiers.WORKBENCH_CONTAINER;
309
		DOM.addClass(this.workbench, 'monaco-workbench');
S
SteVen Batten 已提交
310

B
Benjamin Pasero 已提交
311 312 313
		this._register(DOM.addDisposableListener(this.workbench, DOM.EventType.SCROLL, () => {
			this.workbench.scrollTop = 0; // Prevent workbench from scrolling #55456
		}));
314
	}
E
Erich Gamma 已提交
315

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

B
Benjamin Pasero 已提交
319
		// Actions registered here to adjust for developing vs built workbench
320
		const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
R
Rob Lourens 已提交
321 322
		registry.registerWorkbenchAction(new SyncActionDescriptor(ReloadWindowAction, ReloadWindowAction.ID, ReloadWindowAction.LABEL, isDeveloping ? { primary: KeyMod.CtrlCmd | KeyCode.KEY_R } : undefined), 'Reload Window');
		registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleDevToolsAction, ToggleDevToolsAction.ID, ToggleDevToolsAction.LABEL, isDeveloping ? { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_I, mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_I } } : undefined), 'Developer: Toggle Developer Tools', localize('developer', "Developer"));
323 324
		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');
325
		registry.registerWorkbenchAction(new SyncActionDescriptor(LogStorageAction, LogStorageAction.ID, LogStorageAction.LABEL), 'Developer: Log Storage', localize('developer', "Developer"));
326

327
		// Actions for macOS native tabs management (only when enabled)
328
		const windowConfig = this.configurationService.getValue<IWindowConfiguration>();
329
		if (windowConfig && windowConfig.window && windowConfig.window.nativeTabs) {
330
			registry.registerWorkbenchAction(new SyncActionDescriptor(NewWindowTab, NewWindowTab.ID, NewWindowTab.LABEL), 'New Window Tab');
331 332 333 334 335
			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');
336
		}
337 338
	}

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

E
Erich Gamma 已提交
342
		// Services we contribute
343
		serviceCollection.set(IPartService, this);
E
Erich Gamma 已提交
344

345
		// Clipboard
J
Johannes Rieken 已提交
346
		serviceCollection.set(IClipboardService, new SyncDescriptor(ClipboardService));
347

348 349 350 351
		// Status bar
		this.statusbarPart = this.instantiationService.createInstance(StatusbarPart, Identifiers.STATUSBAR_PART);
		serviceCollection.set(IStatusbarService, this.statusbarPart);

352 353 354
		// Progress 2
		serviceCollection.set(IProgressService2, new SyncDescriptor(ProgressService2));

355
		// Keybindings
A
Alex Dima 已提交
356
		this.contextKeyService = this.instantiationService.createInstance(ContextKeyService);
357
		serviceCollection.set(IContextKeyService, this.contextKeyService);
358

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

362 363 364
		// List
		serviceCollection.set(IListService, this.instantiationService.createInstance(ListService));

J
Joao Moreno 已提交
365
		// Context view service
B
Benjamin Pasero 已提交
366
		this.contextViewService = this.instantiationService.createInstance(ContextViewService, this.workbench);
J
Joao Moreno 已提交
367 368
		serviceCollection.set(IContextViewService, this.contextViewService);

S
SteVen Batten 已提交
369
		// Use themable context menus when custom titlebar is enabled to match custom menubar
B
Benjamin Pasero 已提交
370
		if (!isMacintosh && this.useCustomTitleBarStyle()) {
J
fix npe  
Johannes Rieken 已提交
371
			serviceCollection.set(IContextMenuService, new SyncDescriptor(HTMLContextMenuService, [null]));
S
SteVen Batten 已提交
372 373 374
		} else {
			serviceCollection.set(IContextMenuService, new SyncDescriptor(NativeContextMenuService));
		}
375

376 377
		// Menus/Actions
		serviceCollection.set(IMenuService, new SyncDescriptor(MenuService));
378

P
Pine Wu 已提交
379
		// Sidebar part
380
		this.sidebarPart = this.instantiationService.createInstance(SidebarPart, Identifiers.SIDEBAR_PART);
P
Pine Wu 已提交
381 382

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

I
isidor 已提交
385
		// Panel service (panel part)
386 387
		this.panelPart = this.instantiationService.createInstance(PanelPart, Identifiers.PANEL_PART);
		serviceCollection.set(IPanelService, this.panelPart);
I
isidor 已提交
388

389 390 391
		// views service
		const viewsService = this.instantiationService.createInstance(ViewsService);
		serviceCollection.set(IViewsService, viewsService);
S
Sandeep Somavarapu 已提交
392

E
Erich Gamma 已提交
393
		// Activity service (activitybar part)
394
		this.activitybarPart = this.instantiationService.createInstance(ActivitybarPart, Identifiers.ACTIVITYBAR_PART);
I
isidor 已提交
395 396
		const activityService = this.instantiationService.createInstance(ActivityService, this.activitybarPart, this.panelPart);
		serviceCollection.set(IActivityService, activityService);
E
Erich Gamma 已提交
397

398 399 400
		// File Service
		this.fileService = this.instantiationService.createInstance(RemoteFileService);
		serviceCollection.set(IFileService, this.fileService);
S
#47154  
Sandeep Somavarapu 已提交
401
		this.configurationService.acquireFileService(this.fileService);
A
Alex Dima 已提交
402
		this.themeService.acquireFileService(this.fileService);
403

404 405
		// Editor and Group services
		const restorePreviousEditorState = !this.hasInitialFilesToOpen;
406
		this.editorPart = this.instantiationService.createInstance(EditorPart, Identifiers.EDITOR_PART, restorePreviousEditorState);
B
Benjamin Pasero 已提交
407
		this.editorGroupService = this.editorPart;
408 409 410
		serviceCollection.set(IEditorGroupsService, this.editorPart);
		this.editorService = this.instantiationService.createInstance(EditorService);
		serviceCollection.set(IEditorService, this.editorService);
E
Erich Gamma 已提交
411

412 413 414
		// Title bar
		this.titlebarPart = this.instantiationService.createInstance(TitlebarPart, Identifiers.TITLEBAR_PART);
		serviceCollection.set(ITitleService, this.titlebarPart);
B
Benjamin Pasero 已提交
415

416
		// History
417
		serviceCollection.set(IHistoryService, new SyncDescriptor(HistoryService));
418

M
Martin Aeschlimann 已提交
419 420 421
		// File Dialogs
		serviceCollection.set(IFileDialogService, new SyncDescriptor(FileDialogService));

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

430
		// Text File Service
431
		serviceCollection.set(ITextFileService, new SyncDescriptor(TextFileService));
432

433
		// File Decorations
J
Johannes Rieken 已提交
434
		serviceCollection.set(IDecorationsService, new SyncDescriptor(FileDecorationsService));
435

J
Joao Moreno 已提交
436
		// SCM Service
437
		serviceCollection.set(ISCMService, new SyncDescriptor(SCMService));
438

J
Joao Moreno 已提交
439
		// Inactive extension URL handler
J
Joao Moreno 已提交
440
		serviceCollection.set(IExtensionUrlHandler, new SyncDescriptor(ExtensionUrlHandler));
J
Joao Moreno 已提交
441

B
Benjamin Pasero 已提交
442
		// Text Model Resolver Service
443
		serviceCollection.set(ITextModelService, new SyncDescriptor(TextModelResolverService));
B
Benjamin Pasero 已提交
444

445 446 447 448
		// JSON Editing
		const jsonEditingService = this.instantiationService.createInstance(JSONEditingService);
		serviceCollection.set(IJSONEditingService, jsonEditingService);

449 450 451
		// Workspace Editing
		serviceCollection.set(IWorkspaceEditingService, new SyncDescriptor(WorkspaceEditingService));

452 453 454
		// Keybinding Editing
		serviceCollection.set(IKeybindingEditingService, this.instantiationService.createInstance(KeybindingsEditingService));

455
		// Configuration Resolver
456
		serviceCollection.set(IConfigurationResolverService, new SyncDescriptor(ConfigurationResolverService, [process.env]));
457

E
Erich Gamma 已提交
458
		// Quick open service (quick open controller)
459 460
		this.quickOpen = this.instantiationService.createInstance(QuickOpenController);
		serviceCollection.set(IQuickOpenService, this.quickOpen);
461

C
Christof Marti 已提交
462 463 464 465
		// Quick input service
		this.quickInput = this.instantiationService.createInstance(QuickInputService);
		serviceCollection.set(IQuickInputService, this.quickInput);

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

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

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

480
		this.instantiationService.createInstance(DefaultConfigurationExportHelper);
481

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

485
	//#region event handling
E
Erich Gamma 已提交
486

487
	private registerListeners(): void {
I
isidor 已提交
488

489
		// Storage
490
		this._register(this.storageService.onWillSaveState(e => this.saveState(e)));
491

492
		// Listen to visible editor changes
493
		this._register(this.editorService.onDidVisibleEditorsChange(() => this.onDidVisibleEditorsChange()));
B
Benjamin Pasero 已提交
494

495 496 497
		// Listen to editor closing (if we run with --wait)
		const filesToWait = this.workbenchParams.configuration.filesToWait;
		if (filesToWait) {
498
			const resourcesToWaitFor = filesToWait.paths.map(p => p.fileUri);
499
			const waitMarkerFile = URI.file(filesToWait.waitMarkerFilePath);
500
			const listenerDispose = this.editorService.onDidCloseEditor(() => this.onEditorClosed(listenerDispose, resourcesToWaitFor, waitMarkerFile));
I
isidor 已提交
501

502
			this._register(listenerDispose);
503
		}
S
Sanders Lauture 已提交
504

505
		// Configuration changes
506
		this._register(this.configurationService.onDidChangeConfiguration(() => this.onDidUpdateConfiguration()));
I
isidor 已提交
507

508
		// Fullscreen changes
509
		this._register(browser.onDidChangeFullscreen(() => this.onFullscreenChanged()));
B
Benjamin Pasero 已提交
510 511 512 513

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

516
	private onFullscreenChanged(): void {
S
SrTobi 已提交
517

518 519 520
		// Apply as CSS class
		const isFullscreen = browser.isFullscreen();
		if (isFullscreen) {
B
Benjamin Pasero 已提交
521
			DOM.addClass(this.workbench, 'fullscreen');
522
		} else {
B
Benjamin Pasero 已提交
523 524
			DOM.removeClass(this.workbench, 'fullscreen');

525 526 527 528
			if (this.zenMode.transitionedToFullScreen && this.zenMode.active) {
				this.toggleZenMode();
			}
		}
E
Erich Gamma 已提交
529

530
		// Changing fullscreen state of the window has an impact on custom title bar visibility, so we need to update
B
Benjamin Pasero 已提交
531
		if (this.useCustomTitleBarStyle()) {
532 533 534
			this._onTitleBarVisibilityChange.fire();
			this.layout(); // handle title bar when fullscreen changes
		}
535 536
	}

537 538 539 540
	private onMenubarToggled(visible: boolean) {
		if (visible !== this.menubarToggled) {
			this.menubarToggled = visible;

541 542
			if (browser.isFullscreen() && (this.menubarVisibility === 'toggle' || this.menubarVisibility === 'default')) {
				this._onTitleBarVisibilityChange.fire();
543 544 545 546 547
				this.layout();
			}
		}
	}

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

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

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

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

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

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

587
		this.setPanelPositionFromStorageOrConfig();
E
Erich Gamma 已提交
588

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

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

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

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

610
	//#endregion
B
Benjamin Pasero 已提交
611

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

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

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

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

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

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

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

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

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

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

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

667
		const inputFocused = InputFocusedContext.bindTo(this.contextKeyService);
B
Benjamin Pasero 已提交
668 669 670 671 672 673 674 675 676 677 678

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

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

			if (isInputFocused) {
				const tracker = DOM.trackFocus(document.activeElement as HTMLElement);
J
Joao Moreno 已提交
679
				Event.once(tracker.onDidBlur)(() => {
B
Benjamin Pasero 已提交
680 681 682 683 684 685 686 687
					inputFocused.set(activeElementIsInput());

					tracker.dispose();
				});
			}
		}

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

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

695 696 697 698 699
		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);
		}));
700

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

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

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

714
		updateSplitEditorsVerticallyContext();
715
	}
E
Erich Gamma 已提交
716

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

720 721
		// Restore Editorpart
		perf.mark('willRestoreEditors');
722
		restorePromises.push(this.editorPart.whenRestored.then(() => {
B
Benjamin Pasero 已提交
723 724 725 726

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

B
Benjamin Pasero 已提交
729 730 731 732 733 734 735 736 737 738 739
				return Promise.resolve();
			}

			const editorsToOpen = this.resolveEditorsToOpen();

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

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

741 742 743 744
		// Restore Sidebar
		let viewletIdToRestore: string;
		if (!this.sideBarHidden) {
			this.sideBarVisibleContext.set(true);
745

746
			if (this.shouldRestoreLastOpenedViewlet()) {
747
				viewletIdToRestore = this.storageService.get(SidebarPart.activeViewletSettingsKey, StorageScope.WORKSPACE);
748
			}
749

750
			if (!viewletIdToRestore) {
I
isidor 已提交
751
				viewletIdToRestore = this.sidebarPart.getDefaultViewletId();
752
			}
E
Erich Gamma 已提交
753

754
			perf.mark('willRestoreViewlet');
I
isidor 已提交
755 756
			restorePromises.push(this.sidebarPart.openViewlet(viewletIdToRestore)
				.then(viewlet => viewlet || this.sidebarPart.openViewlet(this.sidebarPart.getDefaultViewletId()))
B
Benjamin Pasero 已提交
757
				.then(() => perf.mark('didRestoreViewlet')));
758 759
		}

760 761
		// Restore Panel
		const panelRegistry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
762
		const panelId = this.storageService.get(PanelPart.activePanelSettingsKey, StorageScope.WORKSPACE, panelRegistry.getDefaultPanelId());
763
		if (!this.panelHidden && !!panelId) {
764
			perf.mark('willRestorePanel');
765
			const isPanelToRestoreEnabled = !!this.panelPart.getPanels().filter(p => p.id === panelId).length;
766
			const panelIdToRestore = isPanelToRestoreEnabled ? panelId : panelRegistry.getDefaultPanelId();
767 768
			this.panelPart.openPanel(panelIdToRestore, false);
			perf.mark('didRestorePanel');
I
isidor 已提交
769 770
		}

771 772 773
		// Restore Zen Mode if active and supported for restore on startup
		const zenConfig = this.configurationService.getValue<IZenModeSettings>('zenMode');
		const wasZenActive = this.storageService.getBoolean(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE, false);
774
		if (wasZenActive && zenConfig.restore) {
I
isidor 已提交
775
			this.toggleZenMode(true, true);
I
isidor 已提交
776 777
		}

B
Benjamin Pasero 已提交
778
		// Restore Forced Editor Center Mode
779
		if (this.storageService.getBoolean(Workbench.centeredEditorLayoutActiveStorageKey, StorageScope.WORKSPACE, false)) {
I
isidor 已提交
780
			this.centerEditorLayout(true);
S
SrTobi 已提交
781
		}
782

783
		const onRestored = (error?: Error): IWorkbenchStartedInfo => {
B
Benjamin Pasero 已提交
784 785 786 787 788
			this.workbenchRestored = true;

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

789 790 791 792 793 794 795
			// Set lifecycle phase to `Eventually` after a short delay and when
			// idle (min 2.5sec, max 5sec)
			setTimeout(() => {
				this._register(runWhenIdle(() => {
					this.lifecycleService.phase = LifecyclePhase.Eventually;
				}, 2500));
			}, 2500);
796

797 798
			if (error) {
				errors.onUnexpectedError(error);
799
			}
I
isidor 已提交
800

801 802
			return {
				customKeybindingsCount: this.keybindingService.customKeybindingsCount(),
P
Pine Wu 已提交
803
				pinnedViewlets: this.activitybarPart.getPinnedViewletIds(),
804
				restoredViewlet: viewletIdToRestore,
805
				restoredEditorsCount: this.editorService.visibleEditors.length
806 807
			};
		};
808

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

812 813 814
	private shouldRestoreLastOpenedViewlet(): boolean {
		if (!this.environmentService.isBuilt) {
			return true; // always restore sidebar when we are in development mode
E
Erich Gamma 已提交
815 816
		}

817 818
		// always restore sidebar when the window was reloaded
		return this.lifecycleService.startupKind === StartupKind.ReloadedWindow;
E
Erich Gamma 已提交
819 820
	}

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

B
Benjamin Pasero 已提交
824
		// Files to open, diff or create
825
		if (this.hasInitialFilesToOpen) {
I
isidor 已提交
826

B
Benjamin Pasero 已提交
827
			// Files to diff is exclusive
828
			const filesToDiff = this.toInputs(config.filesToDiff, false);
829
			if (filesToDiff && filesToDiff.length === 2) {
B
Benjamin Pasero 已提交
830
				return [<IResourceDiffInput>{
831 832
					leftResource: filesToDiff[0].resource,
					rightResource: filesToDiff[1].resource,
B
Benjamin Pasero 已提交
833
					options: { pinned: true },
B
Benjamin Pasero 已提交
834
					forceFile: true
B
Benjamin Pasero 已提交
835
				}];
B
Benjamin Pasero 已提交
836
			}
I
isidor 已提交
837

838 839
			const filesToCreate = this.toInputs(config.filesToCreate, true);
			const filesToOpen = this.toInputs(config.filesToOpen, false);
I
isidor 已提交
840

841
			// Otherwise: Open/Create files
B
Benjamin Pasero 已提交
842
			return [...filesToOpen, ...filesToCreate];
B
Benjamin Pasero 已提交
843
		}
I
isidor 已提交
844

845
		// Empty workbench
846
		else if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY && this.openUntitledFile()) {
B
Benjamin Pasero 已提交
847
			const isEmpty = this.editorGroupService.count === 1 && this.editorGroupService.activeGroup.count === 0;
848
			if (!isEmpty) {
B
Benjamin Pasero 已提交
849
				return []; // do not open any empty untitled file if we restored editors from previous session
850
			}
B
Benjamin Pasero 已提交
851

852 853
			return this.backupFileService.hasBackups().then(hasBackups => {
				if (hasBackups) {
B
Benjamin Pasero 已提交
854
					return []; // do not open any empty untitled file if we have backups to restore
855
				}
B
Benjamin Pasero 已提交
856

B
Benjamin Pasero 已提交
857
				return [<IUntitledResourceInput>{}];
858
			});
859
		}
860

B
Benjamin Pasero 已提交
861
		return [];
B
Benjamin Pasero 已提交
862
	}
863

864
	private toInputs(paths: IPath[], isNew: boolean): Array<IResourceInput | IUntitledResourceInput> {
B
Benjamin Pasero 已提交
865 866
		if (!paths || !paths.length) {
			return [];
867
		}
I
isidor 已提交
868

B
Benjamin Pasero 已提交
869
		return paths.map(p => {
870
			const resource = p.fileUri;
871 872 873 874
			let input: IResourceInput | IUntitledResourceInput;
			if (isNew) {
				input = { filePath: resource.fsPath, options: { pinned: true } } as IUntitledResourceInput;
			} else {
B
Benjamin Pasero 已提交
875
				input = { resource, options: { pinned: true }, forceFile: true } as IResourceInput;
876
			}
E
Erich Gamma 已提交
877

878
			if (!isNew && p.lineNumber) {
B
Benjamin Pasero 已提交
879 880 881 882 883
				input.options.selection = {
					startLineNumber: p.lineNumber,
					startColumn: p.columnNumber
				};
			}
884

B
Benjamin Pasero 已提交
885 886
			return input;
		});
887 888
	}

889
	private openUntitledFile() {
890
		const startupEditor = this.configurationService.inspect('workbench.startupEditor');
B
Benjamin Pasero 已提交
891 892

		// Fallback to previous workbench.welcome.enabled setting in case startupEditor is not defined
893
		if (!startupEditor.user && !startupEditor.workspace) {
894 895 896
			const welcomeEnabledValue = this.configurationService.getValue('workbench.welcome.enabled');
			if (typeof welcomeEnabledValue === 'boolean') {
				return !welcomeEnabledValue;
897
			}
898
		}
E
Erich Gamma 已提交
899

900
		return startupEditor.value === 'newUntitledFile';
901
	}
E
Erich Gamma 已提交
902 903

	private initSettings(): void {
904

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

I
isidor 已提交
908
		// Panel part visibility
909
		const panelRegistry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
910
		this.panelHidden = this.storageService.getBoolean(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE, true);
911 912
		if (!panelRegistry.getDefaultPanelId()) {
			this.panelHidden = true; // we hide panel part if there is no default panel
913 914
		}

E
Erich Gamma 已提交
915
		// Sidebar position
916
		const sideBarPosition = this.configurationService.getValue<string>(Workbench.sidebarPositionConfigurationKey);
917
		this.sideBarPosition = (sideBarPosition === 'right') ? Position.RIGHT : Position.LEFT;
918

I
isidor 已提交
919
		// Panel position
920
		this.setPanelPositionFromStorageOrConfig();
921

922
		// Menubar visibility
923
		const menuBarVisibility = this.configurationService.getValue<MenuBarVisibility>(Workbench.menubarVisibilityConfigurationKey);
S
SteVen Batten 已提交
924
		this.setMenubarVisibility(menuBarVisibility, true);
925

B
Benjamin Pasero 已提交
926
		// Statusbar visibility
927
		const statusBarVisible = this.configurationService.getValue<string>(Workbench.statusbarVisibleConfigurationKey);
928
		this.statusBarHidden = !statusBarVisible;
929

S
Sanders Lauture 已提交
930
		// Activity bar visibility
931
		const activityBarVisible = this.configurationService.getValue<string>(Workbench.activityBarVisibleConfigurationKey);
S
Sanders Lauture 已提交
932
		this.activityBarHidden = !activityBarVisible;
933

934
		// Font aliasing
935
		this.fontAliasing = this.configurationService.getValue<FontAliasingOption>(Workbench.fontAliasingConfigurationKey);
936

I
isidor 已提交
937 938
		// Zen mode
		this.zenMode = {
I
isidor 已提交
939
			active: false,
940
			transitionedToFullScreen: false,
941
			transitionedToCenteredEditorLayout: false,
942
			wasSideBarVisible: false,
943 944
			wasPanelVisible: false,
			transitionDisposeables: []
I
isidor 已提交
945
		};
E
Erich Gamma 已提交
946 947
	}

948 949
	private setPanelPositionFromStorageOrConfig() {
		const defaultPanelPosition = this.configurationService.getValue<string>(Workbench.defaultPanelPositionStorageKey);
950
		const panelPosition = this.storageService.get(Workbench.panelPositionStorageKey, StorageScope.WORKSPACE, defaultPanelPosition);
951

952 953
		this.panelPosition = (panelPosition === 'right') ? Position.RIGHT : Position.BOTTOM;
	}
954

B
Benjamin Pasero 已提交
955 956
	private useCustomTitleBarStyle(): boolean {
		return getTitleBarStyle(this.configurationService, this.environmentService) === 'custom';
B
Benjamin Pasero 已提交
957 958
	}

959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
	private saveLastPanelDimension(): void {
		if (!(this.workbenchGrid instanceof SerializableGrid)) {
			return;
		}

		if (this.panelPosition === Position.BOTTOM) {
			this.uiState.lastPanelHeight = this.workbenchGrid.getViewSize(this.panelPart);
		} else {
			this.uiState.lastPanelWidth = this.workbenchGrid.getViewSize(this.panelPart);
		}
	}

	private getLastPanelDimension(position: Position): number | undefined {
		return position === Position.BOTTOM ? this.uiState.lastPanelHeight : this.uiState.lastPanelWidth;
	}

975 976
	private setStatusBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.statusBarHidden = hidden;
B
Benjamin Pasero 已提交
977

978 979
		// Adjust CSS
		if (hidden) {
B
Benjamin Pasero 已提交
980
			DOM.addClass(this.workbench, 'nostatusbar');
E
Erich Gamma 已提交
981
		} else {
B
Benjamin Pasero 已提交
982
			DOM.removeClass(this.workbench, 'nostatusbar');
E
Erich Gamma 已提交
983 984
		}

985 986
		// Layout
		if (!skipLayout) {
987
			if (this.workbenchGrid instanceof SerializableGrid) {
S
SteVen Batten 已提交
988
				this.layout();
989 990 991
			} else {
				this.workbenchGrid.layout();
			}
992 993 994
		}
	}

995
	private setFontAliasing(aliasing: FontAliasingOption) {
996
		this.fontAliasing = aliasing;
S
Sanders Lauture 已提交
997

B
Benjamin Pasero 已提交
998 999 1000 1001 1002
		// Remove all
		document.body.classList.remove(...fontAliasingValues.map(value => `monaco-font-aliasing-${value}`));

		// Add specific
		if (fontAliasingValues.some(option => option === aliasing)) {
1003
			document.body.classList.add(`monaco-font-aliasing-${aliasing}`);
S
Sanders Lauture 已提交
1004
		}
1005 1006
	}

E
Erich Gamma 已提交
1007
	private createWorkbenchLayout(): void {
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
		if (this.configurationService.getValue('workbench.useExperimentalGridLayout')) {
			const serializedWorkbenchGridString = this.storageService.get(Workbench.workbenchGridUIStateStorageKey, StorageScope.GLOBAL, undefined);

			if (serializedWorkbenchGridString) {
				console.log(serializedWorkbenchGridString);
				const serializedWorkbenchGrid = JSON.parse(serializedWorkbenchGridString) as ISerializedGrid;
				this.workbenchGrid = SerializableGrid.deserialize(serializedWorkbenchGrid, {
					fromJSON: (serializedView: { type: Parts }): WorkbenchView => {
						switch (serializedView.type) {
							case Parts.ACTIVITYBAR_PART: return this.activitybarPart;
							case Parts.EDITOR_PART: return this.editorPart;
							case Parts.PANEL_PART: return this.panelPart;
							case Parts.SIDEBAR_PART: return this.sidebarPart;
							case Parts.STATUSBAR_PART: return this.statusbarPart;
							case Parts.TITLEBAR_PART: return this.titlebarPart;
						}

						return null;
					}
				});
			} else {
				this.workbenchGrid = new SerializableGrid(this.editorPart, { proportionalLayout: false });

				const sidebarDirection = this.sideBarPosition === Position.RIGHT ? Direction.Right : Direction.Left;

				if (!this.statusBarHidden) {
					this.workbenchGrid.addView(this.statusbarPart, Sizing.Split, this.editorPart, Direction.Down);
				}

				if (this.useCustomTitleBarStyle) {
					this.workbenchGrid.addView(this.titlebarPart, Sizing.Split, this.editorPart, Direction.Up);
				}

				if (!this.activityBarHidden) {
					this.workbenchGrid.addView(this.activitybarPart, Sizing.Split, this.editorPart, sidebarDirection);
				}

				if (!this.sideBarHidden) {
					this.workbenchGrid.addView(this.sidebarPart, Sizing.Split, this.editorPart, sidebarDirection);
				}

				if (!this.panelHidden) {
					this.workbenchGrid.addView(this.panelPart, Sizing.Split, this.editorPart, this.panelPosition === Position.BOTTOM ? Direction.Down : Direction.Right);
				}
			}

			this.workbench.appendChild(this.workbenchGrid.element);
		} else {
			this.workbenchGrid = this.instantiationService.createInstance(
				WorkbenchLayout,
				this.container,
				this.workbench,
				{
					titlebar: this.titlebarPart,
					activitybar: this.activitybarPart,
					editor: this.editorPart,
					sidebar: this.sidebarPart,
					panel: this.panelPart,
					statusbar: this.statusbarPart,
				},
				this.quickOpen,
				this.quickInput,
				this.notificationsCenter,
				this.notificationsToasts
			);
		}
E
Erich Gamma 已提交
1074 1075 1076 1077 1078 1079
	}

	private renderWorkbench(): void {

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

1083
		if (this.panelHidden) {
B
Benjamin Pasero 已提交
1084
			DOM.addClass(this.workbench, 'nopanel');
1085
		}
B
Benjamin Pasero 已提交
1086

1087
		if (this.statusBarHidden) {
B
Benjamin Pasero 已提交
1088
			DOM.addClass(this.workbench, 'nostatusbar');
1089
		}
E
Erich Gamma 已提交
1090

B
Benjamin Pasero 已提交
1091
		// Apply font aliasing
1092 1093
		this.setFontAliasing(this.fontAliasing);

1094 1095
		// Apply fullscreen state
		if (browser.isFullscreen()) {
B
Benjamin Pasero 已提交
1096
			DOM.addClass(this.workbench, 'fullscreen');
B
Benjamin Pasero 已提交
1097 1098
		}

E
Erich Gamma 已提交
1099
		// Create Parts
B
Benjamin Pasero 已提交
1100
		this.createTitlebarPart();
E
Erich Gamma 已提交
1101 1102 1103
		this.createActivityBarPart();
		this.createSidebarPart();
		this.createEditorPart();
1104
		this.createPanelPart();
E
Erich Gamma 已提交
1105 1106
		this.createStatusbarPart();

1107 1108
		// Notification Handlers
		this.createNotificationsHandlers();
1109

1110 1111

		// Menubar visibility changes
B
Benjamin Pasero 已提交
1112
		if ((isWindows || isLinux) && this.useCustomTitleBarStyle()) {
1113 1114 1115
			this.titlebarPart.onMenubarVisibilityChange()(e => this.onMenubarToggled(e));
		}

E
Erich Gamma 已提交
1116
		// Add Workbench to DOM
B
Benjamin Pasero 已提交
1117
		this.container.appendChild(this.workbench);
E
Erich Gamma 已提交
1118 1119
	}

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

B
Benjamin Pasero 已提交
1123
		this.titlebarPart.create(titlebarContainer);
B
Benjamin Pasero 已提交
1124 1125
	}

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

B
Benjamin Pasero 已提交
1129
		this.activitybarPart.create(activitybarPartContainer);
E
Erich Gamma 已提交
1130 1131 1132
	}

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

B
Benjamin Pasero 已提交
1135
		this.sidebarPart.create(sidebarPartContainer);
E
Erich Gamma 已提交
1136 1137
	}

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

B
Benjamin Pasero 已提交
1141
		this.panelPart.create(panelPartContainer);
I
isidor 已提交
1142 1143
	}

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

B
Benjamin Pasero 已提交
1147
		this.editorPart.create(editorContainer);
E
Erich Gamma 已提交
1148 1149 1150
	}

	private createStatusbarPart(): void {
B
Benjamin Pasero 已提交
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161
		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 已提交
1162 1163 1164
		// 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 已提交
1165

B
Benjamin Pasero 已提交
1166
		return part;
E
Erich Gamma 已提交
1167 1168
	}

1169 1170
	private createNotificationsHandlers(): void {

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

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

1177
		// Notifications Alerts
1178
		this._register(this.instantiationService.createInstance(NotificationsAlerts, this.notificationService.model));
1179 1180 1181 1182

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

1183
		// Eventing
1184
		this._register(this.notificationsCenter.onDidChangeVisibility(() => {
1185 1186 1187 1188 1189 1190 1191 1192

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

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

1193
		// Register Commands
1194
		registerNotificationCommands(this.notificationsCenter, this.notificationsToasts);
1195 1196
	}

1197
	getInstantiationService(): IInstantiationService {
E
Erich Gamma 已提交
1198 1199 1200
		return this.instantiationService;
	}

1201
	private saveState(e: IWillSaveStateEvent): void {
1202
		if (this.zenMode.active) {
B
Benjamin Pasero 已提交
1203
			this.storageService.store(Workbench.zenModeActiveStorageKey, true, StorageScope.WORKSPACE);
1204
		} else {
B
Benjamin Pasero 已提交
1205
			this.storageService.remove(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE);
1206
		}
1207 1208 1209 1210 1211 1212 1213 1214

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

		if (this.workbenchGrid instanceof SerializableGrid) {
			this.storageService.store(Workbench.workbenchGridUIStateStorageKey, JSON.stringify(this.workbenchGrid.serialize()), StorageScope.GLOBAL);
		}
1219 1220
	}

1221
	dispose(): void {
1222
		super.dispose();
1223 1224 1225 1226 1227 1228

		this.workbenchShutdown = true;
	}

	//#region IPartService

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

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

B
Benjamin Pasero 已提交
1234 1235
	isRestored(): boolean {
		return !!(this.workbenchRestored && this.workbenchStarted);
1236
	}
1237

1238 1239 1240 1241 1242
	hasFocus(part: Parts): boolean {
		const activeElement = document.activeElement;
		if (!activeElement) {
			return false;
		}
1243

1244 1245 1246
		const container = this.getContainer(part);
		return DOM.isAncestor(activeElement, container);
	}
1247

1248
	getContainer(part: Parts): HTMLElement {
1249
		let container: HTMLElement | null = null;
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
		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;
		}
1270

1271 1272
		return container;
	}
1273

1274 1275 1276
	isVisible(part: Parts): boolean {
		switch (part) {
			case Parts.TITLEBAR_PART:
B
Benjamin Pasero 已提交
1277
				if (!this.useCustomTitleBarStyle()) {
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289
					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;
1290 1291 1292 1293 1294 1295 1296 1297
			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 已提交
1298
		}
1299

1300
		return true; // any other part cannot be hidden
E
Erich Gamma 已提交
1301 1302
	}

1303 1304 1305
	getTitleBarOffset(): number {
		let offset = 0;
		if (this.isVisible(Parts.TITLEBAR_PART)) {
S
SteVen Batten 已提交
1306 1307 1308 1309 1310 1311
			if (this.workbenchGrid instanceof SerializableGrid) {
				offset = this.gridHasView(this.titlebarPart) ? this.workbenchGrid.getViewSize2(this.titlebarPart).height : 0;
			} else {
				offset = this.workbenchGrid.partLayoutInfo.titlebar.height;
			}

1312 1313 1314
			if (isMacintosh || this.menubarVisibility === 'hidden') {
				offset /= browser.getZoomFactor();
			}
E
Erich Gamma 已提交
1315
		}
1316 1317

		return offset;
E
Erich Gamma 已提交
1318
	}
1319

1320 1321
	getWorkbenchElement(): HTMLElement {
		return this.workbench;
1322
	}
1323

I
isidor 已提交
1324
	toggleZenMode(skipLayout?: boolean, restoring = false): void {
I
isidor 已提交
1325
		this.zenMode.active = !this.zenMode.active;
1326
		this.zenMode.transitionDisposeables = dispose(this.zenMode.transitionDisposeables);
1327

1328 1329
		// 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)
1330
		let toggleFullScreen = false;
I
isidor 已提交
1331 1332 1333 1334 1335 1336 1337 1338
		const setLineNumbers = (lineNumbers: any) => {
			this.editorService.visibleControls.forEach(editor => {
				const control = <IEditor>editor.getControl();
				if (control) {
					control.updateOptions({ lineNumbers });
				}
			});
		};
1339 1340

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

I
isidor 已提交
1344
			toggleFullScreen = !browser.isFullscreen() && config.fullScreen;
I
isidor 已提交
1345
			this.zenMode.transitionedToFullScreen = restoring ? config.fullScreen : toggleFullScreen;
1346
			this.zenMode.transitionedToCenteredEditorLayout = !this.isEditorLayoutCentered() && config.centerLayout;
1347 1348
			this.zenMode.wasSideBarVisible = this.isVisible(Parts.SIDEBAR_PART);
			this.zenMode.wasPanelVisible = this.isVisible(Parts.PANEL_PART);
1349

1350 1351
			this.setPanelHidden(true, true);
			this.setSideBarHidden(true, true);
I
isidor 已提交
1352

1353 1354 1355
			if (config.hideActivityBar) {
				this.setActivityBarHidden(true, true);
			}
1356

I
isidor 已提交
1357
			if (config.hideStatusBar) {
I
isidor 已提交
1358 1359
				this.setStatusBarHidden(true, true);
			}
1360

I
isidor 已提交
1361 1362 1363 1364 1365
			if (config.hideLineNumbers) {
				setLineNumbers('off');
				this.zenMode.transitionDisposeables.push(this.editorService.onDidVisibleEditorsChange(() => setLineNumbers('off')));
			}

1366 1367
			if (config.hideTabs && this.editorPart.partOptions.showTabs) {
				this.zenMode.transitionDisposeables.push(this.editorPart.enforcePartOptions({ showTabs: false }));
I
isidor 已提交
1368
			}
1369 1370 1371 1372

			if (config.centerLayout) {
				this.centerEditorLayout(true, true);
			}
1373 1374 1375 1376
		}

		// Zen Mode Inactive
		else {
1377
			if (this.zenMode.wasPanelVisible) {
1378
				this.setPanelHidden(false, true);
1379
			}
1380

1381
			if (this.zenMode.wasSideBarVisible) {
1382
				this.setSideBarHidden(false, true);
1383
			}
1384

1385 1386 1387
			if (this.zenMode.transitionedToCenteredEditorLayout) {
				this.centerEditorLayout(false, true);
			}
I
isidor 已提交
1388
			setLineNumbers(this.configurationService.getValue('editor.lineNumbers'));
1389

1390 1391
			// Status bar and activity bar visibility come from settings -> update their visibility.
			this.onDidUpdateConfiguration(true);
1392

B
Benjamin Pasero 已提交
1393
			this.editorGroupService.activeGroup.focus();
1394

1395
			toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
I
isidor 已提交
1396
		}
1397

1398
		this.inZenMode.set(this.zenMode.active);
I
isidor 已提交
1399

I
isidor 已提交
1400
		if (!skipLayout) {
1401
			this.layout();
I
isidor 已提交
1402
		}
1403

1404
		if (toggleFullScreen) {
1405
			this.windowService.toggleFullScreen();
1406
		}
I
isidor 已提交
1407 1408
	}

S
SteVen Batten 已提交
1409 1410 1411 1412
	private gridHasView(view: WorkbenchView): boolean {
		if (!(this.workbenchGrid instanceof SerializableGrid)) {
			return false;
		}
1413

S
SteVen Batten 已提交
1414 1415 1416 1417 1418
		try {
			this.workbenchGrid.getViewSize(view);
			return true;
		} catch {
			return false;
1419 1420 1421
		}
	}

S
SteVen Batten 已提交
1422
	private updateGrid(): void {
1423 1424 1425 1426
		if (!(this.workbenchGrid instanceof SerializableGrid)) {
			return;
		}

S
SteVen Batten 已提交
1427 1428 1429 1430 1431
		let panelInGrid = this.gridHasView(this.panelPart);
		let sidebarInGrid = this.gridHasView(this.sidebarPart);
		let activityBarInGrid = this.gridHasView(this.activitybarPart);
		let statusBarInGrid = this.gridHasView(this.statusbarPart);
		let titlebarInGrid = this.gridHasView(this.titlebarPart);
1432

S
SteVen Batten 已提交
1433 1434 1435 1436 1437 1438
		// Remove hidden parts
		if (this.panelHidden && panelInGrid) {
			this.saveLastPanelDimension();
			this.workbenchGrid.removeView(this.panelPart);
			panelInGrid = false;
		}
1439

S
SteVen Batten 已提交
1440 1441 1442 1443
		if (this.statusBarHidden && statusBarInGrid) {
			this.workbenchGrid.removeView(this.statusbarPart);
			statusBarInGrid = false;
		}
1444

S
SteVen Batten 已提交
1445 1446 1447 1448
		if (this.titleBarHidden && titlebarInGrid) {
			this.workbenchGrid.removeView(this.titlebarPart);
			titlebarInGrid = false;
		}
1449

S
SteVen Batten 已提交
1450 1451 1452 1453
		if (this.activityBarHidden && activityBarInGrid) {
			this.workbenchGrid.removeView(this.activitybarPart);
			activityBarInGrid = false;
		}
1454

S
SteVen Batten 已提交
1455 1456 1457 1458 1459
		if (this.sideBarHidden && sidebarInGrid) {
			this.uiState.lastSidebarDimension = this.workbenchGrid.getViewSize(this.sidebarPart);
			this.workbenchGrid.removeView(this.sidebarPart);
			sidebarInGrid = false;
		}
1460 1461


S
SteVen Batten 已提交
1462 1463 1464 1465 1466 1467 1468
		// Add visible parts
		if (!this.statusBarHidden && !statusBarInGrid) {
			if (sidebarInGrid) {
				this.uiState.lastSidebarDimension = this.workbenchGrid.getViewSize(this.sidebarPart);
				this.workbenchGrid.removeView(this.sidebarPart);
				sidebarInGrid = false;
			}
1469

S
SteVen Batten 已提交
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549
			if (activityBarInGrid) {
				this.workbenchGrid.removeView(this.activitybarPart);
				activityBarInGrid = false;
			}

			if (panelInGrid) {
				this.saveLastPanelDimension();
				this.workbenchGrid.removeView(this.panelPart);
				panelInGrid = false;
			}

			this.workbenchGrid.addView(this.statusbarPart, Sizing.Split, this.editorPart, Direction.Down);
			statusBarInGrid = true;
		}

		if (!this.titleBarHidden && !titlebarInGrid) {
			if (sidebarInGrid) {
				this.uiState.lastSidebarDimension = this.workbenchGrid.getViewSize(this.sidebarPart);
				this.workbenchGrid.removeView(this.sidebarPart);
				sidebarInGrid = false;
			}

			if (activityBarInGrid) {
				this.workbenchGrid.removeView(this.activitybarPart);
				activityBarInGrid = false;
			}

			if (panelInGrid && this.panelPosition !== Position.BOTTOM) {
				this.saveLastPanelDimension();
				this.workbenchGrid.removeView(this.panelPart);
				panelInGrid = false;
			}

			this.workbenchGrid.addView(this.titlebarPart, Sizing.Split, this.editorPart, Direction.Up);
			titlebarInGrid = true;
		}

		if (!this.activityBarHidden && !activityBarInGrid) {
			if (sidebarInGrid) {
				this.uiState.lastSidebarDimension = this.workbenchGrid.getViewSize(this.sidebarPart);
				this.workbenchGrid.removeView(this.sidebarPart);
				sidebarInGrid = false;
			}

			this.workbenchGrid.addView(this.activitybarPart, Sizing.Split, this.editorPart, this.sideBarPosition === Position.RIGHT ? Direction.Right : Direction.Left);
			activityBarInGrid = true;
		}

		if (!this.sideBarHidden && !sidebarInGrid) {
			if (panelInGrid && this.panelPosition === Position.BOTTOM) {
				this.saveLastPanelDimension();
				this.workbenchGrid.removeView(this.panelPart);
				panelInGrid = false;
			}

			this.workbenchGrid.addView(this.sidebarPart, this.uiState.lastSidebarDimension !== undefined ? this.uiState.lastSidebarDimension : Sizing.Split, this.editorPart, this.sideBarPosition === Position.RIGHT ? Direction.Right : Direction.Left);
			sidebarInGrid = true;
		}

		if (!this.panelHidden && !panelInGrid) {
			this.workbenchGrid.addView(this.panelPart, this.getLastPanelDimension(this.panelPosition) !== undefined ? this.getLastPanelDimension(this.panelPosition) : Sizing.Split, this.editorPart, this.panelPosition === Position.BOTTOM ? Direction.Down : Direction.Right);
			panelInGrid = true;
		}
	}

	layout(options?: ILayoutOptions): void {
		this.contextViewService.layout();

		if (this.workbenchStarted && !this.workbenchShutdown) {
			if (this.workbenchGrid instanceof SerializableGrid) {
				const dimensions = DOM.getClientArea(this.container);
				DOM.position(this.workbench, 0, 0, 0, 0, 'relative');
				DOM.size(this.workbench, dimensions.width, dimensions.height);

				this.titleBarHidden = browser.isFullscreen() && (this.getMenubarVisibility() === 'default' || (this.getMenubarVisibility() === 'toggle' && !this.menubarToggled));

				this.updateGrid();
				this.workbenchGrid.layout(dimensions.width, dimensions.height);
			} else {
				this.workbenchGrid.layout(options);
1550
			}
1551 1552 1553
		}
	}

S
SteVen Batten 已提交
1554 1555 1556 1557
	setTitlebarVisibility(visible: boolean): void {
		this.titleBarHidden = visible;
	}

1558
	isEditorLayoutCentered(): boolean {
1559
		return this.shouldCenterLayout;
S
SrTobi 已提交
1560 1561
	}

1562
	centerEditorLayout(active: boolean, skipLayout?: boolean): void {
B
Benjamin Pasero 已提交
1563
		this.storageService.store(Workbench.centeredEditorLayoutActiveStorageKey, active, StorageScope.WORKSPACE);
1564 1565
		this.shouldCenterLayout = active;
		let smartActive = active;
1566
		if (this.editorPart.groups.length > 1 && this.configurationService.getValue('workbench.editor.centeredLayoutAutoResize')) {
B
Benjamin Pasero 已提交
1567
			smartActive = false; // Respect the auto resize setting - do not go into centered layout if there is more than 1 group.
1568
		}
B
Benjamin Pasero 已提交
1569

1570
		// Enter Centered Editor Layout
1571 1572
		if (this.editorPart.isLayoutCentered() !== smartActive) {
			this.editorPart.centerLayout(smartActive);
1573

1574 1575 1576
			if (!skipLayout) {
				this.layout();
			}
1577
		}
S
SrTobi 已提交
1578 1579
	}

1580
	resizePart(part: Parts, sizeChange: number): void {
1581
		let view: WorkbenchView;
1582 1583
		switch (part) {
			case Parts.SIDEBAR_PART:
1584
				view = this.sidebarPart;
1585
			case Parts.PANEL_PART:
1586
				view = this.panelPart;
1587
			case Parts.EDITOR_PART:
1588 1589 1590 1591 1592 1593
				view = this.editorPart;
				if (this.workbenchGrid instanceof SerializableGrid) {
					this.workbenchGrid.resizeView(view, this.workbenchGrid.getViewSize(view) + sizeChange);
				} else {
					this.workbenchGrid.resizePart(part, sizeChange);
				}
1594 1595
				break;
			default:
B
Benjamin Pasero 已提交
1596
				return; // Cannot resize other parts
1597 1598 1599
		}
	}

1600 1601
	setActivityBarHidden(hidden: boolean, skipLayout?: boolean): void {
		this.activityBarHidden = hidden;
1602

1603 1604
		// Layout
		if (!skipLayout) {
1605
			if (this.workbenchGrid instanceof SerializableGrid) {
S
SteVen Batten 已提交
1606
				this.layout();
1607 1608 1609
			} else {
				this.workbenchGrid.layout();
			}
1610
		}
1611
	}
1612

1613
	setSideBarHidden(hidden: boolean, skipLayout?: boolean): void {
1614 1615 1616 1617 1618
		this.sideBarHidden = hidden;
		this.sideBarVisibleContext.set(!hidden);

		// Adjust CSS
		if (hidden) {
B
Benjamin Pasero 已提交
1619
			DOM.addClass(this.workbench, 'nosidebar');
1620
		} else {
B
Benjamin Pasero 已提交
1621
			DOM.removeClass(this.workbench, 'nosidebar');
1622 1623
		}

1624 1625
		// If sidebar becomes hidden, also hide the current active Viewlet if any
		if (hidden && this.sidebarPart.getActiveViewlet()) {
1626 1627 1628 1629 1630 1631 1632 1633 1634
			this.sidebarPart.hideActiveViewlet();
			const activePanel = this.panelPart.getActivePanel();

			// Pass Focus to Editor or Panel if Sidebar is now hidden
			if (this.hasFocus(Parts.PANEL_PART) && activePanel) {
				activePanel.focus();
			} else {
				this.editorGroupService.activeGroup.focus();
			}
1635 1636 1637 1638 1639 1640
		}

		// If sidebar becomes visible, show last active Viewlet or default viewlet
		else if (!hidden && !this.sidebarPart.getActiveViewlet()) {
			const viewletToOpen = this.sidebarPart.getLastActiveViewletId();
			if (viewletToOpen) {
I
isidor 已提交
1641
				const viewlet = this.sidebarPart.openViewlet(viewletToOpen, true);
1642
				if (!viewlet) {
I
isidor 已提交
1643
					this.sidebarPart.openViewlet(this.sidebarPart.getDefaultViewletId(), true);
1644
				}
1645
			}
1646 1647
		}

1648

1649 1650 1651 1652 1653 1654 1655
		// 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);
		}
1656

1657 1658
		// Layout
		if (!skipLayout) {
1659
			if (this.workbenchGrid instanceof SerializableGrid) {
S
SteVen Batten 已提交
1660
				this.layout();
1661 1662 1663
			} else {
				this.workbenchGrid.layout();
			}
1664
		}
1665
	}
1666

1667
	setPanelHidden(hidden: boolean, skipLayout?: boolean): void {
1668 1669 1670 1671
		this.panelHidden = hidden;

		// Adjust CSS
		if (hidden) {
B
Benjamin Pasero 已提交
1672
			DOM.addClass(this.workbench, 'nopanel');
1673
		} else {
B
Benjamin Pasero 已提交
1674
			DOM.removeClass(this.workbench, 'nopanel');
1675 1676 1677 1678
		}

		// If panel part becomes hidden, also hide the current active panel if any
		if (hidden && this.panelPart.getActivePanel()) {
1679 1680
			this.panelPart.hideActivePanel();
			this.editorGroupService.activeGroup.focus(); // Pass focus to editor group if panel part is now hidden
1681 1682 1683 1684 1685 1686
		}

		// 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) {
1687
				this.panelPart.openPanel(panelToOpen, true);
1688 1689 1690 1691
			}
		}


1692 1693 1694 1695 1696 1697
		// Remember in settings
		if (!hidden) {
			this.storageService.store(Workbench.panelHiddenStorageKey, 'false', StorageScope.WORKSPACE);
		} else {
			this.storageService.remove(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE);
		}
1698

1699 1700
		// Layout
		if (!skipLayout) {
1701
			if (this.workbenchGrid instanceof SerializableGrid) {
S
SteVen Batten 已提交
1702
				this.layout();
1703 1704 1705
			} else {
				this.workbenchGrid.layout();
			}
1706
		}
1707 1708 1709
	}

	toggleMaximizedPanel(): void {
1710 1711 1712 1713 1714
		if (this.workbenchGrid instanceof SerializableGrid) {
			this.workbenchGrid.maximizeViewSize(this.panelPart);
		} else {
			this.workbenchGrid.layout({ toggleMaximizedPanel: true, source: Parts.PANEL_PART });
		}
1715 1716 1717
	}

	isPanelMaximized(): boolean {
1718 1719 1720 1721 1722 1723 1724 1725 1726
		if (this.workbenchGrid instanceof SerializableGrid) {
			try {
				return this.workbenchGrid.getViewSize2(this.panelPart).height === this.panelPart.maximumHeight;
			} catch (e) {
				return false;
			}
		} else {
			return this.workbenchGrid.isPanelMaximized();
		}
1727 1728 1729 1730 1731 1732 1733
	}

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

	setSideBarPosition(position: Position): void {
1734 1735
		const wasHidden = this.sideBarHidden;

1736
		if (this.sideBarHidden) {
1737
			this.setSideBarHidden(false, true /* Skip Layout */);
1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754
		}

		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
1755 1756
		if (this.workbenchGrid instanceof SerializableGrid) {

S
SteVen Batten 已提交
1757
			if (!wasHidden) {
1758
				this.uiState.lastSidebarDimension = this.workbenchGrid.getViewSize(this.sidebarPart);
S
SteVen Batten 已提交
1759
				this.workbenchGrid.removeView(this.sidebarPart);
1760 1761
			}

S
SteVen Batten 已提交
1762 1763
			if (!this.activityBarHidden) {
				this.workbenchGrid.removeView(this.activitybarPart);
1764 1765
			}

S
SteVen Batten 已提交
1766
			this.layout();
1767 1768 1769
		} else {
			this.workbenchGrid.layout();
		}
1770 1771
	}

S
SteVen Batten 已提交
1772
	setMenubarVisibility(visibility: MenuBarVisibility, skipLayout: boolean): void {
S
SteVen Batten 已提交
1773 1774
		if (this.menubarVisibility !== visibility) {
			this.menubarVisibility = visibility;
1775

1776
			// Layout
S
SteVen Batten 已提交
1777
			if (!skipLayout) {
1778 1779 1780 1781 1782 1783
				if (this.workbenchGrid instanceof SerializableGrid) {
					const dimensions = DOM.getClientArea(this.container);
					this.workbenchGrid.layout(dimensions.width, dimensions.height);
				} else {
					this.workbenchGrid.layout();
				}
S
SteVen Batten 已提交
1784
			}
1785 1786 1787
		}
	}

S
SteVen Batten 已提交
1788 1789 1790 1791
	getMenubarVisibility(): MenuBarVisibility {
		return this.menubarVisibility;
	}

1792 1793 1794 1795
	getPanelPosition(): Position {
		return this.panelPosition;
	}

1796
	setPanelPosition(position: Position): void {
1797 1798
		const wasHidden = this.panelHidden;

1799 1800
		if (this.panelHidden) {
			this.setPanelHidden(false, true /* Skip Layout */);
1801 1802
		} else {
			this.saveLastPanelDimension();
1803
		}
1804

1805 1806 1807 1808
		const newPositionValue = (position === Position.BOTTOM) ? 'bottom' : 'right';
		const oldPositionValue = (this.panelPosition === Position.BOTTOM) ? 'bottom' : 'right';
		this.panelPosition = position;
		this.storageService.store(Workbench.panelPositionStorageKey, PositionToString(this.panelPosition).toLowerCase(), StorageScope.WORKSPACE);
1809

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

1814 1815 1816 1817
		// Update Styles
		this.panelPart.updateStyles();

		// Layout
1818 1819 1820 1821 1822 1823
		if (this.workbenchGrid instanceof SerializableGrid) {
			if (wasHidden) {
				this.workbenchGrid.addView(this.panelPart, this.getLastPanelDimension(position) !== undefined ? this.getLastPanelDimension(position) : Sizing.Split, this.editorPart, position === Position.BOTTOM ? Direction.Down : Direction.Right);
			} else {
				this.workbenchGrid.moveView(this.panelPart, this.getLastPanelDimension(position) !== undefined ? this.getLastPanelDimension(position) : Sizing.Split, this.editorPart, position === Position.BOTTOM ? Direction.Down : Direction.Right);
			}
1824

1825 1826 1827 1828 1829 1830 1831
			const dimensions = DOM.getClientArea(this.container);
			this.workbenchGrid.layout(dimensions.width, dimensions.height);
		} else {
			this.workbenchGrid.layout();
		}
	}
}