Files
minecraft-modpack-updater/ModpackUpdater.Apps.Manager/Features/Tools/GenerateChangelogFeature.cs
2025-11-15 17:17:52 +01:00

39 lines
1.6 KiB
C#

using ModpackUpdater.Apps.Manager.Api;
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
using ModpackUpdater.Apps.Manager.LangRes;
using ModpackUpdater.Apps.Manager.Ui.Models;
using MsBox.Avalonia;
using MsBox.Avalonia.Enums;
using Pilz.Features;
using Pilz.UI.Symbols;
namespace ModpackUpdater.Apps.Manager.Features.Tools;
internal class GenerateChangelogFeature : PluginFunction, IPluginFeatureProvider<GenerateChangelogFeature>
{
public static GenerateChangelogFeature Instance { get; } = new();
public GenerateChangelogFeature() : base(FeatureTypes.Tools, "origin.genchangelog", FeatureNamesLangRes.GenerateChangelogFeature)
{
Icon = AppGlobals.Symbols.GetImage(AppSymbols.time_machine, SymbolSize.Small);
}
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
{
if (@params is not MainApiParameters p
|| p.Api.Model.CurrentWorkspace?.InstallInfos is null
|| p.Api.Model.SelectedTreeNode is not ActionSetTreeNode node
|| node.Infos is not UpdateInfo updateInfo)
return null;
var changelog = SharedFunctions.GenerateChangelog(p.Api.Model.CurrentWorkspace.InstallInfos, updateInfo);
if (string.IsNullOrWhiteSpace(changelog))
return null;
p.Api.MainWindow.Clipboard?.SetTextAsync(changelog);
MessageBoxManager.GetMessageBoxStandard(MsgBoxLangRes.ChangelogCopiedToClipboard_Title, MsgBoxLangRes.ChangelogCopiedToClipboard, ButtonEnum.Ok, MsBox.Avalonia.Enums.Icon.Info).ShowAsPopupAsync(p.Api.MainWindow);
return null;
}
}