CommandContext.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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<TBindingType> : ICommandContext
  15. {
  16. /// <summary>
  17. /// Initializes a new instance with the specified <see cref="Command"/>,
  18. /// </summary>
  19. /// <param name="command"></param>
  20. /// <param name="binding"></param>
  21. /// <param name="data"></param>
  22. public CommandContext (Command command, TBindingType? binding, object? data = null)
  23. {
  24. Command = command;
  25. Binding = binding;
  26. Data = data;
  27. }
  28. /// <summary>
  29. /// The keyboard or mouse minding that was used to invoke the <see cref="Command"/>, if any.
  30. /// </summary>
  31. public TBindingType? Binding { get; set; }
  32. /// <inheritdoc />
  33. public Command Command { get; set; }
  34. /// <inheritdoc />
  35. public object? Data { get; set; }
  36. }
  37. public interface ICommandContext
  38. {
  39. /// <summary>
  40. /// The <see cref="Command"/> that is being invoked.
  41. /// </summary>
  42. public Command Command { get; set; }
  43. /// <summary>
  44. /// Arbitrary data.
  45. /// </summary>
  46. public object? Data { get; set; }
  47. }