IAutocomplete.cs 3.7 KB

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