ICollectionNavigator.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. namespace Terminal.Gui.Views;
  2. /// <summary>
  3. /// Navigates a collection of items using keystrokes. The keystrokes are used to build a search string. The
  4. /// <see cref="SearchString"/> is used to find the next item in the collection that matches the search string when
  5. /// <see cref="GetNextMatchingItem(int?, char)"/> is called.
  6. /// <para>
  7. /// If the user types keystrokes that can't be found in the collection, the search string is cleared and the next
  8. /// item is found that starts with the last keystroke.
  9. /// </para>
  10. /// <para>If the user pauses keystrokes for a short time (see <see cref="TypingDelay"/>), the search string is cleared.</para>
  11. /// </summary>
  12. public interface ICollectionNavigator
  13. {
  14. /// <summary>
  15. /// Gets or sets the number of milliseconds to delay before clearing the search string. The delay is reset on each
  16. /// call to <see cref="GetNextMatchingItem(int?, char)"/>. The default is 500ms.
  17. /// </summary>
  18. public int TypingDelay { get; set; }
  19. /// <summary>This event is invoked when <see cref="SearchString"/> changes. Useful for debugging.</summary>
  20. public event EventHandler<KeystrokeNavigatorEventArgs>? SearchStringChanged;
  21. /// <summary>
  22. /// Gets the current search string. This includes the set of keystrokes that have been pressed since the last
  23. /// unsuccessful match or after <see cref="TypingDelay"/>) milliseconds. Useful for debugging.
  24. /// </summary>
  25. string SearchString { get; }
  26. /// <summary>
  27. /// Class responsible for deciding whether given entries in the collection match
  28. /// the search term the user is typing.
  29. /// </summary>
  30. ICollectionNavigatorMatcher Matcher { get; set; }
  31. /// <summary>
  32. /// Gets the index of the next item in the collection that matches the current <see cref="SearchString"/> plus the
  33. /// provided character (typically from a key press).
  34. /// </summary>
  35. /// <param name="currentIndex">The index in the collection to start the search from.</param>
  36. /// <param name="keyStruck">The character of the key the user pressed.</param>
  37. /// <returns>
  38. /// The index of the item that matches what the user has typed. Returns <see langword="null"/> if no item in the
  39. /// collection matched.
  40. /// </returns>
  41. int? GetNextMatchingItem (int? currentIndex, char keyStruck);
  42. }