Flow.Launcher/Plugins/Flow.Launcher.Plugin.PluginIndicator/Main.cs

54 lines
2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2014-01-06 11:03:20 +00:00
using System.Linq;
2020-04-21 09:12:17 +00:00
using Flow.Launcher.Core.Plugin;
2014-01-06 11:03:20 +00:00
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Plugin.PluginIndicator
2014-01-06 11:03:20 +00:00
{
2016-05-07 02:55:09 +00:00
public class Main : IPlugin, IPluginI18n
2014-01-06 11:03:20 +00:00
{
2014-07-05 15:10:34 +00:00
private PluginInitContext context;
2014-01-06 11:03:20 +00:00
public List<Result> Query(Query query)
2014-01-06 11:03:20 +00:00
{
var results =
from keyword in PluginManager.NonGlobalPlugins.Keys
2023-01-01 02:57:27 +00:00
let plugin = PluginManager.NonGlobalPlugins[keyword].Metadata
let keywordSearchResult = context.API.FuzzySearch(query.Search, keyword)
let searchResult = keywordSearchResult.IsSearchPrecisionScoreMet() ? keywordSearchResult : context.API.FuzzySearch(query.Search, plugin.Name)
let score = searchResult.Score
where (searchResult.IsSearchPrecisionScoreMet()
|| string.IsNullOrEmpty(query.Search)) // To list all available action keywords
2023-01-01 02:57:27 +00:00
&& !plugin.Disabled
select new Result
{
Title = keyword,
2023-01-01 02:57:27 +00:00
SubTitle = string.Format(context.API.GetTranslation("flowlauncher_plugin_pluginindicator_result_subtitle"), plugin.Name),
Score = score,
IcoPath = plugin.IcoPath,
AutoCompleteText = $"{keyword}{Plugin.Query.TermSeparator}",
Action = c =>
{
context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeparator}");
return false;
}
};
return results.ToList();
2014-01-06 11:03:20 +00:00
}
public void Init(PluginInitContext context)
2014-01-06 11:03:20 +00:00
{
2014-07-05 15:10:34 +00:00
this.context = context;
2014-01-06 11:03:20 +00:00
}
2015-02-07 13:27:48 +00:00
public string GetTranslatedPluginTitle()
{
2020-04-21 12:54:41 +00:00
return context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_name");
2015-02-07 13:27:48 +00:00
}
public string GetTranslatedPluginDescription()
{
2020-04-21 12:54:41 +00:00
return context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_description");
2015-02-07 13:27:48 +00:00
}
2014-01-06 11:03:20 +00:00
}
}