Browse Source

IDesignable for TreeView

Tig 9 months ago
parent
commit
7315ff741a
1 changed files with 20 additions and 1 deletions
  1. 20 1
      Terminal.Gui/Views/TreeView/TreeView.cs

+ 20 - 1
Terminal.Gui/Views/TreeView/TreeView.cs

@@ -3,6 +3,7 @@
 // and code to be used in this library under the MIT license.
 // and code to be used in this library under the MIT license.
 
 
 using System.Collections.ObjectModel;
 using System.Collections.ObjectModel;
+using static Terminal.Gui.SpinnerStyle;
 
 
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
@@ -26,7 +27,7 @@ public interface ITreeView
 ///     Convenience implementation of generic <see cref="TreeView{T}"/> for any tree were all nodes implement
 ///     Convenience implementation of generic <see cref="TreeView{T}"/> for any tree were all nodes implement
 ///     <see cref="ITreeNode"/>. <a href="../docs/treeview.md">See TreeView Deep Dive for more information</a>.
 ///     <see cref="ITreeNode"/>. <a href="../docs/treeview.md">See TreeView Deep Dive for more information</a>.
 /// </summary>
 /// </summary>
-public class TreeView : TreeView<ITreeNode>
+public class TreeView : TreeView<ITreeNode>, IDesignable
 {
 {
     /// <summary>
     /// <summary>
     ///     Creates a new instance of the tree control with absolute positioning and initialises
     ///     Creates a new instance of the tree control with absolute positioning and initialises
@@ -39,6 +40,23 @@ public class TreeView : TreeView<ITreeNode>
         TreeBuilder = new TreeNodeBuilder ();
         TreeBuilder = new TreeNodeBuilder ();
         AspectGetter = o => o is null ? "Null" : o.Text ?? o?.ToString () ?? "Unnamed Node";
         AspectGetter = o => o is null ? "Null" : o.Text ?? o?.ToString () ?? "Unnamed Node";
     }
     }
+
+
+    bool IDesignable.EnableForDesign ()
+    {
+
+        var root1 = new TreeNode ("Root1");
+        root1.Children.Add (new TreeNode ("Child1.1"));
+        root1.Children.Add (new TreeNode ("Child1.2"));
+
+        var root2 = new TreeNode ("Root2");
+        root2.Children.Add (new TreeNode ("Child2.1"));
+        root2.Children.Add (new TreeNode ("Child2.2"));
+
+        AddObject (root1);
+        AddObject (root2);
+        return true;
+    }
 }
 }
 
 
 /// <summary>
 /// <summary>
@@ -1595,4 +1613,5 @@ internal class TreeSelection<T> where T : class
 
 
     public Branch<T> Origin { get; }
     public Branch<T> Origin { get; }
     public bool Contains (T model) { return included.Contains (model); }
     public bool Contains (T model) { return included.Contains (model); }
+
 }
 }