namespace Terminal.Gui;
///
/// implementation which searches the of
/// the model for the given .
///
///
public class TreeViewTextFilter : ITreeViewFilter where T : class
{
private readonly TreeView _forTree;
private string text;
///
/// 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;
/// The text that will be searched for in the
public string Text
{
get => text;
set
{
text = value;
RefreshTreeView ();
}
}
///
/// 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;
}
private void RefreshTreeView ()
{
_forTree.InvalidateLineMap ();
_forTree.SetNeedsDraw ();
}
}