CommandContext.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved
  14. public record struct CommandContext
  15. {
  16. /// <summary>
  17. /// Initializes a new instance of <see cref="CommandContext"/> with the specified <see cref="Command"/>,
  18. /// </summary>
  19. /// <param name="command"></param>
  20. /// <param name="key"></param>
  21. /// <param name="keyBinding"></param>
  22. public CommandContext (Command command, Key? key, KeyBinding? keyBinding = null)
  23. {
  24. Command = command;
  25. Key = key;
  26. KeyBinding = keyBinding;
  27. }
  28. /// <summary>
  29. /// The <see cref="Command"/> that is being invoked.
  30. /// </summary>
  31. public Command Command { get; set; }
  32. /// <summary>
  33. /// The <see cref="Key"/> that is being invoked. This is the key that was pressed to invoke the <see cref="Command"/>.
  34. /// </summary>
  35. public Key? Key { get; set; }
  36. /// <summary>
  37. /// The KeyBinding that was used to invoke the <see cref="Command"/>, if any.
  38. /// </summary>
  39. public KeyBinding? KeyBinding { get; set; }
  40. }