Adds stash commands similar to SCM

This commit is contained in:
Eric Amodio
2017-07-03 02:00:15 -04:00
parent 52275215fe
commit af4f433972
4 changed files with 93 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
'use strict';
import { ExtensionContext, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
import { ExplorerNode, ResourceType } from './explorerNode';
import { getGitStatusIcon, GitCommit, GitService, GitUri, IGitStatusFile, StatusFileFormatter } from '../gitService';
@@ -34,7 +34,13 @@ export class CommitFileNode extends ExplorerNode {
light: this.context.asAbsolutePath(path.join('images', 'light', icon))
};
item.command = {
item.command = this.getCommand();
return item;
}
getCommand(): Command | undefined {
return {
title: 'Compare File with Previous',
command: Commands.DiffWithPrevious,
arguments: [
@@ -49,7 +55,5 @@ export class CommitFileNode extends ExplorerNode {
} as DiffWithPreviousCommandArgs
]
};
return item;
}
}

View File

@@ -1,6 +1,7 @@
'use strict';
import { Event, ExtensionContext, TreeItem} from 'vscode';
import { Command, Event, ExtensionContext, TreeItem} from 'vscode';
import { GitService, GitUri } from '../gitService';
export declare type ResourceType = 'status' | 'branches' | 'repository' | 'branch-history' | 'file-history' | 'stash-history' | 'commit' | 'stash-commit' | 'commit-file';
export abstract class ExplorerNode {
@@ -12,6 +13,11 @@ export abstract class ExplorerNode {
abstract getChildren(): ExplorerNode[] | Promise<ExplorerNode[]>;
abstract getTreeItem(): TreeItem | Promise<TreeItem>;
getCommand(): Command | undefined {
return undefined;
}
onDidChangeTreeData?: Event<ExplorerNode>;
refresh?(): void;
}

View File

@@ -1,7 +1,8 @@
'use strict';
// import { Functions } from '../system';
import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri } from 'vscode';
import { ExplorerNode, StashNode } from './explorerNodes';
import { Commands, DiffWithPreviousCommandArgs, openEditor } from '../commands';
import { ExplorerNode, StashCommitNode, StashNode } from './explorerNodes';
import { GitService, GitUri } from '../gitService';
export * from './explorerNodes';
@@ -18,6 +19,17 @@ export class StashExplorer implements TreeDataProvider<ExplorerNode> {
constructor(private context: ExtensionContext, private git: GitService) {
commands.registerCommand('gitlens.stashExplorer.refresh', () => this.refresh());
commands.registerCommand('gitlens.stashExplorer.openChanges', (node: StashCommitNode) => {
const command = node.getCommand();
if (command === undefined || command.arguments === undefined) return;
const [uri, args] = command.arguments as [Uri, DiffWithPreviousCommandArgs];
args.showOptions!.preview = false;
commands.executeCommand(command.command, uri, args);
});
commands.registerCommand('gitlens.stashExplorer.openFile', (node: StashCommitNode) => openEditor(node.uri, { preserveFocus: true, preview: false }));
commands.registerCommand('gitlens.stashExplorer.openStashedFile', (node: StashCommitNode) => openEditor(GitService.toGitContentUri(node.uri), { preserveFocus: true, preview: false }));
commands.registerCommand('gitlens.stashExplorer.openFileInRemote', (node: StashCommitNode) => commands.executeCommand(Commands.OpenFileInRemote, node.commit.previousUri));
context.subscriptions.push(this.git.onDidChangeRepo(reasons => {
if (!reasons.includes('stash')) return;