IAutocomplete.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. /// <summary>
  45. /// The key that the user must press to accept the currently selected autocomplete suggestion
  46. /// </summary>
  47. Key SelectionKey { get; set; }
  48. /// <summary>
  49. /// The key that the user can press to close the currently popped autocomplete menu
  50. /// </summary>
  51. Key CloseKey { get; set; }
  52. /// <summary>
  53. /// The key that the user can press to reopen the currently popped autocomplete menu
  54. /// </summary>
  55. Key Reopen { get; set; }
  56. /// <summary>
  57. /// The context used by the autocomplete menu.
  58. /// </summary>
  59. AutocompleteContext Context { get; set; }
  60. /// <summary>
  61. /// Renders the autocomplete dialog inside the given <see cref="HostControl"/> at the
  62. /// given point.
  63. /// </summary>
  64. /// <param name="renderAt"></param>
  65. void RenderOverlay (Point renderAt);
  66. /// <summary>
  67. /// Handle key events before <see cref="HostControl"/> e.g. to make key events like
  68. /// up/down apply to the autocomplete control instead of changing the cursor position in
  69. /// the underlying text view.
  70. /// </summary>
  71. /// <param name="kb">The key event.</param>
  72. /// <returns><c>true</c>if the key can be handled <c>false</c>otherwise.</returns>
  73. bool ProcessKey (KeyEvent kb);
  74. /// <summary>
  75. /// Handle mouse events before <see cref="HostControl"/> e.g. to make mouse events like
  76. /// report/click apply to the autocomplete control instead of changing the cursor position in
  77. /// the underlying text view.
  78. /// </summary>
  79. /// <param name="me">The mouse event.</param>
  80. /// <param name="fromHost">If was called from the popup or from the host.</param>
  81. /// <returns><c>true</c>if the mouse can be handled <c>false</c>otherwise.</returns>
  82. bool MouseEvent (MouseEvent me, bool fromHost = false);
  83. /// <summary>
  84. /// Clears <see cref="Suggestions"/>
  85. /// </summary>
  86. void ClearSuggestions ();
  87. /// <summary>
  88. /// Gets or Sets the class responsible for generating <see cref="Suggestions"/>
  89. /// based on a given <see cref="AutocompleteContext"/> of the <see cref="HostControl"/>.
  90. /// </summary>
  91. ISuggestionGenerator SuggestionGenerator { get; set; }
  92. /// <summary>
  93. /// Populates <see cref="Suggestions"/> with all <see cref="Suggestion"/>
  94. /// proposed by <see cref="SuggestionGenerator"/> at the given <paramref name="context"/>
  95. /// (cursor position)
  96. /// </summary>
  97. void GenerateSuggestions (AutocompleteContext context);
  98. }
  99. }