Adapts stash commands to new structure for views

Adds onDidChangeRepo event to GitService
Refreshes stash view when repo changes
This commit is contained in:
Eric Amodio
2017-06-29 01:40:07 -04:00
parent b81d873a34
commit d288985c26
9 changed files with 165 additions and 103 deletions

View File

@@ -13,5 +13,5 @@ export abstract class ExplorerNode {
abstract getTreeItem(): TreeItem | Promise<TreeItem>;
onDidChangeTreeData?: Event<ExplorerNode>;
refreshNode?(): void;
refresh?(): void;
}

View File

@@ -1,4 +1,5 @@
'use strict';
// import { Functions } from '../system';
import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri } from 'vscode';
import { UriComparer } from '../comparers';
import { ExplorerNode, FileHistoryNode, RepositoryNode, ResourceType, StashNode } from './explorerNodes';
@@ -8,6 +9,8 @@ export * from './explorerNodes';
export class GitExplorer implements TreeDataProvider<ExplorerNode> {
// private _refreshDebounced: () => void;
private _onDidChangeTreeData = new EventEmitter<ExplorerNode>();
public get onDidChangeTreeData(): Event<ExplorerNode> {
return this._onDidChangeTreeData.event;
@@ -18,6 +21,8 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
constructor(private context: ExtensionContext, private git: GitService) {
commands.registerCommand('gitlens.gitExplorer.refresh', () => this.refresh());
// this._refreshDebounced = Functions.debounce(this.refresh.bind(this), 250);
// const editor = window.activeTextEditor;
// const uri = (editor !== undefined && editor.document !== undefined)
@@ -29,6 +34,9 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
}
async getTreeItem(node: ExplorerNode): Promise<TreeItem> {
// if (node.onDidChangeTreeData !== undefined) {
// node.onDidChangeTreeData(() => setTimeout(this._refreshDebounced, 1));
// }
return node.getTreeItem();
}
@@ -51,12 +59,12 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
if (!this._roots.some(_ => _.resourceType === type.rootType && UriComparer.equals(uri, _.uri))) {
this._roots.push(new type(uri, this.context, this.git));
}
this._onDidChangeTreeData.fire();
this.refresh();
}
clear() {
this._roots = [];
this._onDidChangeTreeData.fire();
this.refresh();
}
refresh() {

View File

@@ -13,10 +13,6 @@ export class StashCommitNode extends ExplorerNode {
return this._onDidChangeTreeData.event;
}
public refreshNode() {
this._onDidChangeTreeData.fire();
}
constructor(public readonly commit: GitStashCommit, context: ExtensionContext, git: GitService) {
super(new GitUri(commit.uri, commit), context, git);
}
@@ -43,4 +39,8 @@ export class StashCommitNode extends ExplorerNode {
// };
return item;
}
refresh() {
this._onDidChangeTreeData.fire();
}
}

View File

@@ -1,4 +1,5 @@
'use strict';
// import { Functions } from '../system';
import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri } from 'vscode';
import { ExplorerNode, StashNode } from './explorerNodes';
import { GitService, GitUri } from '../gitService';
@@ -8,6 +9,8 @@ export * from './explorerNodes';
export class StashExplorer implements TreeDataProvider<ExplorerNode> {
private _node: ExplorerNode;
// private _refreshDebounced: () => void;
private _onDidChangeTreeData = new EventEmitter<ExplorerNode>();
public get onDidChangeTreeData(): Event<ExplorerNode> {
return this._onDidChangeTreeData.event;
@@ -16,6 +19,14 @@ export class StashExplorer implements TreeDataProvider<ExplorerNode> {
constructor(private context: ExtensionContext, private git: GitService) {
commands.registerCommand('gitlens.stashExplorer.refresh', () => this.refresh());
context.subscriptions.push(this.git.onDidChangeRepo(reasons => {
if (!reasons.includes('stash')) return;
this.refresh();
}, this));
// this._refreshDebounced = Functions.debounce(this.refresh.bind(this), 250);
// const editor = window.activeTextEditor;
// const uri = (editor !== undefined && editor.document !== undefined)
@@ -27,11 +38,9 @@ export class StashExplorer implements TreeDataProvider<ExplorerNode> {
}
async getTreeItem(node: ExplorerNode): Promise<TreeItem> {
if (node.onDidChangeTreeData) {
node.onDidChangeTreeData(() => {
this._onDidChangeTreeData.fire();
});
}
// if (node.onDidChangeTreeData !== undefined) {
// node.onDidChangeTreeData(() => setTimeout(this._refreshDebounced, 1));
// }
return node.getTreeItem();
}