|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | -import { workspace, WorkspaceFoldersChangeEvent, Uri, window, Event, EventEmitter, QuickPickItem, Disposable, SourceControl, SourceControlResourceGroup, TextEditor, Memento, commands, LogOutputChannel, l10n, ProgressLocation, WorkspaceFolder } from 'vscode'; |
| 6 | +import { workspace, WorkspaceFoldersChangeEvent, Uri, window, Event, EventEmitter, QuickPickItem, Disposable, SourceControl, SourceControlResourceGroup, TextEditor, Memento, commands, LogOutputChannel, l10n, ProgressLocation, WorkspaceFolder, ThemeIcon } from 'vscode'; |
7 | 7 | import TelemetryReporter from '@vscode/extension-telemetry'; |
8 | 8 | import { IRepositoryResolver, Repository, RepositoryState } from './repository'; |
9 | 9 | import { memoize, sequentialize, debounce } from './decorators'; |
@@ -32,6 +32,17 @@ class RepositoryPick implements QuickPickItem { |
32 | 32 | .join(' '); |
33 | 33 | } |
34 | 34 |
|
| 35 | + @memoize get iconPath(): ThemeIcon { |
| 36 | + switch (this.repository.kind) { |
| 37 | + case 'submodule': |
| 38 | + return new ThemeIcon('archive'); |
| 39 | + case 'worktree': |
| 40 | + return new ThemeIcon('list-tree'); |
| 41 | + default: |
| 42 | + return new ThemeIcon('repo'); |
| 43 | + } |
| 44 | + } |
| 45 | + |
35 | 46 | constructor(public readonly repository: Repository, public readonly index: number) { } |
36 | 47 | } |
37 | 48 |
|
@@ -840,13 +851,22 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi |
840 | 851 | openRepository.dispose(); |
841 | 852 | } |
842 | 853 |
|
843 | | - async pickRepository(): Promise<Repository | undefined> { |
| 854 | + async pickRepository(repositoryFilter?: ('repository' | 'submodule' | 'worktree')[]): Promise<Repository | undefined> { |
844 | 855 | if (this.openRepositories.length === 0) { |
845 | 856 | throw new Error(l10n.t('There are no available repositories')); |
846 | 857 | } |
847 | 858 |
|
848 | | - const picks = this.openRepositories.map((e, index) => new RepositoryPick(e.repository, index)); |
| 859 | + const repositories = this.openRepositories |
| 860 | + .filter(r => !repositoryFilter || repositoryFilter.includes(r.repository.kind)); |
| 861 | + |
| 862 | + if (repositories.length === 0) { |
| 863 | + throw new Error(l10n.t('There are no available repositories matching the filter')); |
| 864 | + } else if (repositories.length === 1) { |
| 865 | + return repositories[0].repository; |
| 866 | + } |
| 867 | + |
849 | 868 | const active = window.activeTextEditor; |
| 869 | + const picks = repositories.map((e, index) => new RepositoryPick(e.repository, index)); |
850 | 870 | const repository = active && this.getRepository(active.document.fileName); |
851 | 871 | const index = picks.findIndex(pick => pick.repository === repository); |
852 | 872 |
|
|
0 commit comments