IAutocomplete.cs 4.0 KB

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