IAutocomplete.cs 3.9 KB

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