Refactoring directory path for plugin

This commit is contained in:
bao-qian
2016-01-08 01:13:36 +00:00
parent ec40956721
commit 8ee94d75ca
5 changed files with 196 additions and 42 deletions

View File

@@ -13,10 +13,10 @@ namespace Wox.Plugin.Everything
{
public class Main : IPlugin, IPluginI18n, IContextMenu
{
PluginInitContext context;
EverythingAPI api = new EverythingAPI();
private static List<string> imageExts = new List<string> { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico" };
private static List<string> executableExts = new List<string> { ".exe" };
private PluginInitContext _context;
private readonly EverythingAPI _api = new EverythingAPI();
private static readonly List<string> ImageExts = new List<string> { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico" };
private static readonly List<string> ExecutableExts = new List<string> { ".exe" };
public List<Result> Query(Query query)
{
@@ -47,7 +47,7 @@ namespace Wox.Plugin.Everything
try
{
var searchList = api.Search(keyword, maxCount: ContextMenuStorage.Instance.MaxSearchCount).ToList();
var searchList = _api.Search(keyword, maxCount: ContextMenuStorage.Instance.MaxSearchCount).ToList();
foreach (var s in searchList)
{
var path = s.FullPath;
@@ -57,7 +57,7 @@ namespace Wox.Plugin.Everything
r.IcoPath = GetIconPath(s);
r.Action = c =>
{
context.API.HideApp();
_context.API.HideApp();
Process.Start(new ProcessStartInfo
{
FileName = path,
@@ -74,7 +74,7 @@ namespace Wox.Plugin.Everything
StartEverything();
results.Add(new Result
{
Title = context.API.GetTranslation("wox_plugin_everything_is_not_running"),
Title = _context.API.GetTranslation("wox_plugin_everything_is_not_running"),
IcoPath = "Images\\warning.png"
});
}
@@ -82,12 +82,12 @@ namespace Wox.Plugin.Everything
{
results.Add(new Result
{
Title = context.API.GetTranslation("wox_plugin_everything_query_error"),
Title = _context.API.GetTranslation("wox_plugin_everything_query_error"),
SubTitle = e.Message,
Action = _ =>
{
Clipboard.SetText(e.Message + "\r\n" + e.StackTrace);
context.API.ShowMsg(context.API.GetTranslation("wox_plugin_everything_copied"), null, string.Empty);
_context.API.ShowMsg(_context.API.GetTranslation("wox_plugin_everything_copied"), null, string.Empty);
return false;
},
IcoPath = "Images\\error.png"
@@ -95,7 +95,7 @@ namespace Wox.Plugin.Everything
}
}
api.Reset();
_api.Reset();
return results;
}
@@ -109,11 +109,11 @@ namespace Wox.Plugin.Everything
}
else if (!string.IsNullOrEmpty(ext))
{
if (imageExts.Contains(ext.ToLower()))
if (ImageExts.Contains(ext.ToLower()))
{
return "Images\\image.png";
}
else if (executableExts.Contains(ext.ToLower()))
else if (ExecutableExts.Contains(ext.ToLower()))
{
return s.FullPath;
}
@@ -130,7 +130,7 @@ namespace Wox.Plugin.Everything
List<ContextMenu> defaultContextMenus = new List<ContextMenu>();
ContextMenu openFolderContextMenu = new ContextMenu
{
Name = context.API.GetTranslation("wox_plugin_everything_open_containing_folder"),
Name = _context.API.GetTranslation("wox_plugin_everything_open_containing_folder"),
Command = "explorer.exe",
Argument = " /select,\"{path}\"",
ImagePath = "Images\\folder.png"
@@ -142,7 +142,7 @@ namespace Wox.Plugin.Everything
public void Init(PluginInitContext context)
{
this.context = context;
_context = context;
ContextMenuStorage.Instance.API = context.API;
LoadLibrary(Path.Combine(
@@ -225,7 +225,7 @@ namespace Wox.Plugin.Everything
}
catch (Exception e)
{
context.API.ShowMsg("Start Everything failed");
_context.API.ShowMsg("Start Everything failed");
}
}
@@ -250,8 +250,10 @@ namespace Wox.Plugin.Everything
private string GetEverythingPath()
{
string everythingFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "PortableEverything");
return Path.Combine(everythingFolder, "Everything.exe");
string directory = Path.Combine(_context.CurrentPluginMetadata.PluginDirectory,
"PortableEverything",
"Everything.exe");
return directory;
}
public string GetLanguagesFolder()
@@ -261,12 +263,12 @@ namespace Wox.Plugin.Everything
public string GetTranslatedPluginTitle()
{
return context.API.GetTranslation("wox_plugin_everything_plugin_name");
return _context.API.GetTranslation("wox_plugin_everything_plugin_name");
}
public string GetTranslatedPluginDescription()
{
return context.API.GetTranslation("wox_plugin_everything_plugin_description");
return _context.API.GetTranslation("wox_plugin_everything_plugin_description");
}
public List<Result> LoadContextMenus(Result selectedResult)
@@ -296,7 +298,7 @@ namespace Wox.Plugin.Everything
}
catch
{
context.API.ShowMsg(string.Format(context.API.GetTranslation("wox_plugin_everything_canot_start"), record.FullPath), string.Empty, string.Empty);
_context.API.ShowMsg(string.Format(_context.API.GetTranslation("wox_plugin_everything_canot_start"), record.FullPath), string.Empty, string.Empty);
return false;
}
return true;