Skip to content

Commit

Permalink
Reworks git command buttons a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Sep 13, 2019
1 parent 4e568a8 commit 0204a2e
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 199 deletions.
22 changes: 12 additions & 10 deletions src/commands/git/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ export interface PullGitCommandArgs {
}

export class PullGitCommand extends QuickCommandBase<State> {
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'
Expand Down Expand Up @@ -175,17 +185,9 @@ export class PullGitCommand extends QuickCommandBase<State> {
}
]);

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;
Expand Down
45 changes: 23 additions & 22 deletions src/commands/git/rebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ export interface RebaseGitCommandArgs {
}

export class RebaseGitCommand extends QuickCommandBase<State> {
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:
Expand Down Expand Up @@ -115,18 +133,7 @@ export class RebaseGitCommand extends QuickCommandBase<State> {

if (state.reference === undefined || state.counter < 2) {
const pickBranchOrCommitButton: Mutable<QuickInputButton> = {
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<ReferencesQuickPickItem>({
Expand All @@ -147,17 +154,11 @@ export class RebaseGitCommand extends QuickCommandBase<State> {
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)
});
Expand Down
213 changes: 88 additions & 125 deletions src/commands/git/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,80 @@ const searchOperatorToTitleMap = new Map<SearchOperators, string>([
]);

export class SearchGitCommand extends QuickCommandBase<State> {
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'
Expand Down Expand Up @@ -175,67 +249,16 @@ export class SearchGitCommand extends QuickCommandBase<State> {
const titleSuffix = `${Strings.pad(GlyphChars.Dot, 2, 2)}${state.repo.formattedName}`;

const matchCaseButton: Mutable<QuickInputButton> = {
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<QuickInputButton> = {
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<QuickInputButton> = {
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<QuickInputButton> = {
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<QuickPickItemOfT<string>>({
Expand Down Expand Up @@ -265,87 +288,35 @@ export class SearchGitCommand extends QuickCommandBase<State> {
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;
}

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;
}

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;
}

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 => {
Expand Down Expand Up @@ -412,14 +383,6 @@ export class SearchGitCommand extends QuickCommandBase<State> {

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<CommitQuickPickItem>({
title: `${this.title}${Strings.pad(GlyphChars.Dot, 2, 2)}${state.repo.formattedName}`,
placeholder:
Expand All @@ -445,9 +408,9 @@ export class SearchGitCommand extends QuickCommandBase<State> {
)
)
],
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,
Expand Down

0 comments on commit 0204a2e

Please sign in to comment.