From 0204a2e5447a4fb94bb983277c3b2160ced14376 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 13 Sep 2019 02:47:59 -0400 Subject: [PATCH] Reworks git command buttons a bit --- src/commands/git/pull.ts | 22 ++--- src/commands/git/rebase.ts | 45 +++++----- src/commands/git/search.ts | 213 ++++++++++++++++++-------------------------- src/commands/git/switch.ts | 32 +++++-- src/commands/gitCommands.ts | 50 ++++------- 5 files changed, 163 insertions(+), 199 deletions(-) diff --git a/src/commands/git/pull.ts b/src/commands/git/pull.ts index b9dd3ad..a1eac4f 100644 --- a/src/commands/git/pull.ts +++ b/src/commands/git/pull.ts @@ -21,6 +21,16 @@ export interface PullGitCommandArgs { } export class PullGitCommand extends QuickCommandBase { + private readonly Buttons = class { + static readonly Fetch: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-sync.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-sync.svg') as any + }, + tooltip: 'Fetch' + }; + }; + constructor(args?: PullGitCommandArgs) { super('pull', 'pull', 'Pull', { description: 'fetches and integrates changes from a remote into the current branch' @@ -175,17 +185,9 @@ export class PullGitCommand extends QuickCommandBase { } ]); - const fetchButton: QuickInputButton = { - iconPath: { - dark: Container.context.asAbsolutePath('images/dark/icon-sync.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-sync.svg') as any - }, - tooltip: 'Fetch' - }; - - step.additionalButtons = [fetchButton]; + step.additionalButtons = [this.Buttons.Fetch]; step.onDidClickButton = async (quickpick, button) => { - if (button !== fetchButton) return; + if (button !== this.Buttons.Fetch) return; quickpick.title = `${title}${Strings.pad(GlyphChars.Dot, 2, 2)}Fetching${GlyphChars.Ellipsis}`; quickpick.busy = true; diff --git a/src/commands/git/rebase.ts b/src/commands/git/rebase.ts index 3a52eda..fa851d8 100644 --- a/src/commands/git/rebase.ts +++ b/src/commands/git/rebase.ts @@ -36,6 +36,24 @@ export interface RebaseGitCommandArgs { } export class RebaseGitCommand extends QuickCommandBase { + private readonly Buttons = class { + static readonly PickBranch: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-branch.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-branch.svg') as any + }, + tooltip: 'Use the selected Branch or Tag' + }; + + static readonly PickCommit: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-commit.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-commit.svg') as any + }, + tooltip: 'Choose a commit from the selected Branch or Tag' + }; + }; + constructor(args?: RebaseGitCommandArgs) { super('rebase', 'rebase', 'Rebase', { description: @@ -115,18 +133,7 @@ export class RebaseGitCommand extends QuickCommandBase { if (state.reference === undefined || state.counter < 2) { const pickBranchOrCommitButton: Mutable = { - iconPath: pickCommit - ? { - dark: Container.context.asAbsolutePath('images/dark/icon-commit.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-commit.svg') as any - } - : { - dark: Container.context.asAbsolutePath('images/dark/icon-branch.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-branch.svg') as any - }, - tooltip: pickCommit - ? 'Choose a commit from the selected Branch or Tag' - : 'Use the selected Branch or Tag' + ...(pickCommit ? this.Buttons.PickCommit : this.Buttons.PickBranch) }; const step = this.createPickStep({ @@ -147,17 +154,11 @@ export class RebaseGitCommand extends QuickCommandBase { pickCommit = !pickCommit; pickBranchOrCommitButton.iconPath = pickCommit - ? { - dark: Container.context.asAbsolutePath('images/dark/icon-commit.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-commit.svg') as any - } - : { - dark: Container.context.asAbsolutePath('images/dark/icon-branch.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-branch.svg') as any - }; + ? this.Buttons.PickCommit.iconPath + : this.Buttons.PickBranch.iconPath; pickBranchOrCommitButton.tooltip = pickCommit - ? 'Choose a commit from the selected Branch or Tag' - : 'Use the selected Branch or Tag'; + ? this.Buttons.PickCommit.tooltip + : this.Buttons.PickBranch.tooltip; }, onValidateValue: getValidateGitReferenceFn(state.repo) }); diff --git a/src/commands/git/search.ts b/src/commands/git/search.ts index b6fcb0b..94df48a 100644 --- a/src/commands/git/search.ts +++ b/src/commands/git/search.ts @@ -55,6 +55,80 @@ const searchOperatorToTitleMap = new Map([ ]); export class SearchGitCommand extends QuickCommandBase { + private readonly Buttons = class { + static readonly MatchCase: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-match-case.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-match-case.svg') as any + }, + tooltip: 'Match Case' + }; + + static readonly MatchCaseSelected: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-match-case-selected.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-match-case-selected.svg') as any + }, + tooltip: 'Match Case' + }; + + static readonly MatchAll: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-match-all.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-match-all.svg') as any + }, + tooltip: 'Match All' + }; + + static readonly MatchAllSelected: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-match-all-selected.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-match-all-selected.svg') as any + }, + tooltip: 'Match All' + }; + + static readonly MatchRegex: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-match-regex.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-match-regex.svg') as any + }, + tooltip: 'Match using Regular Expressions' + }; + + static readonly MatchRegexSelected: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-match-regex-selected.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-match-regex-selected.svg') as any + }, + tooltip: 'Match using Regular Expressions' + }; + + 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 + }, + tooltip: 'Open in Search Commits View' + }; + + static readonly ShowInView: 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: 'Show Results in Search Commits View' + }; + + static readonly ShowInViewSelected: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-eye-selected.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-eye-selected.svg') as any + }, + tooltip: 'Show Results in Search Commits View' + }; + }; + constructor(args?: SearchGitCommandArgs) { super('search', 'search', 'Search', { description: 'aka grep, searches for commits' @@ -175,67 +249,16 @@ export class SearchGitCommand extends QuickCommandBase { const titleSuffix = `${Strings.pad(GlyphChars.Dot, 2, 2)}${state.repo.formattedName}`; const matchCaseButton: Mutable = { - iconPath: state.matchCase - ? { - dark: Container.context.asAbsolutePath( - 'images/dark/icon-match-case-selected.svg' - ) as any, - light: Container.context.asAbsolutePath( - 'images/light/icon-match-case-selected.svg' - ) as any - } - : { - dark: Container.context.asAbsolutePath('images/dark/icon-match-case.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-match-case.svg') as any - }, - tooltip: 'Match Case' + ...(state.matchCase ? this.Buttons.MatchCaseSelected : this.Buttons.MatchCase) }; - const matchAllButton: Mutable = { - iconPath: state.matchAll - ? { - dark: Container.context.asAbsolutePath( - 'images/dark/icon-match-all-selected.svg' - ) as any, - light: Container.context.asAbsolutePath( - 'images/light/icon-match-all-selected.svg' - ) as any - } - : { - dark: Container.context.asAbsolutePath('images/dark/icon-match-all.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-match-all.svg') as any - }, - tooltip: 'Match All' + ...(state.matchAll ? this.Buttons.MatchAllSelected : this.Buttons.MatchAll) }; - const matchRegexButton: Mutable = { - iconPath: state.matchRegex - ? { - dark: Container.context.asAbsolutePath( - 'images/dark/icon-match-regex-selected.svg' - ) as any, - light: Container.context.asAbsolutePath( - 'images/light/icon-match-regex-selected.svg' - ) as any - } - : { - dark: Container.context.asAbsolutePath('images/dark/icon-match-regex.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-match-regex.svg') as any - }, - tooltip: 'Match using Regular Expressions' + ...(state.matchRegex ? this.Buttons.MatchRegexSelected : this.Buttons.MatchRegex) }; - const showInViewButton: Mutable = { - iconPath: state.showInView - ? { - dark: Container.context.asAbsolutePath('images/dark/icon-eye-selected.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-eye-selected.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: 'Show Results in the Search Commits View' + ...(state.showInView ? this.Buttons.ShowInViewSelected : this.Buttons.ShowInView) }; const step = this.createPickStep>({ @@ -265,22 +288,8 @@ export class SearchGitCommand extends QuickCommandBase { if (button === matchCaseButton) { state.matchCase = !state.matchCase; matchCaseButton.iconPath = state.matchCase - ? { - dark: Container.context.asAbsolutePath( - 'images/dark/icon-match-case-selected.svg' - ) as any, - light: Container.context.asAbsolutePath( - 'images/light/icon-match-case-selected.svg' - ) as any - } - : { - dark: Container.context.asAbsolutePath( - 'images/dark/icon-match-case.svg' - ) as any, - light: Container.context.asAbsolutePath( - 'images/light/icon-match-case.svg' - ) as any - }; + ? this.Buttons.MatchCaseSelected.iconPath + : this.Buttons.MatchCase.iconPath; return; } @@ -288,22 +297,8 @@ export class SearchGitCommand extends QuickCommandBase { if (button === matchAllButton) { state.matchAll = !state.matchAll; matchAllButton.iconPath = state.matchAll - ? { - dark: Container.context.asAbsolutePath( - 'images/dark/icon-match-all-selected.svg' - ) as any, - light: Container.context.asAbsolutePath( - 'images/light/icon-match-all-selected.svg' - ) as any - } - : { - dark: Container.context.asAbsolutePath( - 'images/dark/icon-match-all.svg' - ) as any, - light: Container.context.asAbsolutePath( - 'images/light/icon-match-all.svg' - ) as any - }; + ? this.Buttons.MatchAllSelected.iconPath + : this.Buttons.MatchAll.iconPath; return; } @@ -311,22 +306,8 @@ export class SearchGitCommand extends QuickCommandBase { if (button === matchRegexButton) { state.matchRegex = !state.matchRegex; matchRegexButton.iconPath = state.matchRegex - ? { - dark: Container.context.asAbsolutePath( - 'images/dark/icon-match-regex-selected.svg' - ) as any, - light: Container.context.asAbsolutePath( - 'images/light/icon-match-regex-selected.svg' - ) as any - } - : { - dark: Container.context.asAbsolutePath( - 'images/dark/icon-match-regex.svg' - ) as any, - light: Container.context.asAbsolutePath( - 'images/light/icon-match-regex.svg' - ) as any - }; + ? this.Buttons.MatchRegexSelected.iconPath + : this.Buttons.MatchRegex.iconPath; return; } @@ -334,18 +315,8 @@ export class SearchGitCommand extends QuickCommandBase { if (button === showInViewButton) { state.showInView = !state.showInView; showInViewButton.iconPath = state.showInView - ? { - dark: Container.context.asAbsolutePath( - 'images/dark/icon-eye-selected.svg' - ) as any, - light: Container.context.asAbsolutePath( - 'images/light/icon-eye-selected.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 - }; + ? this.Buttons.ShowInViewSelected.iconPath + : this.Buttons.ShowInView.iconPath; } }, onDidChangeValue: (quickpick): boolean => { @@ -412,14 +383,6 @@ export class SearchGitCommand extends QuickCommandBase { const results = await resultsPromise; - const openInViewButton: QuickInputButton = { - iconPath: { - dark: Container.context.asAbsolutePath('images/dark/icon-link.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-link.svg') as any - }, - tooltip: 'Open Results in the Search Commits View' - }; - const step = this.createPickStep({ title: `${this.title}${Strings.pad(GlyphChars.Dot, 2, 2)}${state.repo.formattedName}`, placeholder: @@ -445,9 +408,9 @@ export class SearchGitCommand extends QuickCommandBase { ) ) ], - additionalButtons: [openInViewButton], + additionalButtons: [this.Buttons.OpenInView], onDidClickButton: (quickpick, button) => { - if (button !== openInViewButton) return; + if (button !== this.Buttons.OpenInView) return; void Container.searchView.search( state.repo!.path, diff --git a/src/commands/git/switch.ts b/src/commands/git/switch.ts index f1ed7eb..01c3d49 100644 --- a/src/commands/git/switch.ts +++ b/src/commands/git/switch.ts @@ -13,7 +13,7 @@ import { StepState } from '../quickCommand'; import { ReferencesQuickPickItem, RepositoryQuickPickItem } from '../../quickpicks'; -import { PickMutable, Strings } from '../../system'; +import { Mutable, Strings } from '../../system'; import { Logger } from '../../logger'; interface State { @@ -30,6 +30,24 @@ export interface SwitchGitCommandArgs { } export class SwitchGitCommand extends QuickCommandBase { + private readonly Buttons = class { + static readonly HideTags: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-tag.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-tag.svg') as any + }, + tooltip: 'Hide Tags' + }; + + static readonly ShowTags: QuickInputButton = { + iconPath: { + dark: Container.context.asAbsolutePath('images/dark/icon-tag.svg') as any, + light: Container.context.asAbsolutePath('images/light/icon-tag.svg') as any + }, + tooltip: 'Show Tags' + }; + }; + constructor(args?: SwitchGitCommandArgs) { super('switch', 'switch', 'Switch', { description: 'aka checkout, switches the current branch to a specified branch' @@ -125,12 +143,8 @@ export class SwitchGitCommand extends QuickCommandBase { if (state.reference === undefined || state.counter < 2) { showTags = state.repos.length === 1; - const toggleTagsButton: PickMutable = { - iconPath: { - dark: Container.context.asAbsolutePath('images/dark/icon-tag.svg') as any, - light: Container.context.asAbsolutePath('images/light/icon-tag.svg') as any - }, - tooltip: showTags ? 'Hide Tags' : 'Show Tags' + const toggleTagsButton: Mutable = { + ...(showTags ? this.Buttons.HideTags : this.Buttons.ShowTags) }; const items = await getBranchesAndOrTags( @@ -160,7 +174,9 @@ export class SwitchGitCommand extends QuickCommandBase { quickpick.enabled = false; showTags = !showTags; - toggleTagsButton.tooltip = showTags ? 'Hide Tags' : 'Show Tags'; + toggleTagsButton.tooltip = showTags + ? this.Buttons.HideTags.tooltip + : this.Buttons.ShowTags.tooltip; quickpick.placeholder = `Choose a branch${ showTags ? ' or tag' : '' diff --git a/src/commands/gitCommands.ts b/src/commands/gitCommands.ts index bbfcbd0..3567a34 100644 --- a/src/commands/gitCommands.ts +++ b/src/commands/gitCommands.ts @@ -42,7 +42,7 @@ export type GitCommandsCommandArgs = @command() export class GitCommandsCommand extends Command { - private readonly GitQuickInputButtons = class { + private readonly Buttons = class { static readonly CloseOnFocusOut: QuickInputButton = { iconPath: { dark: Container.context.asAbsolutePath('images/dark/icon-pin-small.svg') as any, @@ -145,20 +145,14 @@ export class GitCommandsCommand extends Command { return; } - if (e === this.GitQuickInputButtons.WillConfirmForced) return; - if ( - e === this.GitQuickInputButtons.WillConfirm || - e === this.GitQuickInputButtons.WillSkipConfirm - ) { + if (e === this.Buttons.WillConfirmForced) return; + if (e === this.Buttons.WillConfirm || e === this.Buttons.WillSkipConfirm) { await this.toggleConfirmation(input, commandsStep.command); return; } - if ( - e === this.GitQuickInputButtons.CloseOnFocusOut || - e === this.GitQuickInputButtons.KeepOpen - ) { + if (e === this.Buttons.CloseOnFocusOut || e === this.Buttons.KeepOpen) { await this.toggleKeepOpen(input, commandsStep.command); return; @@ -224,12 +218,12 @@ export class GitCommandsCommand extends Command { return; } - if (e === this.GitQuickInputButtons.WillConfirmForced) return; + if (e === this.Buttons.WillConfirmForced) return; if ( - e === this.GitQuickInputButtons.CloseOnFocusOut || - e === this.GitQuickInputButtons.KeepOpen || - e === this.GitQuickInputButtons.WillConfirm || - e === this.GitQuickInputButtons.WillSkipConfirm + e === this.Buttons.CloseOnFocusOut || + e === this.Buttons.KeepOpen || + e === this.Buttons.WillConfirm || + e === this.Buttons.WillSkipConfirm ) { let command = commandsStep.command; if (command === undefined && quickpick.activeItems.length !== 0) { @@ -239,17 +233,11 @@ export class GitCommandsCommand extends Command { command = active; } - if ( - e === this.GitQuickInputButtons.WillConfirm || - e === this.GitQuickInputButtons.WillSkipConfirm - ) { + if (e === this.Buttons.WillConfirm || e === this.Buttons.WillSkipConfirm) { await this.toggleConfirmation(quickpick, command); } - if ( - e === this.GitQuickInputButtons.CloseOnFocusOut || - e === this.GitQuickInputButtons.KeepOpen - ) { + if (e === this.Buttons.CloseOnFocusOut || e === this.Buttons.KeepOpen) { await this.toggleKeepOpen(quickpick, command); } @@ -445,8 +433,8 @@ export class GitCommandsCommand extends Command { buttons.push( ...step.buttons, configuration.get('gitCommands', 'closeOnFocusOut') - ? this.GitQuickInputButtons.CloseOnFocusOut - : this.GitQuickInputButtons.KeepOpen + ? this.Buttons.CloseOnFocusOut + : this.Buttons.KeepOpen ); return buttons; } @@ -460,20 +448,14 @@ export class GitCommandsCommand extends Command { if (command !== undefined && command.canConfirm) { if (command.canSkipConfirm) { - buttons.push( - command.confirm() - ? this.GitQuickInputButtons.WillConfirm - : this.GitQuickInputButtons.WillSkipConfirm - ); + buttons.push(command.confirm() ? this.Buttons.WillConfirm : this.Buttons.WillSkipConfirm); } else { - buttons.push(this.GitQuickInputButtons.WillConfirmForced); + buttons.push(this.Buttons.WillConfirmForced); } } buttons.push( - configuration.get('gitCommands', 'closeOnFocusOut') - ? this.GitQuickInputButtons.CloseOnFocusOut - : this.GitQuickInputButtons.KeepOpen + configuration.get('gitCommands', 'closeOnFocusOut') ? this.Buttons.CloseOnFocusOut : this.Buttons.KeepOpen ); return buttons;