Skip to content

Commit

Permalink
Add prefix to contributed view container ids (#13362)
Browse files Browse the repository at this point in the history
Fixes #13249

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
  • Loading branch information
tsmaeder authored Feb 13, 2024
1 parent 4b8ec2d commit fba46c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- [component] add here -->

## v1.46.0 - 01/25/2024

- [plugin] Add prefix to contributed view container ids [#13362](https://github.com/eclipse-theia/theia/pull/13362) - contributed on behalf of STMicroelectronics
- [application-manager] updated message for missing Electron main entries [#13242](https://github.com/eclipse-theia/theia/pull/13242)
- [application-package] bumped the default supported API from `1.84.2` to `1.85.1` [#13276](https://github.com/eclipse-theia/theia/pull/13276) - contributed on behalf of STMicroelectronics
- [browser-only] added support for 'browser-only' Theia [#12853](https://github.com/eclipse-theia/theia/pull/12853)
Expand Down
21 changes: 18 additions & 3 deletions packages/plugin-ext/src/main/browser/view/plugin-view-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ export class PluginViewRegistry implements FrontendApplicationContribution {

private readonly webviewViewRevivals = new Map<string, { readonly webview: WebviewView; readonly revival: Deferred<void> }>();

private nextViewContainerId = 0;

private static readonly BUILTIN_VIEW_CONTAINERS = new Set<string>([
'explorer',
'scm',
'search',
'test',
'debug'
]);

private static readonly ID_MAPPINGS: Map<string, string> = new Map([
// VS Code Viewlets
[EXPLORER_VIEW_CONTAINER_ID, 'workbench.view.explorer'],
Expand Down Expand Up @@ -266,14 +276,15 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
}

registerViewContainer(location: string, viewContainer: ViewContainer): Disposable {
if (this.viewContainers.has(viewContainer.id)) {
const containerId = `workbench.view.extension.${viewContainer.id}`;
if (this.viewContainers.has(containerId)) {
console.warn('view container such id already registered: ', JSON.stringify(viewContainer));
return Disposable.NULL;
}
const toDispose = new DisposableCollection();
const containerClass = 'theia-plugin-view-container';
let themeIconClass = '';
const iconClass = 'plugin-view-container-icon-' + viewContainer.id;
const iconClass = 'plugin-view-container-icon-' + this.nextViewContainerId++; // having dots in class would not work for css, so we need to generate an id.

if (viewContainer.themeIcon) {
const icon = ThemeIcon.fromString(viewContainer.themeIcon);
Expand All @@ -290,7 +301,7 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
`));
}

toDispose.push(this.doRegisterViewContainer(viewContainer.id, location, {
toDispose.push(this.doRegisterViewContainer(containerId, location, {
label: viewContainer.title,
// The container class automatically sets a mask; if we're using a theme icon, we don't want one.
iconClass: (themeIconClass || containerClass) + ' ' + iconClass,
Expand Down Expand Up @@ -349,6 +360,10 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
}

registerView(viewContainerId: string, view: View): Disposable {
if (!PluginViewRegistry.BUILTIN_VIEW_CONTAINERS.has(viewContainerId)) {
// if it's not a built-in view container, it must be a contributed view container, see https://github.com/eclipse-theia/theia/issues/13249
viewContainerId = `workbench.view.extension.${viewContainerId}`;
}
if (this.views.has(view.id)) {
console.warn('view with such id already registered: ', JSON.stringify(view));
return Disposable.NULL;
Expand Down

0 comments on commit fba46c6

Please sign in to comment.