mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-13 03:28:35 -05:00
Adapts stash commands to new structure for views
Adds onDidChangeRepo event to GitService Refreshes stash view when repo changes
This commit is contained in:
@@ -13,5 +13,5 @@ export abstract class ExplorerNode {
|
||||
abstract getTreeItem(): TreeItem | Promise<TreeItem>;
|
||||
|
||||
onDidChangeTreeData?: Event<ExplorerNode>;
|
||||
refreshNode?(): void;
|
||||
refresh?(): void;
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user