From f726420ef20be9a99cdec3efac63f6b7c4e08200 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 17 Sep 2019 03:54:09 -0400 Subject: [PATCH] Adds reveal in repos view to search Fixes issue stash reveal button Updates reveal|open in view icons Adds gating to reveal methods --- images/dark/icon-eye-selected.svg | 4 +- images/dark/icon-eye.svg | 4 +- images/dark/icon-open.svg | 4 ++ images/light/icon-eye-selected.svg | 4 +- images/light/icon-eye.svg | 4 +- images/light/icon-open.svg | 4 ++ package.json | 4 +- src/commands/git/search.ts | 76 +++++++++++++++++++++++++----------- src/commands/git/stash.ts | 45 ++++++++++----------- src/commands/showQuickFileHistory.ts | 4 +- src/quickpicks/commitQuickPick.ts | 11 +++--- src/quickpicks/commonQuickPicks.ts | 8 ++-- src/views/repositoriesView.ts | 16 ++++++-- src/views/viewBase.ts | 8 +++- 14 files changed, 122 insertions(+), 74 deletions(-) create mode 100644 images/dark/icon-open.svg create mode 100644 images/light/icon-open.svg diff --git a/images/dark/icon-eye-selected.svg b/images/dark/icon-eye-selected.svg index cb1a5ed..ffd75e0 100644 --- a/images/dark/icon-eye-selected.svg +++ b/images/dark/icon-eye-selected.svg @@ -1,4 +1,4 @@ - - + + \ No newline at end of file diff --git a/images/dark/icon-eye.svg b/images/dark/icon-eye.svg index 84c4d32..335f850 100644 --- a/images/dark/icon-eye.svg +++ b/images/dark/icon-eye.svg @@ -1,3 +1,3 @@ - - + + \ No newline at end of file diff --git a/images/dark/icon-open.svg b/images/dark/icon-open.svg new file mode 100644 index 0000000..fe7dd89 --- /dev/null +++ b/images/dark/icon-open.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/images/light/icon-eye-selected.svg b/images/light/icon-eye-selected.svg index f72b624..033d189 100644 --- a/images/light/icon-eye-selected.svg +++ b/images/light/icon-eye-selected.svg @@ -1,4 +1,4 @@ - - + + \ No newline at end of file diff --git a/images/light/icon-eye.svg b/images/light/icon-eye.svg index 1280078..a1e26ae 100644 --- a/images/light/icon-eye.svg +++ b/images/light/icon-eye.svg @@ -1,3 +1,3 @@ - - + + \ No newline at end of file diff --git a/images/light/icon-open.svg b/images/light/icon-open.svg new file mode 100644 index 0000000..a40a84a --- /dev/null +++ b/images/light/icon-open.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/package.json b/package.json index 03f10a8..e55846b 100644 --- a/package.json +++ b/package.json @@ -2228,12 +2228,12 @@ }, { "command": "gitlens.showCommitInView", - "title": "Show Commit in View", + "title": "Open in Search Commits View", "category": "GitLens" }, { "command": "gitlens.showFileHistoryInView", - "title": "Show File History in View", + "title": "Open in File History View", "category": "GitLens" }, { diff --git a/src/commands/git/search.ts b/src/commands/git/search.ts index a0a7a72..3c78ff8 100644 --- a/src/commands/git/search.ts +++ b/src/commands/git/search.ts @@ -102,10 +102,18 @@ export class SearchGitCommand extends QuickCommandBase { static readonly OpenInView: QuickInputButton = { iconPath: { - dark: Container.context.asAbsolutePath('images/dark/icon-link.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-link.svg') as any + dark: Container.context.asAbsolutePath('images/dark/icon-open.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-open.svg') as any }, - tooltip: 'Open in View' + tooltip: 'Open in Search Commits View' + }; + + static readonly RevealInView: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-eye.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-eye.svg') as any + }, + tooltip: 'Reveal in Repositories View' }; static readonly ShowInView: QuickInputButton = { @@ -403,18 +411,30 @@ export class SearchGitCommand extends QuickCommandBase { ) ) ], - additionalButtons: [this.Buttons.OpenInView], + additionalButtons: [this.Buttons.RevealInView, this.Buttons.OpenInView], onDidClickButton: (quickpick, button) => { - if (button !== this.Buttons.OpenInView) return; - - void Container.searchView.search( - state.repo!.path, - search, - { - label: { label: `for ${state.pattern}` } - }, - results - ); + if (button === this.Buttons.OpenInView) { + void Container.searchView.search( + state.repo!.path, + search, + { + label: { label: `for ${state.pattern}` } + }, + results + ); + + return; + } + + if (button === this.Buttons.RevealInView) { + if (quickpick.activeItems.length !== 0) { + void Container.repositoriesView.revealCommit(quickpick.activeItems[0].item, { + select: true, + focus: false, + expand: true + }); + } + } }, keys: ['right', 'alt+right', 'ctrl+right'], onDidPressKey: async (quickpick, key) => { @@ -461,17 +481,27 @@ export class SearchGitCommand extends QuickCommandBase { items: await CommitQuickPick.getItems(pickedCommit, pickedCommit.toGitUri(), { showChanges: false }), - additionalButtons: [this.Buttons.OpenInView], + additionalButtons: [this.Buttons.RevealInView, this.Buttons.OpenInView], onDidClickButton: (quickpick, button) => { - if (button !== this.Buttons.OpenInView) return; + if (button === this.Buttons.OpenInView) { + void Container.searchView.search( + pickedCommit!.repoPath, + { pattern: SearchPattern.fromCommit(pickedCommit!) }, + { + label: { label: `for commit id ${pickedCommit!.shortSha}` } + } + ); - void Container.searchView.search( - pickedCommit!.repoPath, - { pattern: SearchPattern.fromCommit(pickedCommit!) }, - { - label: { label: `for commit id ${pickedCommit!.shortSha}` } - } - ); + return; + } + + if (button === this.Buttons.RevealInView) { + void Container.repositoriesView.revealCommit(pickedCommit!, { + select: true, + focus: false, + expand: true + }); + } } }); const selection: StepSelection = yield step; diff --git a/src/commands/git/stash.ts b/src/commands/git/stash.ts index c42c29f..8b17fea 100644 --- a/src/commands/git/stash.ts +++ b/src/commands/git/stash.ts @@ -2,7 +2,7 @@ /* eslint-disable no-loop-func */ import { QuickInputButton, QuickInputButtons, QuickPickItem, Uri, window } from 'vscode'; import { Container } from '../../container'; -import { GitStashCommit, GitUri, Repository, SearchPattern } from '../../git/gitService'; +import { GitStashCommit, GitUri, Repository } from '../../git/gitService'; import { BreakQuickCommand, QuickCommandBase, @@ -82,12 +82,12 @@ export interface StashGitCommandArgs { export class StashGitCommand extends QuickCommandBase { private readonly Buttons = class { - static readonly OpenInView: QuickInputButton = { + static readonly RevealInView: QuickInputButton = { iconPath: { - dark: Container.context.asAbsolutePath('images/dark/icon-link.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-link.svg') as any + dark: Container.context.asAbsolutePath('images/dark/icon-eye.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-eye.svg') as any }, - tooltip: 'Open in View' + tooltip: 'Reveal in Repositories View' }; }; @@ -345,9 +345,9 @@ export class StashGitCommand extends QuickCommandBase { ) ) ], - additionalButtons: [this.Buttons.OpenInView], + additionalButtons: [this.Buttons.RevealInView], onDidClickButton: (quickpick, button) => { - if (button === this.Buttons.OpenInView) { + if (button === this.Buttons.RevealInView) { if (quickpick.activeItems.length !== 0) { void Container.repositoriesView.revealStash(quickpick.activeItems[0].item, { select: true, @@ -415,9 +415,9 @@ export class StashGitCommand extends QuickCommandBase { undefined, { placeholder: `Confirm ${this.title} ${getSubtitle(state.subcommand)}`, - additionalButtons: [this.Buttons.OpenInView], + additionalButtons: [this.Buttons.RevealInView], onDidClickButton: (quickpick, button) => { - if (button === this.Buttons.OpenInView) { + if (button === this.Buttons.RevealInView) { void Container.repositoriesView.revealStash(state.stash!, { select: true, expand: true @@ -472,9 +472,9 @@ export class StashGitCommand extends QuickCommandBase { ) ) ], - additionalButtons: [this.Buttons.OpenInView], + additionalButtons: [this.Buttons.RevealInView], onDidClickButton: (quickpick, button) => { - if (button === this.Buttons.OpenInView) { + if (button === this.Buttons.RevealInView) { if (quickpick.activeItems.length !== 0) { void Container.repositoriesView.revealStash(quickpick.activeItems[0].item, { select: true, @@ -519,9 +519,9 @@ export class StashGitCommand extends QuickCommandBase { undefined, { placeholder: `Confirm ${this.title} ${getSubtitle(state.subcommand)}`, - additionalButtons: [this.Buttons.OpenInView], + additionalButtons: [this.Buttons.RevealInView], onDidClickButton: (quickpick, button) => { - if (button === this.Buttons.OpenInView) { + if (button === this.Buttons.RevealInView) { void Container.repositoriesView.revealStash(state.stash!, { select: true, expand: true @@ -569,9 +569,9 @@ export class StashGitCommand extends QuickCommandBase { }) ) ], - additionalButtons: [this.Buttons.OpenInView], + additionalButtons: [this.Buttons.RevealInView], onDidClickButton: (quickpick, button) => { - if (button === this.Buttons.OpenInView) { + if (button === this.Buttons.RevealInView) { if (quickpick.activeItems.length !== 0) { void Container.repositoriesView.revealStash(quickpick.activeItems[0].item, { select: true, @@ -616,17 +616,14 @@ export class StashGitCommand extends QuickCommandBase { pickedStash.number === undefined ? '' : `${pickedStash.number}: ` }${pickedStash.getShortMessage()}`, items: await CommitQuickPick.getItems(pickedStash, pickedStash.toGitUri(), { showChanges: false }), - additionalButtons: [this.Buttons.OpenInView], + additionalButtons: [this.Buttons.RevealInView], onDidClickButton: (quickpick, button) => { - if (button !== this.Buttons.OpenInView) return; + if (button !== this.Buttons.RevealInView) return; - void Container.searchView.search( - pickedStash!.repoPath, - { pattern: SearchPattern.fromCommit(pickedStash!) }, - { - label: { label: `for commit id ${pickedStash!.shortSha}` } - } - ); + void Container.repositoriesView.revealStash(pickedStash!, { + select: true, + expand: true + }); } }); const selection: StepSelection = yield step; diff --git a/src/commands/showQuickFileHistory.ts b/src/commands/showQuickFileHistory.ts index e5eabf2..3eecdd5 100644 --- a/src/commands/showQuickFileHistory.ts +++ b/src/commands/showQuickFileHistory.ts @@ -8,7 +8,7 @@ import { Messages } from '../messages'; import { CommandQuickPickItem, FileHistoryQuickPick, - OpenFileHistoryInViewQuickPickItem, + OpenInFileHistoryViewQuickPickItem, ShowFileHistoryFromQuickPickItem } from '../quickpicks'; import { Iterables, Strings } from '../system'; @@ -148,7 +148,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand { : undefined, showInViewCommand: args.log !== undefined - ? new OpenFileHistoryInViewQuickPickItem( + ? new OpenInFileHistoryViewQuickPickItem( gitUri, (args.reference && args.reference.ref) || gitUri.sha ) diff --git a/src/quickpicks/commitQuickPick.ts b/src/quickpicks/commitQuickPick.ts index 2dbd770..7fa7db8 100644 --- a/src/quickpicks/commitQuickPick.ts +++ b/src/quickpicks/commitQuickPick.ts @@ -31,9 +31,9 @@ import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem, - OpenCommitInViewQuickPickItem, + OpenInSearchCommitsViewQuickPickItem, QuickPickItem, - RevealCommitInViewQuickPickItem + RevealInRepositoriesViewQuickPickItem } from './commonQuickPicks'; import { OpenRemotesCommandQuickPickItem } from './remotesQuickPick'; @@ -284,11 +284,10 @@ export class CommitQuickPick { ) ); - items.push(new OpenCommitInViewQuickPickItem(commit)); - items.push(new RevealCommitInViewQuickPickItem(commit)); + items.push(new RevealInRepositoriesViewQuickPickItem(commit)); } else { - items.push(new OpenCommitInViewQuickPickItem(commit)); - items.push(new RevealCommitInViewQuickPickItem(commit)); + items.push(new OpenInSearchCommitsViewQuickPickItem(commit)); + items.push(new RevealInRepositoriesViewQuickPickItem(commit)); items.push(new OpenCommitFilesCommandQuickPickItem(commit)); items.push(new OpenCommitFileRevisionsCommandQuickPickItem(commit)); diff --git a/src/quickpicks/commonQuickPicks.ts b/src/quickpicks/commonQuickPicks.ts index 0d184e0..830e80c 100644 --- a/src/quickpicks/commonQuickPicks.ts +++ b/src/quickpicks/commonQuickPicks.ts @@ -98,11 +98,11 @@ export class MessageQuickPickItem extends CommandQuickPickItem { } } -export class OpenCommitInViewQuickPickItem extends CommandQuickPickItem { +export class OpenInSearchCommitsViewQuickPickItem extends CommandQuickPickItem { constructor( public readonly commit: GitLogCommit, item: QuickPickItem = { - label: '$(eye) Open in Search Commits View', + label: '$(link-external) Open in Search Commits View', description: '' } ) { @@ -124,7 +124,7 @@ export class OpenCommitInViewQuickPickItem extends CommandQuickPickItem { } } -export class OpenFileHistoryInViewQuickPickItem extends CommandQuickPickItem { +export class OpenInFileHistoryViewQuickPickItem extends CommandQuickPickItem { constructor( public readonly uri: GitUri, public readonly baseRef: string | undefined, @@ -141,7 +141,7 @@ export class OpenFileHistoryInViewQuickPickItem extends CommandQuickPickItem { } } -export class RevealCommitInViewQuickPickItem extends CommandQuickPickItem { +export class RevealInRepositoriesViewQuickPickItem extends CommandQuickPickItem { constructor( public readonly commit: GitLogCommit | GitStashCommit, item: QuickPickItem = { diff --git a/src/views/repositoriesView.ts b/src/views/repositoriesView.ts index d5df4c4..9910cf9 100644 --- a/src/views/repositoriesView.ts +++ b/src/views/repositoriesView.ts @@ -8,9 +8,16 @@ import { ProgressLocation, window } from 'vscode'; -import { configuration, RepositoriesViewConfig, ViewFilesLayout, ViewsConfig } from '../configuration'; +import { + configuration, + RepositoriesViewConfig, + ViewFilesLayout, + ViewsConfig, + ViewShowBranchComparison +} from '../configuration'; import { CommandContext, setCommandContext, WorkspaceState } from '../constants'; import { Container } from '../container'; +import { GitLogCommit, GitService, GitStashCommit } from '../git/gitService'; import { BranchesNode, BranchNode, @@ -22,10 +29,8 @@ import { StashNode, ViewNode } from './nodes'; +import { gate } from '../system'; import { ViewBase } from './viewBase'; -import { ViewShowBranchComparison } from '../config'; -import { GitLogCommit, GitStashCommit } from '../git/git'; -import { GitService } from '../git/gitService'; export class RepositoriesView extends ViewBase { constructor() { @@ -175,6 +180,7 @@ export class RepositoriesView extends ViewBase { }); } + @gate(() => '') revealCommit( commit: GitLogCommit | { repoPath: string; ref: string }, options?: { @@ -214,6 +220,7 @@ export class RepositoriesView extends ViewBase { ); } + @gate(() => '') async revealStash( stash: GitStashCommit | { repoPath: string; ref: string; stashName: string }, options?: { @@ -239,6 +246,7 @@ export class RepositoriesView extends ViewBase { ); } + @gate(() => '') async revealStashes( repoPath: string, options?: { diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index 85cfc82..865f4f1 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -175,7 +175,13 @@ export abstract class ViewBase> implements TreeData @log({ args: { 0: (predicate: string | ((node: ViewNode) => boolean)) => - typeof predicate === 'string' ? predicate : false + typeof predicate === 'string' ? predicate : 'function', + 1: (opts: { + allowPaging?: boolean; + canTraverse?: (node: ViewNode) => boolean; + maxDepth?: number; + token?: CancellationToken; + }) => `options=${JSON.stringify({ ...opts, canTraverse: undefined, token: undefined })}` } }) async findNode(