open folders
This commit is contained in:
11
home_page.py
11
home_page.py
@@ -45,15 +45,16 @@ class HomePage(Vertical):
|
|||||||
#bindings {
|
#bindings {
|
||||||
Horizontal {
|
Horizontal {
|
||||||
max-width: 50;
|
max-width: 50;
|
||||||
|
|
||||||
width: 50%;
|
width: 50%;
|
||||||
margin-top: 1;
|
margin-top: 1;
|
||||||
height: 1;
|
height: 1;
|
||||||
|
|
||||||
.bind-name {
|
.bind-name {
|
||||||
width: 85%;
|
width: 75%;
|
||||||
}
|
}
|
||||||
.bind-keys {
|
.bind-keys {
|
||||||
width: 15%;
|
width: 25%;
|
||||||
}
|
}
|
||||||
|
|
||||||
Static {
|
Static {
|
||||||
@@ -94,9 +95,13 @@ class HomePage(Vertical):
|
|||||||
yield Static(f"[@click=app.new]{binds["new"]}[/]", classes="bind-keys")
|
yield Static(f"[@click=app.new]{binds["new"]}[/]", classes="bind-keys")
|
||||||
|
|
||||||
with Horizontal():
|
with Horizontal():
|
||||||
yield Static("[b] Open file[/]", classes="bind-name")
|
yield Static("[b] Open file[/]", classes="bind-name")
|
||||||
yield Static(f"[@click=app.open]{binds["open"]}[/]", classes="bind-keys")
|
yield Static(f"[@click=app.open]{binds["open"]}[/]", classes="bind-keys")
|
||||||
|
|
||||||
|
with Horizontal():
|
||||||
|
yield Static("[b] Open Folder[/]", classes="bind-name")
|
||||||
|
yield Static(f"[@click=app.open_folder]{binds["open-folder"]}[/]", classes="bind-keys")
|
||||||
|
|
||||||
with Horizontal():
|
with Horizontal():
|
||||||
yield Static("[b] Settings[/]", classes="bind-name")
|
yield Static("[b] Settings[/]", classes="bind-name")
|
||||||
yield Static(f"[@click=app.settings]{binds["settings"]}[/]", classes="bind-keys")
|
yield Static(f"[@click=app.settings]{binds["settings"]}[/]", classes="bind-keys")
|
||||||
|
|||||||
31
main.py
31
main.py
@@ -4,7 +4,7 @@ from textual.containers import HorizontalGroup, Vertical
|
|||||||
from textual.binding import Binding
|
from textual.binding import Binding
|
||||||
from textual_window import Window
|
from textual_window import Window
|
||||||
from textual import on
|
from textual import on
|
||||||
from textual_fspicker import FileOpen, FileSave
|
from textual_fspicker import FileOpen, FileSave, SelectDirectory
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -37,16 +37,17 @@ class Berry(App):
|
|||||||
|
|
||||||
|
|
||||||
def __init__(self, path: str):
|
def __init__(self, path: str):
|
||||||
self.config_handler = ConfigHandler(self)
|
|
||||||
|
|
||||||
self.bindings = eval(self.config_handler.get("editor", "bindings"))
|
|
||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self.config_handler = ConfigHandler(self)
|
||||||
|
self.bindings = eval(self.config_handler.get("editor", "bindings"))
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
self.BINDINGS = (
|
self.BINDINGS = (
|
||||||
Binding(self.bindings["new"], "new", "New File"),
|
Binding(self.bindings["new"], "new", "New File"),
|
||||||
Binding(self.bindings["open"], "open", "Open 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"], "save", "Save File"),
|
||||||
Binding(self.bindings["save-as"], "save_as", "Save File As..."),
|
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
|
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):
|
def action_open(self):
|
||||||
self.app.push_screen(FileOpen(), self.chose_file_to_open)
|
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):
|
def action_find(self):
|
||||||
try:
|
try:
|
||||||
self.query_one("#find-window")
|
self.query_one("#find-window")
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ class ConfigHandler:
|
|||||||
self.config_dir: str = self.ensure_hidden_config_dir()
|
self.config_dir: str = self.ensure_hidden_config_dir()
|
||||||
self.load_settings()
|
self.load_settings()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def define_plugin_setting(self, plugin_name: str, option_name: str, description: str, option_type: str, default_value: Any, on_changed_func = None):
|
def define_plugin_setting(self, plugin_name: str, option_name: str, description: str, option_type: str, default_value: Any, on_changed_func = None):
|
||||||
actual_type = None
|
actual_type = None
|
||||||
if option_type == "boolean":
|
if option_type == "boolean":
|
||||||
@@ -88,10 +90,19 @@ class ConfigHandler:
|
|||||||
def load_settings(self):
|
def load_settings(self):
|
||||||
if os.path.isfile(self.config_dir / "config.ini"):
|
if os.path.isfile(self.config_dir / "config.ini"):
|
||||||
self.config.read(self.config_dir / "config.ini")
|
self.config.read(self.config_dir / "config.ini")
|
||||||
return
|
|
||||||
|
if int(self.get("config", "version")) < 2:
|
||||||
|
self.app.notify(
|
||||||
|
message="Your config version is out of date! We've loaded the defaults but your config is untouched.",
|
||||||
|
title="Config Version Outdated",
|
||||||
|
severity="warning",
|
||||||
|
timeout=15
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
self.config["config"] = {
|
self.config["config"] = {
|
||||||
"version": "1"
|
"version": "2"
|
||||||
}
|
}
|
||||||
self.config["editor"] = {
|
self.config["editor"] = {
|
||||||
"word_wrap": "0",
|
"word_wrap": "0",
|
||||||
@@ -99,6 +110,7 @@ class ConfigHandler:
|
|||||||
"default_editors": {},
|
"default_editors": {},
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"open": "ctrl+o",
|
"open": "ctrl+o",
|
||||||
|
"open-folder": "ctrl+shift+o",
|
||||||
"new": "ctrl+n",
|
"new": "ctrl+n",
|
||||||
"save": "ctrl+s",
|
"save": "ctrl+s",
|
||||||
"save-as": "ctrl+shift+s",
|
"save-as": "ctrl+shift+s",
|
||||||
|
|||||||
Reference in New Issue
Block a user