Add sorting

order by result title asc, then type being folder first.
This commit is contained in:
Jeremy Wu
2020-01-08 21:50:29 +11:00
parent c509c02546
commit ac6ee28c5f

View File

@@ -195,7 +195,10 @@ namespace Wox.Plugin.Folder
// match everything before and after search term using supported wildcard '*', ie. *searchterm* // match everything before and after search term using supported wildcard '*', ie. *searchterm*
incompleteName = "*" + incompleteName.Substring(1); incompleteName = "*" + incompleteName.Substring(1);
} }
var folderList = new List<Result>();
var fileList = new List<Result>();
try try
{ {
// search folder and add results // search folder and add results
@@ -206,11 +209,14 @@ namespace Wox.Plugin.Folder
{ {
if ((fileSystemInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue; if ((fileSystemInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue;
var result = if(fileSystemInfo is DirectoryInfo)
fileSystemInfo is DirectoryInfo {
? CreateFolderResult(fileSystemInfo.Name, fileSystemInfo.FullName, query) folderList.Add(CreateFolderResult(fileSystemInfo.Name, fileSystemInfo.FullName, query));
: CreateFileResult(fileSystemInfo.FullName, query); }
results.Add(result); else
{
fileList.Add(CreateFileResult(fileSystemInfo.FullName, query));
}
} }
} }
catch (Exception e) catch (Exception e)
@@ -225,7 +231,8 @@ namespace Wox.Plugin.Folder
throw; throw;
} }
return results; // Intial ordering, this order can be updated later by UpdateResultView.MainViewModel based on history of user selection.
return results.Concat(folderList.OrderBy(x => x.Title)).Concat(fileList.OrderBy(x => x.Title)).ToList();
} }
private static Result CreateFileResult(string filePath, Query query) private static Result CreateFileResult(string filePath, Query query)