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

Refreshing the DirectoryTree without resetting the selected node. #3574

Closed
JoeZiminski opened this issue Oct 23, 2023 · 6 comments
Closed

Refreshing the DirectoryTree without resetting the selected node. #3574

JoeZiminski opened this issue Oct 23, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@JoeZiminski
Copy link

We are really enjoying using the textual for our project and are impressed with its ease of use and powerful features.

Currently we have a DirectoryTree widget that is integral to the project. If a file or folder is deleted through the filesystem (i.e. not through our application), we would like to ensure the DirectoryTree in the app is refreshed to reflect this.

Currently the reload function serves this purpose, and it is sufficient for us to call every now and then (e.g. when a file or folder is clicked on the DirectoryTree). However, the only problem is that the reload function moves the currently selected folder back to the root folder. Is there a way to call reload() without changing the currently selected folder, and avoid having the dropdown structure of entire tree reset?

@willmcgugan
Copy link
Collaborator

willmcgugan commented Oct 23, 2023

Polling the filesystem can be quite inefficient. A better approach might be to use watchdog which uses an OS level API to get notifications when the filesystem changed.

Either way though, I think an incremental reload is a good idea.

@Textualize Textualize deleted a comment from github-actions bot Oct 23, 2023
@davep
Copy link
Contributor

davep commented Oct 24, 2023

@darrenburns darrenburns self-assigned this Oct 24, 2023
@darrenburns
Copy link
Member

How do you actually use reload_node though if you want to reload a node other than the one under the cursor?

Do we need a mechanism for "given a path contained within the tree, return the corresponding TreeNode"?

I can see that on Tree we have a get_node_by_id, but the IDs of the nodes in DirectoryTree seem to be integers. Perhaps the node IDs should the paths?

@JoeZiminski
Copy link
Author

Thanks a lot, I did not know about watchdog that is very useful.

For our case, partial refreshing of the DirectoryTree is nice. However the primary change that would be useful for us is to maintain the currently selected node after refreshing the entire directory tree. At present, if I understand correctly on a reload the gui is set back to the root node being selected - so the user must manually click to return to the node they had selected.

If it is possible, it would be nice to add an option such that the DirectoryTree is reloaded such that the currently selected node is not set back to root.

@willmcgugan
Copy link
Collaborator

Replaced with #4056

Copy link

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants