Bladeren bron

Fixes #2836 adds sorting by repositories

main
aidoskanapyanov 1 jaar geleden
committed by Eric Amodio
bovenliggende
commit
066d3a7fdb
5 gewijzigde bestanden met toevoegingen van 73 en 3 verwijderingen
  1. +20
    -0
      package.json
  2. +2
    -0
      src/config.ts
  3. +34
    -2
      src/git/models/repository.ts
  4. +2
    -1
      src/views/repositoriesView.ts
  5. +15
    -0
      src/webviews/apps/settings/partials/views.repositories.html

+ 20
- 0
package.json Bestand weergeven

@ -1834,6 +1834,26 @@
"scope": "window",
"order": 40
},
"gitlens.sortRepositoriesBy": {
"type": "string",
"default": "lastFetched:desc",
"enum": [
"name:asc",
"name:desc",
"lastFetched:asc",
"lastFetched:desc"
],
"enumDescriptions": [
"Sorts repositories by name in ascending order",
"Sorts repositories by name in descending order",
"Sorts repositories by last fetched date in ascending order",
"Sorts repositories by last fetched date in descending order",
"Sorts repositories by starred first"
],
"markdownDescription": "Specifies how repositories are sorted in quick pick menus and views",
"scope": "window",
"order": 41
},
"gitlens.views.contributors.files.layout": {
"type": "string",
"default": "auto",

+ 2
- 0
src/config.ts Bestand weergeven

@ -162,6 +162,7 @@ export interface Config {
readonly sortBranchesBy: BranchSorting;
readonly sortContributorsBy: ContributorSorting;
readonly sortTagsBy: TagSorting;
readonly sortRepositoriesBy: RepositoriesSorting;
readonly statusBar: {
readonly alignment: 'left' | 'right';
readonly command: StatusBarCommand;
@ -247,6 +248,7 @@ export const enum CodeLensCommand {
export type CodeLensScopes = 'document' | 'containers' | 'blocks';
export type ContributorSorting = 'count:desc' | 'count:asc' | 'date:desc' | 'date:asc' | 'name:asc' | 'name:desc';
export type RepositoriesSorting = 'name:asc' | 'name:desc' | 'lastFetched:asc' | 'lastFetched:desc';
export type CustomRemoteType =
| 'AzureDevOps'
| 'Bitbucket'

+ 34
- 2
src/git/models/repository.ts Bestand weergeven

@ -3,6 +3,7 @@ import { Disposable, EventEmitter, ProgressLocation, RelativePattern, window, wo
import { md5 } from '@env/crypto';
import { ForcePushMode } from '../../@types/vscode.git.enums';
import type { CreatePullRequestActionContext } from '../../api/gitlens';
import type { RepositoriesSorting } from '../../config';
import type { CoreGitConfiguration } from '../../constants';
import { Schemes } from '../../constants';
import type { Container } from '../../container';
@ -21,6 +22,7 @@ import { getLoggableName, Logger } from '../../system/logger';
import { getLogScope } from '../../system/logger.scope';
import { updateRecordValue } from '../../system/object';
import { basename, normalizePath } from '../../system/path';
import { sortCompare } from '../../system/string';
import type { GitDir, GitProviderDescriptor, GitRepositoryCaches } from '../gitProvider';
import type { RichRemoteProvider } from '../remotes/richRemoteProvider';
import type { GitSearch, SearchQuery } from '../search';
@ -40,6 +42,10 @@ import type { GitStatus } from './status';
import type { GitTag, TagSortOptions } from './tag';
import type { GitWorktree } from './worktree';
export interface RepositoriesSortOptions {
orderBy?: RepositoriesSorting;
}
const emptyArray = Object.freeze([]) as unknown as any[];
const millisecondsPerMinute = 60 * 1000;
@ -175,8 +181,34 @@ export class Repository implements Disposable {
: 0;
}
static sort(repositories: Repository[]) {
return repositories.sort((a, b) => (a.starred ? -1 : 1) - (b.starred ? -1 : 1) || a.index - b.index);
static sort(repositories: Repository[], options?: RepositoriesSortOptions) {
options = { orderBy: configuration.get('sortRepositoriesBy'), ...options };
switch (options.orderBy) {
case 'name:asc':
return repositories.sort(
(a, b) => (a.starred ? -1 : 1) - (b.starred ? -1 : 1) || sortCompare(a.name, b.name),
);
case 'name:desc':
return repositories.sort(
(a, b) => (a.starred ? -1 : 1) - (b.starred ? -1 : 1) || sortCompare(b.name, a.name),
);
case 'lastFetched:asc':
return repositories.sort((a, b) => {
if (typeof a._lastFetched === 'undefined' && typeof b._lastFetched === 'undefined') return 0;
else if (typeof a._lastFetched === 'undefined') return 1;
else if (typeof b._lastFetched === 'undefined') return -1;
return (a.starred ? -1 : 1) - (b.starred ? -1 : 1) || a._lastFetched - b._lastFetched;
});
case 'lastFetched:desc':
default:
return repositories.sort((a, b) => {
if (typeof a._lastFetched === 'undefined' && typeof b._lastFetched === 'undefined') return 0;
else if (typeof a._lastFetched === 'undefined') return 1;
else if (typeof b._lastFetched === 'undefined') return -1;
return (a.starred ? -1 : 1) - (b.starred ? -1 : 1) || b._lastFetched - a._lastFetched;
});
}
}
private _onDidChange = new EventEmitter<RepositoryChangeEvent>();

+ 2
- 1
src/views/repositoriesView.ts Bestand weergeven

@ -254,7 +254,8 @@ export class RepositoriesView extends ViewBase<'repositories', RepositoriesNode,
!configuration.changed(e, 'defaultTimeFormat') &&
!configuration.changed(e, 'sortBranchesBy') &&
!configuration.changed(e, 'sortContributorsBy') &&
!configuration.changed(e, 'sortTagsBy')
!configuration.changed(e, 'sortTagsBy') &&
!configuration.changed(e, 'sortRepositoriesBy')
) {
return false;
}

+ 15
- 0
src/webviews/apps/settings/partials/views.repositories.html Bestand weergeven

@ -374,6 +374,21 @@
</div>
</div>
</div>
<div class="setting">
<div class="setting__input">
<label for="sortRepositoriesBy">Sort repositories</label>
<div class="select-container">
<select id="sortRepositoriesBy" name="sortRepositoriesBy" data-setting>
<option value="name:asc">by name, ascending</option>
<option value="name:desc">by name, descending</option>
<option value="lastFetched:asc">by last fetched date, ascending</option>
<option value="lastFetched:desc">by last fetched date, descending</option>
<option value="starredFirst">by starred first</option>
</select>
</div>
</div>
</div>
</div>
</div>

Laden…
Annuleren
Opslaan