IAutocomplete.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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<string> Suggestions { get; set; }
  36. /// <summary>
  37. /// The full set of all strings that can be suggested.
  38. /// </summary>
  39. List<string> AllSuggestions { get; set; }
  40. /// <summary>
  41. /// The currently selected index into <see cref="Suggestions"/> that the user has highlighted
  42. /// </summary>
  43. int SelectedIdx { get; set; }
  44. /// <summary>
  45. /// The colors to use to render the overlay. Accessing this property before
  46. /// the Application has been initialized will cause an error
  47. /// </summary>
  48. ColorScheme ColorScheme { get; set; }
  49. /// <summary>
  50. /// The key that the user must press to accept the currently selected autocomplete suggestion
  51. /// </summary>
  52. Key SelectionKey { get; set; }
  53. /// <summary>
  54. /// The key that the user can press to close the currently popped autocomplete menu
  55. /// </summary>
  56. Key CloseKey { get; set; }
  57. /// <summary>
  58. /// The key that the user can press to reopen the currently popped autocomplete menu
  59. /// </summary>
  60. Key Reopen { get; set; }
  61. /// <summary>
  62. /// Renders the autocomplete dialog inside the given <see cref="HostControl"/> at the
  63. /// given point.
  64. /// </summary>
  65. /// <param name="renderAt"></param>
  66. void RenderOverlay (Point renderAt);
  67. /// <summary>
  68. /// Handle key events before <see cref="HostControl"/> e.g. to make key events like
  69. /// up/down apply to the autocomplete control instead of changing the cursor position in
  70. /// the underlying text view.
  71. /// </summary>
  72. /// <param name="kb">The key event.</param>
  73. /// <returns><c>true</c>if the key can be handled <c>false</c>otherwise.</returns>
  74. bool ProcessKey (KeyEvent kb);
  75. /// <summary>
  76. /// Handle mouse events before <see cref="HostControl"/> e.g. to make mouse events like
  77. /// report/click apply to the autocomplete control instead of changing the cursor position in
  78. /// the underlying text view.
  79. /// </summary>
  80. /// <param name="me">The mouse event.</param>
  81. /// <param name="fromHost">If was called from the popup or from the host.</param>
  82. /// <returns><c>true</c>if the mouse can be handled <c>false</c>otherwise.</returns>
  83. bool MouseEvent (MouseEvent me, bool fromHost = false);
  84. /// <summary>
  85. /// Clears <see cref="Suggestions"/>
  86. /// </summary>
  87. void ClearSuggestions ();
  88. /// <summary>
  89. /// Populates <see cref="Suggestions"/> with all strings in <see cref="AllSuggestions"/> that
  90. /// match with the current cursor position/text in the <see cref="HostControl"/>.
  91. /// </summary>
  92. void GenerateSuggestions ();
  93. }
  94. }