mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
Add IContextMenu interface & lazy load context menus
This commit is contained in:
@@ -6,10 +6,11 @@ using System.Linq;
|
||||
using Wox.Infrastructure;
|
||||
using System.Reflection;
|
||||
using Wox.Plugin.Everything.Everything;
|
||||
using Wox.Plugin.Features;
|
||||
|
||||
namespace Wox.Plugin.Everything
|
||||
{
|
||||
public class Main : IPlugin, IPluginI18n
|
||||
public class Main : IPlugin, IPluginI18n,IContextMenu
|
||||
{
|
||||
PluginInitContext context;
|
||||
EverythingAPI api = new EverythingAPI();
|
||||
@@ -24,7 +25,7 @@ namespace Wox.Plugin.Everything
|
||||
var keyword = query.Search;
|
||||
if (ContextMenuStorage.Instance.MaxSearchCount <= 0)
|
||||
{
|
||||
ContextMenuStorage.Instance.MaxSearchCount = 100;
|
||||
ContextMenuStorage.Instance.MaxSearchCount = 50;
|
||||
ContextMenuStorage.Instance.Save();
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ namespace Wox.Plugin.Everything
|
||||
context.API.ShellRun(path);
|
||||
return true;
|
||||
};
|
||||
r.ContextMenu = GetContextMenu(s);
|
||||
r.ContextData = s;
|
||||
results.Add(r);
|
||||
}
|
||||
}
|
||||
@@ -110,43 +111,6 @@ namespace Wox.Plugin.Everything
|
||||
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
|
||||
private static extern int LoadLibrary(string name);
|
||||
|
||||
private List<Result> GetContextMenu(SearchResult record)
|
||||
{
|
||||
List<Result> contextMenus = new List<Result>();
|
||||
|
||||
List<ContextMenu> availableContextMenus = new List<ContextMenu>();
|
||||
availableContextMenus.AddRange(GetDefaultContextMenu());
|
||||
availableContextMenus.AddRange(ContextMenuStorage.Instance.ContextMenus);
|
||||
|
||||
if (record.Type == ResultType.File)
|
||||
{
|
||||
foreach (ContextMenu contextMenu in availableContextMenus)
|
||||
{
|
||||
contextMenus.Add(new Result()
|
||||
{
|
||||
Title = contextMenu.Name,
|
||||
Action = _ =>
|
||||
{
|
||||
string argument = contextMenu.Argument.Replace("{path}", record.FullPath);
|
||||
try
|
||||
{
|
||||
Process.Start(contextMenu.Command, argument);
|
||||
}
|
||||
catch
|
||||
{
|
||||
context.API.ShowMsg(string.Format(context.API.GetTranslation("wox_plugin_everything_canot_start"), record.FullPath), string.Empty, string.Empty);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
IcoPath = contextMenu.ImagePath
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return contextMenus;
|
||||
}
|
||||
|
||||
private List<ContextMenu> GetDefaultContextMenu()
|
||||
{
|
||||
List<ContextMenu> defaultContextMenus = new List<ContextMenu>();
|
||||
@@ -221,5 +185,45 @@ namespace Wox.Plugin.Everything
|
||||
{
|
||||
return context.API.GetTranslation("wox_plugin_everything_plugin_description");
|
||||
}
|
||||
|
||||
public List<Result> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
SearchResult record = selectedResult.ContextData as SearchResult;
|
||||
List<Result> contextMenus = new List<Result>();
|
||||
if(record == null) return contextMenus;
|
||||
|
||||
List<ContextMenu> availableContextMenus = new List<ContextMenu>();
|
||||
availableContextMenus.AddRange(GetDefaultContextMenu());
|
||||
availableContextMenus.AddRange(ContextMenuStorage.Instance.ContextMenus);
|
||||
|
||||
if (record.Type == ResultType.File)
|
||||
{
|
||||
foreach (ContextMenu contextMenu in availableContextMenus)
|
||||
{
|
||||
var menu = contextMenu;
|
||||
contextMenus.Add(new Result()
|
||||
{
|
||||
Title = contextMenu.Name,
|
||||
Action = _ =>
|
||||
{
|
||||
string argument = menu.Argument.Replace("{path}", record.FullPath);
|
||||
try
|
||||
{
|
||||
Process.Start(menu.Command, argument);
|
||||
}
|
||||
catch
|
||||
{
|
||||
context.API.ShowMsg(string.Format(context.API.GetTranslation("wox_plugin_everything_canot_start"), record.FullPath), string.Empty, string.Empty);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
IcoPath = contextMenu.ImagePath
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return contextMenus;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"ID":"D2D2C23B084D411DB66FE0C79D6C2A6E",
|
||||
"ActionKeyword":"f",
|
||||
"ActionKeyword":"*",
|
||||
"Name":"Everything",
|
||||
"Description":"Search Everything",
|
||||
"Author":"qianlifeng,orzfly",
|
||||
|
||||
Reference in New Issue
Block a user