From 20acc5ec9ff9e1153da17fde08464444d60ac1d1 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Mon, 16 Apr 2018 16:11:34 +0200 Subject: [PATCH] #43645 Prepare for activity groups contribution --- .../api/browser/viewsExtensionPoint.ts | 17 ++++++----- .../browser/parts/views/viewsViewlet.ts | 2 +- src/vs/workbench/common/views.ts | 29 +++++++++---------- .../quickopen/browser/viewPickerHandler.ts | 6 +--- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/vs/workbench/api/browser/viewsExtensionPoint.ts b/src/vs/workbench/api/browser/viewsExtensionPoint.ts index 41a9e24e370eb..4a1c92df99db2 100644 --- a/src/vs/workbench/api/browser/viewsExtensionPoint.ts +++ b/src/vs/workbench/api/browser/viewsExtensionPoint.ts @@ -83,6 +83,14 @@ namespace schema { }; } +function getViewLocation(value: string): ViewLocation { + switch (value) { + case 'explorer': return ViewLocation.Explorer; + case 'debug': return ViewLocation.Debug; + default: return ViewLocation.get(`workbench.view.extension.${value}`) || ViewLocation.Explorer; + } +} + ExtensionsRegistry.registerExtensionPoint<{ [loc: string]: schema.IUserFriendlyViewDescriptor[] }>('views', [], schema.viewsContribution) .setHandler((extensions) => { for (let extension of extensions) { @@ -93,12 +101,7 @@ ExtensionsRegistry.registerExtensionPoint<{ [loc: string]: schema.IUserFriendlyV return; } - const location = ViewLocation.getContributedViewLocation(entry.key); - if (!location) { - collector.warn(localize('locationId.invalid', "`{0}` is not a valid view location", entry.key)); - return; - } - + const location = getViewLocation(entry.key); const registeredViews = ViewsRegistry.getViews(location); const viewIds = []; const viewDescriptors = coalesce(entry.value.map(item => { @@ -129,4 +132,4 @@ ExtensionsRegistry.registerExtensionPoint<{ [loc: string]: schema.IUserFriendlyV ViewsRegistry.registerViews(viewDescriptors); }); } - }); + }); \ No newline at end of file diff --git a/src/vs/workbench/browser/parts/views/viewsViewlet.ts b/src/vs/workbench/browser/parts/views/viewsViewlet.ts index dbc7851633745..61f93e46d4a16 100644 --- a/src/vs/workbench/browser/parts/views/viewsViewlet.ts +++ b/src/vs/workbench/browser/parts/views/viewsViewlet.ts @@ -544,7 +544,7 @@ export class ViewsViewlet extends PanelViewlet implements IViewsViewlet { return false; } - if (ViewLocation.getContributedViewLocation(this.location.id)) { + if (ViewLocation.get(this.location.id)) { let visibleViewsCount = 0; if (this.areExtensionsReady) { visibleViewsCount = this.getViewDescriptorsFromRegistry().reduce((visibleViewsCount, v) => visibleViewsCount + (this.canBeVisible(v) ? 1 : 0), 0); diff --git a/src/vs/workbench/common/views.ts b/src/vs/workbench/common/views.ts index 5947ecba8cdce..aa06fd035a291 100644 --- a/src/vs/workbench/common/views.ts +++ b/src/vs/workbench/common/views.ts @@ -17,24 +17,23 @@ import { ThemeIcon } from 'vs/platform/theme/common/themeService'; export class ViewLocation { - static readonly Explorer = new ViewLocation('workbench.view.explorer'); - static readonly Debug = new ViewLocation('workbench.view.debug'); - static readonly Extensions = new ViewLocation('workbench.view.extensions'); - - constructor(private _id: string) { + private static locations: Map = new Map(); + static register(id: string): ViewLocation { + const viewLocation = new ViewLocation(id); + ViewLocation.locations.set(id, viewLocation); + return viewLocation; } - - get id(): string { - return this._id; + static get(value: string): ViewLocation { + return ViewLocation.locations.get(value); } - static getContributedViewLocation(value: string): ViewLocation { - switch (value) { - case 'explorer': return ViewLocation.Explorer; - case 'debug': return ViewLocation.Debug; - } - return void 0; - } + static readonly Explorer: ViewLocation = ViewLocation.register('workbench.view.explorer'); + static readonly Debug: ViewLocation = ViewLocation.register('workbench.view.debug'); + static readonly Extensions: ViewLocation = ViewLocation.register('workbench.view.extensions'); + + private constructor(private _id: string) { } + get id(): string { return this._id; } + } export interface IViewDescriptor { diff --git a/src/vs/workbench/parts/quickopen/browser/viewPickerHandler.ts b/src/vs/workbench/parts/quickopen/browser/viewPickerHandler.ts index 6c164a8125b98..7dcbf8319e93a 100644 --- a/src/vs/workbench/parts/quickopen/browser/viewPickerHandler.ts +++ b/src/vs/workbench/parts/quickopen/browser/viewPickerHandler.ts @@ -146,11 +146,7 @@ export class ViewPickerHandler extends QuickOpenHandler { // Views viewlets.forEach((viewlet, index) => { - const viewLocation: ViewLocation = viewlet.id === EXPLORER_VIEWLET_ID ? ViewLocation.Explorer - : viewlet.id === DEBUG_VIEWLET_ID ? ViewLocation.Debug - : viewlet.id === EXTENSIONS_VIEWLET_ID ? ViewLocation.Extensions - : null; - + const viewLocation: ViewLocation = ViewLocation.get(viewlet.id); if (viewLocation) { const viewEntriesForViewlet: ViewEntry[] = getViewEntriesForViewlet(viewlet, viewLocation); viewEntries.push(...viewEntriesForViewlet);