This commit is contained in:
bao-qian
2016-05-20 19:19:32 +01:00
parent 9c8cbdd0e6
commit 9e105a362f

View File

@@ -45,10 +45,10 @@ namespace Wox.Plugin.Folder
public List<Result> Query(Query query) public List<Result> Query(Query query)
{ {
string input = query.Search.ToLower(); string search = query.Search.ToLower();
List<FolderLink> userFolderLinks = _settings.FolderLinks.Where( List<FolderLink> userFolderLinks = _settings.FolderLinks.Where(
x => x.Nickname.StartsWith(input, StringComparison.OrdinalIgnoreCase)).ToList(); x => x.Nickname.StartsWith(search, StringComparison.OrdinalIgnoreCase)).ToList();
List<Result> results = List<Result> results =
userFolderLinks.Select( userFolderLinks.Select(
item => new Result() item => new Result()
@@ -71,13 +71,13 @@ namespace Wox.Plugin.Folder
return false; return false;
} }
} }
context.API.ChangeQuery(item.Path + (item.Path.EndsWith("\\")? "": "\\")); context.API.ChangeQuery($"{query.ActionKeyword} {item.Path}{(item.Path.EndsWith("\\") ? "" : "\\")}");
return false; return false;
}, },
ContextData = item, ContextData = item,
}).ToList(); }).ToList();
if (driverNames != null && !driverNames.Any(input.StartsWith)) if (driverNames != null && !driverNames.Any(search.StartsWith))
return results; return results;
//if (!input.EndsWith("\\")) //if (!input.EndsWith("\\"))
@@ -85,7 +85,7 @@ namespace Wox.Plugin.Folder
// //"c:" means "the current directory on the C drive" whereas @"c:\" means "root of the C drive" // //"c:" means "the current directory on the C drive" whereas @"c:\" means "root of the C drive"
// input = input + "\\"; // input = input + "\\";
//} //}
results.AddRange(QueryInternal_Directory_Exists(input)); results.AddRange(QueryInternal_Directory_Exists(query));
// todo temp hack for scores // todo temp hack for scores
foreach (var result in results) foreach (var result in results)
@@ -94,7 +94,8 @@ namespace Wox.Plugin.Folder
} }
return results; return results;
} private void InitialDriverList() }
private void InitialDriverList()
{ {
if (driverNames == null) if (driverNames == null)
{ {
@@ -107,22 +108,23 @@ namespace Wox.Plugin.Folder
} }
} }
private List<Result> QueryInternal_Directory_Exists(string rawQuery) private List<Result> QueryInternal_Directory_Exists(Query query)
{ {
var search = query.Search.ToLower();
var results = new List<Result>(); var results = new List<Result>();
string incompleteName = ""; string incompleteName = "";
if (!Directory.Exists(rawQuery + "\\")) if (!Directory.Exists(search + "\\"))
{ {
//if the last component of the path is incomplete, //if the last component of the path is incomplete,
//then make auto complete for it. //then make auto complete for it.
int index = rawQuery.LastIndexOf('\\'); int index = search.LastIndexOf('\\');
if (index > 0 && index < (rawQuery.Length - 1)) if (index > 0 && index < (search.Length - 1))
{ {
incompleteName = rawQuery.Substring(index + 1); incompleteName = search.Substring(index + 1);
incompleteName = incompleteName.ToLower(); incompleteName = incompleteName.ToLower();
rawQuery = rawQuery.Substring(0, index + 1); search = search.Substring(0, index + 1);
if (!Directory.Exists(rawQuery)) if (!Directory.Exists(search))
return results; return results;
} }
else else
@@ -130,13 +132,13 @@ namespace Wox.Plugin.Folder
} }
else else
{ {
if (!rawQuery.EndsWith("\\")) if (!search.EndsWith("\\"))
rawQuery += "\\"; search += "\\";
} }
string firstResult = "Open current directory"; string firstResult = "Open current directory";
if (incompleteName.Length > 0) if (incompleteName.Length > 0)
firstResult = "Open " + rawQuery; firstResult = "Open " + search;
results.Add(new Result results.Add(new Result
{ {
Title = firstResult, Title = firstResult,
@@ -144,13 +146,13 @@ namespace Wox.Plugin.Folder
Score = 10000, Score = 10000,
Action = c => Action = c =>
{ {
Process.Start(rawQuery); Process.Start(search);
return true; return true;
} }
}); });
//Add children directories //Add children directories
DirectoryInfo[] dirs = new DirectoryInfo(rawQuery).GetDirectories(); DirectoryInfo[] dirs = new DirectoryInfo(search).GetDirectories();
foreach (DirectoryInfo dir in dirs) foreach (DirectoryInfo dir in dirs)
{ {
if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue; if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue;
@@ -178,7 +180,7 @@ namespace Wox.Plugin.Folder
return false; return false;
} }
} }
context.API.ChangeQuery(dirCopy.FullName + "\\"); context.API.ChangeQuery($"{query.ActionKeyword} {dirCopy.FullName}\\");
return false; return false;
} }
}; };
@@ -187,7 +189,7 @@ namespace Wox.Plugin.Folder
} }
//Add children files //Add children files
FileInfo[] files = new DirectoryInfo(rawQuery).GetFiles(); FileInfo[] files = new DirectoryInfo(search).GetFiles();
foreach (FileInfo file in files) foreach (FileInfo file in files)
{ {
if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue; if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue;