Skip to content

Commit

Permalink
8992-enabling-view-when-clause:
Browse files Browse the repository at this point in the history
Enabling setting view when clauses with these values: undefined, true, false or expressions.

Signed-off-by: Dan Arad <[email protected]>
  • Loading branch information
danarad05 committed Mar 8, 2021
1 parent 1110f99 commit 2e4764f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/plugin-ext/src/main/browser/view/plugin-view-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
private readonly viewsWelcome = new Map<string, ViewWelcome[]>();
private readonly viewContainers = new Map<string, [string, ViewContainerTitleOptions]>();
private readonly containerViews = new Map<string, string[]>();
private readonly viewClauseContexts = new Map<string, Set<string>>();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private readonly viewClauseContexts = new Map<string, any>();

private readonly viewDataProviders = new Map<string, ViewDataProvider>();
private readonly viewDataState = new Map<string, object>();
Expand Down Expand Up @@ -152,15 +153,15 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
this.contextKeyService.onDidChange(e => {
for (const [, view] of this.views.values()) {
const clauseContext = this.viewClauseContexts.get(view.id);
if (clauseContext && e.affects(clauseContext)) {
if (this.shouldUpdateViewVisibility(clauseContext, e)) {
this.updateViewVisibility(view.id);
}
}
for (const [viewId, viewWelcomes] of this.viewsWelcome) {
for (const [index] of viewWelcomes.entries()) {
const viewWelcomeId = this.toViewWelcomeId(index, viewId);
const clauseContext = this.viewClauseContexts.get(viewWelcomeId);
if (clauseContext && e.affects(clauseContext)) {
if (this.shouldUpdateViewVisibility(clauseContext, e)) {
this.updateViewWelcomeVisibility(viewId);
}
}
Expand Down Expand Up @@ -207,7 +208,7 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
return false;
}
const [, view] = viewInfo;
return view.when === undefined || this.contextKeyService.match(view.when);
return view.when === undefined || view.when === 'true' || this.contextKeyService.match(view.when);
}

registerViewContainer(location: string, viewContainer: ViewContainer): Disposable {
Expand Down Expand Up @@ -298,8 +299,8 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
}
}));

if (view.when) {
this.viewClauseContexts.set(view.id, this.contextKeyService.parseKeys(view.when));
if (view.when && view.when !== 'false') {
this.viewClauseContexts.set(view.id, view.when === 'true' ? view.when : this.contextKeyService.parseKeys(view.when));
toDispose.push(Disposable.create(() => this.viewClauseContexts.delete(view.id)));
}
toDispose.push(this.quickView.registerItem({
Expand Down Expand Up @@ -728,6 +729,10 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private shouldUpdateViewVisibility(clauseContext: any, e: any): boolean {
return clauseContext === undefined || clauseContext === 'true' || (clauseContext instanceof Set && e.affects(clauseContext));
}
}
export namespace PluginViewRegistry {
export type VisibleView = ({ viewletId: string } | { panelId: string }) & {
Expand Down

0 comments on commit 2e4764f

Please sign in to comment.