|
@ -2,10 +2,38 @@ |
|
|
import { CancellationToken, CancellationTokenSource, QuickPickItem, QuickPickOptions, window } from 'vscode'; |
|
|
import { CancellationToken, CancellationTokenSource, QuickPickItem, QuickPickOptions, window } from 'vscode'; |
|
|
import { GlyphChars } from '../constants'; |
|
|
import { GlyphChars } from '../constants'; |
|
|
import { Container } from '../container'; |
|
|
import { Container } from '../container'; |
|
|
import { GitBranch, GitTag } from '../git/gitService'; |
|
|
|
|
|
|
|
|
import { GitBranch, GitService, GitTag } from '../git/gitService'; |
|
|
import { Functions } from '../system'; |
|
|
import { Functions } from '../system'; |
|
|
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut } from './commonQuickPicks'; |
|
|
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 { |
|
|
export class BranchQuickPickItem implements QuickPickItem { |
|
|
label: string; |
|
|
label: string; |
|
|
description: string; |
|
|
description: string; |
|
@ -20,8 +48,8 @@ export class BranchQuickPickItem implements QuickPickItem { |
|
|
this.description = branch.remote |
|
|
this.description = branch.remote |
|
|
? `${GlyphChars.Space.repeat(2)} remote branch` |
|
|
? `${GlyphChars.Space.repeat(2)} remote branch` |
|
|
: branch.current |
|
|
: branch.current |
|
|
? 'current branch' |
|
|
|
|
|
: ''; |
|
|
|
|
|
|
|
|
? 'current branch' |
|
|
|
|
|
: ''; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
get current() { |
|
|
get current() { |
|
@ -32,7 +60,7 @@ export class BranchQuickPickItem implements QuickPickItem { |
|
|
return this.branch; |
|
|
return this.branch; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
get name() { |
|
|
|
|
|
|
|
|
get ref() { |
|
|
return this.branch.name; |
|
|
return this.branch.name; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -62,7 +90,7 @@ export class TagQuickPickItem implements QuickPickItem { |
|
|
return this.tag; |
|
|
return this.tag; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
get name() { |
|
|
|
|
|
|
|
|
get ref() { |
|
|
return this.tag.name; |
|
|
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 { |
|
|
export interface BranchesAndTagsQuickPickOptions { |
|
|
|
|
|
allowCommitId?: boolean; |
|
|
autoPick?: boolean; |
|
|
autoPick?: boolean; |
|
|
checked?: string; |
|
|
checked?: string; |
|
|
filters?: { |
|
|
filters?: { |
|
@ -92,7 +121,7 @@ export class BranchesAndTagsQuickPick { |
|
|
async show( |
|
|
async show( |
|
|
placeHolder: string, |
|
|
placeHolder: string, |
|
|
options: BranchesAndTagsQuickPickOptions = {} |
|
|
options: BranchesAndTagsQuickPickOptions = {} |
|
|
): Promise<BranchOrTagQuickPickItem | CommandQuickPickItem | undefined> { |
|
|
|
|
|
|
|
|
): Promise<BranchAndTagQuickPickResult | CommandQuickPickItem | undefined> { |
|
|
const cancellation = new CancellationTokenSource(); |
|
|
const cancellation = new CancellationTokenSource(); |
|
|
|
|
|
|
|
|
let scope; |
|
|
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) { |
|
|
if (pick === undefined && autoPick !== undefined) { |
|
|
pick = autoPick; |
|
|
pick = autoPick; |
|
@ -173,7 +259,7 @@ export class BranchesAndTagsQuickPick { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const items: (BranchOrTagQuickPickItem | CommandQuickPickItem)[] = []; |
|
|
|
|
|
|
|
|
const items: (BranchQuickPickItem | TagQuickPickItem | CommandQuickPickItem)[] = []; |
|
|
|
|
|
|
|
|
if (branches !== undefined) { |
|
|
if (branches !== undefined) { |
|
|
const filter = |
|
|
const filter = |
|
|