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

@@ -964,6 +964,7 @@
{
"command": "gitlens.gitExplorer.refresh",
"title": "Refresh",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-refresh.svg",
"light": "images/light/icon-refresh.svg"
@@ -972,10 +973,31 @@
{
"command": "gitlens.stashExplorer.refresh",
"title": "Refresh",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-refresh.svg",
"light": "images/light/icon-refresh.svg"
}
},
{
"command": "gitlens.stashExplorer.openChanges",
"title": "Open Changes",
"category": "GitLens"
},
{
"command": "gitlens.stashExplorer.openFile",
"title": "Open File",
"category": "GitLens"
},
{
"command": "gitlens.stashExplorer.openStashedFile",
"title": "Open Stashed File",
"category": "GitLens"
},
{
"command": "gitlens.stashExplorer.openFileInRemote",
"title": "Open File in Remote",
"category": "GitLens"
}
],
"menus": {
@@ -1127,6 +1149,22 @@
{
"command": "gitlens.stashExplorer.refresh",
"when": "gitlens:enabled"
},
{
"command": "gitlens.stashExplorer.openChanges",
"when": "false"
},
{
"command": "gitlens.stashExplorer.openFile",
"when": "false"
},
{
"command": "gitlens.stashExplorer.openStashedFile",
"when": "false"
},
{
"command": "gitlens.stashExplorer.openFileInRemote",
"when": "false"
}
],
"editor/context": [
@@ -1328,36 +1366,16 @@
{
"command": "gitlens.openFileInRemote",
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == commit-file",
"group": "1_gitlens@2"
},
{
"command": "gitlens.diffWithPrevious",
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == commit-file",
"group": "2_gitlens@1"
},
{
"command": "gitlens.diffWithWorking",
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == commit-file",
"group": "2_gitlens@2"
},
{
"command": "gitlens.openCommitInRemote",
"when": "gitlens:enabled && view == gitlens.stashExplorer && viewItem == stash-commit",
"group": "1_gitlens@1"
},
{
"command": "gitlens.openFileInRemote",
"when": "gitlens:enabled && view == gitlens.stashExplorer && viewItem == commit-file",
"group": "1_gitlens@2"
},
{
"command": "gitlens.diffWithPrevious",
"when": "gitlens:enabled && view == gitlens.stashExplorer && viewItem == commit-file",
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == commit-file",
"group": "2_gitlens@1"
},
{
"command": "gitlens.diffWithWorking",
"when": "gitlens:enabled && view == gitlens.stashExplorer && viewItem == commit-file",
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == commit-file",
"group": "2_gitlens@2"
},
{
@@ -1369,6 +1387,31 @@
"command": "gitlens.stashDelete",
"when": "gitlens:enabled && view == gitlens.stashExplorer && viewItem == stash-commit",
"group": "3_gitlens@1"
},
{
"command": "gitlens.stashExplorer.openChanges",
"when": "gitlens:enabled && view == gitlens.stashExplorer && viewItem == commit-file",
"group": "1_gitlens@1"
},
{
"command": "gitlens.stashExplorer.openFile",
"when": "gitlens:enabled && view == gitlens.stashExplorer && viewItem == commit-file",
"group": "1_gitlens@2"
},
{
"command": "gitlens.stashExplorer.openStashedFile",
"when": "gitlens:enabled && view == gitlens.stashExplorer && viewItem == commit-file",
"group": "1_gitlens@3"
},
{
"command": "gitlens.stashExplorer.openFileInRemote",
"when": "gitlens:enabled && view == gitlens.stashExplorer && viewItem == commit-file",
"group": "1_gitlens@4"
},
{
"command": "gitlens.diffWithWorking",
"when": "gitlens:enabled && view == gitlens.stashExplorer && viewItem == commit-file",
"group": "2_gitlens@2"
}
]
},

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;