Flow.Launcher/Plugins/Flow.Launcher.Plugin.PluginsManager/ContextMenu.cs

81 lines
3.7 KiB
C#
Raw Permalink Normal View History

2025-04-04 07:52:57 +00:00
using System.Collections.Generic;
using System.Text.RegularExpressions;
2020-12-06 10:10:22 +00:00
namespace Flow.Launcher.Plugin.PluginsManager
{
internal class ContextMenu : IContextMenu
{
private PluginInitContext Context { get; set; }
public ContextMenu(PluginInitContext context)
2020-12-06 10:10:22 +00:00
{
Context = context;
}
2023-11-10 17:20:32 +00:00
private readonly GlyphInfo sourcecodeGlyph = new("/Resources/#Segoe Fluent Icons","\uE943");
private readonly GlyphInfo issueGlyph = new("/Resources/#Segoe Fluent Icons", "\ued15");
private readonly GlyphInfo manifestGlyph = new("/Resources/#Segoe Fluent Icons", "\uea37");
2020-12-06 10:10:22 +00:00
public List<Result> LoadContextMenus(Result selectedResult)
{
if(selectedResult.ContextData is not UserPlugin pluginManifestInfo)
return new List<Result>();
2020-12-16 10:52:00 +00:00
return new List<Result>
{
new Result
{
Title = Context.API.GetTranslation("plugin_pluginsmanager_plugin_contextmenu_openwebsite_title"),
SubTitle = Context.API.GetTranslation("plugin_pluginsmanager_plugin_contextmenu_openwebsite_subtitle"),
2021-02-08 10:05:50 +00:00
IcoPath = selectedResult.IcoPath,
2020-12-16 10:52:00 +00:00
Action = _ =>
{
2021-12-05 19:34:23 +00:00
Context.API.OpenUrl(pluginManifestInfo.Website);
2020-12-16 10:52:00 +00:00
return true;
}
},
new Result
{
Title = Context.API.GetTranslation("plugin_pluginsmanager_plugin_contextmenu_gotosourcecode_title"),
SubTitle = Context.API.GetTranslation("plugin_pluginsmanager_plugin_contextmenu_gotosourcecode_subtitle"),
IcoPath = "Images\\sourcecode.png",
2023-11-10 17:20:32 +00:00
Glyph = sourcecodeGlyph,
2020-12-16 10:52:00 +00:00
Action = _ =>
{
2021-12-05 19:34:23 +00:00
Context.API.OpenUrl(pluginManifestInfo.UrlSourceCode);
2020-12-16 10:52:00 +00:00
return true;
}
},
new Result
{
Title = Context.API.GetTranslation("plugin_pluginsmanager_plugin_contextmenu_newissue_title"),
SubTitle = Context.API.GetTranslation("plugin_pluginsmanager_plugin_contextmenu_newissue_subtitle"),
IcoPath = "Images\\request.png",
2023-11-10 17:20:32 +00:00
Glyph = issueGlyph,
2020-12-16 10:52:00 +00:00
Action = _ =>
{
// standard UrlSourceCode format in PluginsManifest's plugins.json file: https://github.com/jjw24/Flow.Launcher.Plugin.Putty/tree/master
2020-12-16 10:52:00 +00:00
var link = pluginManifestInfo.UrlSourceCode.StartsWith("https://github.com")
? Regex.Replace(pluginManifestInfo.UrlSourceCode, @"\/tree\/\w+$", "") + "/issues"
: pluginManifestInfo.UrlSourceCode;
2021-12-05 19:34:23 +00:00
Context.API.OpenUrl(link);
2020-12-16 10:52:00 +00:00
return true;
}
},
new Result
{
Title = Context.API.GetTranslation("plugin_pluginsmanager_plugin_contextmenu_pluginsmanifest_title"),
SubTitle = Context.API.GetTranslation("plugin_pluginsmanager_plugin_contextmenu_pluginsmanifest_subtitle"),
2021-02-08 10:05:50 +00:00
IcoPath = "Images\\manifestsite.png",
2023-11-10 17:20:32 +00:00
Glyph = manifestGlyph,
2020-12-16 10:52:00 +00:00
Action = _ =>
{
2021-12-05 19:34:23 +00:00
Context.API.OpenUrl("https://github.com/Flow-Launcher/Flow.Launcher.PluginsManifest");
2020-12-16 10:52:00 +00:00
return true;
}
}
};
2020-12-06 10:10:22 +00:00
}
}
}