|
|
@ -2,10 +2,38 @@ |
|
|
|
import { CancellationToken, CancellationTokenSource, QuickPickItem, QuickPickOptions, window } from 'vscode'; |
|
|
|
import { GlyphChars } from '../constants'; |
|
|
|
import { Container } from '../container'; |
|
|
|
import { GitBranch, GitTag } from '../git/gitService'; |
|
|
|
import { GitBranch, GitService, GitTag } from '../git/gitService'; |
|
|
|
import { Functions } from '../system'; |
|
|
|
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut } from './commonQuickPicks'; |
|
|
|
|
|
|
|
export class RefQuickPickItem implements QuickPickItem { |
|
|
|
label: string; |
|
|
|
description: string; |
|
|
|
detail: string | undefined; |
|
|
|
|
|
|
|
constructor( |
|
|
|
public readonly ref: string, |
|
|
|
checked?: boolean |
|
|
|
) { |
|
|
|
this.label = `${checked ? `$(check)${GlyphChars.Space}` : GlyphChars.Space.repeat(4)} ${GitService.shortenSha( |
|
|
|
ref |
|
|
|
)}`;
|
|
|
|
this.description = ''; |
|
|
|
} |
|
|
|
|
|
|
|
get current() { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
get item() { |
|
|
|
return undefined; |
|
|
|
} |
|
|
|
|
|
|
|
get remote() { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export class BranchQuickPickItem implements QuickPickItem { |
|
|
|
label: string; |
|
|
|
description: string; |
|
|
@ -20,8 +48,8 @@ export class BranchQuickPickItem implements QuickPickItem { |
|
|
|
this.description = branch.remote |
|
|
|
? `${GlyphChars.Space.repeat(2)} remote branch` |
|
|
|
: branch.current |
|
|
|
? 'current branch' |
|
|
|
: ''; |
|
|
|
? 'current branch' |
|
|
|
: ''; |
|
|
|
} |
|
|
|
|
|
|
|
get current() { |
|
|
@ -32,7 +60,7 @@ export class BranchQuickPickItem implements QuickPickItem { |
|
|
|
return this.branch; |
|
|
|
} |
|
|
|
|
|
|
|
get name() { |
|
|
|
get ref() { |
|
|
|
return this.branch.name; |
|
|
|
} |
|
|
|
|
|
|
@ -62,7 +90,7 @@ export class TagQuickPickItem implements QuickPickItem { |
|
|
|
return this.tag; |
|
|
|
} |
|
|
|
|
|
|
|
get name() { |
|
|
|
get ref() { |
|
|
|
return this.tag.name; |
|
|
|
} |
|
|
|
|
|
|
@ -71,9 +99,10 @@ export class TagQuickPickItem implements QuickPickItem { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export type BranchOrTagQuickPickItem = BranchQuickPickItem | TagQuickPickItem; |
|
|
|
export type BranchAndTagQuickPickResult = BranchQuickPickItem | TagQuickPickItem | RefQuickPickItem; |
|
|
|
|
|
|
|
export interface BranchesAndTagsQuickPickOptions { |
|
|
|
allowCommitId?: boolean; |
|
|
|
autoPick?: boolean; |
|
|
|
checked?: string; |
|
|
|
filters?: { |
|
|
@ -92,7 +121,7 @@ export class BranchesAndTagsQuickPick { |
|
|
|
async show( |
|
|
|
placeHolder: string, |
|
|
|
options: BranchesAndTagsQuickPickOptions = {} |
|
|
|
): Promise<BranchOrTagQuickPickItem | CommandQuickPickItem | undefined> { |
|
|
|
): Promise<BranchAndTagQuickPickResult | CommandQuickPickItem | undefined> { |
|
|
|
const cancellation = new CancellationTokenSource(); |
|
|
|
|
|
|
|
let scope; |
|
|
@ -113,14 +142,71 @@ export class BranchesAndTagsQuickPick { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
let pick = await window.showQuickPick( |
|
|
|
items, |
|
|
|
{ |
|
|
|
placeHolder: placeHolder, |
|
|
|
ignoreFocusOut: getQuickPickIgnoreFocusOut() |
|
|
|
} as QuickPickOptions, |
|
|
|
cancellation.token |
|
|
|
); |
|
|
|
let pick; |
|
|
|
if (options.allowCommitId) { |
|
|
|
placeHolder += `${GlyphChars.Space.repeat(3)}(use # to enter a commit id)`; |
|
|
|
|
|
|
|
const quickpick = window.createQuickPick<BranchAndTagQuickPickResult | CommandQuickPickItem>(); |
|
|
|
quickpick.busy = true; |
|
|
|
quickpick.enabled = false; |
|
|
|
quickpick.placeholder = placeHolder; |
|
|
|
quickpick.ignoreFocusOut = getQuickPickIgnoreFocusOut(); |
|
|
|
quickpick.show(); |
|
|
|
|
|
|
|
quickpick.items = await items; |
|
|
|
quickpick.busy = false; |
|
|
|
quickpick.enabled = true; |
|
|
|
|
|
|
|
pick = await new Promise<BranchAndTagQuickPickResult | CommandQuickPickItem | undefined>(resolve => { |
|
|
|
cancellation.token.onCancellationRequested(() => quickpick.hide()); |
|
|
|
|
|
|
|
quickpick.onDidHide(() => resolve(undefined)); |
|
|
|
quickpick.onDidChangeValue(value => { |
|
|
|
quickpick.title = |
|
|
|
value && value.startsWith('#') |
|
|
|
? `Please enter a commit id (Press 'Enter' to confirm or 'Escape' to cancel)` |
|
|
|
: undefined; |
|
|
|
}); |
|
|
|
quickpick.onDidAccept(async () => { |
|
|
|
if (quickpick.selectedItems.length === 0) { |
|
|
|
let ref = quickpick.value; |
|
|
|
if (!ref || !ref.startsWith('#')) return; |
|
|
|
|
|
|
|
ref = ref.substr(1); |
|
|
|
|
|
|
|
quickpick.busy = true; |
|
|
|
quickpick.enabled = false; |
|
|
|
|
|
|
|
if (await Container.git.validateReference(this.repoPath, ref)) { |
|
|
|
resolve(new RefQuickPickItem(ref)); |
|
|
|
} |
|
|
|
else { |
|
|
|
quickpick.title = 'You must enter a valid commit id'; |
|
|
|
quickpick.busy = false; |
|
|
|
quickpick.enabled = true; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
resolve(quickpick.selectedItems[0]); |
|
|
|
} |
|
|
|
|
|
|
|
quickpick.hide(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
quickpick.dispose(); |
|
|
|
} |
|
|
|
else { |
|
|
|
pick = await window.showQuickPick( |
|
|
|
items, |
|
|
|
{ |
|
|
|
placeHolder: placeHolder, |
|
|
|
ignoreFocusOut: getQuickPickIgnoreFocusOut() |
|
|
|
} as QuickPickOptions, |
|
|
|
cancellation.token |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
if (pick === undefined && autoPick !== undefined) { |
|
|
|
pick = autoPick; |
|
|
@ -173,7 +259,7 @@ export class BranchesAndTagsQuickPick { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const items: (BranchOrTagQuickPickItem | CommandQuickPickItem)[] = []; |
|
|
|
const items: (BranchQuickPickItem | TagQuickPickItem | CommandQuickPickItem)[] = []; |
|
|
|
|
|
|
|
if (branches !== undefined) { |
|
|
|
const filter = |
|
|
|