Skip to content

Add Sort Changes By Extension in the CSM View&Sort #165841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ import { Iterable } from 'vs/base/common/iterator';
import { ICompressedTreeNode, ICompressedTreeElement } from 'vs/base/browser/ui/tree/compressedObjectTreeModel';
import { URI } from 'vs/base/common/uri';
import { FileKind } from 'vs/platform/files/common/files';
import { compareFileNames, comparePaths } from 'vs/base/common/comparers';
import { compareFileExtensions, compareFileNames, comparePaths } from 'vs/base/common/comparers';
import { FuzzyScore, createMatches, IMatch } from 'vs/base/common/filters';
import { IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/common/views';
import { localize } from 'vs/nls';
@@ -690,6 +690,14 @@ export class SCMTreeSorter implements ITreeSorter<TreeElement> {

// List
if (this.viewModel.mode === ViewModelMode.List) {
// Extension
if (this.viewModel.sortKey === ViewModelSortKey.Extension) {
const oneName = basename((one as ISCMResource).sourceUri);
const otherName = basename((other as ISCMResource).sourceUri);

return compareFileExtensions(oneName, otherName);
}

// FileName
if (this.viewModel.sortKey === ViewModelSortKey.Name) {
const oneName = basename((one as ISCMResource).sourceUri);
@@ -892,7 +900,8 @@ const enum ViewModelMode {
const enum ViewModelSortKey {
Path = 'path',
Name = 'name',
Status = 'status'
Status = 'status',
Extension = 'extension'
}

const Menus = {
@@ -1475,11 +1484,14 @@ class ViewModel {

// List
let viewSortKey: ViewModelSortKey;
const viewSortKeyString = this.configurationService.getValue<'path' | 'name' | 'status'>('scm.defaultViewSortKey');
const viewSortKeyString = this.configurationService.getValue<'path' | 'extension' | 'name' | 'status'>('scm.defaultViewSortKey');
switch (viewSortKeyString) {
case 'name':
viewSortKey = ViewModelSortKey.Name;
break;
case 'extension':
viewSortKey = ViewModelSortKey.Extension;
break;
case 'status':
viewSortKey = ViewModelSortKey.Status;
break;
@@ -1641,6 +1653,12 @@ class SetSortByNameAction extends SetSortKeyAction {
}
}

class SetSortByExtensionAction extends SetSortKeyAction {
constructor() {
super(ViewModelSortKey.Extension, localize('sortChangesByExtension', "Sort Changes by Extension"));
}
}

class SetSortByPathAction extends SetSortKeyAction {
constructor() {
super(ViewModelSortKey.Path, localize('sortChangesByPath', "Sort Changes by Path"));
@@ -1654,6 +1672,7 @@ class SetSortByStatusAction extends SetSortKeyAction {
}

registerAction2(SetSortByNameAction);
registerAction2(SetSortByExtensionAction);
registerAction2(SetSortByPathAction);
registerAction2(SetSortByStatusAction);