Skip to content

Commit 20acc5e

Browse files
committed
microsoft#43645 Prepare for activity groups contribution
1 parent 6c22305 commit 20acc5e

4 files changed

Lines changed: 26 additions & 28 deletions

File tree

src/vs/workbench/api/browser/viewsExtensionPoint.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ namespace schema {
8383
};
8484
}
8585

86+
function getViewLocation(value: string): ViewLocation {
87+
switch (value) {
88+
case 'explorer': return ViewLocation.Explorer;
89+
case 'debug': return ViewLocation.Debug;
90+
default: return ViewLocation.get(`workbench.view.extension.${value}`) || ViewLocation.Explorer;
91+
}
92+
}
93+
8694
ExtensionsRegistry.registerExtensionPoint<{ [loc: string]: schema.IUserFriendlyViewDescriptor[] }>('views', [], schema.viewsContribution)
8795
.setHandler((extensions) => {
8896
for (let extension of extensions) {
@@ -93,12 +101,7 @@ ExtensionsRegistry.registerExtensionPoint<{ [loc: string]: schema.IUserFriendlyV
93101
return;
94102
}
95103

96-
const location = ViewLocation.getContributedViewLocation(entry.key);
97-
if (!location) {
98-
collector.warn(localize('locationId.invalid', "`{0}` is not a valid view location", entry.key));
99-
return;
100-
}
101-
104+
const location = getViewLocation(entry.key);
102105
const registeredViews = ViewsRegistry.getViews(location);
103106
const viewIds = [];
104107
const viewDescriptors = coalesce(entry.value.map(item => {
@@ -129,4 +132,4 @@ ExtensionsRegistry.registerExtensionPoint<{ [loc: string]: schema.IUserFriendlyV
129132
ViewsRegistry.registerViews(viewDescriptors);
130133
});
131134
}
132-
});
135+
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ export class ViewsViewlet extends PanelViewlet implements IViewsViewlet {
544544
return false;
545545
}
546546

547-
if (ViewLocation.getContributedViewLocation(this.location.id)) {
547+
if (ViewLocation.get(this.location.id)) {
548548
let visibleViewsCount = 0;
549549
if (this.areExtensionsReady) {
550550
visibleViewsCount = this.getViewDescriptorsFromRegistry().reduce((visibleViewsCount, v) => visibleViewsCount + (this.canBeVisible(v) ? 1 : 0), 0);

src/vs/workbench/common/views.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,23 @@ import { ThemeIcon } from 'vs/platform/theme/common/themeService';
1717

1818
export class ViewLocation {
1919

20-
static readonly Explorer = new ViewLocation('workbench.view.explorer');
21-
static readonly Debug = new ViewLocation('workbench.view.debug');
22-
static readonly Extensions = new ViewLocation('workbench.view.extensions');
23-
24-
constructor(private _id: string) {
20+
private static locations: Map<string, ViewLocation> = new Map<string, ViewLocation>();
21+
static register(id: string): ViewLocation {
22+
const viewLocation = new ViewLocation(id);
23+
ViewLocation.locations.set(id, viewLocation);
24+
return viewLocation;
2525
}
26-
27-
get id(): string {
28-
return this._id;
26+
static get(value: string): ViewLocation {
27+
return ViewLocation.locations.get(value);
2928
}
3029

31-
static getContributedViewLocation(value: string): ViewLocation {
32-
switch (value) {
33-
case 'explorer': return ViewLocation.Explorer;
34-
case 'debug': return ViewLocation.Debug;
35-
}
36-
return void 0;
37-
}
30+
static readonly Explorer: ViewLocation = ViewLocation.register('workbench.view.explorer');
31+
static readonly Debug: ViewLocation = ViewLocation.register('workbench.view.debug');
32+
static readonly Extensions: ViewLocation = ViewLocation.register('workbench.view.extensions');
33+
34+
private constructor(private _id: string) { }
35+
get id(): string { return this._id; }
36+
3837
}
3938

4039
export interface IViewDescriptor {

src/vs/workbench/parts/quickopen/browser/viewPickerHandler.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,7 @@ export class ViewPickerHandler extends QuickOpenHandler {
146146

147147
// Views
148148
viewlets.forEach((viewlet, index) => {
149-
const viewLocation: ViewLocation = viewlet.id === EXPLORER_VIEWLET_ID ? ViewLocation.Explorer
150-
: viewlet.id === DEBUG_VIEWLET_ID ? ViewLocation.Debug
151-
: viewlet.id === EXTENSIONS_VIEWLET_ID ? ViewLocation.Extensions
152-
: null;
153-
149+
const viewLocation: ViewLocation = ViewLocation.get(viewlet.id);
154150
if (viewLocation) {
155151
const viewEntriesForViewlet: ViewEntry[] = getViewEntriesForViewlet(viewlet, viewLocation);
156152
viewEntries.push(...viewEntriesForViewlet);

0 commit comments

Comments
 (0)