From 43b5165854b9047bbc2bb4fea2925caa0e2a394f Mon Sep 17 00:00:00 2001 From: Ives van Hoorne Date: Thu, 16 Nov 2023 02:41:02 +0100 Subject: [PATCH] feat: expose additional options for registering views --- src/service-override/views.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/service-override/views.ts b/src/service-override/views.ts index c60c8b3c..ae716a49 100644 --- a/src/service-override/views.ts +++ b/src/service-override/views.ts @@ -1,6 +1,6 @@ import { IEditorOverrideServices, StandaloneServices } from 'vs/editor/standalone/browser/standaloneServices' import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors' -import { IViewContainersRegistry, IViewDescriptor, IViewDescriptorService, IViewsRegistry, IViewsService, ViewContainerLocation, Extensions as ViewExtensions } from 'vs/workbench/common/views' +import { IViewContainersRegistry, IViewDescriptor, IViewDescriptorService, IViewsRegistry, IViewsService, ViewContainer, ViewContainerLocation, Extensions as ViewExtensions } from 'vs/workbench/common/views' import { ViewsService } from 'vs/workbench/browser/parts/views/viewsService' import { BrandedService, IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart' @@ -388,12 +388,16 @@ interface CustomViewOption { icon?: keyof typeof Codicon render?(container: HTMLElement): void }[] + viewContainer?: ViewContainer + canToggleVisibility?: boolean + hideByDefault?: boolean + collapsed?: boolean } function registerCustomView (options: CustomViewOption): IDisposable { const iconUrl = options.icon != null ? URI.parse(options.icon) : undefined - const VIEW_CONTAINER = Registry.as(ViewExtensions.ViewContainersRegistry).registerViewContainer({ + const VIEW_CONTAINER = options.viewContainer ?? Registry.as(ViewExtensions.ViewContainersRegistry).registerViewContainer({ id: options.id, title: { value: options.name, original: options.name }, order: options.order, @@ -407,7 +411,6 @@ function registerCustomView (options: CustomViewOption): IDisposable { const views: IViewDescriptor[] = [{ id: options.id, name: options.name, - canToggleVisibility: false, ctorDescriptor: new SyncDescriptor(class extends ViewPane { private content?: HTMLElement @@ -437,6 +440,10 @@ function registerCustomView (options: CustomViewOption): IDisposable { } }), canMoveView: options.canMoveView ?? true, + canToggleVisibility: options.canToggleVisibility ?? false, + hideByDefault: options.hideByDefault ?? false, + collapsed: options.collapsed ?? false, + order: options.order, containerIcon: iconUrl }] @@ -446,7 +453,10 @@ function registerCustomView (options: CustomViewOption): IDisposable { disposableCollection.add({ dispose () { Registry.as(ViewExtensions.ViewsRegistry).deregisterViews(views, VIEW_CONTAINER) - Registry.as(ViewExtensions.ViewContainersRegistry).deregisterViewContainer(VIEW_CONTAINER) + if (options.viewContainer == null) { + // Only deregister if it's newly created + Registry.as(ViewExtensions.ViewContainersRegistry).deregisterViewContainer(VIEW_CONTAINER) + } } })