Skip to content

Commit 8fe38cc

Browse files
committed
Merge branch 'develop'
2 parents cbbca9a + 2d14cb7 commit 8fe38cc

File tree

11 files changed

+236
-29
lines changed

11 files changed

+236
-29
lines changed

ReactiveExample/ReactiveExample.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<InformationalVersion>1.10.1+6.Branch.main.Sha.f7ee66ddbf8dbcfb0d96af7d63789879091670ec</InformationalVersion>
1212
</PropertyGroup>
1313
<ItemGroup>
14-
<PackageReference Include="ReactiveUI.Fody" Version="18.4.26" />
15-
<PackageReference Include="ReactiveUI" Version="18.4.26" />
14+
<PackageReference Include="ReactiveUI.Fody" Version="18.4.44" />
15+
<PackageReference Include="ReactiveUI" Version="18.4.44" />
1616
<PackageReference Include="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="1.2.3" PrivateAssets="all" />
1717
</ItemGroup>
1818
<ItemGroup>

Terminal.Gui/ConsoleDrivers/CursesDriver/UnmanagedLibrary.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static class Mono {
256256
/// to avoid the dependency on libc-dev Linux.
257257
/// </summary>
258258
static class CoreCLR {
259-
#if NET6_0
259+
#if NET7_0
260260
// Custom resolver to support true single-file apps
261261
// (those which run directly from bundle; in-memory).
262262
// -1 on Unix means self-referencing binary (libcoreclr.so)
@@ -266,7 +266,6 @@ static CoreCLR() => NativeLibrary.SetDllImportResolver(typeof(CoreCLR).Assembly
266266
(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) =>
267267
libraryName == "libcoreclr.so" ? (IntPtr)(-1) : IntPtr.Zero);
268268
#endif
269-
270269
[DllImport ("libcoreclr.so")]
271270
internal static extern IntPtr dlopen (string filename, int flags);
272271

Terminal.Gui/Core/ConsoleDriver.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ public static (int exitCode, string result) Process (string cmd, string argument
14941494
process.StandardInput.Close ();
14951495
}
14961496

1497-
if (!process.WaitForExit (5000)) {
1497+
if (!process.WaitForExit (10000)) {
14981498
var timeoutError = $@"Process timed out. Command line: {process.StartInfo.FileName} {process.StartInfo.Arguments}.";
14991499
throw new TimeoutException (timeoutError);
15001500
}

Terminal.Gui/Terminal.Gui.csproj

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
33
<DebugType>portable</DebugType>
44
</PropertyGroup>
@@ -10,10 +10,10 @@
1010
<!-- Version numbers are automatically updated by gitversion when a release is released -->
1111
<!-- In the source tree the version will always be 1.0 for all projects. -->
1212
<!-- Do not modify these. Do NOT commit after manually running `dotnet-gitversion /updateprojectfiles` -->
13-
<AssemblyVersion>1.10.1.0</AssemblyVersion>
14-
<FileVersion>1.10.1.0</FileVersion>
15-
<Version>1.10.1</Version>
16-
<InformationalVersion>1.10.1+6.Branch.main.Sha.f7ee66ddbf8dbcfb0d96af7d63789879091670ec</InformationalVersion>
13+
<AssemblyVersion>1.11.0.0</AssemblyVersion>
14+
<FileVersion>1.11.0.0</FileVersion>
15+
<Version>1.11</Version>
16+
<InformationalVersion>1.11</InformationalVersion>
1717
</PropertyGroup>
1818
<ItemGroup>
1919
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
@@ -53,7 +53,7 @@
5353
<!-- Enable Nuget Source Link for github -->
5454
<ItemGroup>
5555
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
56-
<PackageReference Include="System.Management" Version="7.0.0" />
56+
<PackageReference Include="System.Management" Version="7.0.1" />
5757
</ItemGroup>
5858
<PropertyGroup>
5959
<TargetFrameworks>net472;netstandard2.1;net7.0</TargetFrameworks>

Terminal.Gui/Views/ITreeViewFilter.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Terminal.Gui {
2+
3+
/// <summary>
4+
/// Provides filtering for a <see cref="TreeView"/>.
5+
/// </summary>
6+
public interface ITreeViewFilter<T> where T : class {
7+
8+
/// <summary>
9+
/// Return <see langword="true"/> if the <paramref name="model"/> should
10+
/// be included in the tree.
11+
/// </summary>
12+
bool IsMatch (T model);
13+
}
14+
}

Terminal.Gui/Views/TreeView.cs

+46-7
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ public int ScrollOffsetHorizontal {
214214

215215
CursorVisibility desiredCursorVisibility = CursorVisibility.Invisible;
216216

217+
/// <summary>
218+
/// Interface for filtering which lines of the tree are displayed
219+
/// e.g. to provide text searching. Defaults to <see langword="null"/>
220+
/// (no filtering).
221+
/// </summary>
222+
public ITreeViewFilter<T> Filter = null;
223+
217224
/// <summary>
218225
/// Get / Set the wished cursor when the tree is focused.
219226
/// Only applies when <see cref="MultiSelect"/> is true.
@@ -541,7 +548,12 @@ private IReadOnlyCollection<Branch<T>> BuildLineMap ()
541548
List<Branch<T>> toReturn = new List<Branch<T>> ();
542549

543550
foreach (var root in roots.Values) {
544-
toReturn.AddRange (AddToLineMap (root));
551+
552+
var toAdd = AddToLineMap (root, false, out var isMatch);
553+
if(isMatch)
554+
{
555+
toReturn.AddRange (toAdd);
556+
}
545557
}
546558

547559
cachedLineMap = new ReadOnlyCollection<Branch<T>> (toReturn);
@@ -551,17 +563,44 @@ private IReadOnlyCollection<Branch<T>> BuildLineMap ()
551563
return cachedLineMap;
552564
}
553565

554-
private IEnumerable<Branch<T>> AddToLineMap (Branch<T> currentBranch)
566+
private bool IsFilterMatch (Branch<T> branch)
567+
{
568+
return Filter?.IsMatch(branch.Model) ?? true;
569+
}
570+
571+
private IEnumerable<Branch<T>> AddToLineMap (Branch<T> currentBranch,bool parentMatches, out bool match)
555572
{
556-
yield return currentBranch;
573+
bool weMatch = IsFilterMatch(currentBranch);
574+
bool anyChildMatches = false;
575+
576+
var toReturn = new List<Branch<T>>();
577+
var children = new List<Branch<T>>();
557578

558579
if (currentBranch.IsExpanded) {
559580
foreach (var subBranch in currentBranch.ChildBranches.Values) {
560-
foreach (var sub in AddToLineMap (subBranch)) {
561-
yield return sub;
581+
582+
foreach (var sub in AddToLineMap (subBranch, weMatch, out var childMatch)) {
583+
584+
if(childMatch)
585+
{
586+
children.Add(sub);
587+
anyChildMatches = true;
588+
}
562589
}
563590
}
564591
}
592+
593+
if(parentMatches || weMatch || anyChildMatches)
594+
{
595+
match = true;
596+
toReturn.Add(currentBranch);
597+
}
598+
else{
599+
match = false;
600+
}
601+
602+
toReturn.AddRange(children);
603+
return toReturn;
565604
}
566605

567606
/// <summary>
@@ -1289,9 +1328,9 @@ protected void CollapseImpl (T toCollapse, bool all)
12891328
}
12901329

12911330
/// <summary>
1292-
/// Clears any cached results of <see cref="BuildLineMap"/>
1331+
/// Clears any cached results of the tree state.
12931332
/// </summary>
1294-
protected void InvalidateLineMap ()
1333+
public void InvalidateLineMap ()
12951334
{
12961335
cachedLineMap = null;
12971336
}
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
3+
namespace Terminal.Gui {
4+
5+
/// <summary>
6+
/// <see cref="ITreeViewFilter{T}"/> implementation which searches the
7+
/// <see cref="TreeView{T}.AspectGetter"/> of the model for the given
8+
/// <see cref="Text"/>.
9+
/// </summary>
10+
/// <typeparam name="T"></typeparam>
11+
public class TreeViewTextFilter<T> : ITreeViewFilter<T> where T : class {
12+
readonly TreeView<T> _forTree;
13+
14+
/// <summary>
15+
/// Creates a new instance of the filter for use with <paramref name="forTree"/>.
16+
/// Set <see cref="Text"/> to begin filtering.
17+
/// </summary>
18+
/// <param name="forTree"></param>
19+
/// <exception cref="ArgumentNullException"></exception>
20+
public TreeViewTextFilter (TreeView<T> forTree)
21+
{
22+
_forTree = forTree ?? throw new ArgumentNullException (nameof (forTree));
23+
}
24+
25+
/// <summary>
26+
/// The case sensitivity of the search match.
27+
/// Defaults to <see cref="StringComparison.OrdinalIgnoreCase"/>.
28+
/// </summary>
29+
public StringComparison Comparer { get; set; } = StringComparison.OrdinalIgnoreCase;
30+
private string text;
31+
32+
/// <summary>
33+
/// The text that will be searched for in the <see cref="TreeView{T}"/>
34+
/// </summary>
35+
public string Text {
36+
get { return text; }
37+
set {
38+
text = value;
39+
RefreshTreeView ();
40+
}
41+
}
42+
43+
private void RefreshTreeView ()
44+
{
45+
_forTree.InvalidateLineMap ();
46+
_forTree.SetNeedsDisplay ();
47+
}
48+
49+
/// <summary>
50+
/// Returns <typeparamref name="T"/> if there is no <see cref="Text"/> or
51+
/// the text matches the <see cref="TreeView{T}.AspectGetter"/> of the
52+
/// <paramref name="model"/>.
53+
/// </summary>
54+
/// <param name="model"></param>
55+
/// <returns></returns>
56+
public bool IsMatch (T model)
57+
{
58+
if (string.IsNullOrWhiteSpace (Text)) {
59+
return true;
60+
}
61+
62+
return _forTree.AspectGetter (model)?.IndexOf (Text, Comparer) != -1;
63+
}
64+
}
65+
}

UICatalog/Scenarios/ClassExplorer.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,30 @@ public override void Setup ()
8484

8585
treeView = new TreeView<object> () {
8686
X = 0,
87-
Y = 0,
87+
Y = 1,
8888
Width = Dim.Percent (50),
8989
Height = Dim.Fill (),
9090
};
9191

92+
var lblSearch = new Label("Search");
93+
var tfSearch = new TextField(){
94+
Width = 20,
95+
X = Pos.Right(lblSearch),
96+
};
97+
98+
Win.Add(lblSearch);
99+
Win.Add(tfSearch);
100+
101+
var filter = new TreeViewTextFilter<object>(treeView);
102+
treeView.Filter = filter;
103+
tfSearch.TextChanged += (s)=>{
104+
filter.Text = tfSearch.Text.ToString();
105+
if(treeView.SelectedObject != null)
106+
{
107+
treeView.EnsureVisible(treeView.SelectedObject);
108+
}
109+
};
110+
92111
treeView.AddObjects (AppDomain.CurrentDomain.GetAssemblies ());
93112
treeView.AspectGetter = GetRepresentation;
94113
treeView.TreeBuilder = new DelegateTreeBuilder<object> (ChildGetter, CanExpand);

UnitTests/Drivers/ClipboardTests.cs

+10-8
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ public void Contents_Fake_Gets_Sets_When_IsSupportedFalse ()
102102
[Fact, AutoInitShutdown (useFakeClipboard: false)]
103103
public void IsSupported_Get ()
104104
{
105-
if (Clipboard.IsSupported) Assert.True (Clipboard.IsSupported);
106-
else Assert.False (Clipboard.IsSupported);
105+
if (Clipboard.IsSupported) Assert.True (Clipboard.IsSupported);
106+
else Assert.False (Clipboard.IsSupported);
107107
}
108108

109109
[Fact, AutoInitShutdown (useFakeClipboard: false)]
@@ -129,15 +129,15 @@ public void TryGetClipboardData_Gets_From_OS_Clipboard ()
129129
public void TrySetClipboardData_Sets_The_OS_Clipboard ()
130130
{
131131
var clipText = "The TrySetClipboardData_Sets_The_OS_Clipboard unit test pasted this to the OS clipboard.";
132-
if (Clipboard.IsSupported) Assert.True (Clipboard.TrySetClipboardData (clipText));
133-
else Assert.False (Clipboard.TrySetClipboardData (clipText));
132+
if (Clipboard.IsSupported) Assert.True (Clipboard.TrySetClipboardData (clipText));
133+
else Assert.False (Clipboard.TrySetClipboardData (clipText));
134134

135135
Application.Iteration += () => Application.RequestStop ();
136136

137137
Application.Run ();
138138

139-
if (Clipboard.IsSupported) Assert.Equal (clipText, Clipboard.Contents);
140-
else Assert.NotEqual (clipText, Clipboard.Contents);
139+
if (Clipboard.IsSupported) Assert.Equal (clipText, Clipboard.Contents);
140+
else Assert.NotEqual (clipText, Clipboard.Contents);
141141
}
142142

143143

@@ -209,7 +209,9 @@ public void Contents_Copies_From_OS_Clipboard ()
209209

210210
Application.Run ();
211211

212-
if (!failed) Assert.Equal (clipText, getClipText);
212+
if (!failed) {
213+
Assert.Equal (clipText, getClipText);
214+
}
213215
}
214216

215217
[Fact, AutoInitShutdown (useFakeClipboard: false)]
@@ -265,7 +267,7 @@ public void Contents_Pastes_To_OS_Clipboard ()
265267

266268
Application.Run ();
267269

268-
if (!failed) Assert.Equal (clipText, clipReadText.TrimEnd ());
270+
if (!failed) Assert.Equal (clipText, clipReadText.TrimEnd ());
269271

270272
}
271273

UnitTests/UnitTests.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<DefineConstants>TRACE;DEBUG_IDISPOSABLE</DefineConstants>
2222
</PropertyGroup>
2323
<ItemGroup>
24-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
25-
<PackageReference Include="ReportGenerator" Version="5.1.19" />
24+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
25+
<PackageReference Include="ReportGenerator" Version="5.1.20" />
2626
<PackageReference Include="System.Collections" Version="4.3.0" />
2727
<PackageReference Include="xunit" Version="2.4.2" />
2828
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
@@ -56,5 +56,6 @@
5656
<IncludeTestAssembly>
5757
False
5858
</IncludeTestAssembly>
59+
<RunSettingsFilePath>C:\Users\charlie\s\gui-cs\Terminal.Gui\UnitTests\bin\Debug\net7.0\fine-code-coverage\coverage-tool-output\UnitTests-fcc-mscodecoverage-generated.runsettings</RunSettingsFilePath>
5960
</PropertyGroup>
6061
</Project>

0 commit comments

Comments
 (0)