KeyBinding.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #nullable enable
  2. // These classes use a key binding system based on the design implemented in Scintilla.Net which is an
  3. // MIT licensed open source project https://github.com/jacobslusser/ScintillaNET/blob/master/src/ScintillaNET/Command.cs
  4. namespace Terminal.Gui;
  5. /// <summary>
  6. /// Provides a collection of <see cref="Command"/> objects that are scoped to <see cref="KeyBindingScope"/>.
  7. /// </summary>
  8. /// <seealso cref="Application.KeyBindings"/>
  9. /// <seealso cref="View.KeyBindings"/>
  10. /// <seealso cref="Command"/>
  11. public record struct KeyBinding
  12. {
  13. /// <summary>Initializes a new instance.</summary>
  14. /// <param name="commands">The commands this key binding will invoke.</param>
  15. /// <param name="context">Arbitrary context that can be associated with this key binding.</param>
  16. public KeyBinding (Command [] commands, object? context = null)
  17. {
  18. Commands = commands;
  19. Data = context;
  20. }
  21. /// <summary>Initializes a new instance.</summary>
  22. /// <param name="commands">The commands this key binding will invoke.</param>
  23. /// <param name="scope">The scope of the <see cref="Commands"/>.</param>
  24. /// <param name="boundView">The view the key binding is bound to.</param>
  25. /// <param name="data">Arbitrary data that can be associated with this key binding.</param>
  26. public KeyBinding (Command [] commands, View? boundView, object? data = null)
  27. {
  28. Commands = commands;
  29. BoundView = boundView;
  30. Data = data;
  31. }
  32. /// <summary>The commands this key binding will invoke.</summary>
  33. public Command [] Commands { 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? BoundView { get; set; }
  40. /// <summary>
  41. /// Arbitrary context that can be associated with this key binding.
  42. /// </summary>
  43. public object? Data { get; set; }
  44. }