Skip to content

Commit 98215a6

Browse files
committed
Merge branch 'develop' of tig:gui-cs/Terminal.Gui into develop
2 parents 2d14cb7 + 22cf4e3 commit 98215a6

File tree

4 files changed

+108
-2
lines changed

4 files changed

+108
-2
lines changed

Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class Watch {
8282
bool poll_dirty = true;
8383
int [] wakeupPipes = new int [2];
8484
static IntPtr ignore = Marshal.AllocHGlobal (1);
85+
static IntPtr readHandle = Marshal.AllocHGlobal (1);
8586
MainLoop mainLoop;
8687
bool winChanged;
8788

@@ -97,7 +98,7 @@ void IMainLoopDriver.Setup (MainLoop mainLoop)
9798
this.mainLoop = mainLoop;
9899
pipe (wakeupPipes);
99100
AddWatch (wakeupPipes [0], Condition.PollIn, ml => {
100-
read (wakeupPipes [0], ignore, (IntPtr)1);
101+
read (wakeupPipes [0], ignore, readHandle);
101102
return true;
102103
});
103104
}

Terminal.Gui/Core/Trees/Branch.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,15 @@ public virtual void FetchChildren ()
6161
return;
6262
}
6363

64-
var children = tree.TreeBuilder.GetChildren (this.Model) ?? Enumerable.Empty<T> ();
64+
IEnumerable<T> children;
6565

66+
if (Depth >= tree.MaxDepth) {
67+
children = Enumerable.Empty<T> ();
68+
}
69+
else {
70+
children = tree.TreeBuilder.GetChildren (this.Model) ?? Enumerable.Empty<T> ();
71+
}
72+
6673
this.ChildBranches = children.ToDictionary (k => k, val => new Branch<T> (tree, this, val));
6774
}
6875

Terminal.Gui/Views/TreeView.cs

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public class TreeView<T> : View, ITreeView where T : class {
8585
/// <value></value>
8686
public bool MultiSelect { get; set; } = true;
8787

88+
/// <summary>
89+
/// Maximum number of nodes that can be expanded in any given branch.
90+
/// </summary>
91+
public int MaxDepth { get; set; } = 100;
92+
8893
/// <summary>
8994
/// True makes a letter key press navigate to the next visible branch that begins with
9095
/// that letter/digit.

UnitTests/Views/TreeViewTests.cs

+93
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,99 @@ public void TestTreeViewColor ()
908908
new [] { tv.ColorScheme.Normal, pink });
909909
}
910910

911+
[Fact, AutoInitShutdown]
912+
public void TestBottomlessTreeView_MaxDepth_5 ()
913+
{
914+
var tv = new TreeView<string> () { Width = 20, Height = 10 };
915+
916+
tv.TreeBuilder = new DelegateTreeBuilder<string> (
917+
(s) => new [] { (int.Parse (s) + 1).ToString () }
918+
);
919+
920+
tv.AddObject ("1");
921+
tv.ColorScheme = new ColorScheme ();
922+
923+
tv.LayoutSubviews ();
924+
tv.Redraw (tv.Bounds);
925+
926+
// Nothing expanded
927+
TestHelpers.AssertDriverContentsAre (
928+
@"└+1
929+
", output);
930+
tv.MaxDepth = 5;
931+
tv.ExpandAll ();
932+
933+
tv.Redraw (tv.Bounds);
934+
935+
// Normal drawing of the tree view
936+
TestHelpers.AssertDriverContentsAre (
937+
@"
938+
└-1
939+
└-2
940+
└-3
941+
└-4
942+
└-5
943+
└─6
944+
", output);
945+
Assert.False (tv.CanExpand ("6"));
946+
Assert.False (tv.IsExpanded ("6"));
947+
948+
tv.Collapse("6");
949+
950+
Assert.False (tv.CanExpand ("6"));
951+
Assert.False (tv.IsExpanded ("6"));
952+
953+
tv.Collapse ("5");
954+
955+
Assert.True (tv.CanExpand ("5"));
956+
Assert.False (tv.IsExpanded ("5"));
957+
958+
tv.Redraw (tv.Bounds);
959+
960+
// Normal drawing of the tree view
961+
TestHelpers.AssertDriverContentsAre (
962+
@"
963+
└-1
964+
└-2
965+
└-3
966+
└-4
967+
└+5
968+
", output);
969+
}
970+
971+
[Fact, AutoInitShutdown]
972+
public void TestBottomlessTreeView_MaxDepth_3 ()
973+
{
974+
var tv = new TreeView<string> () { Width = 20, Height = 10 };
975+
976+
tv.TreeBuilder = new DelegateTreeBuilder<string> (
977+
(s) => new [] { (int.Parse (s) + 1).ToString () }
978+
);
979+
980+
tv.AddObject ("1");
981+
tv.ColorScheme = new ColorScheme ();
982+
983+
tv.LayoutSubviews ();
984+
tv.Redraw (tv.Bounds);
985+
986+
// Nothing expanded
987+
TestHelpers.AssertDriverContentsAre (
988+
@"└+1
989+
", output);
990+
tv.MaxDepth = 3;
991+
tv.ExpandAll ();
992+
tv.Redraw (tv.Bounds);
993+
994+
// Normal drawing of the tree view
995+
TestHelpers.AssertDriverContentsAre (
996+
@"
997+
└-1
998+
└-2
999+
└-3
1000+
└─4
1001+
", output);
1002+
}
1003+
9111004
[Fact, AutoInitShutdown]
9121005
public void TestTreeView_Filter ()
9131006
{

0 commit comments

Comments
 (0)