2
0

CommandContext.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. #pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved
  4. /// <summary>
  5. /// Provides context for a <see cref="Command"/> that is being invoked.
  6. /// </summary>
  7. /// <remarks>
  8. /// <para>
  9. /// To define a <see cref="Command"/> that is invoked with context,
  10. /// use <see cref="View.AddCommand(Command,Func{CommandContext,System.Nullable{bool}})"/>.
  11. /// </para>
  12. /// </remarks>
  13. /// <seealso cref="Application.KeyBindings"/>
  14. /// <seealso cref="View.KeyBindings"/>
  15. /// <seealso cref="Command"/>
  16. #pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved
  17. public record struct CommandContext
  18. {
  19. /// <summary>
  20. /// Initializes a new instance of <see cref="CommandContext"/> with the specified <see cref="Command"/>,
  21. /// </summary>
  22. /// <param name="command"></param>
  23. /// <param name="key"></param>
  24. /// <param name="keyBinding"></param>
  25. /// <param name="data"></param>
  26. public CommandContext (Command command, Key? key, KeyBinding? keyBinding = null, object? data = null)
  27. {
  28. Command = command;
  29. Key = key;
  30. KeyBinding = keyBinding;
  31. Data = data;
  32. }
  33. /// <summary>
  34. /// The <see cref="Command"/> that is being invoked.
  35. /// </summary>
  36. public Command Command { get; set; }
  37. /// <summary>
  38. /// The <see cref="Key"/> that is being invoked. This is the key that was pressed to invoke the <see cref="Command"/>.
  39. /// </summary>
  40. public Key? Key { get; set; }
  41. /// <summary>
  42. /// The KeyBinding that was used to invoke the <see cref="Command"/>, if any.
  43. /// </summary>
  44. public KeyBinding? KeyBinding { get; set; }
  45. /// <summary>
  46. /// Arbitrary data.
  47. /// </summary>
  48. public object? Data { get; set; }
  49. }