|
@@ -214,6 +214,13 @@ namespace Terminal.Gui {
|
|
|
|
|
|
CursorVisibility desiredCursorVisibility = CursorVisibility.Invisible;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Interface for filtering which lines of the tree are displayed
|
|
|
+ /// e.g. to provide text searching. Defaults to <see langword="null"/>
|
|
|
+ /// (no filtering).
|
|
|
+ /// </summary>
|
|
|
+ public ITreeViewFilter<T> Filter = null;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Get / Set the wished cursor when the tree is focused.
|
|
|
/// Only applies when <see cref="MultiSelect"/> is true.
|
|
@@ -541,7 +548,12 @@ namespace Terminal.Gui {
|
|
|
List<Branch<T>> toReturn = new List<Branch<T>> ();
|
|
|
|
|
|
foreach (var root in roots.Values) {
|
|
|
- toReturn.AddRange (AddToLineMap (root));
|
|
|
+
|
|
|
+ var toAdd = AddToLineMap (root, false, out var isMatch);
|
|
|
+ if(isMatch)
|
|
|
+ {
|
|
|
+ toReturn.AddRange (toAdd);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
cachedLineMap = new ReadOnlyCollection<Branch<T>> (toReturn);
|
|
@@ -551,17 +563,44 @@ namespace Terminal.Gui {
|
|
|
return cachedLineMap;
|
|
|
}
|
|
|
|
|
|
- private IEnumerable<Branch<T>> AddToLineMap (Branch<T> currentBranch)
|
|
|
+ private bool IsFilterMatch (Branch<T> branch)
|
|
|
+ {
|
|
|
+ return Filter?.IsMatch(branch.Model) ?? true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private IEnumerable<Branch<T>> AddToLineMap (Branch<T> currentBranch,bool parentMatches, out bool match)
|
|
|
{
|
|
|
- yield return currentBranch;
|
|
|
+ bool weMatch = IsFilterMatch(currentBranch);
|
|
|
+ bool anyChildMatches = false;
|
|
|
+
|
|
|
+ var toReturn = new List<Branch<T>>();
|
|
|
+ var children = new List<Branch<T>>();
|
|
|
|
|
|
if (currentBranch.IsExpanded) {
|
|
|
foreach (var subBranch in currentBranch.ChildBranches.Values) {
|
|
|
- foreach (var sub in AddToLineMap (subBranch)) {
|
|
|
- yield return sub;
|
|
|
+
|
|
|
+ foreach (var sub in AddToLineMap (subBranch, weMatch, out var childMatch)) {
|
|
|
+
|
|
|
+ if(childMatch)
|
|
|
+ {
|
|
|
+ children.Add(sub);
|
|
|
+ anyChildMatches = true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if(parentMatches || weMatch || anyChildMatches)
|
|
|
+ {
|
|
|
+ match = true;
|
|
|
+ toReturn.Add(currentBranch);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ match = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ toReturn.AddRange(children);
|
|
|
+ return toReturn;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -1289,9 +1328,9 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Clears any cached results of <see cref="BuildLineMap"/>
|
|
|
+ /// Clears any cached results of the tree state.
|
|
|
/// </summary>
|
|
|
- protected void InvalidateLineMap ()
|
|
|
+ public void InvalidateLineMap ()
|
|
|
{
|
|
|
cachedLineMap = null;
|
|
|
}
|