Merge branch 'develop'

This commit is contained in:
Tig Kindel
2023-05-24 15:09:49 +02:00
5 changed files with 112 additions and 6 deletions

View File

@@ -82,6 +82,7 @@ namespace Terminal.Gui {
bool poll_dirty = true;
int [] wakeupPipes = new int [2];
static IntPtr ignore = Marshal.AllocHGlobal (1);
static IntPtr readHandle = Marshal.AllocHGlobal (1);
MainLoop mainLoop;
bool winChanged;
@@ -97,7 +98,7 @@ namespace Terminal.Gui {
this.mainLoop = mainLoop;
pipe (wakeupPipes);
AddWatch (wakeupPipes [0], Condition.PollIn, ml => {
read (wakeupPipes [0], ignore, (IntPtr)1);
read (wakeupPipes [0], ignore, readHandle);
return true;
});
}

View File

@@ -61,8 +61,15 @@ namespace Terminal.Gui.Trees {
return;
}
var children = tree.TreeBuilder.GetChildren (this.Model) ?? Enumerable.Empty<T> ();
IEnumerable<T> children;
if (Depth >= tree.MaxDepth) {
children = Enumerable.Empty<T> ();
}
else {
children = tree.TreeBuilder.GetChildren (this.Model) ?? Enumerable.Empty<T> ();
}
this.ChildBranches = children.ToDictionary (k => k, val => new Branch<T> (tree, this, val));
}

View File

@@ -10,10 +10,10 @@
<!-- Version numbers are automatically updated by gitversion when a release is released -->
<!-- In the source tree the version will always be 1.0 for all projects. -->
<!-- Do not modify these. Do NOT commit after manually running `dotnet-gitversion /updateprojectfiles` -->
<AssemblyVersion>1.11.0.0</AssemblyVersion>
<FileVersion>1.11.0.0</FileVersion>
<Version>1.11</Version>
<InformationalVersion>1.11</InformationalVersion>
<AssemblyVersion>1.0</AssemblyVersion>
<FileVersion>1.0</FileVersion>
<Version>1.0</Version>
<InformationalVersion>1.0</InformationalVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />

View File

@@ -85,6 +85,11 @@ namespace Terminal.Gui {
/// <value></value>
public bool MultiSelect { get; set; } = true;
/// <summary>
/// Maximum number of nodes that can be expanded in any given branch.
/// </summary>
public int MaxDepth { get; set; } = 100;
/// <summary>
/// True makes a letter key press navigate to the next visible branch that begins with
/// that letter/digit.

View File

@@ -908,6 +908,99 @@ namespace Terminal.Gui.ViewTests {
new [] { tv.ColorScheme.Normal, pink });
}
[Fact, AutoInitShutdown]
public void TestBottomlessTreeView_MaxDepth_5 ()
{
var tv = new TreeView<string> () { Width = 20, Height = 10 };
tv.TreeBuilder = new DelegateTreeBuilder<string> (
(s) => new [] { (int.Parse (s) + 1).ToString () }
);
tv.AddObject ("1");
tv.ColorScheme = new ColorScheme ();
tv.LayoutSubviews ();
tv.Redraw (tv.Bounds);
// Nothing expanded
TestHelpers.AssertDriverContentsAre (
@"└+1
", output);
tv.MaxDepth = 5;
tv.ExpandAll ();
tv.Redraw (tv.Bounds);
// Normal drawing of the tree view
TestHelpers.AssertDriverContentsAre (
@"
└-1
└-2
└-3
└-4
└-5
└─6
", output);
Assert.False (tv.CanExpand ("6"));
Assert.False (tv.IsExpanded ("6"));
tv.Collapse("6");
Assert.False (tv.CanExpand ("6"));
Assert.False (tv.IsExpanded ("6"));
tv.Collapse ("5");
Assert.True (tv.CanExpand ("5"));
Assert.False (tv.IsExpanded ("5"));
tv.Redraw (tv.Bounds);
// Normal drawing of the tree view
TestHelpers.AssertDriverContentsAre (
@"
└-1
└-2
└-3
└-4
└+5
", output);
}
[Fact, AutoInitShutdown]
public void TestBottomlessTreeView_MaxDepth_3 ()
{
var tv = new TreeView<string> () { Width = 20, Height = 10 };
tv.TreeBuilder = new DelegateTreeBuilder<string> (
(s) => new [] { (int.Parse (s) + 1).ToString () }
);
tv.AddObject ("1");
tv.ColorScheme = new ColorScheme ();
tv.LayoutSubviews ();
tv.Redraw (tv.Bounds);
// Nothing expanded
TestHelpers.AssertDriverContentsAre (
@"└+1
", output);
tv.MaxDepth = 3;
tv.ExpandAll ();
tv.Redraw (tv.Bounds);
// Normal drawing of the tree view
TestHelpers.AssertDriverContentsAre (
@"
└-1
└-2
└-3
└─4
", output);
}
[Fact, AutoInitShutdown]
public void TestTreeView_Filter ()
{