using System;
namespace Terminal.Gui {
///
/// implementation which searches the
/// of the model for the given
/// .
///
///
public class TreeViewTextFilter : ITreeViewFilter where T : class {
readonly TreeView _forTree;
///
/// Creates a new instance of the filter for use with .
/// Set to begin filtering.
///
///
///
public TreeViewTextFilter (TreeView forTree)
{
_forTree = forTree ?? throw new ArgumentNullException (nameof (forTree));
}
///
/// The case sensitivity of the search match.
/// Defaults to .
///
public StringComparison Comparer { get; set; } = StringComparison.OrdinalIgnoreCase;
private string text;
///
/// The text that will be searched for in the
///
public string Text {
get { return text; }
set {
text = value;
RefreshTreeView ();
}
}
private void RefreshTreeView ()
{
_forTree.InvalidateLineMap ();
_forTree.SetNeedsDisplay ();
}
///
/// Returns if there is no or
/// the text matches the of the
/// .
///
///
///
public bool IsMatch (T model)
{
if (string.IsNullOrWhiteSpace (Text)) {
return true;
}
return _forTree.AspectGetter (model)?.IndexOf (Text, Comparer) != -1;
}
}
}