Skip to content

Commit

Permalink
feat: expose additional options for registering views
Browse files Browse the repository at this point in the history
  • Loading branch information
CompuIves committed Nov 16, 2023
1 parent e6a4a12 commit ae130a0
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/service-override/views.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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<IViewContainersRegistry>(ViewExtensions.ViewContainersRegistry).registerViewContainer({
const viewContainer = options.viewContainer ?? Registry.as<IViewContainersRegistry>(ViewExtensions.ViewContainersRegistry).registerViewContainer({
id: options.id,
title: { value: options.name, original: options.name },
order: options.order,
Expand All @@ -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

Expand Down Expand Up @@ -437,16 +440,23 @@ 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
}]

Registry.as<IViewsRegistry>(ViewExtensions.ViewsRegistry).registerViews(views, VIEW_CONTAINER)
Registry.as<IViewsRegistry>(ViewExtensions.ViewsRegistry).registerViews(views, viewContainer)

const disposableCollection = new DisposableStore()
disposableCollection.add({
dispose () {
Registry.as<IViewsRegistry>(ViewExtensions.ViewsRegistry).deregisterViews(views, VIEW_CONTAINER)
Registry.as<IViewContainersRegistry>(ViewExtensions.ViewContainersRegistry).deregisterViewContainer(VIEW_CONTAINER)
Registry.as<IViewsRegistry>(ViewExtensions.ViewsRegistry).deregisterViews(views, viewContainer)
if (options.viewContainer == null) {
// Only deregister if it's newly created
Registry.as<IViewContainersRegistry>(ViewExtensions.ViewContainersRegistry).deregisterViewContainer(viewContainer)
}
}
})

Expand Down

0 comments on commit ae130a0

Please sign in to comment.