From 805c49b723b84fe6d0b51f80afe13afecad0f2e0 Mon Sep 17 00:00:00 2001 From: Ramin Tadayon <67011668+axosoft-ramint@users.noreply.github.com> Date: Thu, 26 Jan 2023 16:43:24 -0700 Subject: [PATCH] App context menu opens to WIP row on graph (#2458) * App context menu opens to WIP row on graph * Use commit context value * Remove unneeded fallback logic --- package.json | 23 ++++++++++++++++++- src/plus/webviews/graph/graphWebview.ts | 39 +++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 357db2a..5c3cd65 100644 --- a/package.json +++ b/package.json @@ -6581,6 +6581,11 @@ "icon": "$(eye)" }, { + "command": "gitlens.graph.openSCM", + "title": "Open Source Control", + "category": "GitLens" + }, + { "command": "gitlens.graph.openCommitOnRemote", "title": "Open Commit on Remote", "category": "GitLens", @@ -6619,6 +6624,12 @@ "icon": "$(discard)" }, { + "command": "gitlens.graph.saveStash", + "title": "Stash All Changes", + "category": "GitLens", + "icon": "$(gitlens-stash-save)" + }, + { "command": "gitlens.graph.applyStash", "title": "Apply Stash", "category": "GitLens", @@ -11328,10 +11339,15 @@ }, { "command": "gitlens.graph.showInDetailsView", - "when": "webviewItem =~ /gitlens:(commit|stash)\\b/", + "when": "webviewItem =~ /gitlens:(commit|stash|wip)\\b/", "group": "3_gitlens_explore@0" }, { + "command": "gitlens.graph.openSCM", + "when": "webviewItem == gitlens:wip", + "group": "3_gitlens_explore@1" + }, + { "command": "gitlens.graph.openCommitOnRemote", "when": "gitlens:hasRemotes && webviewItem =~ /gitlens:commit\\b/", "group": "3_gitlens_explore@2", @@ -11353,6 +11369,11 @@ "group": "1_gitlens_actions@2" }, { + "command": "gitlens.graph.saveStash", + "when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem == gitlens:wip", + "group": "1_gitlens_actions@3" + }, + { "command": "gitlens.graph.switchToTag", "when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:tag\\b/", "group": "1_gitlens_actions@1" diff --git a/src/plus/webviews/graph/graphWebview.ts b/src/plus/webviews/graph/graphWebview.ts index 318e043..db933ff 100644 --- a/src/plus/webviews/graph/graphWebview.ts +++ b/src/plus/webviews/graph/graphWebview.ts @@ -30,7 +30,7 @@ import { parseCommandContext } from '../../../commands/base'; import { GitActions } from '../../../commands/gitCommands.actions'; import type { Config } from '../../../configuration'; import { configuration } from '../../../configuration'; -import { Commands, ContextKeys, CoreGitCommands, GlyphChars } from '../../../constants'; +import { Commands, ContextKeys, CoreCommands, CoreGitCommands, GlyphChars } from '../../../constants'; import type { Container } from '../../../container'; import { getContext, onDidChangeContext } from '../../../context'; import { PlusFeatures } from '../../../features'; @@ -53,7 +53,13 @@ import type { GitSearch } from '../../../git/search'; import { getSearchQueryComparisonKey } from '../../../git/search'; import { RepositoryPicker } from '../../../quickpicks/repositoryPicker'; import type { StoredGraphFilters, StoredGraphIncludeOnlyRef } from '../../../storage'; -import { executeActionCommand, executeCommand, executeCoreGitCommand, registerCommand } from '../../../system/command'; +import { + executeActionCommand, + executeCommand, + executeCoreCommand, + executeCoreGitCommand, + registerCommand, +} from '../../../system/command'; import { gate } from '../../../system/decorators/gate'; import { debug } from '../../../system/decorators/log'; import type { Deferrable } from '../../../system/function'; @@ -347,6 +353,7 @@ export class GraphWebview extends WebviewBase { registerCommand('gitlens.graph.copyRemoteCommitUrl', item => this.openCommitOnRemote(item, true), this), registerCommand('gitlens.graph.showInDetailsView', this.openInDetailsView, this), registerCommand('gitlens.graph.openCommitOnRemote', this.openCommitOnRemote, this), + registerCommand('gitlens.graph.openSCM', this.openSCM, this), registerCommand('gitlens.graph.rebaseOntoCommit', this.rebase, this), registerCommand('gitlens.graph.resetCommit', this.resetCommit, this), registerCommand('gitlens.graph.resetToCommit', this.resetToCommit, this), @@ -354,6 +361,7 @@ export class GraphWebview extends WebviewBase { registerCommand('gitlens.graph.switchToCommit', this.switchTo, this), registerCommand('gitlens.graph.undoCommit', this.undoCommit, this), + registerCommand('gitlens.graph.saveStash', this.saveStash, this), registerCommand('gitlens.graph.applyStash', this.applyStash, this), registerCommand('gitlens.graph.deleteStash', this.deleteStash, this), @@ -1611,6 +1619,17 @@ export class GraphWebview extends WebviewBase { added: workingTreeStatus?.added ?? 0, deleted: workingTreeStatus?.deleted ?? 0, modified: workingTreeStatus?.changed ?? 0, + context: serializeWebviewItemContext({ + webviewItem: 'gitlens:wip', + webviewItemValue: { + type: 'commit', + ref: this.getRevisionReference( + this.repository.path, + GitRevision.uncommitted, + GitGraphRowType.Working, + )!, + }, + }), }; } @@ -2015,6 +2034,14 @@ export class GraphWebview extends WebviewBase { } @debug() + private openSCM(item?: GraphItemContext) { + const ref = this.getGraphItemRef(item, 'revision'); + if (ref == null) return Promise.resolve(); + + return executeCoreCommand(CoreCommands.ShowSCM); + } + + @debug() private openCommitOnRemote(item?: GraphItemContext, clipboard?: boolean) { const ref = this.getGraphItemRef(item, 'revision'); if (ref == null) return Promise.resolve(); @@ -2126,6 +2153,14 @@ export class GraphWebview extends WebviewBase { } @debug() + private saveStash(item?: GraphItemContext) { + const ref = this.getGraphItemRef(item); + if (ref == null) return Promise.resolve(); + + return GitActions.Stash.push(ref.repoPath); + } + + @debug() private applyStash(item?: GraphItemContext) { const ref = this.getGraphItemRef(item, 'stash'); if (ref == null) return Promise.resolve();