KeyBinding.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 stored in <see cref="KeyBindings"/>.
  7. /// </summary>
  8. /// <seealso cref="Application.KeyBindings"/>
  9. /// <seealso cref="View.KeyBindings"/>
  10. /// <seealso cref="Command"/>
  11. public record struct KeyBinding : IInputBinding
  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="target">The view the key binding is bound to.</param>
  24. /// <param name="data">Arbitrary data that can be associated with this key binding.</param>
  25. public KeyBinding (Command [] commands, View? target, object? data = null)
  26. {
  27. Commands = commands;
  28. Target = target;
  29. Data = data;
  30. }
  31. /// <summary>The commands this key binding will invoke.</summary>
  32. public Command [] Commands { get; set; }
  33. /// <summary>
  34. /// The Key that is bound to the <see cref="Commands"/>.
  35. /// </summary>
  36. public Key? Key { get; set; }
  37. /// <summary>The view the key binding is bound to.</summary>
  38. public View? Target { get; set; }
  39. /// <summary>
  40. /// Arbitrary context that can be associated with this key binding.
  41. /// </summary>
  42. public object? Data { get; set; }
  43. }