From 015878c11ccf76ad1cdfc00d619cbc41d2aad725 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Thu, 29 Aug 2024 00:29:36 +0200 Subject: [PATCH] fix #226725 (#227019) --- .../browser/userDataProfilesEditor.ts | 28 ++++++++++--------- .../browser/userDataProfilesEditorModel.ts | 11 ++++---- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditor.ts b/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditor.ts index 7fa4518bdc5..17ddb9cb36d 100644 --- a/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditor.ts +++ b/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditor.ts @@ -92,6 +92,7 @@ export class UserDataProfilesEditor extends EditorPane implements IUserDataProfi private profileWidget: ProfileWidget | undefined; private model: UserDataProfilesEditorModel | undefined; + private templates: readonly IProfileTemplateInfo[] = []; constructor( group: IEditorGroup, @@ -207,7 +208,7 @@ export class UserDataProfilesEditor extends EditorPane implements IUserDataProfi actions: { getActions: () => { const actions: IAction[] = []; - if (this.model?.templates.length) { + if (this.templates.length) { actions.push(new SubmenuAction('from.template', localize('from template', "From Template"), this.getCreateFromTemplateActions())); actions.push(new Separator()); } @@ -225,15 +226,13 @@ export class UserDataProfilesEditor extends EditorPane implements IUserDataProfi } private getCreateFromTemplateActions(): IAction[] { - return this.model - ? this.model.templates.map(template => - new Action( - `template:${template.url}`, - template.name, - undefined, - true, - () => this.createNewProfile(URI.parse(template.url)))) - : []; + return this.templates.map(template => + new Action( + `template:${template.url}`, + template.name, + undefined, + true, + () => this.createNewProfile(URI.parse(template.url)))); } private registerListeners(): void { @@ -343,9 +342,12 @@ export class UserDataProfilesEditor extends EditorPane implements IUserDataProfi override async setInput(input: UserDataProfilesEditorInput, options: IEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise { await super.setInput(input, options, context, token); this.model = await input.resolve(); - if (this.profileWidget) { - this.profileWidget.templates = this.model.templates; - } + this.model.getTemplates().then(templates => { + this.templates = templates; + if (this.profileWidget) { + this.profileWidget.templates = templates; + } + }); this.updateProfilesList(); this._register(this.model.onDidChange(element => this.updateProfilesList(element))); diff --git a/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditorModel.ts b/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditorModel.ts index 42afc9e189d..87827dcfaa0 100644 --- a/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditorModel.ts +++ b/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditorModel.ts @@ -713,8 +713,7 @@ export class UserDataProfilesEditorModel extends EditorModel { private _onDidChange = this._register(new Emitter()); readonly onDidChange = this._onDidChange.event; - private _templates: IProfileTemplateInfo[] | undefined; - get templates(): readonly IProfileTemplateInfo[] { return this._templates ?? []; } + private templates: Promise | undefined; constructor( @IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService, @@ -761,9 +760,11 @@ export class UserDataProfilesEditorModel extends EditorModel { } } - override async resolve(): Promise { - await super.resolve(); - this._templates = await this.userDataProfileManagementService.getBuiltinProfileTemplates(); + getTemplates(): Promise { + if (!this.templates) { + this.templates = this.userDataProfileManagementService.getBuiltinProfileTemplates(); + } + return this.templates; } private createProfileElement(profile: IUserDataProfile): [UserDataProfileElement, DisposableStore] {