mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-12 04:33:10 +08:00
Fix PluginIndicator for multiple action keywords
1. Fixup, part of #352 2. Refactoring
This commit is contained in:
parent
99d9d14d3b
commit
178710dabc
@ -7,47 +7,32 @@ using Wox.Core.UserSettings;
|
|||||||
|
|
||||||
namespace Wox.Plugin.PluginIndicator
|
namespace Wox.Plugin.PluginIndicator
|
||||||
{
|
{
|
||||||
public class PluginIndicator : IPlugin,IPluginI18n
|
public class PluginIndicator : IPlugin, IPluginI18n
|
||||||
{
|
{
|
||||||
private List<PluginPair> allPlugins = new List<PluginPair>();
|
|
||||||
private PluginInitContext context;
|
private PluginInitContext context;
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
List<Result> results = new List<Result>();
|
var results = from plugin in PluginManager.NonGlobalPlugins
|
||||||
if (allPlugins.Count == 0)
|
select plugin.Metadata into metadata
|
||||||
{
|
from keyword in metadata.ActionKeywords
|
||||||
allPlugins = context.API.GetAllPlugins().Where(o => !PluginManager.IsGlobalPlugin(o.Metadata)).ToList();
|
where keyword.StartsWith(query.Terms[0])
|
||||||
}
|
let customizedPluginConfig =
|
||||||
|
UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID)
|
||||||
foreach (PluginMetadata metadata in allPlugins.Select(o => o.Metadata))
|
where customizedPluginConfig == null || !customizedPluginConfig.Disabled
|
||||||
{
|
select new Result
|
||||||
if (metadata.ActionKeyword.StartsWith(query.Search))
|
{
|
||||||
{
|
Title = keyword,
|
||||||
PluginMetadata metadataCopy = metadata;
|
SubTitle = $"Activate {metadata.Name} plugin",
|
||||||
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadataCopy.ID);
|
Score = 100,
|
||||||
if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
|
IcoPath = metadata.FullIcoPath,
|
||||||
{
|
Action = (c) =>
|
||||||
continue;
|
{
|
||||||
}
|
context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeperater}");
|
||||||
|
return false;
|
||||||
Result result = new Result
|
},
|
||||||
{
|
};
|
||||||
Title = metadata.ActionKeyword,
|
return results.ToList();
|
||||||
SubTitle = string.Format("Activate {0} plugin", metadata.Name),
|
|
||||||
Score = 100,
|
|
||||||
IcoPath = metadata.FullIcoPath,
|
|
||||||
Action = (c) =>
|
|
||||||
{
|
|
||||||
context.API.ChangeQuery(metadataCopy.ActionKeyword + " ");
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
results.Add(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
|
@ -119,7 +119,7 @@ namespace Wox.Core.Plugin
|
|||||||
if (customizedPluginConfig?.ActionKeywords?.Length > 0)
|
if (customizedPluginConfig?.ActionKeywords?.Length > 0)
|
||||||
{
|
{
|
||||||
metadata.ActionKeywords = customizedPluginConfig.ActionKeywords;
|
metadata.ActionKeywords = customizedPluginConfig.ActionKeywords;
|
||||||
metadata.ActionKeyword = customizedPluginConfig.ActionKeywords[0]; //todo reenable
|
metadata.ActionKeyword = customizedPluginConfig.ActionKeywords[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadata;
|
return metadata;
|
||||||
|
@ -29,8 +29,8 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
public static IEnumerable<PluginPair> AllPlugins { get; private set; }
|
public static IEnumerable<PluginPair> AllPlugins { get; private set; }
|
||||||
|
|
||||||
private static List<PluginPair> GlobalPlugins { get; set; }
|
public static IEnumerable<PluginPair> GlobalPlugins { get; private set; }
|
||||||
private static List<PluginPair> NonGlobalPlugins { get; set; }
|
public static IEnumerable<PluginPair> NonGlobalPlugins { get; private set; }
|
||||||
|
|
||||||
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; }
|
||||||
@ -104,19 +104,8 @@ namespace Wox.Core.Plugin
|
|||||||
{
|
{
|
||||||
InstantQueryPlugins = GetPluginsForInterface<IInstantQuery>();
|
InstantQueryPlugins = GetPluginsForInterface<IInstantQuery>();
|
||||||
contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
|
contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
|
||||||
GlobalPlugins = new List<PluginPair>();
|
GlobalPlugins = AllPlugins.Where(p => IsGlobalPlugin(p.Metadata));
|
||||||
NonGlobalPlugins = new List<PluginPair>();
|
NonGlobalPlugins = AllPlugins.Where(p => !IsGlobalPlugin(p.Metadata));
|
||||||
foreach (var plugin in AllPlugins)
|
|
||||||
{
|
|
||||||
if (IsGlobalPlugin(plugin.Metadata))
|
|
||||||
{
|
|
||||||
GlobalPlugins.Add(plugin);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NonGlobalPlugins.Add(plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ namespace Wox.Plugin
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The raw query splited into a string array.
|
/// The raw query splited into a string array.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal string[] Terms { private get; set; }
|
public string[] Terms { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Query can be splited into multiple terms by whitespace
|
/// Query can be splited into multiple terms by whitespace
|
||||||
|
Loading…
Reference in New Issue
Block a user