Skip to content

Commit de0476d

Browse files
committed
Closes #4738 adds view sorting commands and menus
- Adds sort commands and menus for Branches, Contributors, Remotes, Repositories, Tags, and Worktrees views - Adds a new `sortWorktreesBy` configuration option
1 parent 4d351f3 commit de0476d

File tree

12 files changed

+1116
-5
lines changed

12 files changed

+1116
-5
lines changed

contributions.json

Lines changed: 406 additions & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 449 additions & 1 deletion
Large diffs are not rendered by default.

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface Config {
4848
readonly sortContributorsBy: ContributorSorting;
4949
readonly sortTagsBy: TagSorting;
5050
readonly sortRepositoriesBy: RepositoriesSorting;
51+
readonly sortWorktreesBy: WorktreeSorting;
5152
readonly statusBar: StatusBarConfig;
5253
readonly strings: StringsConfig;
5354
readonly telemetry: TelemetryConfig;
@@ -92,6 +93,7 @@ export type ContributorSorting =
9293
| 'score:desc'
9394
| 'score:asc';
9495
export type RepositoriesSorting = 'discovered' | 'lastFetched:desc' | 'lastFetched:asc' | 'name:asc' | 'name:desc';
96+
export type WorktreeSorting = 'date:desc' | 'date:asc' | 'name:asc' | 'name:desc';
9597
export type CustomRemoteType =
9698
| 'AzureDevOps'
9799
| 'Bitbucket'

src/constants.commands.generated.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ export type ContributedCommands =
351351
| 'gitlens.views.branches.setShowRemoteBranchesOn'
352352
| 'gitlens.views.branches.setShowStashesOff'
353353
| 'gitlens.views.branches.setShowStashesOn'
354+
| 'gitlens.views.branches.setSortAscending'
355+
| 'gitlens.views.branches.setSortByDate'
356+
| 'gitlens.views.branches.setSortByName'
357+
| 'gitlens.views.branches.setSortDescending'
354358
| 'gitlens.views.branches.viewOptionsTitle'
355359
| 'gitlens.views.browseRepoAtRevision'
356360
| 'gitlens.views.browseRepoAtRevisionInNewWindow'
@@ -405,6 +409,12 @@ export type ContributedCommands =
405409
| 'gitlens.views.contributors.setShowMergeCommitsOn'
406410
| 'gitlens.views.contributors.setShowStatisticsOff'
407411
| 'gitlens.views.contributors.setShowStatisticsOn'
412+
| 'gitlens.views.contributors.setSortAscending'
413+
| 'gitlens.views.contributors.setSortByCount'
414+
| 'gitlens.views.contributors.setSortByDate'
415+
| 'gitlens.views.contributors.setSortByName'
416+
| 'gitlens.views.contributors.setSortByScore'
417+
| 'gitlens.views.contributors.setSortDescending'
408418
| 'gitlens.views.contributors.viewOptionsTitle'
409419
| 'gitlens.views.copy'
410420
| 'gitlens.views.copy:commitDetails'
@@ -604,6 +614,11 @@ export type ContributedCommands =
604614
| 'gitlens.views.repositories.setShowSectionUpstreamStatusOn'
605615
| 'gitlens.views.repositories.setShowSectionWorktreesOff'
606616
| 'gitlens.views.repositories.setShowSectionWorktreesOn'
617+
| 'gitlens.views.repositories.setSortAscending'
618+
| 'gitlens.views.repositories.setSortByDiscovered'
619+
| 'gitlens.views.repositories.setSortByLastFetched'
620+
| 'gitlens.views.repositories.setSortByName'
621+
| 'gitlens.views.repositories.setSortDescending'
607622
| 'gitlens.views.repositories.viewOptionsTitle'
608623
| 'gitlens.views.resetCommit'
609624
| 'gitlens.views.resetToCommit'
@@ -733,6 +748,10 @@ export type ContributedCommands =
733748
| 'gitlens.views.tags.setLayoutToTree'
734749
| 'gitlens.views.tags.setShowAvatarsOff'
735750
| 'gitlens.views.tags.setShowAvatarsOn'
751+
| 'gitlens.views.tags.setSortAscending'
752+
| 'gitlens.views.tags.setSortByDate'
753+
| 'gitlens.views.tags.setSortByName'
754+
| 'gitlens.views.tags.setSortDescending'
736755
| 'gitlens.views.tags.viewOptionsTitle'
737756
| 'gitlens.views.timeline.refresh'
738757
| 'gitlens.views.title.createBranch'
@@ -776,6 +795,10 @@ export type ContributedCommands =
776795
| 'gitlens.views.worktrees.setShowBranchPullRequestOn'
777796
| 'gitlens.views.worktrees.setShowStashesOff'
778797
| 'gitlens.views.worktrees.setShowStashesOn'
798+
| 'gitlens.views.worktrees.setSortAscending'
799+
| 'gitlens.views.worktrees.setSortByDate'
800+
| 'gitlens.views.worktrees.setSortByName'
801+
| 'gitlens.views.worktrees.setSortDescending'
779802
| 'gitlens.views.worktrees.viewOptionsTitle'
780803
| 'gitlens.visualizeHistory.file:commitDetails'
781804
| 'gitlens.visualizeHistory.file:editor'
@@ -1042,4 +1065,8 @@ export type ContributedKeybindingCommands =
10421065
export type ContributedOrphansOrInternalCommands =
10431066
| 'gitlens.graph.pushWithForce'
10441067
| 'gitlens.openFolderHistoryInGraph'
1045-
| 'gitlens.plus.cloudIntegrations.connect';
1068+
| 'gitlens.plus.cloudIntegrations.connect'
1069+
| 'gitlens.views.remotes.setSortAscending'
1070+
| 'gitlens.views.remotes.setSortByDate'
1071+
| 'gitlens.views.remotes.setSortByName'
1072+
| 'gitlens.views.remotes.setSortDescending';

src/git/utils/-webview/sorting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export function sortWorktrees(
326326
worktrees: GitWorktree[] | WorktreeQuickPickItem[],
327327
options?: WorktreeSortOptions,
328328
): GitWorktree[] | WorktreeQuickPickItem[] {
329-
options = { orderBy: configuration.get('sortBranchesBy'), ...options };
329+
options = { orderBy: configuration.get('sortWorktreesBy'), ...options };
330330

331331
const getWorktree = (worktree: GitWorktree | WorktreeQuickPickItem): GitWorktree => {
332332
return isWorktree(worktree) ? worktree : worktree.item;

src/views/branchesView.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type { ViewNode } from './nodes/abstract/viewNode';
1919
import { BranchesNode } from './nodes/branchesNode';
2020
import { BranchNode } from './nodes/branchNode';
2121
import { BranchOrTagFolderNode } from './nodes/branchOrTagFolderNode';
22+
import { updateSorting, updateSortingDirection } from './utils/-webview/sorting.utils';
2223
import type { GroupedViewContext, RevealOptions } from './viewBase';
2324
import { ViewBase } from './viewBase';
2425
import type { CopyNodeCommandArgs } from './viewCommands';
@@ -144,6 +145,10 @@ export class BranchesView extends ViewBase<'branches', BranchesViewNode, Branche
144145
),
145146
registerViewCommand(this.getQualifiedCommand('setLayoutToList'), () => this.setLayout('list'), this),
146147
registerViewCommand(this.getQualifiedCommand('setLayoutToTree'), () => this.setLayout('tree'), this),
148+
registerViewCommand(this.getQualifiedCommand('setSortByDate'), () => this.setSortByDate(), this),
149+
registerViewCommand(this.getQualifiedCommand('setSortByName'), () => this.setSortByName(), this),
150+
registerViewCommand(this.getQualifiedCommand('setSortDescending'), () => this.setSortDescending(), this),
151+
registerViewCommand(this.getQualifiedCommand('setSortAscending'), () => this.setSortAscending(), this),
147152
registerViewCommand(
148153
this.getQualifiedCommand('setFilesLayoutToAuto'),
149154
() => this.setFilesLayout('auto'),
@@ -340,6 +345,22 @@ export class BranchesView extends ViewBase<'branches', BranchesViewNode, Branche
340345
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
341346
}
342347

348+
private setSortByDate() {
349+
return updateSorting('sortBranchesBy', 'date', 'desc');
350+
}
351+
352+
private setSortByName() {
353+
return updateSorting('sortBranchesBy', 'name', 'asc');
354+
}
355+
356+
private setSortDescending() {
357+
return updateSortingDirection('sortBranchesBy', 'desc');
358+
}
359+
360+
private setSortAscending() {
361+
return updateSortingDirection('sortBranchesBy', 'asc');
362+
}
363+
343364
private setShowAvatars(enabled: boolean) {
344365
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
345366
}

src/views/contributorsView.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { RepositoryFolderNode } from './nodes/abstract/repositoryFolderNode';
1717
import type { ViewNode } from './nodes/abstract/viewNode';
1818
import { ContributorNode } from './nodes/contributorNode';
1919
import { ContributorsNode } from './nodes/contributorsNode';
20+
import { updateSorting, updateSortingDirection } from './utils/-webview/sorting.utils';
2021
import type { GroupedViewContext, RevealOptions } from './viewBase';
2122
import { ViewBase } from './viewBase';
2223
import type { CopyNodeCommandArgs } from './viewCommands';
@@ -170,6 +171,12 @@ export class ContributorsView extends ViewBase<'contributors', ContributorsViewN
170171
() => this.setFilesLayout('tree'),
171172
this,
172173
),
174+
registerViewCommand(this.getQualifiedCommand('setSortByCount'), () => this.setSortByCount(), this),
175+
registerViewCommand(this.getQualifiedCommand('setSortByDate'), () => this.setSortByDate(), this),
176+
registerViewCommand(this.getQualifiedCommand('setSortByName'), () => this.setSortByName(), this),
177+
registerViewCommand(this.getQualifiedCommand('setSortByScore'), () => this.setSortByScore(), this),
178+
registerViewCommand(this.getQualifiedCommand('setSortDescending'), () => this.setSortDescending(), this),
179+
registerViewCommand(this.getQualifiedCommand('setSortAscending'), () => this.setSortAscending(), this),
173180

174181
registerViewCommand(
175182
this.getQualifiedCommand('setShowAllBranchesOn'),
@@ -291,6 +298,30 @@ export class ContributorsView extends ViewBase<'contributors', ContributorsViewN
291298
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
292299
}
293300

301+
private setSortByCount() {
302+
return updateSorting('sortContributorsBy', 'count', 'desc');
303+
}
304+
305+
private setSortByDate() {
306+
return updateSorting('sortContributorsBy', 'date', 'desc');
307+
}
308+
309+
private setSortByName() {
310+
return updateSorting('sortContributorsBy', 'name', 'asc');
311+
}
312+
313+
private setSortByScore() {
314+
return updateSorting('sortContributorsBy', 'score', 'desc');
315+
}
316+
317+
private setSortDescending() {
318+
return updateSortingDirection('sortContributorsBy', 'desc');
319+
}
320+
321+
private setSortAscending() {
322+
return updateSortingDirection('sortContributorsBy', 'asc');
323+
}
324+
294325
private setShowAllBranches(enabled: boolean) {
295326
return configuration.updateEffective(`views.${this.configKey}.showAllBranches` as const, enabled);
296327
}

src/views/remotesView.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { BranchOrTagFolderNode } from './nodes/branchOrTagFolderNode';
2222
import { RemoteNode } from './nodes/remoteNode';
2323
import { RemotesNode } from './nodes/remotesNode';
2424
import { RepositoryNode } from './nodes/repositoryNode';
25+
import { updateSorting, updateSortingDirection } from './utils/-webview/sorting.utils';
2526
import type { GroupedViewContext, RevealOptions } from './viewBase';
2627
import { ViewBase } from './viewBase';
2728
import type { CopyNodeCommandArgs } from './viewCommands';
@@ -129,6 +130,10 @@ export class RemotesView extends ViewBase<'remotes', RemotesViewNode, RemotesVie
129130
),
130131
registerViewCommand(this.getQualifiedCommand('setLayoutToList'), () => this.setLayout('list'), this),
131132
registerViewCommand(this.getQualifiedCommand('setLayoutToTree'), () => this.setLayout('tree'), this),
133+
registerViewCommand(this.getQualifiedCommand('setSortByDate'), () => this.setSortByDate(), this),
134+
registerViewCommand(this.getQualifiedCommand('setSortByName'), () => this.setSortByName(), this),
135+
registerViewCommand(this.getQualifiedCommand('setSortDescending'), () => this.setSortDescending(), this),
136+
registerViewCommand(this.getQualifiedCommand('setSortAscending'), () => this.setSortAscending(), this),
132137
registerViewCommand(
133138
this.getQualifiedCommand('setFilesLayoutToAuto'),
134139
() => this.setFilesLayout('auto'),
@@ -355,6 +360,22 @@ export class RemotesView extends ViewBase<'remotes', RemotesViewNode, RemotesVie
355360
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
356361
}
357362

363+
private setSortByDate() {
364+
return updateSorting('sortBranchesBy', 'date', 'desc');
365+
}
366+
367+
private setSortByName() {
368+
return updateSorting('sortBranchesBy', 'name', 'asc');
369+
}
370+
371+
private setSortDescending() {
372+
return updateSortingDirection('sortBranchesBy', 'desc');
373+
}
374+
375+
private setSortAscending() {
376+
return updateSortingDirection('sortBranchesBy', 'asc');
377+
}
378+
358379
private setShowAvatars(enabled: boolean) {
359380
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
360381
}

src/views/repositoriesView.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { StashesNode } from './nodes/stashesNode';
3636
import { TagsNode } from './nodes/tagsNode';
3737
import { WorktreeNode } from './nodes/worktreeNode';
3838
import { WorktreesNode } from './nodes/worktreesNode';
39+
import { updateSorting, updateSortingDirection } from './utils/-webview/sorting.utils';
3940
import type { GroupedViewContext, RevealOptions } from './viewBase';
4041
import { ViewBase } from './viewBase';
4142
import type { CopyNodeCommandArgs } from './viewCommands';
@@ -95,6 +96,19 @@ export class RepositoriesView extends ViewBase<'repositories', RepositoriesNode,
9596
() => this.setBranchesLayout('tree'),
9697
this,
9798
),
99+
registerViewCommand(
100+
this.getQualifiedCommand('setSortByDiscovered'),
101+
() => this.setSortByDiscovered(),
102+
this,
103+
),
104+
registerViewCommand(
105+
this.getQualifiedCommand('setSortByLastFetched'),
106+
() => this.setSortByLastFetched(),
107+
this,
108+
),
109+
registerViewCommand(this.getQualifiedCommand('setSortByName'), () => this.setSortByName(), this),
110+
registerViewCommand(this.getQualifiedCommand('setSortDescending'), () => this.setSortDescending(), this),
111+
registerViewCommand(this.getQualifiedCommand('setSortAscending'), () => this.setSortAscending(), this),
98112
registerViewCommand(
99113
this.getQualifiedCommand('setFilesLayoutToAuto'),
100114
() => this.setFilesLayout('auto'),
@@ -796,6 +810,26 @@ export class RepositoriesView extends ViewBase<'repositories', RepositoriesNode,
796810
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
797811
}
798812

813+
private setSortByDiscovered() {
814+
return updateSorting('sortRepositoriesBy', 'discovered', undefined);
815+
}
816+
817+
private setSortByLastFetched() {
818+
return updateSorting('sortRepositoriesBy', 'lastFetched', 'desc');
819+
}
820+
821+
private setSortByName() {
822+
return updateSorting('sortRepositoriesBy', 'name', 'asc');
823+
}
824+
825+
private setSortDescending() {
826+
return updateSortingDirection('sortRepositoriesBy', 'desc');
827+
}
828+
829+
private setSortAscending() {
830+
return updateSortingDirection('sortRepositoriesBy', 'asc');
831+
}
832+
799833
private setShowAvatars(enabled: boolean) {
800834
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
801835
}

src/views/tagsView.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { RepositoryFolderNode } from './nodes/abstract/repositoryFolderNode';
1515
import type { ViewNode } from './nodes/abstract/viewNode';
1616
import { BranchOrTagFolderNode } from './nodes/branchOrTagFolderNode';
1717
import { TagsNode } from './nodes/tagsNode';
18+
import { updateSorting, updateSortingDirection } from './utils/-webview/sorting.utils';
1819
import type { GroupedViewContext, RevealOptions } from './viewBase';
1920
import { ViewBase } from './viewBase';
2021
import type { CopyNodeCommandArgs } from './viewCommands';
@@ -116,6 +117,10 @@ export class TagsView extends ViewBase<'tags', TagsViewNode, TagsViewConfig> {
116117
),
117118
registerViewCommand(this.getQualifiedCommand('setLayoutToList'), () => this.setLayout('list'), this),
118119
registerViewCommand(this.getQualifiedCommand('setLayoutToTree'), () => this.setLayout('tree'), this),
120+
registerViewCommand(this.getQualifiedCommand('setSortByDate'), () => this.setSortByDate(), this),
121+
registerViewCommand(this.getQualifiedCommand('setSortByName'), () => this.setSortByName(), this),
122+
registerViewCommand(this.getQualifiedCommand('setSortDescending'), () => this.setSortDescending(), this),
123+
registerViewCommand(this.getQualifiedCommand('setSortAscending'), () => this.setSortAscending(), this),
119124
registerViewCommand(
120125
this.getQualifiedCommand('setFilesLayoutToAuto'),
121126
() => this.setFilesLayout('auto'),
@@ -219,6 +224,22 @@ export class TagsView extends ViewBase<'tags', TagsViewNode, TagsViewConfig> {
219224
return configuration.updateEffective(`views.${this.configKey}.files.layout` as const, layout);
220225
}
221226

227+
private setSortByDate() {
228+
return updateSorting('sortTagsBy', 'date', 'desc');
229+
}
230+
231+
private setSortByName() {
232+
return updateSorting('sortTagsBy', 'name', 'asc');
233+
}
234+
235+
private setSortDescending() {
236+
return updateSortingDirection('sortTagsBy', 'desc');
237+
}
238+
239+
private setSortAscending() {
240+
return updateSortingDirection('sortTagsBy', 'asc');
241+
}
242+
222243
private setShowAvatars(enabled: boolean) {
223244
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
224245
}

0 commit comments

Comments
 (0)