TreeNode.cs 1.6 KB

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