open folders
This commit is contained in:
31
main.py
31
main.py
@@ -4,7 +4,7 @@ from textual.containers import HorizontalGroup, Vertical
|
||||
from textual.binding import Binding
|
||||
from textual_window import Window
|
||||
from textual import on
|
||||
from textual_fspicker import FileOpen, FileSave
|
||||
from textual_fspicker import FileOpen, FileSave, SelectDirectory
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
@@ -37,16 +37,17 @@ class Berry(App):
|
||||
|
||||
|
||||
def __init__(self, path: str):
|
||||
self.config_handler = ConfigHandler(self)
|
||||
|
||||
self.bindings = eval(self.config_handler.get("editor", "bindings"))
|
||||
|
||||
super().__init__()
|
||||
self.config_handler = ConfigHandler(self)
|
||||
self.bindings = eval(self.config_handler.get("editor", "bindings"))
|
||||
self.path = path
|
||||
|
||||
self.BINDINGS = (
|
||||
Binding(self.bindings["new"], "new", "New File"),
|
||||
Binding(self.bindings["open"], "open", "Open File"),
|
||||
Binding(self.bindings["open-folder"], "open_folder", "Open Folder"),
|
||||
Binding(self.bindings["save"], "save", "Save File"),
|
||||
Binding(self.bindings["save-as"], "save_as", "Save File As..."),
|
||||
Binding(self.bindings["find"], "find", "Find and Replace", priority=True), # this is priority because otherwise TextArea overrides it
|
||||
@@ -161,6 +162,30 @@ class Berry(App):
|
||||
def action_open(self):
|
||||
self.app.push_screen(FileOpen(), self.chose_file_to_open)
|
||||
|
||||
async def choose_folder_to_open(self, result):
|
||||
if result == None: return
|
||||
|
||||
self.path = result
|
||||
|
||||
tabs: Tabs = self.query_one("#file-tabs")
|
||||
tabs.clear()
|
||||
|
||||
first_tab = Tab("Home")
|
||||
first_tab.file_path = "berry://home"
|
||||
self.file_tabs["berry://home"] = first_tab
|
||||
|
||||
tabs.add_tab(first_tab)
|
||||
|
||||
self.current_editor.remove_children()
|
||||
self.current_editor.mount(HomePage())
|
||||
|
||||
|
||||
file_tree: CustomDirectoryTree = self.query_one("#directory")
|
||||
file_tree.path = result
|
||||
|
||||
def action_open_folder(self):
|
||||
self.push_screen(SelectDirectory(), self.choose_folder_to_open)
|
||||
|
||||
def action_find(self):
|
||||
try:
|
||||
self.query_one("#find-window")
|
||||
|
||||
Reference in New Issue
Block a user