Skip to content

Commit 015878c

Browse files
authored
1 parent b3cbbb4 commit 015878c

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditor.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class UserDataProfilesEditor extends EditorPane implements IUserDataProfi
9292
private profileWidget: ProfileWidget | undefined;
9393

9494
private model: UserDataProfilesEditorModel | undefined;
95+
private templates: readonly IProfileTemplateInfo[] = [];
9596

9697
constructor(
9798
group: IEditorGroup,
@@ -207,7 +208,7 @@ export class UserDataProfilesEditor extends EditorPane implements IUserDataProfi
207208
actions: {
208209
getActions: () => {
209210
const actions: IAction[] = [];
210-
if (this.model?.templates.length) {
211+
if (this.templates.length) {
211212
actions.push(new SubmenuAction('from.template', localize('from template', "From Template"), this.getCreateFromTemplateActions()));
212213
actions.push(new Separator());
213214
}
@@ -225,15 +226,13 @@ export class UserDataProfilesEditor extends EditorPane implements IUserDataProfi
225226
}
226227

227228
private getCreateFromTemplateActions(): IAction[] {
228-
return this.model
229-
? this.model.templates.map(template =>
230-
new Action(
231-
`template:${template.url}`,
232-
template.name,
233-
undefined,
234-
true,
235-
() => this.createNewProfile(URI.parse(template.url))))
236-
: [];
229+
return this.templates.map(template =>
230+
new Action(
231+
`template:${template.url}`,
232+
template.name,
233+
undefined,
234+
true,
235+
() => this.createNewProfile(URI.parse(template.url))));
237236
}
238237

239238
private registerListeners(): void {
@@ -343,9 +342,12 @@ export class UserDataProfilesEditor extends EditorPane implements IUserDataProfi
343342
override async setInput(input: UserDataProfilesEditorInput, options: IEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise<void> {
344343
await super.setInput(input, options, context, token);
345344
this.model = await input.resolve();
346-
if (this.profileWidget) {
347-
this.profileWidget.templates = this.model.templates;
348-
}
345+
this.model.getTemplates().then(templates => {
346+
this.templates = templates;
347+
if (this.profileWidget) {
348+
this.profileWidget.templates = templates;
349+
}
350+
});
349351
this.updateProfilesList();
350352
this._register(this.model.onDidChange(element =>
351353
this.updateProfilesList(element)));

src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditorModel.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,7 @@ export class UserDataProfilesEditorModel extends EditorModel {
713713
private _onDidChange = this._register(new Emitter<AbstractUserDataProfileElement | undefined>());
714714
readonly onDidChange = this._onDidChange.event;
715715

716-
private _templates: IProfileTemplateInfo[] | undefined;
717-
get templates(): readonly IProfileTemplateInfo[] { return this._templates ?? []; }
716+
private templates: Promise<readonly IProfileTemplateInfo[]> | undefined;
718717

719718
constructor(
720719
@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,
@@ -761,9 +760,11 @@ export class UserDataProfilesEditorModel extends EditorModel {
761760
}
762761
}
763762

764-
override async resolve(): Promise<void> {
765-
await super.resolve();
766-
this._templates = await this.userDataProfileManagementService.getBuiltinProfileTemplates();
763+
getTemplates(): Promise<readonly IProfileTemplateInfo[]> {
764+
if (!this.templates) {
765+
this.templates = this.userDataProfileManagementService.getBuiltinProfileTemplates();
766+
}
767+
return this.templates;
767768
}
768769

769770
private createProfileElement(profile: IUserDataProfile): [UserDataProfileElement, DisposableStore] {

0 commit comments

Comments
 (0)