Skip to content

Commit d4b2782

Browse files
author
tznind
committed
Prevent user editing the main right click context menu as if it were designable!
1 parent 9a80397 commit d4b2782

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/MenuTracker.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Terminal.Gui;
44
using Terminal.Gui.App;
55
using Terminal.Gui.Views;
6+
using TerminalGuiDesigner.UI;
67

78
namespace TerminalGuiDesigner;
89

@@ -295,6 +296,13 @@ private void ConvertEmptySubMenus(MenuItem menuItem)
295296
internal static MenuItem? GetFocusedMenuItemIfAny(IApplication app)
296297
{
297298
var m = app.Popovers?.Popovers?.FirstOrDefault(p => p.Visible) as PopoverMenu;
299+
300+
// Don't let user edit the literal popup context menu in main app (that appears
301+
// when right clicking in empty space).
302+
if(m?.Data is string s && s == Editor.DesignerCorePopoverName)
303+
{
304+
return null;
305+
}
298306

299307
var focused = m?.Focused;
300308

src/UI/Editor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public class Editor : Runnable, IErrorReporter
6565
/// </summary>
6666
public const string Error = "Error";
6767

68+
/// <summary>
69+
/// String to assign to popover data field so that we don't accidentally edit our own context menus!
70+
/// </summary>
71+
public const string? DesignerCorePopoverName = "CoreDesignerPopupMenu";
72+
6873
/// <summary>
6974
/// Initializes a new instance of the <see cref="Editor"/> class.
7075
/// </summary>
@@ -1022,6 +1027,8 @@ private void CreateAndShowContextMenu(Mouse? m, Design? rightClicked)
10221027
}
10231028

10241029
var menu = new PopoverMenu(all.ToArray());
1030+
menu.Data = DesignerCorePopoverName;
1031+
10251032
Point position;
10261033
if (m != null && m.Position.HasValue)
10271034
{

0 commit comments

Comments
 (0)