From 9b9ac875cec08774a2f8a29c939cccc26983215a Mon Sep 17 00:00:00 2001 From: Vyshnav Vinod Date: Fri, 12 Apr 2024 18:03:28 +0530 Subject: [PATCH 1/2] Fix #287 --- .../views/sidebar/explorer/directorytree.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/biscuit/core/components/views/sidebar/explorer/directorytree.py b/biscuit/core/components/views/sidebar/explorer/directorytree.py index 666dacdc..5695528b 100644 --- a/biscuit/core/components/views/sidebar/explorer/directorytree.py +++ b/biscuit/core/components/views/sidebar/explorer/directorytree.py @@ -178,7 +178,25 @@ def new_file(self, filename) -> None: return parent = self.selected_directory() + + if not parent: + # This condition is necessary to avoid a edge case where the user might + # try to create a new file without a folder opened, causing self.selected_directory() + # to return None + + # TODO Let the user know that the file was not created because no folder was selected + + print("New file not created because user did not select a folder.") + return + path = os.path.join(parent, filename) + + if os.path.exists(path): + # If user tries to create a new file with the name of an existing file in that directory, + # open an editor for the existing file + self.base.open_editor(path) + return + with open(path, 'w+') as f: f.write("") self.create_root(parent, self.nodes[parent]) From d901395edc4509d7290aadf92df68bd1a6527e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Billy=20=E3=83=93=E3=83=AA=E3=82=A2=E3=83=A0?= Date: Sun, 14 Apr 2024 00:06:43 +0530 Subject: [PATCH 2/2] fix: Set directory to active directory or the working directory if no folder selected (new-file) --- .../views/sidebar/explorer/directorytree.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/biscuit/core/components/views/sidebar/explorer/directorytree.py b/biscuit/core/components/views/sidebar/explorer/directorytree.py index 5695528b..9f4502eb 100644 --- a/biscuit/core/components/views/sidebar/explorer/directorytree.py +++ b/biscuit/core/components/views/sidebar/explorer/directorytree.py @@ -177,23 +177,12 @@ def new_file(self, filename) -> None: if not filename: return - parent = self.selected_directory() - - if not parent: - # This condition is necessary to avoid a edge case where the user might - # try to create a new file without a folder opened, causing self.selected_directory() - # to return None - - # TODO Let the user know that the file was not created because no folder was selected - - print("New file not created because user did not select a folder.") - return - + parent = self.selected_directory() or self.base.active_directory or os.path.abspath('.') path = os.path.join(parent, filename) if os.path.exists(path): - # If user tries to create a new file with the name of an existing file in that directory, - # open an editor for the existing file + # If user tries to create a new file with the name of an existing file + # open that existing file in editor instead. self.base.open_editor(path) return