KeyBinding.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // These classes use a key binding system based on the design implemented in Scintilla.Net which is an
  2. // MIT licensed open source project https://github.com/jacobslusser/ScintillaNET/blob/master/src/ScintillaNET/Command.cs
  3. namespace Terminal.Gui.Input;
  4. /// <summary>
  5. /// Provides a collection of <see cref="Command"/> objects stored in <see cref="KeyBindings"/>.
  6. /// </summary>
  7. /// <seealso cref="KeyBindings"/>
  8. /// <seealso cref="KeyBindings"/>
  9. /// <seealso cref="Command"/>
  10. public record struct KeyBinding : IInputBinding
  11. {
  12. /// <summary>Initializes a new instance.</summary>
  13. /// <param name="commands">The commands this key binding will invoke.</param>
  14. /// <param name="context">Arbitrary context that can be associated with this key binding.</param>
  15. public KeyBinding (Command [] commands, object? context = null)
  16. {
  17. Commands = commands;
  18. Data = context;
  19. }
  20. /// <summary>Initializes a new instance.</summary>
  21. /// <param name="commands">The commands this key binding will invoke.</param>
  22. /// <param name="target">The view the key binding is bound to.</param>
  23. /// <param name="data">Arbitrary data that can be associated with this key binding.</param>
  24. public KeyBinding (Command [] commands, View? target, object? data = null)
  25. {
  26. Commands = commands;
  27. Target = target;
  28. Data = data;
  29. }
  30. /// <summary>The commands this key binding will invoke.</summary>
  31. public Command [] Commands { get; set; }
  32. /// <inheritdoc />
  33. public object? Data { get; set; }
  34. /// <summary>
  35. /// The Key that is bound to the <see cref="Commands"/>.
  36. /// </summary>
  37. public Key? Key { get; set; }
  38. /// <summary>The view the key binding is bound to.</summary>
  39. public View? Target { get; set; }
  40. }