Browse Source

Adds a mulit-repo picker

main
Eric Amodio 1 year ago
parent
commit
d801687395
1 changed files with 74 additions and 0 deletions
  1. +74
    -0
      src/quickpicks/repositoryPicker.ts

+ 74
- 0
src/quickpicks/repositoryPicker.ts View File

@ -134,3 +134,77 @@ export async function showRepositoryPicker(
disposables.forEach(d => void d.dispose());
}
}
export async function showRepositoriesPicker(
title: string | undefined,
placeholder?: string,
repositories?: Repository[],
): Promise<readonly RepositoryQuickPickItem[]>;
export async function showRepositoriesPicker(
title: string | undefined,
placeholder?: string,
options?: { filter?: (r: Repository) => Promise<boolean> },
): Promise<readonly RepositoryQuickPickItem[]>;
export async function showRepositoriesPicker(
title: string | undefined,
placeholder: string = 'Choose a repository',
repositoriesOrOptions?: Repository[] | { filter?: (r: Repository) => Promise<boolean> },
): Promise<readonly RepositoryQuickPickItem[]> {
if (
repositoriesOrOptions != null &&
!Array.isArray(repositoriesOrOptions) &&
repositoriesOrOptions.filter == null
) {
repositoriesOrOptions = undefined;
}
let items: RepositoryQuickPickItem[];
if (repositoriesOrOptions == null || Array.isArray(repositoriesOrOptions)) {
items = await Promise.all<Promise<RepositoryQuickPickItem>>([
...map(repositoriesOrOptions ?? Container.instance.git.openRepositories, r =>
createRepositoryQuickPickItem(r, undefined, { branch: true, status: true }),
),
]);
} else {
const { filter } = repositoriesOrOptions;
items = await filterMapAsync(Container.instance.git.openRepositories, async r =>
(await filter!(r))
? createRepositoryQuickPickItem(r, undefined, { branch: true, status: true })
: undefined,
);
}
if (items.length === 0) return [];
const quickpick = window.createQuickPick<RepositoryQuickPickItem>();
quickpick.ignoreFocusOut = getQuickPickIgnoreFocusOut();
const disposables: Disposable[] = [];
try {
const picks = await new Promise<readonly RepositoryQuickPickItem[] | undefined>(resolve => {
disposables.push(
quickpick.onDidHide(() => resolve(undefined)),
quickpick.onDidAccept(() => resolve(quickpick.selectedItems)),
);
quickpick.title = title;
quickpick.placeholder = placeholder;
quickpick.matchOnDescription = true;
quickpick.matchOnDetail = true;
quickpick.items = items;
quickpick.canSelectMany = true;
// Select all the repositories by default
quickpick.selectedItems = items;
quickpick.show();
});
if (picks == null) return [];
return picks;
} finally {
quickpick.dispose();
disposables.forEach(d => void d.dispose());
}
}

Loading…
Cancel
Save