Skip to content

Commit

Permalink
Add alternative explorer sort order: foldersNestsFiles
Browse files Browse the repository at this point in the history
ref #6328
  • Loading branch information
Jackson Kearl committed Jan 18, 2022
1 parent 7ae7f9d commit 3f1f126
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/vs/workbench/contrib/files/browser/files.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,15 @@ configurationRegistry.registerConfiguration({
},
'explorer.sortOrder': {
'type': 'string',
'enum': [SortOrder.Default, SortOrder.Mixed, SortOrder.FilesFirst, SortOrder.Type, SortOrder.Modified],
'enum': [SortOrder.Default, SortOrder.Mixed, SortOrder.FilesFirst, SortOrder.Type, SortOrder.Modified, SortOrder.FoldersNestsFiles],
'default': SortOrder.Default,
'enumDescriptions': [
nls.localize('sortOrder.default', 'Files and folders are sorted by their names. Folders are displayed before files.'),
nls.localize('sortOrder.mixed', 'Files and folders are sorted by their names. Files are interwoven with folders.'),
nls.localize('sortOrder.filesFirst', 'Files and folders are sorted by their names. Files are displayed before folders.'),
nls.localize('sortOrder.type', 'Files and folders are grouped by extension type then sorted by their names. Folders are displayed before files.'),
nls.localize('sortOrder.modified', 'Files and folders are sorted by last modified date in descending order. Folders are displayed before files.')
nls.localize('sortOrder.modified', 'Files and folders are sorted by last modified date in descending order. Folders are displayed before files.'),
nls.localize('sortOrder.foldersNestsFiles', 'Files and folders are sorted by their names. Folders are displayed before files. Files with nested children are displayed before other files.')
],
'description': nls.localize('sortOrder', "Controls the property-based sorting of files and folders in the explorer.")
},
Expand Down Expand Up @@ -459,12 +460,12 @@ configurationRegistry.registerConfiguration({
},
'explorer.experimental.fileNesting.expand': {
'type': 'boolean',
'markdownDescription': nls.localize('fileNestingExpand', "Experimental. Controls whether file nests are automatically expended. `#explorer.fileNesting.enabled#` must be set for this to take effect."),
'markdownDescription': nls.localize('fileNestingExpand', "Experimental. Controls whether file nests are automatically expended. `#explorer.experimental.fileNesting.enabled#` must be set for this to take effect."),
'default': true,
},
'explorer.experimental.fileNesting.patterns': {
'type': 'object',
'markdownDescription': nls.localize('fileNestingPatterns', "Experimental. Controls nesting of files in the explorer. `#explorer.fileNesting.enabled#` must be set for this to take effect. Each key describes a parent file pattern and each value should be a comma separated list of children file patterns that will be nested under the parent.\n\nA single `*` in a parent pattern may be used to capture any substring, which can then be matched against using `$(capture)` in a child pattern. Child patterns may also contain one `*` to match any substring."),
'markdownDescription': nls.localize('fileNestingPatterns', "Experimental. Controls nesting of files in the explorer. `#explorer.experimental.fileNesting.enabled#` must be set for this to take effect. Each key describes a parent file pattern and each value should be a comma separated list of children file patterns that will be nested under the parent.\n\nA single `*` in a parent pattern may be used to capture any substring, which can then be matched against using `$(capture)` in a child pattern. Child patterns may also contain one `*` to match any substring."),
patternProperties: {
'^[^*]*\\*?[^*]*$': {
description: nls.localize('fileNesting.description', "Key patterns may contain a single `*` capture group which matches any string. Each value pattern may contain one `$(capture)` token to be substituted with the parent capture group and one `*` token to match any string"),
Expand Down
19 changes: 19 additions & 0 deletions src/vs/workbench/contrib/files/browser/views/explorerViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,25 @@ export class FileSorter implements ITreeSorter<ExplorerItem> {

break;

case 'foldersNestsFiles':
if (statA.isDirectory && !statB.isDirectory) {
return -1;
}

if (statB.isDirectory && !statA.isDirectory) {
return 1;
}

if (statA.hasNests && !statB.hasNests) {
return -1;
}

if (statB.hasNests && !statA.hasNests) {
return 1;
}

break;

case 'mixed':
break; // not sorting when "mixed" is on

Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/files/common/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export const enum SortOrder {
Mixed = 'mixed',
FilesFirst = 'filesFirst',
Type = 'type',
Modified = 'modified'
Modified = 'modified',
FoldersNestsFiles = 'foldersNestsFiles',
}

export const enum UndoEnablement {
Expand Down

0 comments on commit 3f1f126

Please sign in to comment.