Refactor code

This commit is contained in:
弘韬 张 2021-04-13 19:40:04 +08:00
parent 50b5336688
commit 1015177b45
4 changed files with 14 additions and 19 deletions

View file

@ -62,11 +62,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo
if (fileSystemInfo is System.IO.DirectoryInfo)
{
folderList.Add(ResultManager.CreateFolderResult(fileSystemInfo.Name, fileSystemInfo.FullName,
fileSystemInfo.FullName, query, true, false));
fileSystemInfo.FullName, query, 0, true, false));
}
else
{
fileList.Add(ResultManager.CreateFileResult(fileSystemInfo.FullName, query, true, false));
fileList.Add(ResultManager.CreateFileResult(fileSystemInfo.FullName, query, 0, true, false));
}
token.ThrowIfCancellationRequested();

View file

@ -19,20 +19,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks
.OrderBy(x => x.Type)
.ThenBy(x => x.Nickname);
var matched = queriedAccessLinks.Select(l => l.Type switch
return queriedAccessLinks.Select(l => l.Type switch
{
ResultType.Folder => ResultManager.CreateFolderResult(l.Nickname, l.Path, l.Path, query),
ResultType.File => ResultManager.CreateFileResult(l.Path, query),
ResultType.Folder => ResultManager.CreateFolderResult(l.Nickname, l.Path, l.Path, query, 100),
ResultType.File => ResultManager.CreateFileResult(l.Path, query, 100),
_ => throw new ArgumentOutOfRangeException()
}).ToList();
foreach (var r in matched)
{
r.Score = 100;
}
return matched;
}
internal static List<Result> AccessLinkListAll(Query query, List<AccessLink> accessLinks)
@ -42,7 +35,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks
.Select(l => l.Type switch
{
ResultType.Folder => ResultManager.CreateFolderResult(l.Nickname, l.Path, l.Path, query),
ResultType.File => ResultManager.CreateFileResult(l.Path, query),
ResultType.File => ResultManager.CreateFileResult(l.Path, query, 100),
_ => throw new ArgumentOutOfRangeException()
}).ToList();

View file

@ -16,7 +16,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
Context = context;
}
internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, bool showIndexState = false, bool windowsIndexed = false)
internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, int score = 0, bool showIndexState = false, bool windowsIndexed = false)
{
return new Result
{
@ -46,6 +46,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
query.ActionKeyword + " " + changeTo);
return false;
},
Score = score,
TitleToolTip = Constants.ToolTipOpenDirectory,
SubTitleToolTip = Constants.ToolTipOpenDirectory,
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path, ShowIndexState = showIndexState, WindowsIndexed = windowsIndexed }
@ -69,9 +70,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search
if (retrievedDirectoryPath != path)
title = "Open " + folderName;
var subtitleFolderName = folderName;
// ie. max characters can be displayed without subtitle cutting off: "Program Files (x86)"
if (folderName.Length > 19)
subtitleFolderName = "the directory";
@ -94,7 +95,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
};
}
internal static Result CreateFileResult(string filePath, Query query, bool showIndexState = false, bool windowsIndexed = false)
internal static Result CreateFileResult(string filePath, Query query, int score = 0, bool showIndexState = false, bool windowsIndexed = false)
{
var result = new Result
{
@ -102,6 +103,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
SubTitle = filePath,
IcoPath = filePath,
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, Path.GetFileName(filePath)).MatchData,
Score = score,
Action = c =>
{
try

View file

@ -53,11 +53,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
dataReaderResults.GetString(0),
path,
path,
query, true, true));
query, 0, true, true));
}
else
{
fileResults.Add(ResultManager.CreateFileResult(path, query, true, true));
fileResults.Add(ResultManager.CreateFileResult(path, query, 0, true, true));
}
}
}