Skip to content

Commit 3dc0754

Browse files
authored
Add variables to welcome views (microsoft#167163)
1 parent 0597499 commit 3dc0754

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/vs/workbench/browser/parts/views/viewPane.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import { FilterWidget, IFilterWidgetOptions } from 'vs/workbench/browser/parts/v
4545
import { BaseActionViewItem } from 'vs/base/browser/ui/actionbar/actionViewItems';
4646
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
4747
import { defaultButtonStyles, defaultProgressBarStyles } from 'vs/platform/theme/browser/defaultStyles';
48+
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
49+
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
4850

4951
export interface IViewPaneOptions extends IPaneOptions {
5052
id: string;
@@ -83,21 +85,34 @@ class ViewWelcomeController {
8385

8486
private defaultItem: IItem | undefined;
8587
private items: IItem[] = [];
86-
get contents(): IViewContentDescriptor[] {
88+
get contents(): Promise<IViewContentDescriptor[]> {
8789
const visibleItems = this.items.filter(v => v.visible);
8890

8991
if (visibleItems.length === 0 && this.defaultItem) {
90-
return [this.defaultItem.descriptor];
92+
return Promise.resolve([this.defaultItem.descriptor]);
9193
}
9294

93-
return visibleItems.map(v => v.descriptor);
95+
const workspace = this.workspaceContextService.getWorkspace();
96+
const workspaceFolder = workspace.folders.length > 0 ? workspace.folders[0] : undefined;
97+
98+
return Promise.all(visibleItems.map(async (v) => {
99+
return {
100+
content: workspaceFolder ? await this.configurationResolverService.resolveWithInteractionReplace(workspaceFolder, v.descriptor.content) : v.descriptor.content,
101+
when: v.descriptor.when,
102+
group: v.descriptor.group,
103+
order: v.descriptor.order,
104+
precondition: v.descriptor.precondition
105+
};
106+
}));
94107
}
95108

96109
private disposables = new DisposableStore();
97110

98111
constructor(
99112
private id: string,
100113
@IContextKeyService private contextKeyService: IContextKeyService,
114+
@IConfigurationResolverService private readonly configurationResolverService: IConfigurationResolverService,
115+
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService
101116
) {
102117
contextKeyService.onDidChangeContext(this.onDidChangeContext, this, this.disposables);
103118
Event.filter(viewsRegistry.onDidChangeViewWelcomeContent, id => id === this.id)(this.onDidChangeViewWelcomeContent, this, this.disposables);
@@ -228,7 +243,7 @@ export abstract class ViewPane extends Pane implements IView {
228243
this.menuActions = this._register(this.instantiationService.createChild(new ServiceCollection([IContextKeyService, this.scopedContextKeyService])).createInstance(CompositeMenuActions, options.titleMenuId ?? MenuId.ViewTitle, MenuId.ViewTitleContext, { shouldForwardArgs: !options.donotForwardArgs }));
229244
this._register(this.menuActions.onDidChange(() => this.updateActions()));
230245

231-
this.viewWelcomeController = new ViewWelcomeController(this.id, contextKeyService);
246+
this.viewWelcomeController = this.instantiationService.createInstance(ViewWelcomeController, this.id);
232247
}
233248

234249
override get headerVisible(): boolean {
@@ -549,7 +564,7 @@ export abstract class ViewPane extends Pane implements IView {
549564
// Subclasses to implement for saving state
550565
}
551566

552-
private updateViewWelcome(): void {
567+
private async updateViewWelcome(): Promise<void> {
553568
this.viewWelcomeDisposable.dispose();
554569

555570
if (!this.shouldShowWelcome()) {
@@ -559,7 +574,7 @@ export abstract class ViewPane extends Pane implements IView {
559574
return;
560575
}
561576

562-
const contents = this.viewWelcomeController.contents;
577+
const contents = await this.viewWelcomeController.contents;
563578

564579
if (contents.length === 0) {
565580
this.bodyContainer.classList.remove('welcome');

0 commit comments

Comments
 (0)