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

Add the ability to remove nodes from a Tree #2510

Merged
merged 8 commits into from
May 8, 2023
Merged

Conversation

davep
Copy link
Contributor

@davep davep commented May 8, 2023

This PR adds two methods of removing nodes from a Tree, bother methods being on the nodes themselves (to match TreeNode.add and TreeNode.add_leaf. They are:

  • TreeNode.remove_children -- removes any children of the node, but leaves the node itself intact.
  • TreeNode.remove -- removes the node and any of its children.

Note that any attempt to remove the Tree.root will result in an exception being raised because the Textual Tree always expects to have a root.

As a convenience (used by this PR but not the point of this PR) this also adds TreeNode.is_root.

davep added 6 commits May 8, 2023 08:44
This is for removing an individual node, via the node. Note that attempting
to remove the root node of a Tree is an error and will case
TreeNode.RemoveRootError to be raised.

See Textualize#2462.
Up until now there wasn't really a way for the tree to go empty, outside of
clear/reset. Now that we can remove nodes on the fly, that is possible. This
takes that into account.

See Textualize#2462.
Sometimes the user may wish to delete a given node, other times it might be
a requirement to just remove the children (this will be especially useful
for Textualize#2448 where we'll want to keep the directory entry itself, but remove
and recreate its contents).

See Textualize#2462.
@davep davep added enhancement New feature or request Task labels May 8, 2023
@davep davep self-assigned this May 8, 2023
@davep davep marked this pull request as ready for review May 8, 2023 09:47
@davep davep merged commit c2a19bd into Textualize:main May 8, 2023
@davep davep deleted the chainsaw branch May 8, 2023 09:51
@davep davep linked an issue May 8, 2023 that may be closed by this pull request
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
Development

Successfully merging this pull request may close these issues.

Add the ability to remove Tree nodes
2 participants