Skip to content

Commit acc91e1

Browse files
committed
separate tree view and custom view
1 parent 46c98a9 commit acc91e1

3 files changed

Lines changed: 60 additions & 36 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema';
99
import * as resources from 'vs/base/common/resources';
1010
import { ExtensionMessageCollector, ExtensionsRegistry, IExtensionPoint, IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry';
1111
import { ViewContainer, IViewsRegistry, ITreeViewDescriptor, IViewContainersRegistry, Extensions as ViewContainerExtensions, TEST_VIEW_CONTAINER_ID, IViewDescriptor, ViewContainerLocation } from 'vs/workbench/common/views';
12-
import { CustomTreeViewPane, CustomTreeView } from 'vs/workbench/browser/parts/views/customView';
12+
import { TreeViewPane, CustomTreeView } from 'vs/workbench/browser/parts/views/treeView';
1313
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1414
import { coalesce, } from 'vs/base/common/arrays';
1515
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWorkbenchContribution } from 'vs/workbench/common/contributions';
@@ -396,7 +396,7 @@ class ViewsExtensionHandler implements IWorkbenchContribution {
396396
const viewDescriptor = <ICustomViewDescriptor>{
397397
id: item.id,
398398
name: item.name,
399-
ctorDescriptor: new SyncDescriptor(CustomTreeViewPane),
399+
ctorDescriptor: new SyncDescriptor(TreeViewPane),
400400
when: ContextKeyExpr.deserialize(item.when),
401401
canToggleVisibility: true,
402402
canMoveView: true,

src/vs/workbench/browser/parts/views/customView.ts renamed to src/vs/workbench/browser/parts/views/treeView.ts

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import { SIDE_BAR_BACKGROUND, PANEL_BACKGROUND } from 'vs/workbench/common/theme
4444
import { IOpenerService } from 'vs/platform/opener/common/opener';
4545
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
4646

47-
export class CustomTreeViewPane extends ViewPane {
47+
export class TreeViewPane extends ViewPane {
4848

4949
private treeView: ITreeView;
5050

@@ -79,7 +79,7 @@ export class CustomTreeViewPane extends ViewPane {
7979
renderBody(container: HTMLElement): void {
8080
super.renderBody(container);
8181

82-
if (this.treeView instanceof CustomTreeView) {
82+
if (this.treeView instanceof TreeView) {
8383
this.treeView.show(container);
8484
}
8585
}
@@ -119,12 +119,11 @@ class Root implements ITreeItem {
119119

120120
const noDataProviderMessage = localize('no-dataprovider', "There is no data provider registered that can provide view data.");
121121

122-
class CustomTree extends WorkbenchAsyncDataTree<ITreeItem, ITreeItem, FuzzyScore> { }
122+
class Tree extends WorkbenchAsyncDataTree<ITreeItem, ITreeItem, FuzzyScore> { }
123123

124-
export class CustomTreeView extends Disposable implements ITreeView {
124+
export class TreeView extends Disposable implements ITreeView {
125125

126126
private isVisible: boolean = false;
127-
private activated: boolean = false;
128127
private _hasIconForParentNode = false;
129128
private _hasIconForLeafNode = false;
130129
private _showCollapseAllAction = false;
@@ -135,7 +134,7 @@ export class CustomTreeView extends Disposable implements ITreeView {
135134
private _messageValue: string | undefined;
136135
private _canSelectMany: boolean = false;
137136
private messageElement!: HTMLDivElement;
138-
private tree: CustomTree | undefined;
137+
private tree: Tree | undefined;
139138
private treeLabels: ResourceLabels | undefined;
140139

141140
private root: ITreeItem;
@@ -165,14 +164,13 @@ export class CustomTreeView extends Disposable implements ITreeView {
165164
private readonly _onDidCompleteRefresh: Emitter<void> = this._register(new Emitter<void>());
166165

167166
constructor(
168-
private id: string,
167+
protected readonly id: string,
169168
private _title: string,
170-
@IExtensionService private readonly extensionService: IExtensionService,
171169
@IThemeService private readonly themeService: IThemeService,
172170
@IInstantiationService private readonly instantiationService: IInstantiationService,
173171
@ICommandService private readonly commandService: ICommandService,
174172
@IConfigurationService private readonly configurationService: IConfigurationService,
175-
@IProgressService private readonly progressService: IProgressService,
173+
@IProgressService protected readonly progressService: IProgressService,
176174
@IContextMenuService private readonly contextMenuService: IContextMenuService,
177175
@IKeybindingService private readonly keybindingService: IKeybindingService,
178176
@INotificationService private readonly notificationService: INotificationService,
@@ -305,9 +303,6 @@ export class CustomTreeView extends Disposable implements ITreeView {
305303
}
306304

307305
this.isVisible = isVisible;
308-
if (this.isVisible) {
309-
this.activate();
310-
}
311306

312307
if (this.tree) {
313308
if (this.isVisible) {
@@ -365,9 +360,9 @@ export class CustomTreeView extends Disposable implements ITreeView {
365360
const aligner = new Aligner(this.themeService);
366361
const renderer = this.instantiationService.createInstance(TreeRenderer, this.id, treeMenus, this.treeLabels, actionViewItemProvider, aligner);
367362

368-
this.tree = this._register(this.instantiationService.createInstance(CustomTree, 'CustomView', this.treeContainer, new CustomTreeDelegate(), [renderer],
363+
this.tree = this._register(this.instantiationService.createInstance(Tree, this.id, this.treeContainer, new TreeViewDelegate(), [renderer],
369364
dataSource, {
370-
identityProvider: new CustomViewIdentityProvider(),
365+
identityProvider: new TreeViewIdentityProvider(),
371366
accessibilityProvider: {
372367
getAriaLabel(element: ITreeItem): string {
373368
return element.tooltip ? element.tooltip : element.label ? element.label.label : '';
@@ -409,9 +404,9 @@ export class CustomTreeView extends Disposable implements ITreeView {
409404
}));
410405
this.tree.setInput(this.root).then(() => this.updateContentAreas());
411406

412-
const customTreeNavigator = ResourceNavigator.createTreeResourceNavigator(this.tree, { openOnFocus: false, openOnSelection: false });
413-
this._register(customTreeNavigator);
414-
this._register(customTreeNavigator.onDidOpenResource(e => {
407+
const treeNavigator = ResourceNavigator.createTreeResourceNavigator(this.tree, { openOnFocus: false, openOnSelection: false });
408+
this._register(treeNavigator);
409+
this._register(treeNavigator.onDidOpenResource(e => {
415410
if (!e.browserEvent) {
416411
return;
417412
}
@@ -462,7 +457,7 @@ export class CustomTreeView extends Disposable implements ITreeView {
462457
});
463458
}
464459

465-
private updateMessage(): void {
460+
protected updateMessage(): void {
466461
if (this._message) {
467462
this.showMessage(this._message);
468463
} else if (!this.dataProvider) {
@@ -579,17 +574,6 @@ export class CustomTreeView extends Disposable implements ITreeView {
579574
return Promise.resolve();
580575
}
581576

582-
private activate() {
583-
if (!this.activated) {
584-
this.progressService.withProgress({ location: this.viewContainer.id }, () => this.extensionService.activateByEvent(`onView:${this.id}`))
585-
.then(() => timeout(2000))
586-
.then(() => {
587-
this.updateMessage();
588-
});
589-
this.activated = true;
590-
}
591-
}
592-
593577
private refreshing: boolean = false;
594578
private async doRefresh(elements: ITreeItem[]): Promise<void> {
595579
const tree = this.tree;
@@ -618,13 +602,13 @@ export class CustomTreeView extends Disposable implements ITreeView {
618602
}
619603
}
620604

621-
class CustomViewIdentityProvider implements IIdentityProvider<ITreeItem> {
605+
class TreeViewIdentityProvider implements IIdentityProvider<ITreeItem> {
622606
getId(element: ITreeItem): { toString(): string; } {
623607
return element.handle;
624608
}
625609
}
626610

627-
class CustomTreeDelegate implements IListVirtualDelegate<ITreeItem> {
611+
class TreeViewDelegate implements IListVirtualDelegate<ITreeItem> {
628612

629613
getHeight(element: ITreeItem): number {
630614
return TreeRenderer.ITEM_HEIGHT;
@@ -943,3 +927,43 @@ class TreeMenus extends Disposable implements IDisposable {
943927
return result;
944928
}
945929
}
930+
931+
export class CustomTreeView extends TreeView {
932+
933+
private activated: boolean = false;
934+
935+
constructor(
936+
id: string,
937+
title: string,
938+
@IThemeService themeService: IThemeService,
939+
@IInstantiationService instantiationService: IInstantiationService,
940+
@ICommandService commandService: ICommandService,
941+
@IConfigurationService configurationService: IConfigurationService,
942+
@IProgressService progressService: IProgressService,
943+
@IContextMenuService contextMenuService: IContextMenuService,
944+
@IKeybindingService keybindingService: IKeybindingService,
945+
@INotificationService notificationService: INotificationService,
946+
@IViewDescriptorService viewDescriptorService: IViewDescriptorService,
947+
@IExtensionService private readonly extensionService: IExtensionService,
948+
) {
949+
super(id, title, themeService, instantiationService, commandService, configurationService, progressService, contextMenuService, keybindingService, notificationService, viewDescriptorService);
950+
}
951+
952+
setVisibility(isVisible: boolean): void {
953+
super.setVisibility(isVisible);
954+
if (this.visible) {
955+
this.activate();
956+
}
957+
}
958+
959+
private activate() {
960+
if (!this.activated) {
961+
this.progressService.withProgress({ location: this.viewContainer.id }, () => this.extensionService.activateByEvent(`onView:${this.id}`))
962+
.then(() => timeout(2000))
963+
.then(() => {
964+
this.updateMessage();
965+
});
966+
this.activated = true;
967+
}
968+
}
969+
}

src/vs/workbench/contrib/userDataSync/browser/userDataSyncHistory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
88
import { IViewsRegistry, Extensions, ITreeViewDescriptor, ITreeViewDataProvider, ITreeItem, TreeItemCollapsibleState, IViewsService, TreeViewItemHandleArg } from 'vs/workbench/common/views';
99
import { localize } from 'vs/nls';
1010
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
11-
import { CustomTreeViewPane, CustomTreeView } from 'vs/workbench/browser/parts/views/customView';
11+
import { TreeViewPane, TreeView } from 'vs/workbench/browser/parts/views/treeView';
1212
import { VIEW_CONTAINER } from 'vs/workbench/contrib/files/browser/explorerViewlet';
1313
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
1414
import { ALL_RESOURCE_KEYS, CONTEXT_SYNC_ENABLEMENT, IUserDataSyncStoreService, USER_DATA_SYNC_SCHEME, ResourceKey } from 'vs/platform/userDataSync/common/userDataSync';
@@ -37,7 +37,7 @@ export class UserDataSyncHistoryViewContribution implements IWorkbenchContributi
3737
const that = this;
3838
const name = localize('title', "Sync History");
3939
const viewEnablementContext = CONTEXT_SHOW_USER_DATA_SYNC_HISTORY_VIEW.bindTo(this.contextKeyService);
40-
const treeView = this.instantiationService.createInstance(CustomTreeView, this.viewId, name);
40+
const treeView = this.instantiationService.createInstance(TreeView, this.viewId, name);
4141
const disposable = treeView.onDidChangeVisibility(visible => {
4242
if (visible && !treeView.dataProvider) {
4343
disposable.dispose();
@@ -48,7 +48,7 @@ export class UserDataSyncHistoryViewContribution implements IWorkbenchContributi
4848
viewsRegistry.registerViews([<ITreeViewDescriptor>{
4949
id: this.viewId,
5050
name,
51-
ctorDescriptor: new SyncDescriptor(CustomTreeViewPane),
51+
ctorDescriptor: new SyncDescriptor(TreeViewPane),
5252
when: ContextKeyExpr.and(CONTEXT_SYNC_ENABLEMENT, CONTEXT_SHOW_USER_DATA_SYNC_HISTORY_VIEW),
5353
canToggleVisibility: false,
5454
canMoveView: true,

0 commit comments

Comments
 (0)