Add IContextMenu service (#1682)

This commit is contained in:
Asriel Camora 2024-02-29 15:15:02 -08:00 committed by GitHub
parent 3d59fa3da0
commit 5f62c703bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 1387 additions and 146 deletions

View file

@ -1,6 +1,7 @@
using System.Linq;
using Dalamud.Game;
using Dalamud.Game.Gui.ContextMenu;
using Dalamud.Plugin.Services;
using Serilog;
@ -99,6 +100,23 @@ internal static class EventHandlerExtensions
}
}
/// <summary>
/// Replacement for Invoke() on OnMenuOpenedDelegate to catch exceptions that stop event propagation in case
/// of a thrown Exception inside of an invocation.
/// </summary>
/// <param name="openedDelegate">The OnMenuOpenedDelegate in question.</param>
/// <param name="argument">Templated argument for Action.</param>
public static void InvokeSafely(this IContextMenu.OnMenuOpenedDelegate? openedDelegate, MenuOpenedArgs argument)
{
if (openedDelegate == null)
return;
foreach (var action in openedDelegate.GetInvocationList().Cast<IContextMenu.OnMenuOpenedDelegate>())
{
HandleInvoke(() => action(argument));
}
}
private static void HandleInvoke(Action act)
{
try