KeyBinding.cs 2.1 KB

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