adasdasdasdasd Ctrl+O action
This commit is contained in:
43
main.py
43
main.py
@@ -4,10 +4,11 @@ from textual.containers import HorizontalGroup, Vertical
|
||||
from textual.binding import Binding
|
||||
from textual_window import Window
|
||||
from textual import on
|
||||
from assets.theme_mappings import theme_mappings
|
||||
|
||||
from textual_fspicker import FileOpen, FileSave
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from assets.theme_mappings import theme_mappings
|
||||
from plugin_loader import PluginLoader
|
||||
|
||||
from watchdog.observers import Observer
|
||||
@@ -97,6 +98,44 @@ class Berry(App):
|
||||
|
||||
self.query_one("#console-input").focus()
|
||||
|
||||
async def chose_file_to_open(self, result):
|
||||
if result == None: return
|
||||
result = str(result)
|
||||
if self.open_file == result:
|
||||
return
|
||||
|
||||
def is_within_directory(file_path: str, directory: str) -> bool:
|
||||
file_path = Path(file_path).resolve()
|
||||
directory = Path(directory).resolve()
|
||||
return directory in file_path.parents
|
||||
|
||||
self.switching = True
|
||||
|
||||
tabs: Tabs = self.query_one("#file-tabs")
|
||||
|
||||
if self.open_file not in self.unsaved_files:
|
||||
if self.open_file:
|
||||
self.file_tabs.pop(self.open_file)
|
||||
tabs.remove_tab(tabs.active_tab)
|
||||
|
||||
self.open_file = result
|
||||
inside_dir = is_within_directory(result, self.path)
|
||||
|
||||
self.sub_title = os.path.basename(self.open_file) if inside_dir else self.open_file
|
||||
|
||||
if result not in self.file_tabs:
|
||||
new_tab = Tab(os.path.basename(result) if inside_dir else result)
|
||||
new_tab.tooltip = str(new_tab.label)
|
||||
setattr(new_tab, "file_path", result)
|
||||
await tabs.add_tab(new_tab)
|
||||
self.file_tabs[result] = new_tab
|
||||
tabs.active = new_tab.id
|
||||
else:
|
||||
tabs.active = self.file_tabs[result].id
|
||||
|
||||
def action_open(self):
|
||||
self.app.push_screen(FileOpen(), self.chose_file_to_open)
|
||||
|
||||
def action_find(self):
|
||||
try:
|
||||
self.query_one("#find-window")
|
||||
|
||||
@@ -1,14 +1,3 @@
|
||||
local plugin = {}
|
||||
|
||||
function plugin.run()
|
||||
local window = berry.ui.createWindow("test window")
|
||||
berry.ui.app.mount(window)
|
||||
berry.ui.runOnEvent(window.Initialized, function()
|
||||
local test = berry.ui.createWidget("Static", "the absolute minimal experience")
|
||||
window.mount_in_window(test)
|
||||
end)
|
||||
|
||||
|
||||
end
|
||||
|
||||
return plugin
|
||||
Reference in New Issue
Block a user