change strings to Constants

This commit is contained in:
Jeremy Wu 2020-05-28 21:35:12 +10:00
parent 0c53d76fec
commit 758b565f01
4 changed files with 13 additions and 14 deletions

View file

@ -14,9 +14,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search
internal const string DefaultFolderSubtitleString = "Ctrl + Enter to open the directory";
internal static readonly char[] SpecialSearchChars = new char[]
{
'?', '*', '>'
};
internal const char AllFilesFolderSearchWildcard = '>';
internal const char DirectorySeperator = '\\';
}
}

View file

@ -21,7 +21,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo
{
var criteria = ConstructSearchCriteria(search);
if (search.LastIndexOf('>') > search.LastIndexOf('\\'))
if (search.LastIndexOf(Constants.AllFilesFolderSearchWildcard) > search.LastIndexOf(Constants.DirectorySeperator))
return DirectorySearch(SearchOption.AllDirectories, query, search, criteria);
return DirectorySearch(SearchOption.TopDirectoryOnly, query, search, criteria);
@ -31,13 +31,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo
{
string incompleteName = "";
if (!search.EndsWith("\\"))
if (!search.EndsWith(Constants.DirectorySeperator))
{
var indexOfSeparator = search.LastIndexOf('\\');
var indexOfSeparator = search.LastIndexOf(Constants.DirectorySeperator);
incompleteName = search.Substring(indexOfSeparator + 1).ToLower();
if (incompleteName.StartsWith('>'))
if (incompleteName.StartsWith(Constants.AllFilesFolderSearchWildcard))
incompleteName = "*" + incompleteName.Substring(1);
}

View file

@ -35,7 +35,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
}
}
string changeTo = path.EndsWith("\\") ? path : path + "\\";
string changeTo = path.EndsWith(Constants.DirectorySeperator) ? path : path + Constants.DirectorySeperator;
Main.Context.API.ChangeQuery(string.IsNullOrEmpty(query.ActionKeyword) ?
changeTo :
query.ActionKeyword + " " + changeTo);
@ -56,7 +56,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
}
else
{
folderName = folderName.TrimEnd('\\').Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None).Last();
folderName = folderName.TrimEnd(Constants.DirectorySeperator).Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None).Last();
}
var firstResult = "";

View file

@ -68,14 +68,14 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
private string QueryWhereRestrictionsFromLocationPath(string path, string searchDepth)
{
if (path.EndsWith("\\"))
if (path.EndsWith(Constants.DirectorySeperator))
return searchDepth + $"{path}'";
var indexOfSeparator = path.LastIndexOf('\\');
var indexOfSeparator = path.LastIndexOf(Constants.DirectorySeperator);
var itemName = path.Substring(indexOfSeparator + 1);
if (itemName.StartsWith('>'))
if (itemName.StartsWith(Constants.AllFilesFolderSearchWildcard))
itemName = itemName.Substring(1);
var previousLevelDirectory = path.Substring(0, indexOfSeparator);
@ -95,7 +95,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
{
string query = "SELECT TOP " + _settings.MaxResult + $" {CreateBaseQuery().QuerySelectColumns} FROM {SystemIndex} WHERE ";
if (path.IndexOfAny(Constants.SpecialSearchChars) >= 0)
if (path.LastIndexOf(Constants.AllFilesFolderSearchWildcard) > path.LastIndexOf(Constants.DirectorySeperator))
return query + QueryWhereRestrictionsForTopLevelDirectoryAllFilesAndFoldersSearch(path);
return query + QueryWhereRestrictionsForTopLevelDirectorySearch(path);