Skip to content

Commit

Permalink
Add variables to welcome views (#167163)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 committed Nov 24, 2022
1 parent 0597499 commit 3dc0754
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/vs/workbench/browser/parts/views/viewPane.ts
Expand Up @@ -45,6 +45,8 @@ import { FilterWidget, IFilterWidgetOptions } from 'vs/workbench/browser/parts/v
import { BaseActionViewItem } from 'vs/base/browser/ui/actionbar/actionViewItems';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { defaultButtonStyles, defaultProgressBarStyles } from 'vs/platform/theme/browser/defaultStyles';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';

export interface IViewPaneOptions extends IPaneOptions {
id: string;
Expand Down Expand Up @@ -83,21 +85,34 @@ class ViewWelcomeController {

private defaultItem: IItem | undefined;
private items: IItem[] = [];
get contents(): IViewContentDescriptor[] {
get contents(): Promise<IViewContentDescriptor[]> {
const visibleItems = this.items.filter(v => v.visible);

if (visibleItems.length === 0 && this.defaultItem) {
return [this.defaultItem.descriptor];
return Promise.resolve([this.defaultItem.descriptor]);
}

return visibleItems.map(v => v.descriptor);
const workspace = this.workspaceContextService.getWorkspace();
const workspaceFolder = workspace.folders.length > 0 ? workspace.folders[0] : undefined;

return Promise.all(visibleItems.map(async (v) => {
return {
content: workspaceFolder ? await this.configurationResolverService.resolveWithInteractionReplace(workspaceFolder, v.descriptor.content) : v.descriptor.content,
when: v.descriptor.when,
group: v.descriptor.group,
order: v.descriptor.order,
precondition: v.descriptor.precondition
};
}));
}

private disposables = new DisposableStore();

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

this.viewWelcomeController = new ViewWelcomeController(this.id, contextKeyService);
this.viewWelcomeController = this.instantiationService.createInstance(ViewWelcomeController, this.id);
}

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

private updateViewWelcome(): void {
private async updateViewWelcome(): Promise<void> {
this.viewWelcomeDisposable.dispose();

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

const contents = this.viewWelcomeController.contents;
const contents = await this.viewWelcomeController.contents;

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

0 comments on commit 3dc0754

Please sign in to comment.