|
|
@ -2,7 +2,7 @@ |
|
|
|
import { Disposable, window } from 'vscode'; |
|
|
|
import { configuration } from '../configuration'; |
|
|
|
import { Container } from '../container'; |
|
|
|
import { GitLog, GitLogCommit } from '../git/git'; |
|
|
|
import { GitLog, GitLogCommit, GitStash, GitStashCommit } from '../git/git'; |
|
|
|
import { KeyboardScope, Keys } from '../keyboard'; |
|
|
|
import { |
|
|
|
CommandQuickPickItem, |
|
|
@ -22,7 +22,7 @@ export namespace CommitPicker { |
|
|
|
picked?: string; |
|
|
|
keys?: Keys[]; |
|
|
|
onDidPressKey?(key: Keys, item: CommitQuickPickItem): void | Promise<void>; |
|
|
|
showOtherReferences?: CommandQuickPickItem; |
|
|
|
showOtherReferences?: CommandQuickPickItem[]; |
|
|
|
}, |
|
|
|
): Promise<GitLogCommit | undefined> { |
|
|
|
const quickpick = window.createQuickPick<CommandQuickPickItem | CommitQuickPickItem | DirectiveQuickPickItem>(); |
|
|
@ -55,7 +55,7 @@ export namespace CommitPicker { |
|
|
|
return log == null |
|
|
|
? [DirectiveQuickPickItem.create(Directive.Cancel)] |
|
|
|
: [ |
|
|
|
...(options?.showOtherReferences != null ? [options?.showOtherReferences] : []), |
|
|
|
...(options?.showOtherReferences ?? []), |
|
|
|
...Iterables.map(log.commits.values(), commit => |
|
|
|
CommitQuickPickItem.create(commit, options?.picked === commit.ref, { |
|
|
|
compact: true, |
|
|
@ -181,3 +181,139 @@ export namespace CommitPicker { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export namespace StashPicker { |
|
|
|
export async function show( |
|
|
|
stash: GitStash | undefined | Promise<GitStash | undefined>, |
|
|
|
title: string, |
|
|
|
placeholder: string, |
|
|
|
options?: { |
|
|
|
empty?: string; |
|
|
|
filter?: (c: GitStashCommit) => boolean; |
|
|
|
keys?: Keys[]; |
|
|
|
onDidPressKey?(key: Keys, item: CommitQuickPickItem<GitStashCommit>): void | Promise<void>; |
|
|
|
picked?: string; |
|
|
|
showOtherReferences?: CommandQuickPickItem[]; |
|
|
|
}, |
|
|
|
): Promise<GitStashCommit | undefined> { |
|
|
|
const quickpick = window.createQuickPick< |
|
|
|
CommandQuickPickItem | CommitQuickPickItem<GitStashCommit> | DirectiveQuickPickItem |
|
|
|
>(); |
|
|
|
quickpick.ignoreFocusOut = getQuickPickIgnoreFocusOut(); |
|
|
|
|
|
|
|
quickpick.title = title; |
|
|
|
quickpick.placeholder = placeholder; |
|
|
|
quickpick.matchOnDescription = true; |
|
|
|
quickpick.matchOnDetail = true; |
|
|
|
|
|
|
|
if (Promises.is(stash)) { |
|
|
|
quickpick.busy = true; |
|
|
|
quickpick.enabled = false; |
|
|
|
quickpick.show(); |
|
|
|
|
|
|
|
stash = await stash; |
|
|
|
} |
|
|
|
|
|
|
|
if (stash != null) { |
|
|
|
quickpick.items = [ |
|
|
|
...(options?.showOtherReferences ?? []), |
|
|
|
...Iterables.map( |
|
|
|
options?.filter != null |
|
|
|
? Iterables.filter(stash.commits.values(), options.filter) |
|
|
|
: stash.commits.values(), |
|
|
|
commit => |
|
|
|
CommitQuickPickItem.create(commit, options?.picked === commit.ref, { |
|
|
|
compact: true, |
|
|
|
icon: true, |
|
|
|
}), |
|
|
|
), |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
if (stash == null || quickpick.items.length <= (options?.showOtherReferences?.length ?? 0)) { |
|
|
|
quickpick.placeholder = stash == null ? 'No stashes found' : options?.empty ?? `No matching stashes found`; |
|
|
|
quickpick.items = [DirectiveQuickPickItem.create(Directive.Cancel)]; |
|
|
|
} |
|
|
|
|
|
|
|
if (options?.picked) { |
|
|
|
quickpick.activeItems = quickpick.items.filter(i => (CommandQuickPickItem.is(i) ? false : i.picked)); |
|
|
|
} |
|
|
|
|
|
|
|
const disposables: Disposable[] = []; |
|
|
|
|
|
|
|
let scope: KeyboardScope | undefined; |
|
|
|
if (options?.keys != null && options.keys.length !== 0 && options?.onDidPressKey !== null) { |
|
|
|
scope = Container.instance.keyboard.createScope( |
|
|
|
Object.fromEntries( |
|
|
|
options.keys.map(key => [ |
|
|
|
key, |
|
|
|
{ |
|
|
|
onDidPressKey: key => { |
|
|
|
if (quickpick.activeItems.length !== 0) { |
|
|
|
const [item] = quickpick.activeItems; |
|
|
|
if ( |
|
|
|
item != null && |
|
|
|
!DirectiveQuickPickItem.is(item) && |
|
|
|
!CommandQuickPickItem.is(item) |
|
|
|
) { |
|
|
|
void options.onDidPressKey!(key, item); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
]), |
|
|
|
), |
|
|
|
); |
|
|
|
void scope.start(); |
|
|
|
disposables.push(scope); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
const pick = await new Promise< |
|
|
|
CommandQuickPickItem | CommitQuickPickItem<GitStashCommit> | DirectiveQuickPickItem | undefined |
|
|
|
>(resolve => { |
|
|
|
disposables.push( |
|
|
|
quickpick.onDidHide(() => resolve(undefined)), |
|
|
|
quickpick.onDidAccept(() => { |
|
|
|
if (quickpick.activeItems.length !== 0) { |
|
|
|
const [item] = quickpick.activeItems; |
|
|
|
if (DirectiveQuickPickItem.is(item)) { |
|
|
|
resolve(undefined); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
resolve(item); |
|
|
|
} |
|
|
|
}), |
|
|
|
quickpick.onDidChangeValue(async e => { |
|
|
|
if (scope == null) return; |
|
|
|
|
|
|
|
// Pause the left/right keyboard commands if there is a value, otherwise the left/right arrows won't work in the input properly
|
|
|
|
if (e.length !== 0) { |
|
|
|
await scope.pause(['left', 'right']); |
|
|
|
} else { |
|
|
|
await scope.resume(); |
|
|
|
} |
|
|
|
}), |
|
|
|
); |
|
|
|
|
|
|
|
quickpick.busy = false; |
|
|
|
quickpick.enabled = true; |
|
|
|
|
|
|
|
quickpick.show(); |
|
|
|
}); |
|
|
|
if (pick == null || DirectiveQuickPickItem.is(pick)) return undefined; |
|
|
|
|
|
|
|
if (pick instanceof CommandQuickPickItem) { |
|
|
|
void (await pick.execute()); |
|
|
|
|
|
|
|
return undefined; |
|
|
|
} |
|
|
|
|
|
|
|
return pick.item; |
|
|
|
} finally { |
|
|
|
quickpick.dispose(); |
|
|
|
disposables.forEach(d => d.dispose()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |