Browse Source

Added ShowExpandableSymbol option to toggle displaying '+' symbol

tznind 4 years ago
parent
commit
5c5d0eee0a
2 changed files with 15 additions and 3 deletions
  1. 7 2
      Terminal.Gui/Views/TreeView.cs
  2. 8 1
      UICatalog/Scenarios/TreeViewFileSystem.cs

+ 7 - 2
Terminal.Gui/Views/TreeView.cs

@@ -212,6 +212,11 @@ namespace Terminal.Gui {
 		/// <value></value>
 		public bool ShowBranchLines {get;set;} = true;
 
+		/// <summary>
+		/// True to render <see cref="ExpandableSymbol"/> next to branches that can be expanded.  Defaults to true
+		/// </summary>
+		public bool ShowExpandableSymbol {get;set;} = true;
+
 		/// <summary>
 		/// Determines how sub branches of the tree are dynamically built at runtime as the user expands root nodes
 		/// </summary>
@@ -800,7 +805,7 @@ namespace Terminal.Gui {
 			
 				//if there is a rapid method for determining whether there are children
 				if(tree.TreeBuilder.SupportsCanExpand) {
-					return tree.TreeBuilder.CanExpand(Model) ? tree.ExpandableSymbol : leafSymbol;
+					return tree.TreeBuilder.CanExpand(Model) && tree.ShowExpandableSymbol? tree.ExpandableSymbol : leafSymbol;
 				}
 				
 				//there is no way of knowing whether we can expand without fetching the children
@@ -808,7 +813,7 @@ namespace Terminal.Gui {
 			}
 
 			//we fetched or already know the children, so return whether we are a leaf or a expandable branch
-			return ChildBranches.Any() ? tree.ExpandableSymbol : leafSymbol;
+			return ChildBranches.Any() && tree.ShowExpandableSymbol? tree.ExpandableSymbol : leafSymbol;
 		}
 
 		/// <summary>

+ 8 - 1
UICatalog/Scenarios/TreeViewFileSystem.cs

@@ -29,6 +29,7 @@ namespace UICatalog.Scenarios {
 				}),
 				new MenuBarItem ("_View", new MenuItem [] {
 					new MenuItem ("_ShowLines", "", () => ShowLines()),
+					new MenuItem ("_ShowExpandableSymbol", "", () => ShowExpandableSymbol()),
 				}),
 			});
 			Top.Add (menu);
@@ -62,12 +63,18 @@ namespace UICatalog.Scenarios {
 			Win.Add (_treeView);
 		}
 
+
 		private void ShowLines ()
 		{
 			_treeView.ShowBranchLines = !_treeView.ShowBranchLines;
 			_treeView.SetNeedsDisplay();
 		}
-
+		
+		private void ShowExpandableSymbol ()
+		{
+			_treeView.ShowExpandableSymbol = !_treeView.ShowExpandableSymbol;
+			_treeView.SetNeedsDisplay();
+		}
 		/// <summary>
 		/// Sets up children getter delegates that return subfolders/files from directories
 		/// </summary>