diff --git a/Terminal.Gui/Views/TreeView.cs b/Terminal.Gui/Views/TreeView.cs index 4f8692d743..aa070d499c 100644 --- a/Terminal.Gui/Views/TreeView.cs +++ b/Terminal.Gui/Views/TreeView.cs @@ -140,12 +140,12 @@ public Key ObjectActivationKey { /// public MouseFlags? ObjectActivationButton { get; set; } = MouseFlags.Button1DoubleClicked; - + /// /// Delegate for multi colored tree views. Return the to use /// for each passed object or null to use the default. /// - public Func ColorGetter {get;set;} + public Func ColorGetter { get; set; } /// /// Secondary selected regions of tree when is true @@ -227,14 +227,15 @@ public int ScrollOffsetHorizontal { /// Defaults to /// public CursorVisibility DesiredCursorVisibility { - get { + get { return MultiSelect ? desiredCursorVisibility : CursorVisibility.Invisible; } set { - desiredCursorVisibility = value; - - if (desiredCursorVisibility != value && HasFocus) { - Application.Driver.SetCursorVisibility (DesiredCursorVisibility); + if (desiredCursorVisibility != value) { + desiredCursorVisibility = value; + if (HasFocus) { + Application.Driver.SetCursorVisibility (DesiredCursorVisibility); + } } } } @@ -626,7 +627,7 @@ public void ActivateSelectedObjectIfAny () /// /// /// - public int? GetObjectRow(T toFind) + public int? GetObjectRow (T toFind) { var idx = BuildLineMap ().IndexOf (o => o.Model.Equals (toFind)); diff --git a/UnitTests/TreeViewTests.cs b/UnitTests/TreeViewTests.cs index 7e47e58d51..31c6bf5389 100644 --- a/UnitTests/TreeViewTests.cs +++ b/UnitTests/TreeViewTests.cs @@ -839,26 +839,26 @@ public void TestGetObjectRow () Assert.Equal (0, tv.GetObjectRow (n2)); } [Fact, AutoInitShutdown] - public void TestTreeViewColor() + public void TestTreeViewColor () { - var tv = new TreeView{Width = 20,Height = 10}; + var tv = new TreeView { Width = 20, Height = 10 }; - var n1 = new TreeNode("normal"); - var n1_1 = new TreeNode("pink"); - var n1_2 = new TreeNode("normal"); - n1.Children.Add(n1_1); - n1.Children.Add(n1_2); + var n1 = new TreeNode ("normal"); + var n1_1 = new TreeNode ("pink"); + var n1_2 = new TreeNode ("normal"); + n1.Children.Add (n1_1); + n1.Children.Add (n1_2); - var n2 = new TreeNode("pink"); - tv.AddObject(n1); - tv.AddObject(n2); - tv.Expand(n1); + var n2 = new TreeNode ("pink"); + tv.AddObject (n1); + tv.AddObject (n2); + tv.Expand (n1); - var pink = new Attribute(Color.Magenta,Color.Black); - var hotpink = new Attribute(Color.BrightMagenta,Color.Black); + var pink = new Attribute (Color.Magenta, Color.Black); + var hotpink = new Attribute (Color.BrightMagenta, Color.Black); - tv.ColorScheme = new ColorScheme(); - tv.Redraw(tv.Bounds); + tv.ColorScheme = new ColorScheme (); + tv.Redraw (tv.Bounds); // Normal drawing of the tree view TestHelpers.AssertDriverContentsAre( @@ -866,7 +866,7 @@ public void TestTreeViewColor() │ ├─pink │ └─normal └─pink -",output); +", output); // Should all be the same color TestHelpers.AssertDriverColorsAre( @"00000000 @@ -874,30 +874,29 @@ public void TestTreeViewColor() 0000000000 000000 ", - new []{tv.ColorScheme.Normal,pink}); + new [] { tv.ColorScheme.Normal, pink }); // create a new color scheme - var pinkScheme = new ColorScheme - { + var pinkScheme = new ColorScheme { Normal = pink, Focus = hotpink }; // and a delegate that uses the pink color scheme // for nodes "pink" - tv.ColorGetter = (n)=> n.Text.Equals("pink") ? pinkScheme : null; + tv.ColorGetter = (n) => n.Text.Equals ("pink") ? pinkScheme : null; // redraw now that the custom color // delegate is registered - tv.Redraw(tv.Bounds); - + tv.Redraw (tv.Bounds); + // Same text TestHelpers.AssertDriverContentsAre( @"├-normal │ ├─pink │ └─normal └─pink -",output); +", output); // but now the item (only not lines) appear // in pink when they are the word "pink" TestHelpers.AssertDriverColorsAre( @@ -906,7 +905,32 @@ public void TestTreeViewColor() 0000000000 001111 ", - new []{tv.ColorScheme.Normal,pink}); + new [] { tv.ColorScheme.Normal, pink }); + } + + [Fact, AutoInitShutdown] + public void DesiredCursorVisibility_MultiSelect () + { + var tv = new TreeView { Width = 20, Height = 10 }; + + var n1 = new TreeNode ("normal"); + var n2 = new TreeNode ("pink"); + tv.AddObject (n1); + tv.AddObject (n2); + + Application.Top.Add (tv); + Application.Begin (Application.Top); + + Assert.True (tv.MultiSelect); + Assert.True (tv.HasFocus); + Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility); + + tv.SelectAll (); + tv.DesiredCursorVisibility = CursorVisibility.Default; + Application.Refresh (); + Application.Driver.GetCursorVisibility (out CursorVisibility visibility); + Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility); + Assert.Equal (CursorVisibility.Default, visibility); } ///