From 66ce2fed82a52044c6f30eb18be11dee58fea9fb Mon Sep 17 00:00:00 2001 From: SpookyDervish Date: Tue, 28 Jul 2026 15:59:58 +1000 Subject: [PATCH] add opening files --- new.txt | 1 + src/main.py | 8 +++++++- src/widgets/file_tabs.py | 10 +++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 new.txt diff --git a/new.txt b/new.txt new file mode 100644 index 0000000..6b584e8 --- /dev/null +++ b/new.txt @@ -0,0 +1 @@ +content \ No newline at end of file diff --git a/src/main.py b/src/main.py index 6b7748e..f76acbf 100644 --- a/src/main.py +++ b/src/main.py @@ -44,7 +44,7 @@ class Berry(App): Binding(self.bind_keys['open'], "open_file", "Open file"), Binding(self.bind_keys['open-folder'], "open_folder", "Open directory"), Binding(self.bind_keys['save'], "save", "Save"), - Binding(self.bind_keys['save-as'], "save_as", "Save as..."), + Binding(self.bind_keys['save-as'], "save_as", "Save as...", priority=True), Binding(self.bind_keys['home'], "home", "Home"), Binding(self.bind_keys['find'], "find", "Find and replace") ) @@ -67,6 +67,12 @@ class Berry(App): async def action_save(self): await self.file_tabs.save() + async def action_save_as(self): + await self.file_tabs.save_as() + + async def action_open_file(self): + await self.file_tabs.open_file_dialog() + async def action_new(self): await self.file_tabs.new_file() diff --git a/src/widgets/file_tabs.py b/src/widgets/file_tabs.py index 799d17c..d1c68a8 100644 --- a/src/widgets/file_tabs.py +++ b/src/widgets/file_tabs.py @@ -88,7 +88,7 @@ class FileTabs(TabbedContent): await self.remove_pane(self.active) for tab in self.query(TabPane): - if isinstance(self.active_pane, HomeTab): + if isinstance(tab, HomeTab): continue if tab.path == new_path: @@ -154,6 +154,14 @@ class FileTabs(TabbedContent): file_tab.saved = True + async def open_file_dialog(self): + async def callback(path: str | None): + if path == None: + return + await self.open_file(path) + + await self.app.push_screen(FileOpen(), callback=callback) + async def open_home(self) -> None: await self.add_pane(HomeTab())