Is your feature request related to a problem? Please describe.
I am trying to update to latest v2 in TGD, in gui-cs/TerminalGuiDesigner#320
I have this code that was working before and now not so much, it wants to:
- In mouse right click handler
- Figure out what you have right clicked on and/or if theres multi select going on etc
- Show a popup context menu based on what was right clicked and the state of editor etc at the time
The method can also be raised by pressing a shortcut key, in this case the right MouseEventArgs is null and the context menu opens right at the focused control.
private void CreateAndShowContextMenu(MouseEventArgs? m, Design? rightClicked)
[...]
var menu = new PopoverMenu(all.ToArray());
Point position;
if (m != null)
{
position = m.Position;
}
else
{
var d = SelectionManager.Instance.Selected.FirstOrDefault() ?? this.viewBeingEdited;
var pt = d.View.ContentToScreen(new Point(0, 0));
position = new Point(pt
[...]
// Code to build the menu items
this.menuOpen = true;
SelectionManager.Instance.LockSelection = true;
if(m != null)
{
m.Handled = true;
}
+ // Throws null ref if you don't add it
+ Add(menu);
+ // Throws 'must be registered' invalid operation
menu.MakeVisible(position);
menu.Accepted += (_, _) =>
{
this.menuOpen = false;
SelectionManager.Instance.LockSelection = false;
};
The above diff is my attempt to make it work.
Firstly without Add to the Editor.cs view it throws null reference on MakeVisible
If you add it to the Editor view it then throws
Popovers must be registered before being shown.
Describe the solution you'd like
What is the correct way to create and show a popup context menu arbitrarily on demand?
Is your feature request related to a problem? Please describe.
I am trying to update to latest v2 in TGD, in gui-cs/TerminalGuiDesigner#320
I have this code that was working before and now not so much, it wants to:
The method can also be raised by pressing a shortcut key, in this case the right MouseEventArgs is null and the context menu opens right at the focused control.
private void CreateAndShowContextMenu(MouseEventArgs? m, Design? rightClicked) [...] var menu = new PopoverMenu(all.ToArray()); Point position; if (m != null) { position = m.Position; } else { var d = SelectionManager.Instance.Selected.FirstOrDefault() ?? this.viewBeingEdited; var pt = d.View.ContentToScreen(new Point(0, 0)); position = new Point(pt [...] // Code to build the menu items this.menuOpen = true; SelectionManager.Instance.LockSelection = true; if(m != null) { m.Handled = true; } + // Throws null ref if you don't add it + Add(menu); + // Throws 'must be registered' invalid operation menu.MakeVisible(position); menu.Accepted += (_, _) => { this.menuOpen = false; SelectionManager.Instance.LockSelection = false; };The above diff is my attempt to make it work.
Firstly without Add to the Editor.cs view it throws null reference on MakeVisible
If you add it to the Editor view it then throws
Popovers must be registered before being shown.Describe the solution you'd like
What is the correct way to create and show a popup context menu arbitrarily on demand?