-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
236 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Terminal.Gui { | ||
|
||
/// <summary> | ||
/// Provides filtering for a <see cref="TreeView"/>. | ||
/// </summary> | ||
public interface ITreeViewFilter<T> where T : class { | ||
|
||
/// <summary> | ||
/// Return <see langword="true"/> if the <paramref name="model"/> should | ||
/// be included in the tree. | ||
/// </summary> | ||
bool IsMatch (T model); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
|
||
namespace Terminal.Gui { | ||
|
||
/// <summary> | ||
/// <see cref="ITreeViewFilter{T}"/> implementation which searches the | ||
/// <see cref="TreeView{T}.AspectGetter"/> of the model for the given | ||
/// <see cref="Text"/>. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
public class TreeViewTextFilter<T> : ITreeViewFilter<T> where T : class { | ||
readonly TreeView<T> _forTree; | ||
|
||
/// <summary> | ||
/// Creates a new instance of the filter for use with <paramref name="forTree"/>. | ||
/// Set <see cref="Text"/> to begin filtering. | ||
/// </summary> | ||
/// <param name="forTree"></param> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
public TreeViewTextFilter (TreeView<T> forTree) | ||
{ | ||
_forTree = forTree ?? throw new ArgumentNullException (nameof (forTree)); | ||
} | ||
|
||
/// <summary> | ||
/// The case sensitivity of the search match. | ||
/// Defaults to <see cref="StringComparison.OrdinalIgnoreCase"/>. | ||
/// </summary> | ||
public StringComparison Comparer { get; set; } = StringComparison.OrdinalIgnoreCase; | ||
private string text; | ||
|
||
/// <summary> | ||
/// The text that will be searched for in the <see cref="TreeView{T}"/> | ||
/// </summary> | ||
public string Text { | ||
get { return text; } | ||
set { | ||
text = value; | ||
RefreshTreeView (); | ||
} | ||
} | ||
|
||
private void RefreshTreeView () | ||
{ | ||
_forTree.InvalidateLineMap (); | ||
_forTree.SetNeedsDisplay (); | ||
} | ||
|
||
/// <summary> | ||
/// Returns <typeparamref name="T"/> if there is no <see cref="Text"/> or | ||
/// the text matches the <see cref="TreeView{T}.AspectGetter"/> of the | ||
/// <paramref name="model"/>. | ||
/// </summary> | ||
/// <param name="model"></param> | ||
/// <returns></returns> | ||
public bool IsMatch (T model) | ||
{ | ||
if (string.IsNullOrWhiteSpace (Text)) { | ||
return true; | ||
} | ||
|
||
return _forTree.AspectGetter (model)?.IndexOf (Text, Comparer) != -1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.