KeyBinding.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. public record struct KeyBinding
  9. {
  10. /// <summary>Initializes a new instance.</summary>
  11. /// <param name="commands">The commands this key binding will invoke.</param>
  12. /// <param name="scope">The scope of the <see cref="Commands"/>.</param>
  13. /// <param name="context">Arbitrary context that can be associated with this key binding.</param>
  14. public KeyBinding (Command [] commands, KeyBindingScope scope, object? context = null)
  15. {
  16. Commands = commands;
  17. Scope = scope;
  18. Context = context;
  19. }
  20. /// <summary>Initializes a new instance.</summary>
  21. /// <param name="commands">The commands this key binding will invoke.</param>
  22. /// <param name="scope">The scope of the <see cref="Commands"/>.</param>
  23. /// <param name="boundView">The view the key binding is bound to.</param>
  24. /// <param name="context">Arbitrary context that can be associated with this key binding.</param>
  25. public KeyBinding (Command [] commands, KeyBindingScope scope, View? boundView, object? context = null)
  26. {
  27. Commands = commands;
  28. Scope = scope;
  29. BoundView = boundView;
  30. Context = context;
  31. }
  32. /// <summary>The commands this key binding will invoke.</summary>
  33. public Command [] Commands { get; set; }
  34. /// <summary>The scope of the <see cref="Commands"/>.</summary>
  35. public KeyBindingScope Scope { get; set; }
  36. /// <summary>The view the key binding is bound to.</summary>
  37. public View? BoundView { get; set; }
  38. /// <summary>
  39. /// Arbitrary context that can be associated with this key binding.
  40. /// </summary>
  41. public object? Context { get; set; }
  42. }