From cbcf22c4d7fb7692c3b54859cc39f7825b999fca Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Fri, 14 Jul 2023 20:46:35 -0400 Subject: [PATCH] Clean up old _expanding_directory_tree flag, and logging --- src/textual_paint/enhanced_directory_tree.py | 6 +++--- src/textual_paint/file_dialogs.py | 19 ++----------------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/textual_paint/enhanced_directory_tree.py b/src/textual_paint/enhanced_directory_tree.py index 16d5ca7..744b7a9 100644 --- a/src/textual_paint/enhanced_directory_tree.py +++ b/src/textual_paint/enhanced_directory_tree.py @@ -25,7 +25,7 @@ class EnhancedDirectoryTree(DirectoryTree): """Scroll to the node, and select it.""" def _go_to_node_now(): - print("set flag") + # print("set flag") self.node_highlighted_by_expand_to_path = True self.select_node(node) # def clear_flag() -> None: @@ -60,9 +60,9 @@ class EnhancedDirectoryTree(DirectoryTree): This handler is used to clear the flag set by expand_to_path. See _go_to_node for more details. """ - print("EnhancedDirectoryTree.on_tree_node_highlighted (queue clearing flag)") + # print("EnhancedDirectoryTree.on_tree_node_highlighted (queue clearing flag)") def clear_flag() -> None: - print("clear flag") + # print("clear flag") self.node_highlighted_by_expand_to_path = False # Now that we've received the NodeHighlighted event, # we just need to wait for subclasses/parent widgets to handle it, diff --git a/src/textual_paint/file_dialogs.py b/src/textual_paint/file_dialogs.py index 18d8d3e..f5aa71d 100644 --- a/src/textual_paint/file_dialogs.py +++ b/src/textual_paint/file_dialogs.py @@ -39,9 +39,6 @@ class FileDialogWindow(DialogWindow): self._directory_tree_selected_path: str | None = None """Last highlighted item in the directory tree""" - self._expanding_directory_tree: bool = False - """Flag to prevent setting the filename input when initially expanding the directory tree""" - self._auto_add_default_extension: str = auto_add_default_extension """The default extension to add to the filename if it doesn't have one""" @@ -115,13 +112,7 @@ class FileDialogWindow(DialogWindow): self._directory_tree_selected_path = str(event.node.parent.data.path) name = os.path.basename(event.node.data.path) assert isinstance(event.control, EnhancedDirectoryTree) - print( - "self._expanding_directory_tree", - self._expanding_directory_tree, - "event.control.node_highlighted_by_expand_to_path", - event.control.node_highlighted_by_expand_to_path - ) - # if not self._expanding_directory_tree: + # print("node_highlighted_by_expand_to_path", event.control.node_highlighted_by_expand_to_path) if not event.control.node_highlighted_by_expand_to_path: # TODO: handle NoMatches if dialog is opened and closed immediately # such as by spamming Ctrl+O @@ -132,14 +123,8 @@ class FileDialogWindow(DialogWindow): def _expand_directory_tree(self) -> None: """Expand the directory tree to the target directory, either the folder of the open file or the current working directory.""" tree = self.content.query_one(EnhancedDirectoryTree) - self._expanding_directory_tree = True target_dir = (self._selected_file_path or os.getcwd()).rstrip(os.path.sep) - # Tree expansion is asynchronous because it loads folder contents in a worker. - def done_expanding(): - # In expand_to_path, once all the folders are expanded, it will select the target node. - # The _expanding_directory_tree flag is for avoiding responding to that automatic initial selection. - self._expanding_directory_tree = False - tree.expand_to_path(target_dir, done_expanding) + tree.expand_to_path(target_dir) class OpenDialogWindow(FileDialogWindow): """A dialog window that lets the user select a file to open.