IAutocomplete.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #nullable disable
  2. using System.Collections.ObjectModel;
  3. namespace Terminal.Gui.Views;
  4. /// <summary>
  5. /// Renders an overlay on another view at a given point that allows selecting from a range of 'autocomplete'
  6. /// options.
  7. /// </summary>
  8. public interface IAutocomplete
  9. {
  10. /// <summary>Clears <see cref="Suggestions"/></summary>
  11. void ClearSuggestions ();
  12. /// <summary>The key that the user can press to close the currently popped autocomplete menu</summary>
  13. Key CloseKey { get; set; }
  14. /// <summary>
  15. /// The colors to use to render the overlay. Accessing this property before the Application has been initialized
  16. /// will cause an error
  17. /// </summary>
  18. Scheme Scheme { get; set; }
  19. /// <summary>The context used by the autocomplete menu.</summary>
  20. AutocompleteContext Context { get; set; }
  21. /// <summary>
  22. /// Populates <see cref="Suggestions"/> with all <see cref="Suggestion"/> proposed by
  23. /// <see cref="SuggestionGenerator"/> at the given <paramref name="context"/> (cursor position)
  24. /// </summary>
  25. void GenerateSuggestions (AutocompleteContext context);
  26. /// <summary>The host control that will use autocomplete.</summary>
  27. View HostControl { get; set; }
  28. /// <summary>The maximum number of visible rows in the autocomplete dropdown to render</summary>
  29. int MaxHeight { get; set; }
  30. /// <summary>The maximum width of the autocomplete dropdown</summary>
  31. int MaxWidth { get; set; }
  32. /// <summary>
  33. /// Handle mouse events before <see cref="HostControl"/> e.g. to make mouse events like report/click apply to the
  34. /// autocomplete control instead of changing the cursor position in the underlying text view.
  35. /// </summary>
  36. /// <param name="me">The mouse event.</param>
  37. /// <param name="fromHost">If was called from the popup or from the host.</param>
  38. /// <returns><c>true</c>if the mouse can be handled <c>false</c>otherwise.</returns>
  39. bool OnMouseEvent (MouseEventArgs me, bool fromHost = false);
  40. /// <summary>Gets or sets where the popup will be displayed.</summary>
  41. bool PopupInsideContainer { get; set; }
  42. /// <summary>
  43. /// Handle key events before <see cref="HostControl"/> e.g. to make key events like up/down apply to the
  44. /// autocomplete control instead of changing the cursor position in the underlying text view.
  45. /// </summary>
  46. /// <param name="a">The key event.</param>
  47. /// <returns><c>true</c>if the key can be handled <c>false</c>otherwise.</returns>
  48. bool ProcessKey (Key a);
  49. /// <summary>Renders the autocomplete dialog inside the given <see cref="HostControl"/> at the given point.</summary>
  50. /// <param name="renderAt"></param>
  51. void RenderOverlay (Point renderAt);
  52. /// <summary>The key that the user can press to reopen the currently popped autocomplete menu</summary>
  53. Key Reopen { get; set; }
  54. /// <summary>The currently selected index into <see cref="Suggestions"/> that the user has highlighted</summary>
  55. int SelectedIdx { get; set; }
  56. /// <summary>The key that the user must press to accept the currently selected autocomplete suggestion</summary>
  57. Key SelectionKey { get; set; }
  58. /// <summary>
  59. /// Gets or Sets the class responsible for generating <see cref="Suggestions"/> based on a given
  60. /// <see cref="AutocompleteContext"/> of the <see cref="HostControl"/>.
  61. /// </summary>
  62. ISuggestionGenerator SuggestionGenerator { get; set; }
  63. /// <summary>The strings that form the current list of suggestions to render based on what the user has typed so far.</summary>
  64. ReadOnlyCollection<Suggestion> Suggestions { get; set; }
  65. /// <summary>True if the autocomplete should be considered open and visible</summary>
  66. bool Visible { get; set; }
  67. }