Skip to content

Commit 268f0a2

Browse files
committed
add eventing to VDS to enable custom views
1 parent 1c4e229 commit 268f0a2

4 files changed

Lines changed: 35 additions & 7 deletions

File tree

src/vs/workbench/api/browser/viewsExtensionPoint.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/wor
3737
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
3838
import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer';
3939
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
40-
// import { SIDE_BAR_BACKGROUND, PANEL_BACKGROUND } from 'vs/workbench/common/theme';
4140

4241
export interface IUserFriendlyViewsContainerDescriptor {
4342
id: string;

src/vs/workbench/browser/parts/views/customView.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
1313
import { IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions';
1414
import { ContextAwareMenuEntryActionViewItem, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
1515
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
16-
import { ITreeView, ITreeItem, TreeItemCollapsibleState, ITreeViewDataProvider, TreeViewItemHandleArg, ITreeViewDescriptor, IViewsRegistry, ViewContainer, ITreeItemLabel, Extensions, IViewDescriptorService, IViewContainersRegistry, ViewContainerLocation } from 'vs/workbench/common/views';
16+
import { ITreeView, ITreeItem, TreeItemCollapsibleState, ITreeViewDataProvider, TreeViewItemHandleArg, ITreeViewDescriptor, IViewsRegistry, ITreeItemLabel, Extensions, IViewDescriptorService, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views';
1717
import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet';
1818
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1919
import { INotificationService } from 'vs/platform/notification/common/notification';
@@ -162,8 +162,8 @@ export class CustomTreeView extends Disposable implements ITreeView {
162162
@IProgressService private readonly progressService: IProgressService,
163163
@IContextMenuService private readonly contextMenuService: IContextMenuService,
164164
@IKeybindingService private readonly keybindingService: IKeybindingService,
165-
@IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService,
166-
@INotificationService private readonly notificationService: INotificationService
165+
@INotificationService private readonly notificationService: INotificationService,
166+
@IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService
167167
) {
168168
super();
169169
this.root = new Root();
@@ -174,10 +174,23 @@ export class CustomTreeView extends Disposable implements ITreeView {
174174
this.doRefresh([this.root]); /** soft refresh **/
175175
}
176176
}));
177+
this._register(this.viewDescriptorService.onDidChangeLocation(({ views, from, to }) => {
178+
if (views.some(v => v.id === this.id)) {
179+
this.tree?.updateOptions({ overrideStyles: { listBackground: this.viewLocation === ViewContainerLocation.Sidebar ? SIDE_BAR_BACKGROUND : PANEL_BACKGROUND } });
180+
}
181+
}));
177182

178183
this.create();
179184
}
180185

186+
get viewContainer(): ViewContainer {
187+
return this.viewDescriptorService.getViewContainer(this.id)!;
188+
}
189+
190+
get viewLocation(): ViewContainerLocation {
191+
return this.viewDescriptorService.getViewLocation(this.id)!;
192+
}
193+
181194
private _dataProvider: ITreeViewDataProvider | undefined;
182195
get dataProvider(): ITreeViewDataProvider | undefined {
183196
return this._dataProvider;
@@ -356,7 +369,7 @@ export class CustomTreeView extends Disposable implements ITreeView {
356369
},
357370
multipleSelectionSupport: this.canSelectMany,
358371
overrideStyles: {
359-
listBackground: SIDE_BAR_BACKGROUND
372+
listBackground: this.viewLocation === ViewContainerLocation.Sidebar ? SIDE_BAR_BACKGROUND : PANEL_BACKGROUND
360373
}
361374
}) as WorkbenchAsyncDataTree<ITreeItem, ITreeItem, FuzzyScore>);
362375
aligner.tree = this.tree;

src/vs/workbench/common/views.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,8 @@ export interface IViewsViewlet extends IViewlet {
349349

350350
}
351351

352-
export const IViewDescriptorService = createDecorator<IViewDescriptorService>('viewDescriptorService');
353352
export const IViewsService = createDecorator<IViewsService>('viewsService');
354353

355-
356354
export interface IViewsService {
357355
_serviceBrand: undefined;
358356

@@ -361,12 +359,14 @@ export interface IViewsService {
361359
openView(id: string, focus?: boolean): Promise<IView | null>;
362360
}
363361

362+
export const IViewDescriptorService = createDecorator<IViewDescriptorService>('viewDescriptorService');
364363

365364
export interface IViewDescriptorService {
366365

367366
_serviceBrand: undefined;
368367

369368
readonly onDidChangeContainer: Event<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }>;
369+
readonly onDidChangeLocation: Event<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }>;
370370

371371
moveViewToLocation(view: IViewDescriptor, location: ViewContainerLocation): void;
372372

src/vs/workbench/services/views/browser/viewDescriptorService.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
184184
private readonly _onDidChangeContainer: Emitter<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }> = this._register(new Emitter<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }>());
185185
readonly onDidChangeContainer: Event<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }> = this._onDidChangeContainer.event;
186186

187+
private readonly _onDidChangeLocation: Emitter<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }> = this._register(new Emitter<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }>());
188+
readonly onDidChangeLocation: Event<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }> = this._onDidChangeLocation.event;
189+
187190
private readonly viewDescriptorCollections: Map<ViewContainer, { viewDescriptorCollection: ViewDescriptorCollection, disposable: IDisposable; }>;
188191
private readonly activeViewContextKeys: Map<string, IContextKey<boolean>>;
189192
private readonly movableViewContextKeys: Map<string, IContextKey<boolean>>;
@@ -298,6 +301,11 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
298301
const viewDescriptor = this.getViewDescriptor(viewId);
299302
if (viewContainer && viewDescriptor) {
300303
this.addViews(viewContainer, [viewDescriptor]);
304+
305+
const newLocation = this.viewContainersRegistry.getViewContainerLocation(viewContainer)!;
306+
if (containerInfo.location && containerInfo.location !== newLocation) {
307+
this._onDidChangeLocation.fire({ views: [viewDescriptor], from: containerInfo.location, to: newLocation });
308+
}
301309
}
302310
}
303311

@@ -399,6 +407,14 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
399407
if (from && to && from !== to) {
400408
this.removeViews(from, views);
401409
this.addViews(to, views);
410+
411+
const oldLocation = this.viewContainersRegistry.getViewContainerLocation(from)!;
412+
const newLocation = this.viewContainersRegistry.getViewContainerLocation(to)!;
413+
414+
if (oldLocation !== newLocation) {
415+
this._onDidChangeLocation.fire({ views, from: oldLocation, to: newLocation });
416+
}
417+
402418
this._onDidChangeContainer.fire({ views, from, to });
403419
this.saveViewPositionsToCache();
404420
}

0 commit comments

Comments
 (0)