implemented more right click options
This commit is contained in:
@@ -19,6 +19,9 @@ class CustomDirectoryTree(DirectoryTree):
|
||||
if result == "Delete":
|
||||
def delete_confirm(will_delete: bool | None):
|
||||
if will_delete == True:
|
||||
if os.path.isfile(self.right_clicked_node.data.path):
|
||||
os.remove(self.right_clicked_node.data.path)
|
||||
else:
|
||||
shutil.rmtree(self.right_clicked_node.data.path)
|
||||
self.reload()
|
||||
|
||||
@@ -29,6 +32,9 @@ class CustomDirectoryTree(DirectoryTree):
|
||||
elif result == "Rename":
|
||||
def rename_confirm(new_name: str | None):
|
||||
if new_name == None: return
|
||||
if new_name.strip() == "":
|
||||
self.notify("Filename can't be empty.", title="Failed to rename", severity="error")
|
||||
return
|
||||
|
||||
os.rename(self.right_clicked_node.data.path, os.path.join(os.path.dirname(self.right_clicked_node.data.path), new_name))
|
||||
self.reload()
|
||||
@@ -38,6 +44,44 @@ class CustomDirectoryTree(DirectoryTree):
|
||||
self.right_clicked_node = None
|
||||
|
||||
self.app.push_screen(Prompt(f"Enter the new name for \"{self.right_clicked_node.label}\".", "string", "Rename"), rename_confirm)
|
||||
elif result == "New Folder":
|
||||
def new_folder(folder_name: str | None):
|
||||
if folder_name == None: return
|
||||
if folder_name.strip() == "":
|
||||
self.notify("Folder name can't be empty.", title="Failed to create folder", severity="error")
|
||||
return
|
||||
|
||||
new_folder_path = os.path.join(self.right_clicked_node.data.path, folder_name)
|
||||
try:
|
||||
os.mkdir(new_folder_path)
|
||||
self.reload()
|
||||
except Exception as e:
|
||||
self.notify(str(e), title="Failed to create folder", severity="error")
|
||||
return
|
||||
|
||||
self.app.push_screen(Prompt("Enter the name of the new folder.", "string", "Create New Folder"), new_folder)
|
||||
elif result == "New File":
|
||||
def new_file(file_name: str | None):
|
||||
if file_name == None: return
|
||||
if file_name.strip() == "":
|
||||
self.notify("File name can't be empty.", title="Failed to create file", severity="error")
|
||||
return
|
||||
|
||||
new_file_path = os.path.join(self.right_clicked_node.data.path, file_name)
|
||||
|
||||
if os.path.isfile(new_file_path):
|
||||
self.notify("That file already exists.", title="Failed to create file", severity="error")
|
||||
return
|
||||
|
||||
try:
|
||||
with open(new_file_path, "w") as f:
|
||||
pass
|
||||
self.reload()
|
||||
except Exception as e:
|
||||
self.notify(str(e), title="Failed to create file", severity="error")
|
||||
return
|
||||
|
||||
self.app.push_screen(Prompt("Enter the name of the new file", "string", "Create New File"), new_file)
|
||||
|
||||
def on_mouse_down(self, event: MouseDown):
|
||||
if event.button != 3 or not "line" in event.style.meta:
|
||||
|
||||
@@ -182,6 +182,7 @@ class PluginLoader(Window):
|
||||
no_errors = False
|
||||
continue
|
||||
|
||||
try:
|
||||
if executed_code.run:
|
||||
try:
|
||||
executed_code.run()
|
||||
@@ -190,6 +191,11 @@ class PluginLoader(Window):
|
||||
self.notify("A plugin has created an error. Check the log for more details.", title="Lua Error", severity="error", timeout=10)
|
||||
no_errors = False
|
||||
continue
|
||||
except:
|
||||
log.write(f"[b red]Error in {lua_file_path}: file returned invalid value, you should only return a table.")
|
||||
self.notify("A plugin has created an error. Check the log for more details.", title="Lua Error", severity="error", timeout=10)
|
||||
no_errors = False
|
||||
continue
|
||||
|
||||
plugin_paths.append(plugin_folder)
|
||||
|
||||
|
||||
7
plugins/my plugin/lua/main.lua
Normal file
7
plugins/my plugin/lua/main.lua
Normal file
@@ -0,0 +1,7 @@
|
||||
local plugin = {}
|
||||
|
||||
function plugin.run()
|
||||
berry.config.defineSetting("my plugin", "test setting", "description", "boolean", "1")
|
||||
end
|
||||
|
||||
return plugin
|
||||
6
plugins/my plugin/plugin.json
Normal file
6
plugins/my plugin/plugin.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "my plugin",
|
||||
"author": "SpookyDervish",
|
||||
"version": "1.0.0",
|
||||
"dependencies": []
|
||||
}
|
||||
Reference in New Issue
Block a user