Fix API breakage from changes in textual 0.23.0

This commit is contained in:
Isaiah Odhner 2023-05-17 12:00:38 -04:00
parent 6a3ab712a5
commit 55419d671e
2 changed files with 7 additions and 8 deletions

View File

@ -23,8 +23,7 @@ class EnhancedDirectoryTree(DirectoryTree):
node = self.root
def get_node_name(node: TreeNode[DirEntry]) -> str:
assert node.data
return os.path.basename(node.data.path.rstrip(os.path.sep))
# return os.path.basename(node.data.path.rstrip("/\\"))
return os.path.basename(node.data.path)
for path_segment in target_path.split(os.path.sep):
# Find the child node with the right name.
for child in node.children:
@ -32,11 +31,11 @@ class EnhancedDirectoryTree(DirectoryTree):
node = child
break
if get_node_name(node) == path_segment:
assert node.data
if node.data.is_dir:
assert isinstance(node.data, DirEntry)
if node.data.path.is_dir():
if not node.is_expanded and not node.data.loaded:
# load_directory also calls node.expand()
self.load_directory(node)
self._load_directory(node)
else:
# Found a file.
break

View File

@ -85,11 +85,11 @@ class FileDialogWindow(DialogWindow):
DirectoryTree gives FileSelected, but only for files, not folders.
"""
assert event.node.data
if event.node.data.is_dir:
self._directory_tree_selected_path = event.node.data.path
if event.node.data.path.is_dir():
self._directory_tree_selected_path = str(event.node.data.path)
elif event.node.parent:
assert event.node.parent.data
self._directory_tree_selected_path = event.node.parent.data.path
self._directory_tree_selected_path = str(event.node.parent.data.path)
name = os.path.basename(event.node.data.path)
if not self._expanding_directory_tree:
self.query_one("FileDialogWindow .filename_input", Input).value = name