GuiTestContext.ContextMenu.cs 1.2 KB

12345678910111213141516171819202122232425262728
  1. #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
  2. namespace TerminalGuiFluentTesting;
  3. public partial class GuiTestContext
  4. {
  5. /// <summary>
  6. /// Registers a right click handler on the <see cref="LastView"/> added view (or root view) that
  7. /// will open the supplied <paramref name="contextMenu"/>.
  8. /// </summary>
  9. /// <param name="contextMenu"></param>
  10. /// <returns></returns>
  11. public GuiTestContext WithContextMenu (PopoverMenu? contextMenu)
  12. {
  13. LastView.MouseEvent += (s, e) =>
  14. {
  15. if (e.Flags.HasFlag (MouseFlags.Button3Clicked))
  16. {
  17. // Registering with the PopoverManager will ensure that the context menu is closed when the view is no longer focused
  18. // and the context menu is disposed when it is closed.
  19. Application.Popover?.Register (contextMenu);
  20. contextMenu?.MakeVisible (e.ScreenPosition);
  21. }
  22. };
  23. return this;
  24. }
  25. }