|
|
@ -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); |
|
|
|
} |
|
|
|