mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add the node to the FileSelected message
Until now it wasn't really possible to know *which* DirectoryTree widget had sent a given message; this makes it available by providing the `node`, which in turn will provide the `tree`.
This commit is contained in:
@@ -64,11 +64,16 @@ class DirectoryTree(Tree[DirEntry]):
|
|||||||
`DirectoryTree` or in a parent widget in the DOM.
|
`DirectoryTree` or in a parent widget in the DOM.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, path: Path) -> None:
|
def __init__(self, node: TreeNode[DirEntry], path: Path) -> None:
|
||||||
|
"""Initialise the FileSelected object.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
node: The tree node for the file that was selected.
|
||||||
|
path: The path of the file that was selected.
|
||||||
|
"""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
# TODO: Add the node here too to mimic what Tree provides.
|
self.node: TreeNode[DirEntry] = node
|
||||||
# Without it there's no sensible way of knowing which tree sent
|
"""The tree node of the file that was selected."""
|
||||||
# the message.
|
|
||||||
self.path: Path = path
|
self.path: Path = path
|
||||||
"""The path of the file that was selected."""
|
"""The path of the file that was selected."""
|
||||||
|
|
||||||
@@ -216,7 +221,7 @@ class DirectoryTree(Tree[DirEntry]):
|
|||||||
if not dir_entry.loaded:
|
if not dir_entry.loaded:
|
||||||
self._load_directory(event.node)
|
self._load_directory(event.node)
|
||||||
else:
|
else:
|
||||||
self.post_message(self.FileSelected(dir_entry.path))
|
self.post_message(self.FileSelected(event.node, dir_entry.path))
|
||||||
|
|
||||||
def _on_tree_node_selected(self, event: Tree.NodeSelected) -> None:
|
def _on_tree_node_selected(self, event: Tree.NodeSelected) -> None:
|
||||||
event.stop()
|
event.stop()
|
||||||
@@ -224,4 +229,4 @@ class DirectoryTree(Tree[DirEntry]):
|
|||||||
if dir_entry is None:
|
if dir_entry is None:
|
||||||
return
|
return
|
||||||
if not dir_entry.path.is_dir():
|
if not dir_entry.path.is_dir():
|
||||||
self.post_message(self.FileSelected(dir_entry.path))
|
self.post_message(self.FileSelected(event.node, dir_entry.path))
|
||||||
|
|||||||
Reference in New Issue
Block a user