From 268f0a22a37376a260ce1bc4d69b5efc000b03cc Mon Sep 17 00:00:00 2001 From: SteVen Batten Date: Fri, 24 Jan 2020 09:37:52 -0800 Subject: [PATCH] add eventing to VDS to enable custom views --- .../api/browser/viewsExtensionPoint.ts | 1 - .../browser/parts/views/customView.ts | 21 +++++++++++++++---- src/vs/workbench/common/views.ts | 4 ++-- .../views/browser/viewDescriptorService.ts | 16 ++++++++++++++ 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/api/browser/viewsExtensionPoint.ts b/src/vs/workbench/api/browser/viewsExtensionPoint.ts index d313f037550..e88f2c3df7c 100644 --- a/src/vs/workbench/api/browser/viewsExtensionPoint.ts +++ b/src/vs/workbench/api/browser/viewsExtensionPoint.ts @@ -37,7 +37,6 @@ import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/wor import { SyncActionDescriptor } from 'vs/platform/actions/common/actions'; import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; -// import { SIDE_BAR_BACKGROUND, PANEL_BACKGROUND } from 'vs/workbench/common/theme'; export interface IUserFriendlyViewsContainerDescriptor { id: string; diff --git a/src/vs/workbench/browser/parts/views/customView.ts b/src/vs/workbench/browser/parts/views/customView.ts index a814eb0a15f..c573df84e12 100644 --- a/src/vs/workbench/browser/parts/views/customView.ts +++ b/src/vs/workbench/browser/parts/views/customView.ts @@ -13,7 +13,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView import { IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions'; import { ContextAwareMenuEntryActionViewItem, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; -import { ITreeView, ITreeItem, TreeItemCollapsibleState, ITreeViewDataProvider, TreeViewItemHandleArg, ITreeViewDescriptor, IViewsRegistry, ViewContainer, ITreeItemLabel, Extensions, IViewDescriptorService, IViewContainersRegistry, ViewContainerLocation } from 'vs/workbench/common/views'; +import { ITreeView, ITreeItem, TreeItemCollapsibleState, ITreeViewDataProvider, TreeViewItemHandleArg, ITreeViewDescriptor, IViewsRegistry, ITreeItemLabel, Extensions, IViewDescriptorService, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views'; import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { INotificationService } from 'vs/platform/notification/common/notification'; @@ -162,8 +162,8 @@ export class CustomTreeView extends Disposable implements ITreeView { @IProgressService private readonly progressService: IProgressService, @IContextMenuService private readonly contextMenuService: IContextMenuService, @IKeybindingService private readonly keybindingService: IKeybindingService, - @IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService, - @INotificationService private readonly notificationService: INotificationService + @INotificationService private readonly notificationService: INotificationService, + @IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService ) { super(); this.root = new Root(); @@ -174,10 +174,23 @@ export class CustomTreeView extends Disposable implements ITreeView { this.doRefresh([this.root]); /** soft refresh **/ } })); + this._register(this.viewDescriptorService.onDidChangeLocation(({ views, from, to }) => { + if (views.some(v => v.id === this.id)) { + this.tree?.updateOptions({ overrideStyles: { listBackground: this.viewLocation === ViewContainerLocation.Sidebar ? SIDE_BAR_BACKGROUND : PANEL_BACKGROUND } }); + } + })); this.create(); } + get viewContainer(): ViewContainer { + return this.viewDescriptorService.getViewContainer(this.id)!; + } + + get viewLocation(): ViewContainerLocation { + return this.viewDescriptorService.getViewLocation(this.id)!; + } + private _dataProvider: ITreeViewDataProvider | undefined; get dataProvider(): ITreeViewDataProvider | undefined { return this._dataProvider; @@ -356,7 +369,7 @@ export class CustomTreeView extends Disposable implements ITreeView { }, multipleSelectionSupport: this.canSelectMany, overrideStyles: { - listBackground: SIDE_BAR_BACKGROUND + listBackground: this.viewLocation === ViewContainerLocation.Sidebar ? SIDE_BAR_BACKGROUND : PANEL_BACKGROUND } }) as WorkbenchAsyncDataTree); aligner.tree = this.tree; diff --git a/src/vs/workbench/common/views.ts b/src/vs/workbench/common/views.ts index d5f1e856ea7..65cb05175d9 100644 --- a/src/vs/workbench/common/views.ts +++ b/src/vs/workbench/common/views.ts @@ -349,10 +349,8 @@ export interface IViewsViewlet extends IViewlet { } -export const IViewDescriptorService = createDecorator('viewDescriptorService'); export const IViewsService = createDecorator('viewsService'); - export interface IViewsService { _serviceBrand: undefined; @@ -361,12 +359,14 @@ export interface IViewsService { openView(id: string, focus?: boolean): Promise; } +export const IViewDescriptorService = createDecorator('viewDescriptorService'); export interface IViewDescriptorService { _serviceBrand: undefined; readonly onDidChangeContainer: Event<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }>; + readonly onDidChangeLocation: Event<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }>; moveViewToLocation(view: IViewDescriptor, location: ViewContainerLocation): void; diff --git a/src/vs/workbench/services/views/browser/viewDescriptorService.ts b/src/vs/workbench/services/views/browser/viewDescriptorService.ts index f4f0e77d123..b7a164dee5e 100644 --- a/src/vs/workbench/services/views/browser/viewDescriptorService.ts +++ b/src/vs/workbench/services/views/browser/viewDescriptorService.ts @@ -184,6 +184,9 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor private readonly _onDidChangeContainer: Emitter<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }> = this._register(new Emitter<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }>()); readonly onDidChangeContainer: Event<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }> = this._onDidChangeContainer.event; + private readonly _onDidChangeLocation: Emitter<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }> = this._register(new Emitter<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }>()); + readonly onDidChangeLocation: Event<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }> = this._onDidChangeLocation.event; + private readonly viewDescriptorCollections: Map; private readonly activeViewContextKeys: Map>; private readonly movableViewContextKeys: Map>; @@ -298,6 +301,11 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor const viewDescriptor = this.getViewDescriptor(viewId); if (viewContainer && viewDescriptor) { this.addViews(viewContainer, [viewDescriptor]); + + const newLocation = this.viewContainersRegistry.getViewContainerLocation(viewContainer)!; + if (containerInfo.location && containerInfo.location !== newLocation) { + this._onDidChangeLocation.fire({ views: [viewDescriptor], from: containerInfo.location, to: newLocation }); + } } } @@ -399,6 +407,14 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor if (from && to && from !== to) { this.removeViews(from, views); this.addViews(to, views); + + const oldLocation = this.viewContainersRegistry.getViewContainerLocation(from)!; + const newLocation = this.viewContainersRegistry.getViewContainerLocation(to)!; + + if (oldLocation !== newLocation) { + this._onDidChangeLocation.fire({ views, from: oldLocation, to: newLocation }); + } + this._onDidChangeContainer.fire({ views, from, to }); this.saveViewPositionsToCache(); }