Skip to content
Snippets Groups Projects
Commit 9e1499e5 authored by Anthropy's avatar Anthropy
Browse files

fix a bug with root_folder being different than the working dir of the script...

fix a bug with root_folder being different than the working dir of the script causing the todo to not open when doubleclicked on
parent f899c40a
Branches main
No related tags found
No related merge requests found
......@@ -10,32 +10,55 @@ from tkinter.scrolledtext import ScrolledText
from tkinter import simpledialog
class SymlinkTypeDialog(simpledialog.Dialog):
def body(self, master):
tk.Label(master, text="Select the type of symlink to create:").grid(row=0, padx=5, pady=5)
self.var = tk.StringVar(value="File")
tk.Radiobutton(master, text="File", variable=self.var, value="File").grid(row=1, column=0)
tk.Radiobutton(master, text="Folder", variable=self.var, value="Folder").grid(row=2, column=0)
return master # Return the frame to be focused
def apply(self):
self.result = self.var.get() # Set the result from the selected radio button
def create_symlink():
"""Creates a new symlink using the currently selected directory."""
selected_items = tree.selection()
if not selected_items:
messagebox.showerror("Error", "No directory selected.")
return
selected_items = tree.selection()
if not selected_items:
messagebox.showerror("Error", "No directory selected.")
return
selected_path = tree.item(selected_items[0], 'values')[0]
if os.path.isfile(selected_path):
selected_path = os.path.dirname(selected_path) # Use parent directory for files
selected_path = tree.item(selected_items[0], 'values')[0]
if os.path.isfile(selected_path):
selected_path = os.path.dirname(selected_path) # Use parent directory for files
source_path = filedialog.askopenfilename(title="Select Source File/Folder")
if not source_path:
return # Cancel if no source selected
dialog = SymlinkTypeDialog(root, title="Symlink Type")
if not dialog.result:
return # Cancel if no option was chosen
symlink_name = simpledialog.askstring("Symlink Name", "Enter symlink name:")
if not symlink_name:
return # Cancel if no name provided
if dialog.result == "File":
source_path = filedialog.askopenfilename(title="Select Source File")
else:
source_path = filedialog.askdirectory(title="Select Source Folder")
if not source_path:
return # Cancel if no source selected
symlink_name = simpledialog.askstring("Symlink Name", "Enter symlink name:")
if not symlink_name:
return # Cancel if no name provided
final_target_path = os.path.join(selected_path, symlink_name)
try:
os.symlink(source_path, final_target_path)
refresh_tree() # Refresh after creating the symlink
except Exception as e:
messagebox.showerror("Error", f"Failed to create symlink: {e}")
final_target_path = os.path.join(selected_path, symlink_name)
try:
os.symlink(source_path, final_target_path)
refresh_tree() # Refresh after creating the symlink
except Exception as e:
messagebox.showerror("Error", f"Failed to create symlink: {e}")
def open_symlink(event):
......@@ -118,7 +141,7 @@ def open_todo_file(event):
elif item_type == 'file':
file_path = todo_tree.item(selected_item)['text']
parent_item = todo_tree.parent(selected_item)
folder_path = todo_tree.item(parent_item)['text'] if parent_item else root_folder
folder_path = todo_tree.item(parent_item)['text'] if parent_item else ''
else:
messagebox.showinfo("Information", "Invalid selection.")
return
......@@ -126,9 +149,13 @@ def open_todo_file(event):
messagebox.showinfo("Information", "Missing item metadata.")
return
full_path = os.path.join(folder_path, file_path) if folder_path else file_path
# Construct the absolute path for file operations
if folder_path:
full_path = os.path.join(root_folder, folder_path, file_path)
else:
full_path = os.path.join(root_folder, file_path)
current_open_file_path = full_path
find_and_select_in_tree(full_path)
try:
with open(full_path, 'r') as file:
......@@ -143,6 +170,11 @@ def open_todo_file(event):
except Exception as e:
messagebox.showerror("Error", f"Failed to open the file: {full_path}\n{e}")
# Select the item in the tree using a relative path
relative_path = os.path.join(folder_path, file_path) if folder_path else file_path
find_and_select_in_tree(relative_path)
def open_file_with_default_app(event):
selection = tree.selection()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment