mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 03:37:10 +08:00
ContextMenu 4: for non c# plugin #1366
This commit is contained in:
parent
f3d79d906e
commit
5640b2157f
@ -19,7 +19,8 @@ class Wox(object):
|
|||||||
|
|
||||||
request_method = dict(methods)[request_method_name]
|
request_method = dict(methods)[request_method_name]
|
||||||
results = request_method(*request_parameters)
|
results = request_method(*request_parameters)
|
||||||
if request_method_name == "query":
|
|
||||||
|
if request_method_name == "query" or request_method_name == "context_menu":
|
||||||
print(json.dumps({"result": results}))
|
print(json.dumps({"result": results}))
|
||||||
|
|
||||||
def query(self,query):
|
def query(self,query):
|
||||||
@ -28,6 +29,12 @@ class Wox(object):
|
|||||||
"""
|
"""
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def context_menu(self, data):
|
||||||
|
"""
|
||||||
|
optional context menu entries for a result
|
||||||
|
"""
|
||||||
|
return []
|
||||||
|
|
||||||
def debug(self,msg):
|
def debug(self,msg):
|
||||||
"""
|
"""
|
||||||
alert msg
|
alert msg
|
||||||
|
@ -9,6 +9,16 @@ class HelloWorld(Wox):
|
|||||||
results.append({
|
results.append({
|
||||||
"Title": "Hello World",
|
"Title": "Hello World",
|
||||||
"SubTitle": "Query: {}".format(query),
|
"SubTitle": "Query: {}".format(query),
|
||||||
|
"IcoPath":"Images/app.ico",
|
||||||
|
"ContextData": "ctxData"
|
||||||
|
})
|
||||||
|
return results
|
||||||
|
|
||||||
|
def context_menu(self, data):
|
||||||
|
results = []
|
||||||
|
results.append({
|
||||||
|
"Title": "Context menu entry",
|
||||||
|
"SubTitle": "Data: {}".format(data),
|
||||||
"IcoPath":"Images/app.ico"
|
"IcoPath":"Images/app.ico"
|
||||||
})
|
})
|
||||||
return results
|
return results
|
||||||
|
@ -39,5 +39,16 @@ namespace Wox.Core.Plugin
|
|||||||
_startInfo.Arguments = $"\"{rpcRequest}\"";
|
_startInfo.Arguments = $"\"{rpcRequest}\"";
|
||||||
return Execute(_startInfo);
|
return Execute(_startInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override string ExecuteContextMenu(Result selectedResult) {
|
||||||
|
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel {
|
||||||
|
Method = "contextmenu",
|
||||||
|
Parameters = new object[] { selectedResult.ContextData },
|
||||||
|
};
|
||||||
|
|
||||||
|
_startInfo.Arguments = $"\"{request}\"";
|
||||||
|
|
||||||
|
return Execute(_startInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,7 @@ namespace Wox.Core.Plugin
|
|||||||
/// Represent the plugin that using JsonPRC
|
/// Represent the plugin that using JsonPRC
|
||||||
/// every JsonRPC plugin should has its own plugin instance
|
/// every JsonRPC plugin should has its own plugin instance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal abstract class JsonRPCPlugin : IPlugin
|
internal abstract class JsonRPCPlugin : IPlugin, IContextMenu
|
||||||
{
|
{
|
||||||
protected PluginInitContext context;
|
protected PluginInitContext context;
|
||||||
public const string JsonRPC = "JsonRPC";
|
public const string JsonRPC = "JsonRPC";
|
||||||
@ -29,6 +29,7 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
protected abstract string ExecuteQuery(Query query);
|
protected abstract string ExecuteQuery(Query query);
|
||||||
protected abstract string ExecuteCallback(JsonRPCRequestModel rpcRequest);
|
protected abstract string ExecuteCallback(JsonRPCRequestModel rpcRequest);
|
||||||
|
protected abstract string ExecuteContextMenu(Result selectedResult);
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
@ -44,7 +45,21 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Result> DeserializedResult(string output)
|
public List<Result> LoadContextMenus(Result selectedResult)
|
||||||
|
{
|
||||||
|
string output = ExecuteContextMenu(selectedResult);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return DeserializedResult(output);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Exception($"|JsonRPCPlugin.LoadContextMenus|Exception on result <{selectedResult}>", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Result> DeserializedResult(string output)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(output))
|
if (!String.IsNullOrEmpty(output))
|
||||||
{
|
{
|
||||||
@ -84,9 +99,11 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ExecuteWoxAPI(string method, object[] parameters)
|
private void ExecuteWoxAPI(string method, object[] parameters)
|
||||||
{
|
{
|
||||||
|
@ -49,5 +49,16 @@ namespace Wox.Core.Plugin
|
|||||||
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
||||||
return Execute(_startInfo);
|
return Execute(_startInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override string ExecuteContextMenu(Result selectedResult) {
|
||||||
|
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel {
|
||||||
|
Method = "context_menu",
|
||||||
|
Parameters = new object[] { selectedResult.ContextData },
|
||||||
|
};
|
||||||
|
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\"";
|
||||||
|
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
||||||
|
|
||||||
|
return Execute(_startInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user