39 lines
1.6 KiB
C#
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.MainWindow;
|
|
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 async Task<object?> ExecuteFunctionAsync(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;
|
|
|
|
await p.Api.MainWindow.Clipboard?.SetTextAsync(changelog);
|
|
await MessageBoxManager.GetMessageBoxStandard(MsgBoxLangRes.ChangelogCopiedToClipboard_Title, MsgBoxLangRes.ChangelogCopiedToClipboard, ButtonEnum.Ok, MsBox.Avalonia.Enums.Icon.Info).ShowAsPopupAsync(p.Api.MainWindow);
|
|
|
|
return null;
|
|
}
|
|
}
|