Skip to content

Commit 3f38d81

Browse files
tznindtig
andauthored
Fixes #4027. Add collection search matcher (#4029)
* Add collection search matcher * Fix naming * fix naming * Move FileDialogCollectionNavigator to its own file (no longer private class) Add class diagram for collectionNavigation * Add ICollectionNavigator interface * Move to separate file IListCollectionNavigator * Update class diagram * update class diagram * Add tests for overriding ICollectionNavigatorMatcher * xmldoc and nullability warning fixes * Code Cleanup * Make requested changes to naming and terminology * Move to seperate namespace * Update class diagram and change TreeView to reference the interface not concrete class * Switch to implicit new * highlight that this class also works with tree view * Apply tig patch to ensure keybindings get priority over navigator See: #4027 (comment) * Apply 'keybinding has priority' fix to TreeView too * Apply 'keybindngs priority over navigation' fix to TableView * Remove entire branch for selectively returning false now that it is default when there is a keybinding collision * Make classes internal and remove 'custom' navigator that was configured in UICatlaogToplevel * Change logging in collection navigator from Trace to Debug * Switch to NewKeyDownEvent and directly setting HasFocus * Remove application top dependency * Remove references to application * Remove Application * Move new tests to parallel --------- Co-authored-by: Tig <tig@users.noreply.github.com>
1 parent 0baa881 commit 3f38d81

21 files changed

+577
-203
lines changed

Examples/UICatalog/Scenarios/CollectionNavigatorTester.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class CollectionNavigatorTester : Scenario
5858
"$200.00",
5959
"$210.99",
6060
"$$",
61-
"appricot",
61+
"apricot",
6262
"arm",
6363
"丗丙业丞",
6464
"丗丙丛",

Examples/UICatalog/UICatalogTop.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,6 @@ private void UpdateThemesMenu ()
380380

381381
public static ObservableCollection<Scenario>? CachedScenarios { get; set; }
382382

383-
// UI Catalog uses TableView for the scenario list instead of a ListView to demonstrate how
384-
// TableView works. There's no real reason not to use ListView. Because we use TableView, and TableView
385-
// doesn't (currently) have CollectionNavigator support built in, we implement it here, within the app.
386-
private readonly CollectionNavigator _scenarioCollectionNav = new ();
387-
388383
// If set, holds the scenario the user selected to run
389384
public static Scenario? CachedSelectedScenario { get; set; }
390385

@@ -561,16 +556,6 @@ private void CategoryView_SelectedChanged (object? sender, ListViewItemEventArgs
561556
}
562557
);
563558

564-
// Create a collection of just the scenario names (the 1st column in our TableView)
565-
// for CollectionNavigator.
566-
List<object> firstColumnList = [];
567-
568-
for (var i = 0; i < _scenarioList.Table.Rows; i++)
569-
{
570-
firstColumnList.Add (_scenarioList.Table [i, 0]);
571-
}
572-
573-
_scenarioCollectionNav.Collection = firstColumnList;
574559
}
575560

576561
#endregion Category List
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ClassDiagram MajorVersion="1" MinorVersion="1">
3+
<Comment CommentText="Views that use the CollectionNavigation system">
4+
<Position X="0.5" Y="0.5" Height="0.458" Width="1.856" />
5+
</Comment>
6+
<Comment CommentText="Specialized navigators for each collection type (e.g. list, tree etc)">
7+
<Position X="4.646" Y="0.5" Height="0.5" Width="3.169" />
8+
</Comment>
9+
<Comment CommentText="Shared matching component (users should provide alternative implementations of this class if they want to modify collection navigation behaviour)">
10+
<Position X="9.448" Y="0.5" Height="0.708" Width="3.169" />
11+
</Comment>
12+
<Class Name="Terminal.Gui.CollectionNavigatorBase" Collapsed="true">
13+
<Position X="6.25" Y="1.5" Width="2" />
14+
<TypeIdentifier>
15+
<HashCode>AAgEAAAAAAAQAAAIAAEAAgAAAAAABAAEAAAAACwAAAA=</HashCode>
16+
<FileName>Views\CollectionNavigation\CollectionNavigatorBase.cs</FileName>
17+
</TypeIdentifier>
18+
<ShowAsAssociation>
19+
<Property Name="Matcher" />
20+
</ShowAsAssociation>
21+
<Lollipop Position="0.2" />
22+
</Class>
23+
<Class Name="Terminal.Gui.CollectionNavigator" Collapsed="true">
24+
<Position X="4.5" Y="3.5" Width="2" />
25+
<TypeIdentifier>
26+
<HashCode>AAAAAAAAAAAAQAAAAAAAAgAAAAAAAAAEAAAAAAAAAAA=</HashCode>
27+
<FileName>Views\CollectionNavigation\CollectionNavigator.cs</FileName>
28+
</TypeIdentifier>
29+
<Lollipop Position="0.2" />
30+
</Class>
31+
<Class Name="Terminal.Gui.DefaultCollectionNavigatorMatcher">
32+
<Position X="9.5" Y="2.5" Width="2.75" />
33+
<TypeIdentifier>
34+
<HashCode>AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAQA=</HashCode>
35+
<FileName>Views\CollectionNavigation\DefaultCollectionNavigatorMatcher.cs</FileName>
36+
</TypeIdentifier>
37+
<Lollipop Position="0.2" />
38+
</Class>
39+
<Class Name="Terminal.Gui.TableCollectionNavigator" Collapsed="true">
40+
<Position X="4.75" Y="6.5" Width="2.25" />
41+
<TypeIdentifier>
42+
<HashCode>AAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAEAAAAIAAAAAA=</HashCode>
43+
<FileName>Views\CollectionNavigation\TableCollectionNavigator.cs</FileName>
44+
</TypeIdentifier>
45+
</Class>
46+
<Class Name="Terminal.Gui.ListView" Collapsed="true">
47+
<Position X="0.5" Y="4.25" Width="1.5" />
48+
<TypeIdentifier>
49+
<HashCode>AAE+ASAkEnAAABAAKGAggYAZJAIAABEAcBAaAwAQIAA=</HashCode>
50+
<FileName>Views\ListView.cs</FileName>
51+
</TypeIdentifier>
52+
<ShowAsAssociation>
53+
<Property Name="KeystrokeNavigator" />
54+
</ShowAsAssociation>
55+
<Lollipop Position="0.2" />
56+
</Class>
57+
<Class Name="Terminal.Gui.FileDialog" Collapsed="true">
58+
<Position X="0.5" Y="5.5" Width="1.75" />
59+
<Compartments>
60+
<Compartment Name="Nested Types" Collapsed="false" />
61+
</Compartments>
62+
<TypeIdentifier>
63+
<HashCode>iIY4LQFUHDKVIHIESBgigQcFT6GxhBDABGJItBQAwAQ=</HashCode>
64+
<FileName>Views\FileDialog.cs</FileName>
65+
</TypeIdentifier>
66+
<Lollipop Position="0.2" />
67+
</Class>
68+
<Class Name="Terminal.Gui.FileDialogCollectionNavigator" Collapsed="true">
69+
<Position X="4.75" Y="5.5" Width="2.25" />
70+
<TypeIdentifier>
71+
<HashCode>AAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAEAAAAAAAAAAA=</HashCode>
72+
<FileName>Views\FileDialogCollectionNavigator.cs</FileName>
73+
</TypeIdentifier>
74+
</Class>
75+
<Class Name="Terminal.Gui.TableView" Collapsed="true" BaseTypeListCollapsed="true">
76+
<Position X="0.5" Y="6.5" Width="1.5" />
77+
<TypeIdentifier>
78+
<HashCode>QwUeAxwgICIAcABIABeR0oBAkhoFGGOBDABgAN3oPEI=</HashCode>
79+
<FileName>Views\TableView\TableView.cs</FileName>
80+
</TypeIdentifier>
81+
<Lollipop Position="0.2" />
82+
</Class>
83+
<Class Name="Terminal.Gui.TreeView" Collapsed="true">
84+
<Position X="0.5" Y="3" Width="1.5" />
85+
<TypeIdentifier>
86+
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAA=</HashCode>
87+
<FileName>Views\TreeView\TreeView.cs</FileName>
88+
</TypeIdentifier>
89+
<Lollipop Position="0.2" />
90+
</Class>
91+
<Class Name="Terminal.Gui.TreeView&lt;T&gt;" Collapsed="true">
92+
<Position X="0.5" Y="2" Width="1.5" />
93+
<TypeIdentifier>
94+
<HashCode>UwAGySBgBSBGMAQgIiCaBDUItJIBSAWwRMQOSgQCwJI=</HashCode>
95+
<FileName>Views\TreeView\TreeView.cs</FileName>
96+
</TypeIdentifier>
97+
<ShowAsAssociation>
98+
<Property Name="KeystrokeNavigator" />
99+
</ShowAsAssociation>
100+
<Lollipop Position="0.2" />
101+
</Class>
102+
<Interface Name="Terminal.Gui.ICollectionNavigatorMatcher" Collapsed="true">
103+
<Position X="9.5" Y="1.5" Width="2.75" />
104+
<TypeIdentifier>
105+
<HashCode>AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAA=</HashCode>
106+
<FileName>Views\CollectionNavigation\ICollectionNavigatorMatcher.cs</FileName>
107+
</TypeIdentifier>
108+
</Interface>
109+
<Interface Name="Terminal.Gui.IListCollectionNavigator" Collapsed="true">
110+
<Position X="3.75" Y="2.25" Width="2" />
111+
<TypeIdentifier>
112+
<HashCode>AAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
113+
<FileName>Views\CollectionNavigation\IListCollectionNavigator.cs</FileName>
114+
</TypeIdentifier>
115+
</Interface>
116+
<Interface Name="Terminal.Gui.ICollectionNavigator" Collapsed="true">
117+
<Position X="3.75" Y="1.5" Width="2" />
118+
<TypeIdentifier>
119+
<HashCode>AAgAAAAAAAAAAAAIAAAAAAAAAAAABAAAAAAAACgAAAA=</HashCode>
120+
<FileName>Views\CollectionNavigation\ICollectionNavigator.cs</FileName>
121+
</TypeIdentifier>
122+
</Interface>
123+
<Font Name="Segoe UI" Size="9" />
124+
</ClassDiagram>

Terminal.Gui/Text/CollectionNavigator.cs renamed to Terminal.Gui/Views/CollectionNavigation/CollectionNavigator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Terminal.Gui;
44

5-
/// <inheritdoc/>
5+
/// <inheritdoc cref="CollectionNavigatorBase"/>
66
/// <remarks>This implementation is based on a static <see cref="Collection"/> of objects.</remarks>
7-
public class CollectionNavigator : CollectionNavigatorBase
7+
internal class CollectionNavigator : CollectionNavigatorBase, IListCollectionNavigator
88
{
99
/// <summary>Constructs a new CollectionNavigator.</summary>
1010
public CollectionNavigator () { }
@@ -13,12 +13,12 @@ public CollectionNavigator () { }
1313
/// <param name="collection"></param>
1414
public CollectionNavigator (IList collection) { Collection = collection; }
1515

16-
/// <summary>The collection of objects to search. <see cref="object.ToString()"/> is used to search the collection.</summary>
16+
/// <inheritdoc/>
1717
public IList Collection { get; set; }
1818

1919
/// <inheritdoc/>
2020
protected override object ElementAt (int idx) { return Collection [idx]; }
2121

2222
/// <inheritdoc/>
2323
protected override int GetCollectionLength () { return Collection.Count; }
24-
}
24+
}

0 commit comments

Comments
 (0)