IAutocomplete.cs 3.7 KB

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