-
Notifications
You must be signed in to change notification settings - Fork 727
Fixes #4027. Add collection search matcher #4029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
39c0e4b
Add collection search matcher
tznind ee0748e
Fix naming
tznind 4509780
fix naming
tznind b76212e
Move FileDialogCollectionNavigator to its own file (no longer private…
tznind bd364f7
Add ICollectionNavigator interface
tznind 98383b4
Move to separate file IListCollectionNavigator
tznind 9db1071
Update class diagram
tznind 4b29940
update class diagram
tznind 135d3c5
Add tests for overriding ICollectionNavigatorMatcher
tznind d1d5534
xmldoc and nullability warning fixes
tznind be56a8e
Code Cleanup
tznind 26ff23d
Make requested changes to naming and terminology
tznind 1f686f9
Move to seperate namespace
tznind dbeba5d
Update class diagram and change TreeView to reference the interface n…
tznind 94219c6
Switch to implicit new
tznind 18c3d90
Merge branch 'v2_develop' into collection-navigator-matcher
tig 0511ad9
highlight that this class also works with tree view
tznind 932c6aa
Merge branch 'collection-navigator-matcher' of https://github.com/tzn…
tznind 58b0178
Apply tig patch to ensure keybindings get priority over navigator
tznind 3ec5cc6
Apply 'keybinding has priority' fix to TreeView too
tznind 41c9134
Apply 'keybindngs priority over navigation' fix to TableView
tznind 0e29e04
Remove entire branch for selectively returning false now that it is d…
tznind d142ff1
Make classes internal and remove 'custom' navigator that was configur…
tznind 35e402d
Fix merged conflicts
tznind ebecbc8
Change logging in collection navigator from Trace to Debug
tznind ab8c830
Switch to NewKeyDownEvent and directly setting HasFocus
tznind 65a12da
Remove application top dependency
tznind d15bd12
Remove references to application
tznind e803d37
Remove Application
tznind 1b8ab97
Merge branch 'v2_develop' into collection-navigator-matcher
tznind 639b1d1
Move new tests to parallel
tznind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,96 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <ClassDiagram MajorVersion="1" MinorVersion="1"> | ||
| <Class Name="Terminal.Gui.CollectionNavigatorBase"> | ||
| <Position X="5.75" Y="2" Width="2" /> | ||
| <TypeIdentifier> | ||
| <HashCode>AAgEAAAAAAAQAAAIAAEAAgAAAAAABAAEAAAAACwAAAA=</HashCode> | ||
| <FileName>Text\CollectionNavigatorBase.cs</FileName> | ||
| </TypeIdentifier> | ||
| <ShowAsAssociation> | ||
| <Property Name="Matcher" /> | ||
| </ShowAsAssociation> | ||
| <Lollipop Position="0.2" /> | ||
| </Class> | ||
| <Class Name="Terminal.Gui.CollectionNavigator"> | ||
| <Position X="2.75" Y="1.75" Width="2" /> | ||
| <TypeIdentifier> | ||
| <HashCode>AAAAAAAAAAAAQAAAAAAAAgAAAAAAAAAEAAAAAAAAAAA=</HashCode> | ||
| <FileName>Text\CollectionNavigator.cs</FileName> | ||
| </TypeIdentifier> | ||
| <Lollipop Position="0.2" /> | ||
| </Class> | ||
| <Class Name="Terminal.Gui.DefaultCollectionNavigatorMatcher"> | ||
| <Position X="8.75" Y="3.75" Width="2.75" /> | ||
| <TypeIdentifier> | ||
| <HashCode>AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAQA=</HashCode> | ||
| <FileName>Text\DefaultCollectionNavigatorMatcher.cs</FileName> | ||
| </TypeIdentifier> | ||
| <Lollipop Position="0.2" /> | ||
| </Class> | ||
| <Class Name="Terminal.Gui.TableCollectionNavigator" Collapsed="true"> | ||
| <Position X="2.5" Y="6" Width="2.25" /> | ||
| <TypeIdentifier> | ||
| <HashCode>AAAAAAAAAAAAAAAAAAAAAgABAAAAAAAEAAAAAAAAAAA=</HashCode> | ||
| <FileName>Text\TableCollectionNavigator.cs</FileName> | ||
| </TypeIdentifier> | ||
| </Class> | ||
| <Class Name="Terminal.Gui.ListView" Collapsed="true"> | ||
| <Position X="0.5" Y="2.5" Width="1.5" /> | ||
| <TypeIdentifier> | ||
| <HashCode>AAE+ASAkEnAAABAAKGAggYAZJAIAABEAcBAaAwAQIAA=</HashCode> | ||
| <FileName>Views\ListView.cs</FileName> | ||
| </TypeIdentifier> | ||
| <ShowAsAssociation> | ||
| <Property Name="KeystrokeNavigator" /> | ||
| </ShowAsAssociation> | ||
| <Lollipop Position="0.2" /> | ||
| </Class> | ||
| <Class Name="Terminal.Gui.FileDialog" Collapsed="true"> | ||
| <Position X="0.5" Y="4.5" Width="1.75" /> | ||
| <Compartments> | ||
| <Compartment Name="Nested Types" Collapsed="false" /> | ||
| </Compartments> | ||
| <TypeIdentifier> | ||
| <HashCode>iIY4LQFUHDKVIHIESBgigQcFT6GxhBDABGJItBQAwAQ=</HashCode> | ||
| <FileName>Views\FileDialog.cs</FileName> | ||
| </TypeIdentifier> | ||
| <Lollipop Position="0.2" /> | ||
| </Class> | ||
| <Class Name="Terminal.Gui.FileDialogCollectionNavigator" Collapsed="true"> | ||
| <Position X="2.5" Y="4.5" Width="2.25" /> | ||
| <TypeIdentifier> | ||
| <HashCode>AAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAEAAAAAAAAAAA=</HashCode> | ||
| <FileName>Views\FileDialogCollectionNavigator.cs</FileName> | ||
| </TypeIdentifier> | ||
| </Class> | ||
| <Class Name="Terminal.Gui.TableView" Collapsed="true" BaseTypeListCollapsed="true"> | ||
| <Position X="0.5" Y="6" Width="1.5" /> | ||
| <TypeIdentifier> | ||
| <HashCode>QwUeAxwgICIAcABIABeR0oBAkhoFGGOBDABgAN3oPEI=</HashCode> | ||
| <FileName>Views\TableView\TableView.cs</FileName> | ||
| </TypeIdentifier> | ||
| <Lollipop Position="0.2" /> | ||
| </Class> | ||
| <Interface Name="Terminal.Gui.ICollectionNavigatorhMatcher" Collapsed="true"> | ||
| <Position X="8.75" Y="2.75" Width="2.75" /> | ||
| <TypeIdentifier> | ||
| <HashCode>AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAA=</HashCode> | ||
| <FileName>Text\ICollectionNavigatorhMatcher.cs</FileName> | ||
| </TypeIdentifier> | ||
| </Interface> | ||
| <Interface Name="Terminal.Gui.IListCollectionNavigator" Collapsed="true"> | ||
| <Position X="2.75" Y="0.75" Width="2" /> | ||
| <TypeIdentifier> | ||
| <HashCode>AAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode> | ||
| <FileName>Text\IListCollectionNavigator.cs</FileName> | ||
| </TypeIdentifier> | ||
| </Interface> | ||
| <Interface Name="Terminal.Gui.ICollectionNavigator" Collapsed="true"> | ||
| <Position X="5.75" Y="0.75" Width="2" /> | ||
| <TypeIdentifier> | ||
| <HashCode>AAgAAAAAAAAAAAAIAAAAAAAAAAAABAAAAAAAACgAAAA=</HashCode> | ||
| <FileName>Text\ICollectionNavigator.cs</FileName> | ||
| </TypeIdentifier> | ||
| </Interface> | ||
| <Font Name="Segoe UI" Size="9" /> | ||
| </ClassDiagram> |
This file contains hidden or 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 hidden or 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 hidden or 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,30 @@ | ||
| #nullable enable | ||
|
|
||
| namespace Terminal.Gui; | ||
|
|
||
| /// <summary> | ||
| /// Default implementation of <see cref="ICollectionNavigatorMatcher"/>, performs | ||
| /// case-insensitive (see <see cref="Comparer"/>) matching of items based on | ||
| /// <see cref="object.ToString()"/>. | ||
| /// </summary> | ||
| public class DefaultCollectionNavigatorMatcher : ICollectionNavigatorMatcher | ||
| { | ||
| /// <summary>The comparer function to use when searching the collection.</summary> | ||
| public StringComparison Comparer { get; set; } = StringComparison.InvariantCultureIgnoreCase; | ||
|
|
||
| /// <inheritdoc/> | ||
| public bool IsMatch (string search, object? value) { return value?.ToString ()?.StartsWith (search, Comparer) ?? false; } | ||
|
|
||
| /// <summary> | ||
| /// Returns true if <paramref name="a"/> is a searchable key (e.g. letters, numbers, etc) that are valid to pass | ||
| /// to this class for search filtering. | ||
| /// </summary> | ||
| /// <param name="a"></param> | ||
| /// <returns></returns> | ||
| public bool IsCompatibleKey (Key a) | ||
tznind marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| Rune rune = a.AsRune; | ||
|
|
||
| return rune != default (Rune) && !Rune.IsControl (rune); | ||
| } | ||
| } | ||
This file contains hidden or 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,48 @@ | ||
| #nullable enable | ||
| namespace Terminal.Gui; | ||
|
|
||
| /// <summary> | ||
| /// Navigates a collection of items using keystrokes. The keystrokes are used to build a search string. The | ||
| /// <see cref="SearchString"/> is used to find the next item in the collection that matches the search string when | ||
| /// <see cref="GetNextMatchingItem(int, char)"/> is called. | ||
| /// <para> | ||
| /// If the user types keystrokes that can't be found in the collection, the search string is cleared and the next | ||
| /// item is found that starts with the last keystroke. | ||
| /// </para> | ||
| /// <para>If the user pauses keystrokes for a short time (see <see cref="TypingDelay"/>), the search string is cleared.</para> | ||
| /// </summary> | ||
| public interface ICollectionNavigator | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the number of milliseconds to delay before clearing the search string. The delay is reset on each | ||
| /// call to <see cref="GetNextMatchingItem(int, char)"/>. The default is 500ms. | ||
| /// </summary> | ||
| public int TypingDelay { get; set; } | ||
|
|
||
| /// <summary>This event is invoked when <see cref="SearchString"/> changes. Useful for debugging.</summary> | ||
| public event EventHandler<KeystrokeNavigatorEventArgs>? SearchStringChanged; | ||
|
|
||
| /// <summary> | ||
| /// Gets the current search string. This includes the set of keystrokes that have been pressed since the last | ||
| /// unsuccessful match or after <see cref="TypingDelay"/>) milliseconds. Useful for debugging. | ||
| /// </summary> | ||
| string SearchString { get; } | ||
|
|
||
| /// <summary> | ||
| /// Class responsible for deciding whether given entries in the collection match | ||
| /// the search term the user is typing. | ||
| /// </summary> | ||
| ICollectionNavigatorMatcher Matcher { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the index of the next item in the collection that matches the current <see cref="SearchString"/> plus the | ||
| /// provided character (typically from a key press). | ||
| /// </summary> | ||
| /// <param name="currentIndex">The index in the collection to start the search from.</param> | ||
| /// <param name="keyStruck">The character of the key the user pressed.</param> | ||
| /// <returns> | ||
| /// The index of the item that matches what the user has typed. Returns <see langword="-1"/> if no item in the | ||
| /// collection matched. | ||
| /// </returns> | ||
| int GetNextMatchingItem (int currentIndex, char keyStruck); | ||
| } |
This file contains hidden or 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,26 @@ | ||
| namespace Terminal.Gui; | ||
|
|
||
| /// <summary> | ||
| /// Determines which keys trigger collection manager navigation | ||
| /// and how to match typed strings to objects in the collection. | ||
| /// Default implementation is <see cref="DefaultCollectionNavigatorMatcher"/>. | ||
| /// </summary> | ||
| public interface ICollectionNavigatorMatcher | ||
| { | ||
| /// <summary> | ||
| /// Returns true if <paramref name="a"/> is a searchable key (e.g. letters, numbers, etc) that are valid to pass | ||
| /// to this class for search filtering. | ||
| /// </summary> | ||
| /// <param name="a"></param> | ||
| /// <returns></returns> | ||
| bool IsCompatibleKey (Key a); | ||
tznind marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// <summary> | ||
| /// Return true if the <paramref name="value"/> matches (e.g. starts with) | ||
| /// the <paramref name="search"/> term. | ||
| /// </summary> | ||
| /// <param name="search"></param> | ||
| /// <param name="value"></param> | ||
| /// <returns></returns> | ||
| bool IsMatch (string search, object value); | ||
tig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
tig marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,13 @@ | ||
| using System.Collections; | ||
|
|
||
| namespace Terminal.Gui; | ||
|
|
||
| /// <summary> | ||
| /// <see cref="ICollectionNavigator"/> sub-interface for <see cref="ListView"/>. See also | ||
| /// <see cref="ListView.KeystrokeNavigator"/> | ||
| /// </summary> | ||
| public interface IListCollectionNavigator : ICollectionNavigator | ||
| { | ||
| /// <summary>The collection of objects to search. <see cref="object.ToString()"/> is used to search the collection.</summary> | ||
| IList Collection { get; set; } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.