IAutocomplete.cs 3.7 KB

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