TreeNode.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #nullable disable
  2. namespace Terminal.Gui.Views;
  3. /// <summary>
  4. /// Interface to implement when you want the regular (non-generic) <see cref="TreeView"/> to automatically
  5. /// determine children for your class (without having to specify an <see cref="ITreeBuilder{T}"/>)
  6. /// </summary>
  7. public interface ITreeNode
  8. {
  9. /// <summary>The children of your class which should be rendered underneath it when expanded</summary>
  10. /// <value></value>
  11. IList<ITreeNode> Children { get; }
  12. /// <summary>Optionally allows you to store some custom data/class here.</summary>
  13. object Tag { get; set; }
  14. /// <summary>Text to display when rendering the node</summary>
  15. string Text { get; set; }
  16. }
  17. /// <summary>Simple class for representing nodes, use with regular (non-generic) <see cref="TreeView"/>.</summary>
  18. public class TreeNode : ITreeNode
  19. {
  20. /// <summary>Initialises a new instance with no <see cref="Text"/></summary>
  21. public TreeNode () { }
  22. /// <summary>Initialises a new instance and sets starting <see cref="Text"/></summary>
  23. public TreeNode (string text) { Text = text; }
  24. /// <summary>Children of the current node</summary>
  25. /// <returns></returns>
  26. public virtual IList<ITreeNode> Children { get; set; } = new List<ITreeNode> ();
  27. /// <summary>Text to display in tree node for current entry</summary>
  28. /// <value></value>
  29. public virtual string Text { get; set; }
  30. /// <summary>Optionally allows you to store some custom data/class here.</summary>
  31. public object Tag { get; set; }
  32. /// <summary>returns <see cref="Text"/></summary>
  33. /// <returns></returns>
  34. public override string ToString () { return Text ?? "Unnamed Node"; }
  35. }