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