diff --git a/package.json b/package.json index af55bde..0ffd62b 100644 --- a/package.json +++ b/package.json @@ -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" } ] }, diff --git a/src/views/commitFileNode.ts b/src/views/commitFileNode.ts index aa3aaf2..3db5060 100644 --- a/src/views/commitFileNode.ts +++ b/src/views/commitFileNode.ts @@ -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; } } \ No newline at end of file diff --git a/src/views/explorerNode.ts b/src/views/explorerNode.ts index 2f36fd8..f0fb445 100644 --- a/src/views/explorerNode.ts +++ b/src/views/explorerNode.ts @@ -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; abstract getTreeItem(): TreeItem | Promise; + getCommand(): Command | undefined { + return undefined; + } + onDidChangeTreeData?: Event; + refresh?(): void; } \ No newline at end of file diff --git a/src/views/stashExplorer.ts b/src/views/stashExplorer.ts index c8a21e3..5b1c017 100644 --- a/src/views/stashExplorer.ts +++ b/src/views/stashExplorer.ts @@ -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 { 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;