Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tree] Allow for the complete repopulation of a Tree. #1437

Closed
davep opened this issue Dec 24, 2022 · 3 comments · Fixed by #1709
Closed

[Tree] Allow for the complete repopulation of a Tree. #1437

davep opened this issue Dec 24, 2022 · 3 comments · Fixed by #1709
Assignees
Labels
enhancement New feature or request Task

Comments

@davep
Copy link
Contributor

davep commented Dec 24, 2022

Slightly related to #1396 in that to do it now the ability to change a TreeNode.label would be required. At the moment it is possible to use Tree.clear to clear all the nodes under the root node, but there appears to be no public interface for totally clearing a Tree and repopulating it from scratch -- other that performing a remove on the widget itself and then a mount of a fresh instance.

A use case for this would be if the Tree is being used to view the content of a file in a structured way, and you want the user to be able to load in a new file.

@davep davep added the enhancement New feature or request label Dec 24, 2022
@github-actions
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

Maybe add a root label option to clear()

@willmcgugan willmcgugan changed the title Consider allowing for the complete repopulation of a Tree. [Tree] Consider allowing for the complete repopulation of a Tree. Jan 19, 2023
@davep davep added the Task label Feb 1, 2023
@davep davep changed the title [Tree] Consider allowing for the complete repopulation of a Tree. [Tree] Allow for the complete repopulation of a Tree. Feb 1, 2023
davep added a commit to davep/textual that referenced this issue Feb 1, 2023
See Textualize#1437 for background. While it would be ideal to allow for the complete
emptying of a Tree, the root node is required (and it's part of the
construction of a Tree). So, here, when clearing the Tree we optionally
allow for a new label to be given.

Ideally we'll also allow for fresh data to be provided too; but there's a
wrinkle there in knowing the difference between the data being None, and no
data being provided (so the current root's data being carried over).
Following the method of defaulting used in __init__ would cause problems. As
such, rather than roll all of this into one commit, this goes with the basic
requirement and the solution for data will follow.

Note this also starts some unit tests for the clearing of a Tree.
@github-actions
Copy link

github-actions bot commented Feb 1, 2023

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Task
Projects
None yet
2 participants