From 33acce6f523174060c88754185207a26f5ed8a84 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 22 May 2019 02:37:57 -0400 Subject: [PATCH] Changes to only add checkmarks when it makes sense --- src/commands/diffBranchWith.ts | 8 +++++++- src/commands/diffDirectory.ts | 2 +- src/commands/diffWithRef.ts | 1 + src/commands/openBranchInRemote.ts | 1 + src/commands/openFileInRemote.ts | 1 + src/commands/openFileRevisionFrom.ts | 3 ++- src/commands/showQuickBranchHistory.ts | 1 + src/quickpicks/commonQuickPicks.ts | 1 + src/quickpicks/referencesQuickPick.ts | 34 +++++++++++++++++++++++-------- src/views/nodes/compareBranchNode.ts | 13 ++++++------ src/views/nodes/compareNode.ts | 10 +++++++-- src/views/nodes/fileHistoryTrackerNode.ts | 3 ++- src/views/nodes/lineHistoryTrackerNode.ts | 3 ++- 13 files changed, 59 insertions(+), 22 deletions(-) diff --git a/src/commands/diffBranchWith.ts b/src/commands/diffBranchWith.ts index c4c08fa..076c583 100644 --- a/src/commands/diffBranchWith.ts +++ b/src/commands/diffBranchWith.ts @@ -60,21 +60,27 @@ export class DiffBranchWithCommand extends ActiveEditorCommand { if (!repoPath) return undefined; if (!args.ref1) { + let checkmarks; let placeHolder; switch (args.ref2) { case '': + checkmarks = false; placeHolder = `Compare Working Tree with${GlyphChars.Ellipsis}`; break; case 'HEAD': + checkmarks = false; placeHolder = `Compare HEAD with${GlyphChars.Ellipsis}`; break; default: + checkmarks = true; placeHolder = `Compare ${args.ref2} with${GlyphChars.Ellipsis}`; break; } const pick = await new ReferencesQuickPick(repoPath).show(placeHolder, { - allowEnteringRefs: true + allowEnteringRefs: true, + checked: args.ref2, + checkmarks: checkmarks }); if (pick === undefined) return undefined; diff --git a/src/commands/diffDirectory.ts b/src/commands/diffDirectory.ts index 7a5fdcf..6b0672d 100644 --- a/src/commands/diffDirectory.ts +++ b/src/commands/diffDirectory.ts @@ -73,7 +73,7 @@ export class DiffDirectoryCommand extends ActiveEditorCommand { const pick = await new ReferencesQuickPick(repoPath).show( `Compare Working Tree with${GlyphChars.Ellipsis}`, - { allowEnteringRefs: true } + { allowEnteringRefs: true, checkmarks: false } ); if (pick === undefined) return undefined; diff --git a/src/commands/diffWithRef.ts b/src/commands/diffWithRef.ts index e993722..feefbf2 100644 --- a/src/commands/diffWithRef.ts +++ b/src/commands/diffWithRef.ts @@ -39,6 +39,7 @@ export class DiffWithRefCommand extends ActiveEditorCommand { `Compare ${paths.basename(gitUri.fsPath)} with${GlyphChars.Ellipsis}`, { allowEnteringRefs: true, + checkmarks: false, goBack: args.goBackCommand } ); diff --git a/src/commands/openBranchInRemote.ts b/src/commands/openBranchInRemote.ts index 6001993..8c95272 100644 --- a/src/commands/openBranchInRemote.ts +++ b/src/commands/openBranchInRemote.ts @@ -57,6 +57,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand { `Open which branch on remote${GlyphChars.Ellipsis}`, { autoPick: true, + checkmarks: false, filters: { branches: b => b.tracking !== undefined }, diff --git a/src/commands/openFileInRemote.ts b/src/commands/openFileInRemote.ts index 8521951..2cb61b6 100644 --- a/src/commands/openFileInRemote.ts +++ b/src/commands/openFileInRemote.ts @@ -86,6 +86,7 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand { : `Open ${gitUri.relativePath} on remote for which branch${GlyphChars.Ellipsis}`, { autoPick: true, + checkmarks: false, filters: { branches: b => b.tracking !== undefined }, diff --git a/src/commands/openFileRevisionFrom.ts b/src/commands/openFileRevisionFrom.ts index ee5a75d..4063d96 100644 --- a/src/commands/openFileRevisionFrom.ts +++ b/src/commands/openFileRevisionFrom.ts @@ -32,7 +32,8 @@ export class OpenFileRevisionFromCommand extends ActiveEditorCommand { } from${GlyphChars.Ellipsis}`; const pick = await new ReferencesQuickPick(gitUri.repoPath).show(placeHolder, { - allowEnteringRefs: true + allowEnteringRefs: true, + checkmarks: false }); if (pick === undefined) return undefined; if (pick instanceof CommandQuickPickItem) return pick.execute(); diff --git a/src/commands/showQuickBranchHistory.ts b/src/commands/showQuickBranchHistory.ts index 081fe21..b5796b5 100644 --- a/src/commands/showQuickBranchHistory.ts +++ b/src/commands/showQuickBranchHistory.ts @@ -61,6 +61,7 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand { const pick = await new ReferencesQuickPick(repoPath).show( `Show history for branch${GlyphChars.Ellipsis}`, { + checkmarks: false, goBack: goBackCommand, include: 'branches' } diff --git a/src/quickpicks/commonQuickPicks.ts b/src/quickpicks/commonQuickPicks.ts index f71a830..d7d2e4c 100644 --- a/src/quickpicks/commonQuickPicks.ts +++ b/src/quickpicks/commonQuickPicks.ts @@ -198,6 +198,7 @@ export class ShowFileHistoryFromQuickPickItem extends CommandQuickPickItem { execute(): Promise { return new ReferencesQuickPick(this.repoPath).show(this.placeHolder, { allowEnteringRefs: true, + checkmarks: false, goBack: this._goBack }); } diff --git a/src/quickpicks/referencesQuickPick.ts b/src/quickpicks/referencesQuickPick.ts index bd994e4..36c1c29 100644 --- a/src/quickpicks/referencesQuickPick.ts +++ b/src/quickpicks/referencesQuickPick.ts @@ -37,9 +37,11 @@ export class BranchQuickPickItem implements QuickPickItem { description: string; detail: string | undefined; - constructor(public readonly branch: GitBranch, checked?: boolean) { - checked = checked || (checked === undefined && branch.current); - this.label = `${checked ? `$(check)${GlyphChars.Space}` : GlyphChars.Space.repeat(4)} ${branch.name}`; + constructor(public readonly branch: GitBranch, showCheckmarks: boolean, checked: boolean | undefined) { + checked = showCheckmarks && (checked || (checked === undefined && branch.current)); + this.label = `${ + checked ? `$(check)${GlyphChars.Space.repeat(2)}` : showCheckmarks ? GlyphChars.Space.repeat(6) : '' + }${branch.name}`; this.description = branch.remote ? `${GlyphChars.Space.repeat(2)} remote branch` : branch.current @@ -69,8 +71,11 @@ export class TagQuickPickItem implements QuickPickItem { description: string; detail: string | undefined; - constructor(public readonly tag: GitTag, checked?: boolean) { - this.label = `${checked ? `$(check)${GlyphChars.Space}` : GlyphChars.Space.repeat(4)} ${tag.name}`; + constructor(public readonly tag: GitTag, showCheckmarks: boolean, checked: boolean) { + checked = showCheckmarks && checked; + this.label = `${ + checked ? `$(check)${GlyphChars.Space.repeat(2)}` : showCheckmarks ? GlyphChars.Space.repeat(6) : '' + }${tag.name}`; this.description = `${GlyphChars.Space.repeat(2)} tag`; } @@ -97,6 +102,7 @@ export interface ReferencesQuickPickOptions { allowEnteringRefs?: boolean; autoPick?: boolean; checked?: string; + checkmarks: boolean; filters?: { branches?(branch: GitBranch): boolean; tags?(tag: GitTag): boolean; @@ -110,7 +116,7 @@ export class ReferencesQuickPick { async show( placeHolder: string, - options: ReferencesQuickPickOptions = {} + options: ReferencesQuickPickOptions = { checkmarks: true } ): Promise { const cancellation = new CancellationTokenSource(); @@ -211,7 +217,7 @@ export class ReferencesQuickPick { } private async getItems(options: ReferencesQuickPickOptions, token: CancellationToken) { - const { checked, filters, goBack, include } = { include: 'all', ...options }; + const { checked, checkmarks, filters, goBack, include } = { include: 'all', ...options }; let branches; let tags; @@ -257,7 +263,12 @@ export class ReferencesQuickPick { for (const b of branches) { if (filter !== undefined && !filter(b)) continue; - items.push(new BranchQuickPickItem(b, checked !== undefined ? b.name === checked : undefined)); + if (checkmarks && checked !== undefined && b.name === checked) { + items.splice(0, 0, new BranchQuickPickItem(b, checkmarks, true)); + } + else { + items.push(new BranchQuickPickItem(b, checkmarks, checked === undefined ? undefined : false)); + } } } @@ -268,7 +279,12 @@ export class ReferencesQuickPick { for (const t of tags) { if (filter !== undefined && !filter(t)) continue; - items.push(new TagQuickPickItem(t, checked !== undefined ? t.name === checked : undefined)); + if (checkmarks && checked !== undefined && t.name === checked) { + items.splice(0, 0, new TagQuickPickItem(t, checkmarks, true)); + } + else { + items.push(new TagQuickPickItem(t, checkmarks, false)); + } } } diff --git a/src/views/nodes/compareBranchNode.ts b/src/views/nodes/compareBranchNode.ts index 381a0a4..8d5a37c 100644 --- a/src/views/nodes/compareBranchNode.ts +++ b/src/views/nodes/compareBranchNode.ts @@ -60,11 +60,12 @@ export class CompareBranchNode extends ViewNode { } else { label = `${this.branch.name}`; - description = `${GlyphChars.ArrowLeftRightLong}${ - GlyphChars.Space - } ${GitService.shortenSha(this._compareWith, { - working: 'Working Tree' - })}`; + description = `${GlyphChars.ArrowLeftRightLong}${GlyphChars.Space} ${GitService.shortenSha( + this._compareWith, + { + working: 'Working Tree' + } + )}`; state = TreeItemCollapsibleState.Collapsed; } @@ -89,7 +90,7 @@ export class CompareBranchNode extends ViewNode { async compareWith() { const pick = await new ReferencesQuickPick(this.branch.repoPath).show( `Compare ${this.branch.name} with${GlyphChars.Ellipsis}`, - { allowEnteringRefs: true } + { allowEnteringRefs: true, checked: this.branch.ref, checkmarks: true } ); if (pick === undefined || pick instanceof CommandQuickPickItem) return; diff --git a/src/views/nodes/compareNode.ts b/src/views/nodes/compareNode.ts index 76d7f03..ad1d64d 100644 --- a/src/views/nodes/compareNode.ts +++ b/src/views/nodes/compareNode.ts @@ -141,7 +141,12 @@ export class CompareNode extends ViewNode { if (ref === undefined) { const pick = await new ReferencesQuickPick(repoPath).show( `Compare ${this.getRefName(this._selectedRef.ref)} with${GlyphChars.Ellipsis}`, - { allowEnteringRefs: true } + { + allowEnteringRefs: true, + checked: + typeof this._selectedRef.ref === 'string' ? this._selectedRef.ref : this._selectedRef.ref.ref, + checkmarks: true + } ); if (pick === undefined || pick instanceof CommandQuickPickItem) return; @@ -165,7 +170,8 @@ export class CompareNode extends ViewNode { let autoCompare = false; if (ref === undefined) { const pick = await new ReferencesQuickPick(repoPath).show(`Compare${GlyphChars.Ellipsis}`, { - allowEnteringRefs: true + allowEnteringRefs: true, + checkmarks: false }); if (pick === undefined || pick instanceof CommandQuickPickItem) return; diff --git a/src/views/nodes/fileHistoryTrackerNode.ts b/src/views/nodes/fileHistoryTrackerNode.ts index 49e1d32..921f8ee 100644 --- a/src/views/nodes/fileHistoryTrackerNode.ts +++ b/src/views/nodes/fileHistoryTrackerNode.ts @@ -72,7 +72,8 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode