diff --git a/src/views/branchesView.ts b/src/views/branchesView.ts index 9dc6835..f0ebe3f 100644 --- a/src/views/branchesView.ts +++ b/src/views/branchesView.ts @@ -55,8 +55,6 @@ export class BranchesRepositoryNode extends SubscribeableViewNode } async getChildren(): Promise { - void this.ensureSubscription(); - if (this.child == null) { this.child = new BranchesNode(this.uri, this.view, this, this.repo); } @@ -66,7 +64,6 @@ export class BranchesRepositoryNode extends SubscribeableViewNode getTreeItem(): TreeItem { this.splatted = false; - void this.ensureSubscription(); const item = new TreeItem( this.repo.formattedName ?? this.uri.repoPath ?? '', diff --git a/src/views/commitsView.ts b/src/views/commitsView.ts index 48e5003..9cb2df8 100644 --- a/src/views/commitsView.ts +++ b/src/views/commitsView.ts @@ -48,8 +48,6 @@ export class CommitsRepositoryNode extends SubscribeableViewNode { } async getChildren(): Promise { - void this.ensureSubscription(); - if (this.child == null) { const branch = await this.repo.getBranch(); if (branch == null) return [new MessageNode(this.view, this, 'No commits could be found.')]; @@ -76,7 +74,6 @@ export class CommitsRepositoryNode extends SubscribeableViewNode { async getTreeItem(): Promise { this.splatted = false; - void this.ensureSubscription(); const branch = await this.repo.getBranch(); diff --git a/src/views/contributorsView.ts b/src/views/contributorsView.ts index c4138ac..56bcabd 100644 --- a/src/views/contributorsView.ts +++ b/src/views/contributorsView.ts @@ -37,8 +37,6 @@ export class ContributorsRepositoryNode extends SubscribeableViewNode { - void this.ensureSubscription(); - if (this.child == null) { this.child = new ContributorsNode(this.uri, this.view, this, this.repo); } @@ -47,8 +45,6 @@ export class ContributorsRepositoryNode extends SubscribeableViewNode { +export class CompareResultsNode extends ViewNode implements Disposable { static key = ':compare-results'; static getId(repoPath: string, ref1: string, ref2: string, instanceId: number): string { return `${RepositoryNode.getId(repoPath)}${this.key}(${ref1}|${ref2}):${instanceId}`; } private _children: ViewNode[] | undefined; + private _disposable: Disposable; private _instanceId: number; constructor( @@ -32,6 +34,19 @@ export class CompareResultsNode extends SubscribeableViewNode { ) { super(GitUri.fromRepoPath(repoPath), view); this._instanceId = instanceId++; + + this._disposable = this.view.onDidChangeNodeCollapsibleState(this.onCollapsibleStateChanged, this); + } + + dispose() { + this._disposable.dispose(); + } + + private _collapsibleState: TreeItemCollapsibleState | undefined; + private onCollapsibleStateChanged(e: TreeViewNodeCollapsibleStateChangeEvent) { + if (e.element !== this) return; + + this._collapsibleState = e.state; } get id(): string { @@ -78,7 +93,7 @@ export class CompareResultsNode extends SubscribeableViewNode { this._compareWith.label ?? GitRevision.shorten(this._compareWith.ref, { strings: { working: 'Working Tree' } }) }`, - this._state ?? TreeItemCollapsibleState.Collapsed, + this._collapsibleState ?? TreeItemCollapsibleState.Collapsed, ); item.contextValue = `${ContextValues.CompareResults}+${ this.comparisonNotation === '..' ? 'twodot' : 'threedot' @@ -190,10 +205,6 @@ export class CompareResultsNode extends SubscribeableViewNode { void this.triggerChange(); } - protected subscribe() { - return undefined; - } - private get comparisonNotation() { return this._comparisonNotation ?? (Container.config.advanced.useSymmetricDifferenceNotation ? '...' : '..'); } diff --git a/src/views/nodes/fileHistoryNode.ts b/src/views/nodes/fileHistoryNode.ts index ecb92f0..e091084 100644 --- a/src/views/nodes/fileHistoryNode.ts +++ b/src/views/nodes/fileHistoryNode.ts @@ -40,8 +40,6 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi } async getChildren(): Promise { - void this.ensureSubscription(); - this.view.titleDescription = `${this.label}${ this.parent instanceof FileHistoryTrackerNode && !this.parent.followingEditor ? ' (pinned)' : '' }`; @@ -92,7 +90,6 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi getTreeItem(): TreeItem { this.splatted = false; - void this.ensureSubscription(); const label = this.label; const item = new TreeItem(label, TreeItemCollapsibleState.Expanded); diff --git a/src/views/nodes/fileHistoryTrackerNode.ts b/src/views/nodes/fileHistoryTrackerNode.ts index e571e3f..6f0a162 100644 --- a/src/views/nodes/fileHistoryTrackerNode.ts +++ b/src/views/nodes/fileHistoryTrackerNode.ts @@ -65,8 +65,6 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode { - void this.ensureSubscription(); - this.view.titleDescription = `${this.label}${ this.parent instanceof LineHistoryTrackerNode && !this.parent.followingEditor ? ' (pinned)' : '' }`; @@ -213,7 +211,6 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi getTreeItem(): TreeItem { this.splatted = false; - void this.ensureSubscription(); const label = this.label; const item = new TreeItem(label, TreeItemCollapsibleState.Expanded); diff --git a/src/views/nodes/repositoriesNode.ts b/src/views/nodes/repositoriesNode.ts index 1dc31bc..e364380 100644 --- a/src/views/nodes/repositoriesNode.ts +++ b/src/views/nodes/repositoriesNode.ts @@ -49,8 +49,6 @@ export class RepositoriesNode extends SubscribeableViewNode { const item = new TreeItem('Repositories', TreeItemCollapsibleState.Expanded); item.contextValue = ContextValues.Repositories; - void this.ensureSubscription(); - return item; } diff --git a/src/views/nodes/repositoryNode.ts b/src/views/nodes/repositoryNode.ts index 7b23e12..9b1ebcf 100644 --- a/src/views/nodes/repositoryNode.ts +++ b/src/views/nodes/repositoryNode.ts @@ -197,8 +197,6 @@ export class RepositoryNode extends SubscribeableViewNode { item.id = this.id; item.tooltip = tooltip; - void this.ensureSubscription(); - return item; } diff --git a/src/views/nodes/viewNode.ts b/src/views/nodes/viewNode.ts index b6faeea..f3a5d98 100644 --- a/src/views/nodes/viewNode.ts +++ b/src/views/nodes/viewNode.ts @@ -4,7 +4,7 @@ import { GitFile, GitReference, GitRevisionReference } from '../../git/git'; import { GitUri } from '../../git/gitUri'; import { Logger } from '../../logger'; import { debug, Functions, gate, logName } from '../../system'; -import { TreeViewNodeStateChangeEvent, View } from '../viewBase'; +import { TreeViewNodeCollapsibleStateChangeEvent, View } from '../viewBase'; export enum ContextValues { ActiveFileHistory = 'gitlens:history:active:file', @@ -169,7 +169,7 @@ export abstract class SubscribeableViewNode extends V const disposables = [ this.view.onDidChangeVisibility(this.onVisibilityChanged, this), - this.view.onDidChangeNodeState(this.onNodeStateChanged, this), + this.view.onDidChangeNodeCollapsibleState(this.onNodeCollapsibleStateChanged, this), ]; if (viewSupportsAutoRefresh(this.view)) { @@ -179,16 +179,14 @@ export abstract class SubscribeableViewNode extends V const getTreeItem = this.getTreeItem; this.getTreeItem = function (this: SubscribeableViewNode) { this._loaded = true; - // TODO@eamodio: Rework, so we can do this here - // void this.ensureSubscription(); + void this.ensureSubscription(); return getTreeItem.apply(this); }; const getChildren = this.getChildren; this.getChildren = function (this: SubscribeableViewNode) { this._loaded = true; - // TODO@eamodio: Rework, so we can do this here - // void this.ensureSubscription(); + void this.ensureSubscription(); return getChildren.apply(this); }; @@ -242,19 +240,19 @@ export abstract class SubscribeableViewNode extends V this.onVisibilityChanged({ visible: this.view.visible }); } - protected onParentStateChanged?(state: TreeItemCollapsibleState): void; - protected onStateChanged?(state: TreeItemCollapsibleState): void; + protected onParentCollapsibleStateChanged?(state: TreeItemCollapsibleState): void; + protected onCollapsibleStateChanged?(state: TreeItemCollapsibleState): void; - protected _state: TreeItemCollapsibleState | undefined; - protected onNodeStateChanged(e: TreeViewNodeStateChangeEvent) { + protected collapsibleState: TreeItemCollapsibleState | undefined; + protected onNodeCollapsibleStateChanged(e: TreeViewNodeCollapsibleStateChangeEvent) { if (e.element === this) { - this._state = e.state; - if (this.onStateChanged !== undefined) { - this.onStateChanged(e.state); + this.collapsibleState = e.state; + if (this.onCollapsibleStateChanged !== undefined) { + this.onCollapsibleStateChanged(e.state); } } else if (e.element === this.parent) { - if (this.onParentStateChanged !== undefined) { - this.onParentStateChanged(e.state); + if (this.onParentCollapsibleStateChanged !== undefined) { + this.onParentCollapsibleStateChanged(e.state); } } } diff --git a/src/views/remotesView.ts b/src/views/remotesView.ts index 0ddbaf3..65016e9 100644 --- a/src/views/remotesView.ts +++ b/src/views/remotesView.ts @@ -52,8 +52,6 @@ export class RemotesRepositoryNode extends SubscribeableViewNode { } async getChildren(): Promise { - void this.ensureSubscription(); - if (this.child == null) { this.child = new RemotesNode(this.uri, this.view, this, this.repo); } @@ -63,7 +61,6 @@ export class RemotesRepositoryNode extends SubscribeableViewNode { getTreeItem(): TreeItem { this.splatted = false; - void this.ensureSubscription(); const item = new TreeItem( this.repo.formattedName ?? this.uri.repoPath ?? '', diff --git a/src/views/stashesView.ts b/src/views/stashesView.ts index 0ac8d8d..b7e0f4a 100644 --- a/src/views/stashesView.ts +++ b/src/views/stashesView.ts @@ -40,8 +40,6 @@ export class StashesRepositoryNode extends SubscribeableViewNode { } async getChildren(): Promise { - void this.ensureSubscription(); - if (this.child == null) { this.child = new StashesNode(this.uri, this.view, this, this.repo); } @@ -51,7 +49,6 @@ export class StashesRepositoryNode extends SubscribeableViewNode { getTreeItem(): TreeItem { this.splatted = false; - void this.ensureSubscription(); const item = new TreeItem( this.repo.formattedName ?? this.uri.repoPath ?? '', diff --git a/src/views/tagsView.ts b/src/views/tagsView.ts index 7b76f34..72f9613 100644 --- a/src/views/tagsView.ts +++ b/src/views/tagsView.ts @@ -40,8 +40,6 @@ export class TagsRepositoryNode extends SubscribeableViewNode { } async getChildren(): Promise { - void this.ensureSubscription(); - if (this.child == null) { this.child = new TagsNode(this.uri, this.view, this, this.repo); } @@ -51,7 +49,6 @@ export class TagsRepositoryNode extends SubscribeableViewNode { getTreeItem(): TreeItem { this.splatted = false; - void this.ensureSubscription(); const item = new TreeItem( this.repo.formattedName ?? this.uri.repoPath ?? '', diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index 22cc7dd..77e7e73 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -74,7 +74,7 @@ export type ViewsWithFiles = | StashesView | TagsView; -export interface TreeViewNodeStateChangeEvent extends TreeViewExpansionEvent { +export interface TreeViewNodeCollapsibleStateChangeEvent extends TreeViewExpansionEvent { state: TreeItemCollapsibleState; } @@ -103,9 +103,9 @@ export abstract class ViewBase< return this._onDidChangeVisibility.event; } - private _onDidChangeNodeState = new EventEmitter>(); - get onDidChangeNodeState(): Event> { - return this._onDidChangeNodeState.event; + private _onDidChangeNodeCollapsibleState = new EventEmitter>(); + get onDidChangeNodeCollapsibleState(): Event> { + return this._onDidChangeNodeCollapsibleState.event; } protected disposable: Disposable | undefined; @@ -261,11 +261,11 @@ export abstract class ViewBase< } protected onElementCollapsed(e: TreeViewExpansionEvent) { - this._onDidChangeNodeState.fire({ ...e, state: TreeItemCollapsibleState.Collapsed }); + this._onDidChangeNodeCollapsibleState.fire({ ...e, state: TreeItemCollapsibleState.Collapsed }); } protected onElementExpanded(e: TreeViewExpansionEvent) { - this._onDidChangeNodeState.fire({ ...e, state: TreeItemCollapsibleState.Expanded }); + this._onDidChangeNodeCollapsibleState.fire({ ...e, state: TreeItemCollapsibleState.Expanded }); } protected onVisibilityChanged(e: TreeViewVisibilityChangeEvent) {