Browse Source

Adds node events for expand/collapse

main
Eric Amodio 6 years ago
parent
commit
73690a41f6
2 changed files with 42 additions and 4 deletions
  1. +20
    -3
      src/views/nodes/viewNode.ts
  2. +22
    -1
      src/views/viewBase.ts

+ 20
- 3
src/views/nodes/viewNode.ts View File

@ -1,8 +1,8 @@
'use strict';
import { Command, Disposable, Event, TreeItem, TreeViewVisibilityChangeEvent } from 'vscode';
import { Command, Disposable, Event, TreeItem, TreeItemCollapsibleState, TreeViewVisibilityChangeEvent } from 'vscode';
import { GitUri } from '../../git/gitService';
import { debug, logName } from '../../system';
import { RefreshReason, View } from '../viewBase';
import { RefreshReason, TreeViewNodeStateChangeEvent, View } from '../viewBase';
export enum ResourceType {
ActiveFileHistory = 'gitlens:active:history-file',
@ -122,7 +122,10 @@ export abstract class SubscribeableViewNode extends ViewNode
) {
super(uri, parent);
const disposables = [this.view.onDidChangeVisibility(this.onVisibilityChanged, this)];
const disposables = [
this.view.onDidChangeVisibility(this.onVisibilityChanged, this),
this.view.onDidChangeNodeState(this.onNodeStateChanged, this)
];
if (supportsAutoRefresh(this.view)) {
disposables.push(this.view.onDidChangeAutoRefresh(this.onAutoRefreshChanged, this));
@ -180,6 +183,20 @@ export abstract class SubscribeableViewNode extends ViewNode
this.onVisibilityChanged({ visible: this.view.visible });
}
protected onParentStateChanged(state: TreeItemCollapsibleState) {}
protected onStateChanged(state: TreeItemCollapsibleState) {}
protected _state: TreeItemCollapsibleState | undefined;
protected onNodeStateChanged(e: TreeViewNodeStateChangeEvent<ViewNode>) {
if (e.element === this) {
this._state = e.state;
this.onStateChanged(e.state);
}
else if (e.element === this._parent) {
this.onParentStateChanged(e.state);
}
}
@debug()
protected onVisibilityChanged(e: TreeViewVisibilityChangeEvent) {
void this.ensureSubscription();

+ 22
- 1
src/views/viewBase.ts View File

@ -6,7 +6,9 @@ import {
EventEmitter,
TreeDataProvider,
TreeItem,
TreeItemCollapsibleState,
TreeView,
TreeViewExpansionEvent,
TreeViewVisibilityChangeEvent,
window
} from 'vscode';
@ -30,6 +32,10 @@ export enum RefreshReason {
export type View = RepositoriesView | FileHistoryView | LineHistoryView | ResultsView;
export interface TreeViewNodeStateChangeEvent<T> extends TreeViewExpansionEvent<T> {
state: TreeItemCollapsibleState;
}
export abstract class ViewBase<TRoot extends ViewNode> implements TreeDataProvider<ViewNode>, Disposable {
protected _onDidChangeTreeData = new EventEmitter<ViewNode>();
public get onDidChangeTreeData(): Event<ViewNode> {
@ -41,6 +47,11 @@ export abstract class ViewBase implements TreeDataProvid
return this._onDidChangeVisibility.event;
}
private _onDidChangeNodeState = new EventEmitter<TreeViewNodeStateChangeEvent<ViewNode>>();
public get onDidChangeNodeState(): Event<TreeViewNodeStateChangeEvent<ViewNode>> {
return this._onDidChangeNodeState.event;
}
protected _disposable: Disposable | undefined;
protected _root: TRoot | undefined;
protected _tree: TreeView<ViewNode> | undefined;
@ -77,7 +88,9 @@ export abstract class ViewBase implements TreeDataProvid
});
this._disposable = Disposable.from(
this._tree,
this._tree.onDidChangeVisibility(this.onVisibilityChanged, this)
this._tree.onDidChangeVisibility(this.onVisibilityChanged, this),
this._tree.onDidCollapseElement(this.onElementCollapsed, this),
this._tree.onDidExpandElement(this.onElementExpanded, this)
);
}
@ -99,6 +112,14 @@ export abstract class ViewBase implements TreeDataProvid
return node.getTreeItem();
}
protected onElementCollapsed(e: TreeViewExpansionEvent<ViewNode>) {
this._onDidChangeNodeState.fire({ ...e, state: TreeItemCollapsibleState.Collapsed });
}
protected onElementExpanded(e: TreeViewExpansionEvent<ViewNode>) {
this._onDidChangeNodeState.fire({ ...e, state: TreeItemCollapsibleState.Expanded });
}
protected onVisibilityChanged(e: TreeViewVisibilityChangeEvent) {
this._onDidChangeVisibility.fire(e);
}

Loading…
Cancel
Save