diff --git a/src/vs/workbench/api/browser/viewsContainersExtensionPoint.ts b/src/vs/workbench/api/browser/viewsContainersExtensionPoint.ts index 5528735ff51..5fd69ca019e 100644 --- a/src/vs/workbench/api/browser/viewsContainersExtensionPoint.ts +++ b/src/vs/workbench/api/browser/viewsContainersExtensionPoint.ts @@ -143,56 +143,62 @@ class ViewsContainersExtensionHandler implements IWorkbenchContribution { } private registerCustomViewlet(descriptor: IUserFriendlyViewsContainerDescriptor, order: number, cssClass: string): void { + const viewletRegistry = Registry.as(ViewletExtensions.Viewlets); const id = `workbench.view.extension.${descriptor.id}`; - const location: ViewLocation = ViewLocation.register(id); - // Register as viewlet - class CustomViewlet extends PersistentViewsViewlet { - constructor( - @IPartService partService: IPartService, - @ITelemetryService telemetryService: ITelemetryService, - @IWorkspaceContextService contextService: IWorkspaceContextService, - @IStorageService storageService: IStorageService, - @IWorkbenchEditorService editorService: IWorkbenchEditorService, - @IInstantiationService instantiationService: IInstantiationService, - @IContextKeyService contextKeyService: IContextKeyService, - @IThemeService themeService: IThemeService, - @IContextMenuService contextMenuService: IContextMenuService, - @IExtensionService extensionService: IExtensionService - ) { - super(id, location, `${id}.state`, true, partService, telemetryService, storageService, instantiationService, themeService, contextService, contextKeyService, contextMenuService, extensionService); + if (!viewletRegistry.getViewlet(id)) { + + const location: ViewLocation = ViewLocation.register(id); + + // Register as viewlet + class CustomViewlet extends PersistentViewsViewlet { + constructor( + @IPartService partService: IPartService, + @ITelemetryService telemetryService: ITelemetryService, + @IWorkspaceContextService contextService: IWorkspaceContextService, + @IStorageService storageService: IStorageService, + @IWorkbenchEditorService editorService: IWorkbenchEditorService, + @IInstantiationService instantiationService: IInstantiationService, + @IContextKeyService contextKeyService: IContextKeyService, + @IThemeService themeService: IThemeService, + @IContextMenuService contextMenuService: IContextMenuService, + @IExtensionService extensionService: IExtensionService + ) { + super(id, location, `${id}.state`, true, partService, telemetryService, storageService, instantiationService, themeService, contextService, contextKeyService, contextMenuService, extensionService); + } } - } - const viewletDescriptor = new ViewletDescriptor( - CustomViewlet, - id, - descriptor.title, - cssClass, - order - ); + const viewletDescriptor = new ViewletDescriptor( + CustomViewlet, + id, + descriptor.title, + cssClass, + order + ); - Registry.as(ViewletExtensions.Viewlets).registerViewlet(viewletDescriptor); + viewletRegistry.registerViewlet(viewletDescriptor); - // Register Action to Open Viewlet - class OpenCustomViewletAction extends ToggleViewletAction { - constructor( - id: string, label: string, - @IViewletService viewletService: IViewletService, - @IWorkbenchEditorService editorService: IWorkbenchEditorService - ) { - super(id, label, id, viewletService, editorService); + // Register Action to Open Viewlet + class OpenCustomViewletAction extends ToggleViewletAction { + constructor( + id: string, label: string, + @IViewletService viewletService: IViewletService, + @IWorkbenchEditorService editorService: IWorkbenchEditorService + ) { + super(id, label, id, viewletService, editorService); + } } - } - const registry = Registry.as(ActionExtensions.WorkbenchActions); - registry.registerWorkbenchAction( - new SyncActionDescriptor(OpenCustomViewletAction, id, localize('showViewlet', "Show {0}", descriptor.title)), - 'View: Show {0}', - localize('view', "View") - ); + const registry = Registry.as(ActionExtensions.WorkbenchActions); + registry.registerWorkbenchAction( + new SyncActionDescriptor(OpenCustomViewletAction, id, localize('showViewlet', "Show {0}", descriptor.title)), + 'View: Show {0}', + localize('view', "View") + ); + + // Generate CSS to show the icon in the activity bar + const iconClass = `.monaco-workbench > .activitybar .monaco-action-bar .action-label.${cssClass}`; + createCSSRule(iconClass, `-webkit-mask: url('${descriptor.icon}') no-repeat 50% 50%`); + } - // Generate CSS to show the icon in the activity bar - const iconClass = `.monaco-workbench > .activitybar .monaco-action-bar .action-label.${cssClass}`; - createCSSRule(iconClass, `-webkit-mask: url('${descriptor.icon}') no-repeat 50% 50%`); } }