Skip to content

Commit

Permalink
Fixes #96939 - reworks default view layout api
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Amodio committed Jun 11, 2020
1 parent e3df1e2 commit 9e0ab5c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/vs/workbench/browser/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
hidden: false
},

views: {
defaults: undefined as (string[] | undefined)
},

zenMode: {
active: false,
restore: false,
Expand Down Expand Up @@ -556,7 +560,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
}

private applyDefaultLayout(environmentService: IWorkbenchEnvironmentService, storageService: IStorageService) {
const defaultLayout = environmentService.options?.defaultLayout;
let defaultLayout = environmentService.options?.defaultLayout;
if (!defaultLayout) {
return;
}
Expand All @@ -566,6 +570,15 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
return;
}

const { views } = defaultLayout;
if (views?.length) {
this.state.views.defaults = views.map(v => v.id);

return;
}

// Everything below here is deprecated and will be removed once Codespaces migrates

const { sidebar } = defaultLayout;
if (sidebar) {
if (sidebar.visible !== undefined) {
Expand Down
65 changes: 63 additions & 2 deletions src/vs/workbench/browser/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import { InstantiationService } from 'vs/platform/instantiation/common/instantia
import { Layout } from 'vs/workbench/browser/layout';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { Extensions as PanelExtensions, PanelRegistry } from 'vs/workbench/browser/panel';
import { IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/common/views';
import { IViewDescriptorService, ViewContainerLocation, IViewsService } from 'vs/workbench/common/views';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';

export class Workbench extends Layout {

Expand Down Expand Up @@ -164,7 +165,11 @@ export class Workbench extends Layout {

// Restore
try {
await this.restoreWorkbench(accessor.get(IEditorService), accessor.get(IEditorGroupsService), accessor.get(IViewDescriptorService), accessor.get(IViewletService), accessor.get(IPanelService), accessor.get(ILogService), lifecycleService);
await this.restoreWorkbench(
accessor.get(IEditorService), accessor.get(IEditorGroupsService), accessor.get(IExtensionService), accessor.get(IViewDescriptorService),
accessor.get(IViewsService), accessor.get(IViewletService), accessor.get(IPanelService),
accessor.get(ILogService), lifecycleService
);
} catch (error) {
onUnexpectedError(error);
}
Expand Down Expand Up @@ -401,7 +406,9 @@ export class Workbench extends Layout {
private async restoreWorkbench(
editorService: IEditorService,
editorGroupService: IEditorGroupsService,
extensionService: IExtensionService,
viewDescriptorService: IViewDescriptorService,
viewsService: IViewsService,
viewletService: IViewletService,
panelService: IPanelService,
logService: ILogService,
Expand Down Expand Up @@ -431,6 +438,60 @@ export class Workbench extends Layout {
mark('didRestoreEditors');
})());

if (this.state.views.defaults?.length) {
mark('willOpenDefaultViews');

const defaultViews = [...this.state.views.defaults];

let locationsRestored: boolean[] = [];

async function tryOpenView(viewId: string, index: number) {
const location = viewDescriptorService.getViewLocationById(viewId);
// eslint-disable-next-line eqeqeq
if (location != null) {
// 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 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 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');
}

// Restore Sidebar
if (this.state.sideBar.viewletToRestore) {
restorePromises.push((async () => {
Expand Down
7 changes: 7 additions & 0 deletions src/vs/workbench/workbench.web.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,22 @@ interface IDefaultPanelLayout {
})[];
}

interface IDefaultView {
readonly id: string;
}

interface IDefaultEditor {
readonly uri: UriComponents;
readonly openOnlyIfExists?: boolean;
readonly openWith?: string;
}

interface IDefaultLayout {
/** @deprecated Use views instead */
readonly sidebar?: IDefaultSideBarLayout;
/** @deprecated Use views instead */
readonly panel?: IDefaultPanelLayout;
readonly views?: IDefaultView[];

This comment has been minimized.

Copy link
@bpasero

bpasero Jun 12, 2020

Member

@eamodio can you export this IDefaultView from the end of the file?

readonly editors?: IDefaultEditor[];
}

Expand Down

0 comments on commit 9e0ab5c

Please sign in to comment.