TextView.ContextMenu.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Globalization;
  2. namespace Terminal.Gui.Views;
  3. /// <summary>Context menu functionality</summary>
  4. public partial class TextView
  5. {
  6. private PopoverMenu CreateContextMenu ()
  7. {
  8. PopoverMenu menu = new (
  9. new List<View>
  10. {
  11. new MenuItem (this, Command.SelectAll, Strings.ctxSelectAll),
  12. new MenuItem (this, Command.DeleteAll, Strings.ctxDeleteAll),
  13. new MenuItem (this, Command.Copy, Strings.ctxCopy),
  14. new MenuItem (this, Command.Cut, Strings.ctxCut),
  15. new MenuItem (this, Command.Paste, Strings.ctxPaste),
  16. new MenuItem (this, Command.Undo, Strings.ctxUndo),
  17. new MenuItem (this, Command.Redo, Strings.ctxRedo)
  18. });
  19. menu.KeyChanged += ContextMenu_KeyChanged;
  20. return menu;
  21. }
  22. private void ShowContextMenu (Point? mousePosition)
  23. {
  24. if (!Equals (_currentCulture, Thread.CurrentThread.CurrentUICulture))
  25. {
  26. _currentCulture = Thread.CurrentThread.CurrentUICulture;
  27. }
  28. if (mousePosition is null)
  29. {
  30. mousePosition = ViewportToScreen (new Point (CursorPosition.X, CursorPosition.Y));
  31. }
  32. ContextMenu?.MakeVisible (mousePosition);
  33. }
  34. private void ContextMenu_KeyChanged (object? sender, KeyChangedEventArgs e)
  35. {
  36. KeyBindings.Replace (e.OldKey, e.NewKey);
  37. }
  38. }