Skip to content

Commit

Permalink
fix #461
Browse files Browse the repository at this point in the history
  • Loading branch information
bao-qian committed May 20, 2016
1 parent 4bdf977 commit eacfb9b
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions Plugins/Wox.Plugin.Folder/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public void Init(PluginInitContext context)

public List<Result> Query(Query query)
{
string input = query.Search.ToLower();
string search = query.Search.ToLower();

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 =
userFolderLinks.Select(
item => new Result()
Expand All @@ -71,21 +71,21 @@ public List<Result> Query(Query query)
return false;
}
}
context.API.ChangeQuery(item.Path + (item.Path.EndsWith("\\")? "": "\\"));
context.API.ChangeQuery($"{query.ActionKeyword} {item.Path}{(item.Path.EndsWith("\\") ? "" : "\\")}");
return false;
},
ContextData = item,
}).ToList();

if (driverNames != null && !driverNames.Any(input.StartsWith))
if (driverNames != null && !driverNames.Any(search.StartsWith))
return results;

//if (!input.EndsWith("\\"))
//{
// //"c:" means "the current directory on the C drive" whereas @"c:\" means "root of the C drive"
// input = input + "\\";
//}
results.AddRange(QueryInternal_Directory_Exists(input));
results.AddRange(QueryInternal_Directory_Exists(query));

// todo temp hack for scores
foreach (var result in results)
Expand All @@ -94,7 +94,8 @@ public List<Result> Query(Query query)
}

return results;
} private void InitialDriverList()
}
private void InitialDriverList()
{
if (driverNames == null)
{
Expand All @@ -107,50 +108,51 @@ public List<Result> Query(Query query)
}
}

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>();

string incompleteName = "";
if (!Directory.Exists(rawQuery + "\\"))
if (!Directory.Exists(search + "\\"))
{
//if the last component of the path is incomplete,
//then make auto complete for it.
int index = rawQuery.LastIndexOf('\\');
if (index > 0 && index < (rawQuery.Length - 1))
int index = search.LastIndexOf('\\');
if (index > 0 && index < (search.Length - 1))
{
incompleteName = rawQuery.Substring(index + 1);
incompleteName = search.Substring(index + 1);
incompleteName = incompleteName.ToLower();
rawQuery = rawQuery.Substring(0, index + 1);
if (!Directory.Exists(rawQuery))
search = search.Substring(0, index + 1);
if (!Directory.Exists(search))
return results;
}
else
return results;
}
else
{
if (!rawQuery.EndsWith("\\"))
rawQuery += "\\";
if (!search.EndsWith("\\"))
search += "\\";
}

string firstResult = "Open current directory";
if (incompleteName.Length > 0)
firstResult = "Open " + rawQuery;
firstResult = "Open " + search;
results.Add(new Result
{
Title = firstResult,
IcoPath = "Images/folder.png",
Score = 10000,
Action = c =>
{
Process.Start(rawQuery);
Process.Start(search);
return true;
}
});

//Add children directories
DirectoryInfo[] dirs = new DirectoryInfo(rawQuery).GetDirectories();
DirectoryInfo[] dirs = new DirectoryInfo(search).GetDirectories();
foreach (DirectoryInfo dir in dirs)
{
if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue;
Expand Down Expand Up @@ -178,7 +180,7 @@ private List<Result> QueryInternal_Directory_Exists(string rawQuery)
return false;
}
}
context.API.ChangeQuery(dirCopy.FullName + "\\");
context.API.ChangeQuery($"{query.ActionKeyword} {dirCopy.FullName}\\");
return false;
}
};
Expand All @@ -187,7 +189,7 @@ private List<Result> QueryInternal_Directory_Exists(string rawQuery)
}

//Add children files
FileInfo[] files = new DirectoryInfo(rawQuery).GetFiles();
FileInfo[] files = new DirectoryInfo(search).GetFiles();
foreach (FileInfo file in files)
{
if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue;
Expand Down

0 comments on commit eacfb9b

Please sign in to comment.