Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed May 24, 2023
2 parents 8fe38cc + 1197a28 commit 9e878e3
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Watch {
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;

Expand All @@ -97,7 +98,7 @@ void IMainLoopDriver.Setup (MainLoop mainLoop)
this.mainLoop = mainLoop;
pipe (wakeupPipes);
AddWatch (wakeupPipes [0], Condition.PollIn, ml => {
read (wakeupPipes [0], ignore, (IntPtr)1);
read (wakeupPipes [0], ignore, readHandle);
return true;
});
}
Expand Down
9 changes: 8 additions & 1 deletion Terminal.Gui/Core/Trees/Branch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ public virtual void FetchChildren ()
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));
}

Expand Down
8 changes: 4 additions & 4 deletions Terminal.Gui/Terminal.Gui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
5 changes: 5 additions & 0 deletions Terminal.Gui/Views/TreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public class TreeView<T> : View, ITreeView where T : class {
/// <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.
Expand Down
93 changes: 93 additions & 0 deletions UnitTests/Views/TreeViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,99 @@ public void TestTreeViewColor ()
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 ()
{
Expand Down

0 comments on commit 9e878e3

Please sign in to comment.