mirror of
https://github.com/rivo/tview.git
synced 2026-04-27 05:45:49 +03:00
[GH-ISSUE #896] Add func (*TreeNode) GetParent #653
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#653
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @paololazzari on GitHub (Oct 4, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/896
Being able to get the parent of a given node would make traversing the tree much easier
@rivo commented on GitHub (Oct 5, 2023):
Can you give some details how this would help you in your specific application? There is
Walk()which is a public function, which also gives you parent information for each traversed node.@paololazzari commented on GitHub (Oct 5, 2023):
@rivo I have something similar to the demo here https://github.com/rivo/tview/tree/master/demos/treeview . When I press enter and a node which corresponds to a valid file is selected, I want to open that file in a textview. Opening the file for files within folders requires having the name of the parent nodes too
@rivo commented on GitHub (Oct 5, 2023):
Isn't your actual requirement then to get the entire path to the current node, not just to the parent? Like the breadcrumbs you see on many websites?
If so, a better solution would then be to provide a
GetPath(node *TreeNode) []*TreeNodemethod which gives you all nodes leading to your current node, starting at the root.What do you think?
@paololazzari commented on GitHub (Oct 5, 2023):
Yes, absolutely!
@paololazzari commented on GitHub (Oct 5, 2023):
Actually, this seems to be simple enough already. As long as the reference is set to the full path (as shown here then its trivial to get the full path of the selected node with
GetCurrentNode().GetReference().(string)@rivo commented on GitHub (Oct 5, 2023):
Well, I added the function (check out the latest commit) while I was travelling and offline so I only saw your message afterwards. But you are right, in the demo, the full path is stored as a reference object so it's available anyway.