mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode 4d91d96e5e121b38d33508cdef17868bab255eae
This commit is contained in:
committed by
AzureDataStudio
parent
a971aee5bd
commit
5e7071e466
@@ -16,7 +16,7 @@ import { PanelPart } from 'vs/workbench/browser/parts/panel/panelPart';
|
||||
import { PanelRegistry, Extensions as PanelExtensions } from 'vs/workbench/browser/panel';
|
||||
import { Position, Parts, IWorkbenchLayoutService, positionFromString, positionToString } from 'vs/workbench/services/layout/browser/layoutService';
|
||||
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
||||
import { IStorageService, StorageScope, WillSaveStateReason } from 'vs/platform/storage/common/storage';
|
||||
import { IStorageService, StorageScope, WillSaveStateReason, WorkspaceStorageSettings } from 'vs/platform/storage/common/storage';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
|
||||
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
|
||||
@@ -43,8 +43,10 @@ import { WINDOW_ACTIVE_BORDER, WINDOW_INACTIVE_BORDER } from 'vs/workbench/commo
|
||||
import { LineNumbersType } from 'vs/editor/common/config/editorOptions';
|
||||
import { ActivitybarPart } from 'vs/workbench/browser/parts/activitybar/activitybarPart';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/common/views';
|
||||
import { IViewDescriptorService, ViewContainerLocation, IViewsService } from 'vs/workbench/common/views';
|
||||
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
|
||||
import { mark } from 'vs/base/common/performance';
|
||||
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
||||
|
||||
export enum Settings {
|
||||
ACTIVITYBAR_VISIBLE = 'workbench.activityBar.visible',
|
||||
@@ -54,7 +56,6 @@ export enum Settings {
|
||||
PANEL_POSITION = 'workbench.panel.defaultLocation',
|
||||
|
||||
ZEN_MODE_RESTORE = 'zenMode.restore',
|
||||
WORKSPACE_FIRST_OPEN = 'workbench.workspaceFirstOpen'
|
||||
}
|
||||
|
||||
enum Storage {
|
||||
@@ -104,7 +105,7 @@ interface SideBarActivityState {
|
||||
|
||||
export abstract class Layout extends Disposable implements IWorkbenchLayoutService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
declare readonly _serviceBrand: undefined;
|
||||
|
||||
//#region Events
|
||||
|
||||
@@ -131,12 +132,11 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
|
||||
//#endregion
|
||||
|
||||
readonly container: HTMLElement = document.createElement('div');
|
||||
|
||||
private _dimension!: IDimension;
|
||||
get dimension(): IDimension { return this._dimension; }
|
||||
|
||||
private _container: HTMLElement = document.createElement('div');
|
||||
get container(): HTMLElement { return this._container; }
|
||||
|
||||
get offset() {
|
||||
return {
|
||||
top: (() => {
|
||||
@@ -150,7 +150,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
};
|
||||
}
|
||||
|
||||
private parts: Map<string, Part> = new Map<string, Part>();
|
||||
private readonly parts = new Map<string, Part>();
|
||||
|
||||
private workbenchGrid!: SerializableGrid<ISerializableView>;
|
||||
|
||||
@@ -164,6 +164,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
private statusBarPartView!: ISerializableView;
|
||||
|
||||
private environmentService!: IWorkbenchEnvironmentService;
|
||||
private extensionService!: IExtensionService;
|
||||
private configurationService!: IConfigurationService;
|
||||
private lifecycleService!: ILifecycleService;
|
||||
private storageService!: IStorageService;
|
||||
@@ -174,6 +175,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
private titleService!: ITitleService;
|
||||
private viewletService!: IViewletService;
|
||||
private viewDescriptorService!: IViewDescriptorService;
|
||||
private viewsService!: IViewsService;
|
||||
private contextService!: IWorkspaceContextService;
|
||||
private backupFileService!: IBackupFileService;
|
||||
private notificationService!: INotificationService;
|
||||
@@ -223,6 +225,10 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
hidden: false
|
||||
},
|
||||
|
||||
views: {
|
||||
defaults: undefined as (string[] | undefined)
|
||||
},
|
||||
|
||||
zenMode: {
|
||||
active: false,
|
||||
restore: false,
|
||||
@@ -233,8 +239,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
transitionDisposables: new DisposableStore(),
|
||||
setNotificationsFilter: false,
|
||||
editorWidgetSet: new Set<IEditor>()
|
||||
},
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
constructor(
|
||||
@@ -254,6 +259,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
this.storageService = accessor.get(IStorageService);
|
||||
this.backupFileService = accessor.get(IBackupFileService);
|
||||
this.themeService = accessor.get(IThemeService);
|
||||
this.extensionService = accessor.get(IExtensionService);
|
||||
|
||||
// Parts
|
||||
this.editorService = accessor.get(IEditorService);
|
||||
@@ -261,6 +267,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
this.panelService = accessor.get(IPanelService);
|
||||
this.viewletService = accessor.get(IViewletService);
|
||||
this.viewDescriptorService = accessor.get(IViewDescriptorService);
|
||||
this.viewsService = accessor.get(IViewsService);
|
||||
this.titleService = accessor.get(ITitleService);
|
||||
this.notificationService = accessor.get(INotificationService);
|
||||
this.activityBarService = accessor.get(IActivityBarService);
|
||||
@@ -476,6 +483,8 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
}
|
||||
|
||||
private initLayoutState(lifecycleService: ILifecycleService, fileService: IFileService): void {
|
||||
|
||||
// Default Layout
|
||||
this.applyDefaultLayout(this.environmentService, this.storageService);
|
||||
|
||||
// Fullscreen
|
||||
@@ -551,7 +560,6 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
|
||||
// Window border
|
||||
this.updateWindowBorder(true);
|
||||
|
||||
}
|
||||
|
||||
private applyDefaultLayout(environmentService: IWorkbenchEnvironmentService, storageService: IStorageService) {
|
||||
@@ -560,11 +568,20 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
return;
|
||||
}
|
||||
|
||||
const firstOpen = storageService.getBoolean(Settings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE);
|
||||
const firstOpen = storageService.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE);
|
||||
if (!firstOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { views } = defaultLayout;
|
||||
if (views?.length) {
|
||||
this.state.views.defaults = views.map(v => v.id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO@eamodio Everything below here is deprecated and will be removed once Codespaces migrates
|
||||
|
||||
const { sidebar } = defaultLayout;
|
||||
if (sidebar) {
|
||||
if (sidebar.visible !== undefined) {
|
||||
@@ -777,7 +794,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
|
||||
private getInitialFilesToOpen(): { filesToOpenOrCreate?: IPath[], filesToDiff?: IPath[] } | undefined {
|
||||
const defaultLayout = this.environmentService.options?.defaultLayout;
|
||||
if (defaultLayout?.editors?.length && this.storageService.getBoolean(Settings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE)) {
|
||||
if (defaultLayout?.editors?.length && this.storageService.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE)) {
|
||||
this._openedDefaultEditors = true;
|
||||
|
||||
return {
|
||||
@@ -787,7 +804,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
if ('path' in f && 'scheme' in f) {
|
||||
return { fileUri: URI.file((f as any).path).with({ scheme: (f as any).scheme }) };
|
||||
}
|
||||
return { fileUri: URI.revive(f.uri), openOnlyIfExists: f.openOnlyIfExists };
|
||||
return { fileUri: URI.revive(f.uri), openOnlyIfExists: f.openOnlyIfExists, overrideId: f.openWith };
|
||||
})
|
||||
};
|
||||
}
|
||||
@@ -803,6 +820,143 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
return undefined;
|
||||
}
|
||||
|
||||
protected async restoreWorkbenchLayout(): Promise<void> {
|
||||
const restorePromises: Promise<void>[] = [];
|
||||
|
||||
// Restore editors
|
||||
restorePromises.push((async () => {
|
||||
mark('willRestoreEditors');
|
||||
|
||||
// first ensure the editor part is restored
|
||||
await this.editorGroupService.whenRestored;
|
||||
|
||||
// then see for editors to open as instructed
|
||||
let editors: IResourceEditorInputType[];
|
||||
if (Array.isArray(this.state.editor.editorsToOpen)) {
|
||||
editors = this.state.editor.editorsToOpen;
|
||||
} else {
|
||||
editors = await this.state.editor.editorsToOpen;
|
||||
}
|
||||
|
||||
if (editors.length) {
|
||||
await this.editorService.openEditors(editors);
|
||||
}
|
||||
|
||||
mark('didRestoreEditors');
|
||||
})());
|
||||
|
||||
// Restore default views
|
||||
const restoreDefaultViewsPromise = (async () => {
|
||||
if (this.state.views.defaults?.length) {
|
||||
mark('willOpenDefaultViews');
|
||||
|
||||
const defaultViews = [...this.state.views.defaults];
|
||||
|
||||
let locationsRestored: boolean[] = [];
|
||||
|
||||
const tryOpenView = async (viewId: string, index: number) => {
|
||||
const location = this.viewDescriptorService.getViewLocationById(viewId);
|
||||
if (location) {
|
||||
|
||||
// If the view is in the same location that has already been restored, remove it and continue
|
||||
if (locationsRestored[location]) {
|
||||
defaultViews.splice(index, 1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const view = await this.viewsService.openView(viewId);
|
||||
if (view) {
|
||||
locationsRestored[location] = true;
|
||||
defaultViews.splice(index, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let i = -1;
|
||||
for (const viewId of defaultViews) {
|
||||
await tryOpenView(viewId, ++i);
|
||||
}
|
||||
|
||||
// If we still have views left over, wait until all extensions have been registered and try again
|
||||
if (defaultViews.length) {
|
||||
await this.extensionService.whenInstalledExtensionsRegistered();
|
||||
|
||||
let i = -1;
|
||||
for (const viewId of defaultViews) {
|
||||
await tryOpenView(viewId, ++i);
|
||||
}
|
||||
}
|
||||
|
||||
// If we opened a view in the sidebar, stop any restore there
|
||||
if (locationsRestored[ViewContainerLocation.Sidebar]) {
|
||||
this.state.sideBar.viewletToRestore = undefined;
|
||||
}
|
||||
|
||||
// If we opened a view in the panel, stop any restore there
|
||||
if (locationsRestored[ViewContainerLocation.Panel]) {
|
||||
this.state.panel.panelToRestore = undefined;
|
||||
}
|
||||
|
||||
mark('didOpenDefaultViews');
|
||||
}
|
||||
})();
|
||||
restorePromises.push(restoreDefaultViewsPromise);
|
||||
|
||||
// Restore Sidebar
|
||||
restorePromises.push((async () => {
|
||||
|
||||
// Restoring views could mean that sidebar already
|
||||
// restored, as such we need to test again
|
||||
await restoreDefaultViewsPromise;
|
||||
if (!this.state.sideBar.viewletToRestore) {
|
||||
return;
|
||||
}
|
||||
|
||||
mark('willRestoreViewlet');
|
||||
|
||||
const viewlet = await this.viewletService.openViewlet(this.state.sideBar.viewletToRestore);
|
||||
if (!viewlet) {
|
||||
await this.viewletService.openViewlet(this.viewDescriptorService.getDefaultViewContainer(ViewContainerLocation.Sidebar)?.id); // fallback to default viewlet as needed
|
||||
}
|
||||
|
||||
mark('didRestoreViewlet');
|
||||
})());
|
||||
|
||||
// Restore Panel
|
||||
restorePromises.push((async () => {
|
||||
|
||||
// Restoring views could mean that panel already
|
||||
// restored, as such we need to test again
|
||||
await restoreDefaultViewsPromise;
|
||||
if (!this.state.panel.panelToRestore) {
|
||||
return;
|
||||
}
|
||||
|
||||
mark('willRestorePanel');
|
||||
|
||||
const panel = await this.panelService.openPanel(this.state.panel.panelToRestore!);
|
||||
if (!panel) {
|
||||
await this.panelService.openPanel(Registry.as<PanelRegistry>(PanelExtensions.Panels).getDefaultPanelId()); // fallback to default panel as needed
|
||||
}
|
||||
|
||||
mark('didRestorePanel');
|
||||
})());
|
||||
|
||||
// Restore Zen Mode
|
||||
if (this.state.zenMode.restore) {
|
||||
this.toggleZenMode(false, true);
|
||||
}
|
||||
|
||||
// Restore Editor Center Mode
|
||||
if (this.state.editor.restoreCentered) {
|
||||
this.centerEditorLayout(true, true);
|
||||
}
|
||||
|
||||
// Await restore to be done
|
||||
await Promise.all(restorePromises);
|
||||
}
|
||||
|
||||
private updatePanelPosition() {
|
||||
const defaultPanelPosition = this.configurationService.getValue<string>(Settings.PANEL_POSITION);
|
||||
const panelPosition = this.storageService.get(Storage.PANEL_POSITION, StorageScope.WORKSPACE, defaultPanelPosition);
|
||||
@@ -1398,9 +1552,10 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
}
|
||||
|
||||
// If panel part becomes hidden, also hide the current active panel if any
|
||||
let focusEditor = false;
|
||||
if (hidden && this.panelService.getActivePanel()) {
|
||||
this.panelService.hideActivePanel();
|
||||
this.editorGroupService.activeGroup.focus(); // Pass focus to editor group if panel part is now hidden
|
||||
focusEditor = true;
|
||||
}
|
||||
|
||||
// If panel part becomes visible, show last active panel or default panel
|
||||
@@ -1431,6 +1586,10 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
if (hidden && this.state.editor.hidden) {
|
||||
this.setEditorHidden(false, true);
|
||||
}
|
||||
|
||||
if (focusEditor) {
|
||||
this.editorGroupService.activeGroup.focus(); // Pass focus to editor group if panel part is now hidden
|
||||
}
|
||||
}
|
||||
|
||||
toggleMaximizedPanel(): void {
|
||||
@@ -1450,7 +1609,6 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
||||
} else {
|
||||
this.setEditorHidden(false);
|
||||
this.workbenchGrid.resizeView(this.panelPartView, { width: this.state.panel.position === Position.BOTTOM ? size.width : this.state.panel.lastNonMaximizedWidth, height: this.state.panel.position === Position.BOTTOM ? this.state.panel.lastNonMaximizedHeight : size.height });
|
||||
this.editorGroupService.activeGroup.focus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user