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

View File

@ -18,5 +18,166 @@ namespace Wox.Plugin.WebSearch
public string WebSearchSuggestionSource { get; set; } public string WebSearchSuggestionSource { get; set; }
protected override string FileName { get; } = "settings_plugin_websearch"; protected override string FileName { get; } = "settings_plugin_websearch";
protected override WebSearchStorage LoadDefault()
{
WebSearches = new List<WebSearch>(new List<WebSearch>()
{
new WebSearch
{
Title = "Google",
ActionKeyword = "g",
IconPath = "Images\\google.png",
Url = "https://www.google.com/search?q=new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Wikipedia",
ActionKeyword = "wiki",
IconPath = "Images\\wiki.png",
Url = "http://en.wikipedia.org/wiki/new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "FindIcon",
ActionKeyword = "findicon",
IconPath = "Images\\pictures.png",
Url = "http://findicons.com/search/new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Facebook",
ActionKeyword = "facebook",
IconPath = "Images\\facebook.png",
Url = "http://www.facebook.com/search/?q=new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Twitter",
ActionKeyword = "twitter",
IconPath = "Images\\twitter.png",
Url = "http://twitter.com/search?q=new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Google Maps",
ActionKeyword = "maps",
IconPath = "Images\\google_maps.png",
Url = "http://maps.google.com/maps?q=new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Google Translate",
ActionKeyword = "translate",
IconPath = "Images\\google_translate.png",
Url = "http://translate.google.com/#auto|en|new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Duckduckgo",
ActionKeyword = "duckduckgo",
IconPath = "Images\\duckduckgo.png",
Url = "https://duckduckgo.com/?q=new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Github",
ActionKeyword = "github",
IconPath = "Images\\github.png",
Url = "https://github.com/search?q=new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Github Gist",
ActionKeyword = "gist",
IconPath = "Images\\gist.png",
Url = "https://gist.github.com/search?q=new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Gmail",
ActionKeyword = "gmail",
IconPath = "Images\\gmail.png",
Url = "https://mail.google.com/mail/ca/u/0/#apps/new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Google Drive",
ActionKeyword = "drive",
IconPath = "Images\\google_drive.png",
Url = "http://drive.google.com/?hl=en&tab=bo#search/new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Wolframalpha",
ActionKeyword = "wolframalpha",
IconPath = "Images\\wolframalpha.png",
Url = "http://www.wolframalpha.com/input/?i=new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Stackoverflow",
ActionKeyword = "stackoverflow",
IconPath = "Images\\stackoverflow.png",
Url = "http://stackoverflow.com/search?q=new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "I'm Feeling Lucky",
ActionKeyword = "lucky",
IconPath = "Images\\google.png",
Url = "http://google.com/search?q=new WebSearch {q}&btnI=I",
Enabled = true
},
new WebSearch
{
Title = "Google Image",
ActionKeyword = "image",
IconPath = "Images\\google.png",
Url = "https://www.google.com/search?q=new WebSearch {q}&tbm=isch",
Enabled = true
},
new WebSearch
{
Title = "Youtube",
ActionKeyword = "youtube",
IconPath = "Images\\youtube.png",
Url = "http://www.youtube.com/results?search_query=new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Bing",
ActionKeyword = "bing",
IconPath = "Images\\bing.png",
Url = "https://www.bing.com/search?q=new WebSearch {q}",
Enabled = true
},
new WebSearch
{
Title = "Yahoo",
ActionKeyword = "yahoo",
IconPath = "Images\\yahoo.png",
Url = "http://www.search.yahoo.com/search?p=new WebSearch {q}",
Enabled = true
}
});
return this;
}
} }
} }

View File

@ -136,9 +136,6 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="setting.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Page Include="WebSearchesSetting.xaml"> <Page Include="WebSearchesSetting.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>

View File

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Threading; using System.Threading;
using Wox.Core.Resource; using Wox.Core.Resource;
using Wox.Core.UserSettings; using Wox.Core.UserSettings;
@ -19,35 +18,33 @@ namespace Wox.Core.Plugin
public static class PluginManager public static class PluginManager
{ {
public const string DirectoryName = "Plugins"; public const string DirectoryName = "Plugins";
private static IEnumerable<PluginPair> contextMenuPlugins; private static IEnumerable<PluginPair> _contextMenuPlugins;
/// <summary> /// <summary>
/// Directories that will hold Wox plugin directory /// Directories that will hold Wox plugin directory
/// </summary> /// </summary>
private static List<string> pluginDirectories = new List<string>(); private static readonly List<string> PluginDirectories = new List<string>();
public static IEnumerable<PluginPair> AllPlugins { get; private set; } public static IEnumerable<PluginPair> AllPlugins { get; private set; }
public static List<PluginPair> GlobalPlugins { get; } = new List<PluginPair>(); public static readonly List<PluginPair> GlobalPlugins = new List<PluginPair>();
public static Dictionary<string, PluginPair> NonGlobalPlugins { get; set; } = new Dictionary<string, PluginPair>();
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new Dictionary<string, PluginPair>();
private static IEnumerable<PluginPair> InstantQueryPlugins { get; set; } private static IEnumerable<PluginPair> InstantQueryPlugins { get; set; }
public static IPublicAPI API { private set; get; } public static IPublicAPI API { private set; get; }
public static string PluginDirectory public static readonly string PluginDirectory = Path.Combine(WoxDirectroy.Executable, DirectoryName);
{
get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), DirectoryName); }
}
private static void SetupPluginDirectories() private static void SetupPluginDirectories()
{ {
pluginDirectories.Add(PluginDirectory); PluginDirectories.Add(PluginDirectory);
MakesurePluginDirectoriesExist(); MakesurePluginDirectoriesExist();
} }
private static void MakesurePluginDirectoriesExist() private static void MakesurePluginDirectoriesExist()
{ {
foreach (string pluginDirectory in pluginDirectories) foreach (string pluginDirectory in PluginDirectories)
{ {
if (!Directory.Exists(pluginDirectory)) if (!Directory.Exists(pluginDirectory))
{ {
@ -73,7 +70,7 @@ namespace Wox.Core.Plugin
SetupPluginDirectories(); SetupPluginDirectories();
API = api; API = api;
var metadatas = PluginConfig.Parse(pluginDirectories); var metadatas = PluginConfig.Parse(PluginDirectories);
AllPlugins = (new CSharpPluginLoader().LoadPlugin(metadatas)). AllPlugins = (new CSharpPluginLoader().LoadPlugin(metadatas)).
Concat(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(metadatas)); Concat(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(metadatas));
@ -102,7 +99,7 @@ namespace Wox.Core.Plugin
ThreadPool.QueueUserWorkItem(o => ThreadPool.QueueUserWorkItem(o =>
{ {
InstantQueryPlugins = GetPluginsForInterface<IInstantQuery>(); InstantQueryPlugins = GetPluginsForInterface<IInstantQuery>();
contextMenuPlugins = GetPluginsForInterface<IContextMenu>(); _contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
foreach (var plugin in AllPlugins) foreach (var plugin in AllPlugins)
{ {
if (IsGlobalPlugin(plugin.Metadata)) if (IsGlobalPlugin(plugin.Metadata))
@ -231,7 +228,7 @@ namespace Wox.Core.Plugin
public static List<Result> GetContextMenusForPlugin(Result result) public static List<Result> GetContextMenusForPlugin(Result result)
{ {
var pluginPair = contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID); var pluginPair = _contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);
var plugin = (IContextMenu)pluginPair?.Plugin; var plugin = (IContextMenu)pluginPair?.Plugin;
if (plugin != null) if (plugin != null)
{ {

View File

@ -15,10 +15,7 @@ namespace Wox.Plugin
public string Website { get; set; } public string Website { get; set; }
public string ExecuteFilePath public string ExecuteFilePath => Path.Combine(PluginDirectory, ExecuteFileName);
{
get { return Path.Combine(PluginDirectory, ExecuteFileName); }
}
public string ExecuteFileName { get; set; } public string ExecuteFileName { get; set; }