commit 65

This commit is contained in:
2025-08-07 16:16:07 +02:00
parent b1bd928a76
commit e5d10dded6
4 changed files with 60 additions and 82 deletions

View File

@@ -342,30 +342,27 @@ class WidgetManager:
self.action_status_frame.grid_columnconfigure(1, weight=1)
self.action_status_frame.grid_rowconfigure(0, weight=1)
self.left_container.grid(row=0, column=0, sticky='nsw', pady=(5,0))
self.center_container.grid(row=0, column=1, sticky='nsew', padx=5, pady=(5,0))
self.right_container.grid(row=0, column=2, sticky='nse', pady=(5,0))
self.left_container.grid(row=0, column=0, sticky='nsw', pady=(5, 0))
self.center_container.grid(row=0, column=1, sticky='nsew', padx=5, pady=(5, 0))
self.right_container.grid(row=0, column=2, sticky='nse', pady=(5, 0))
self.separator_color = "#a9a9a9" if self.style_manager.is_dark else "#7c7c7c"
self.separator = tk.Frame(self.action_status_frame, height=1, bg=self.separator_color)
self.separator.grid(row=1, column=0, columnspan=3, sticky="ew", pady=(4,0))
self.separator.grid(row=1, column=0, columnspan=3, sticky="ew", pady=(4, 0))
self.status_container.grid(row=2, column=0, columnspan=3, sticky='ew')
# --- Define Widgets ---
self.search_status_label = ttk.Label(self.status_container, text="", style="AccentBottom.TLabel")
self.status_bar = ttk.Label(self.center_container, text="", anchor="w", style="AccentBottom.TLabel")
self.search_entry = ttk.Entry(self.center_container)
self.filename_entry = ttk.Entry(self.center_container)
self.settings_button = ttk.Button(self.action_status_frame, image=self.dialog.icon_manager.get_icon('settings-2_small'),
command=self.dialog.open_settings_dialog, style="Bottom.TButton.Borderless.Round")
self.trash_button = ttk.Button(self.action_status_frame, image=self.dialog.icon_manager.get_icon('trash_small2'),
command=self.dialog.delete_selected_item, style="Bottom.TButton.Borderless.Round")
Tooltip(self.trash_button, "Ausgewähltes Element löschen/verschieben")
button_box_pos = self.settings.get("button_box_pos", "left")
if self.dialog.dialog_mode == "save":
self.filename_entry = ttk.Entry(self.center_container)
self.trash_button = ttk.Button(self.action_status_frame, image=self.dialog.icon_manager.get_icon('trash_small2'),
command=self.dialog.delete_selected_item, style="Bottom.TButton.Borderless.Round")
Tooltip(self.trash_button, "Ausgewähltes Element löschen/verschieben")
self.save_button = ttk.Button(self.action_status_frame, text="Speichern", command=self.dialog.on_save)
self.cancel_button = ttk.Button(self.action_status_frame, text="Abbrechen", command=self.dialog.on_cancel)
self.filter_combobox = ttk.Combobox(self.center_container, values=[ft[0] for ft in self.dialog.filetypes], state="readonly")
@@ -387,9 +384,7 @@ class WidgetManager:
self.filter_combobox.set(self.dialog.filetypes[0][0])
self.center_container.grid_rowconfigure(0, weight=1)
self.status_bar.grid(row=0, column=0, columnspan=2, sticky="ew")
self.search_entry.grid(row=0, column=0, columnspan=2, sticky="ew")
self.search_entry.grid_forget()
self.filename_entry.grid(row=0, column=0, columnspan=2, sticky="ew")
if button_box_pos == 'left':
self._layout_open_buttons_left()
@@ -402,27 +397,26 @@ class WidgetManager:
self.cancel_button.grid(in_=self.left_container, row=1, column=0)
self.center_container.grid_columnconfigure(0, weight=1)
self.filter_combobox.grid(in_=self.center_container, row=1, column=0, sticky="w", pady=(5,0))
self.search_status_label.grid(row=0, column=0, sticky="w", pady=(5,0), padx=(5,0))
self.filter_combobox.grid(in_=self.center_container, row=1, column=0, sticky="w", pady=(5, 0))
self.search_status_label.grid(row=0, column=0, sticky="w", pady=(5, 0), padx=(5, 0))
self.right_container.grid_rowconfigure(0, weight=1)
self.settings_button.grid(in_=self.right_container, row=0, column=0, sticky="se")
self.trash_button.grid(in_=self.right_container, row=1, column=0, sticky="se", padx=(5,0))
self.trash_button.grid(in_=self.right_container, row=1, column=0, sticky="se", padx=(5, 0))
def _layout_save_buttons_right(self):
self.right_container.grid_rowconfigure(0, weight=1)
self.left_container.grid_rowconfigure(0, weight=1)
self.save_button.grid(in_=self.right_container, row=0, column=0, pady=(0, 5))
self.cancel_button.grid(in_=self.right_container, row=1, column=0)
self.settings_button.grid(in_=self.right_container, row=0, column=1, sticky="ne", padx=(5,0))
self.settings_button.grid(in_=self.right_container, row=0, column=1, sticky="ne", padx=(5, 0))
self.left_container.grid_rowconfigure(0, weight=1)
self.trash_button.grid(in_=self.left_container, row=0, column=0, sticky="sw")
self.center_container.grid_columnconfigure(1, weight=1)
self.filter_combobox.grid(in_=self.center_container, row=1, column=1, sticky="e", pady=(5,0))
self.search_status_label.grid(row=0, column=0, sticky="w", pady=(5,0), padx=(5,0))
self.filter_combobox.grid(in_=self.center_container, row=1, column=1, sticky="e", pady=(5, 0))
self.search_status_label.grid(row=0, column=0, sticky="w", pady=(5, 0), padx=(5, 0))
def _layout_open_buttons_left(self):
self.left_container.grid_rowconfigure(0, weight=1)
@@ -430,8 +424,8 @@ class WidgetManager:
self.cancel_button.grid(in_=self.left_container, row=1, column=0)
self.center_container.grid_columnconfigure(0, weight=1)
self.filter_combobox.grid(in_=self.center_container, row=1, column=0, sticky="w", pady=(5,0))
self.search_status_label.grid(row=0, column=1, sticky="w", pady=(5,0), padx=(5,0))
self.filter_combobox.grid(in_=self.center_container, row=1, column=0, sticky="w", pady=(5, 0))
self.search_status_label.grid(row=0, column=0, sticky="w", pady=(5, 0), padx=(5, 0))
self.right_container.grid_rowconfigure(0, weight=1)
self.settings_button.grid(in_=self.right_container, row=0, column=0, sticky="ne")
@@ -440,13 +434,13 @@ class WidgetManager:
self.right_container.grid_rowconfigure(0, weight=1)
self.open_button.grid(in_=self.right_container, row=0, column=0, pady=(0, 5))
self.cancel_button.grid(in_=self.right_container, row=1, column=0)
self.settings_button.grid(in_=self.right_container, row=0, column=1, sticky="ne", padx=(5,0))
self.settings_button.grid(in_=self.right_container, row=0, column=1, sticky="ne", padx=(5, 0))
self.left_container.grid_rowconfigure(0, weight=1)
self.center_container.grid_columnconfigure(1, weight=1)
self.filter_combobox.grid(in_=self.center_container, row=1, column=1, sticky="e", pady=(5,0))
self.search_status_label.grid(row=0, column=0, sticky="w", pady=(5,0), padx=(5,0))
self.filter_combobox.grid(in_=self.center_container, row=1, column=1, sticky="e", pady=(5, 0))
self.search_status_label.grid(row=0, column=0, sticky="w", pady=(5, 0), padx=(5, 0))

View File

@@ -241,37 +241,28 @@ class CustomFileDialog(tk.Toplevel):
return
self.search_mode = True
if self.dialog_mode == "open":
self.widget_manager.status_bar.grid_remove()
self.widget_manager.search_entry.grid(row=1, column=0, sticky="ew", in_=self.widget_manager.center_container)
self.widget_manager.center_container.grid_rowconfigure(1, weight=0)
self.widget_manager.search_entry.focus_set()
self.widget_manager.search_entry.insert(0, event.char)
self.widget_manager.search_entry.bind("<Return>", self.execute_search)
self.widget_manager.search_entry.bind("<Escape>", self.hide_search_bar)
else: # save mode
self.widget_manager.filename_entry.focus_set()
self.widget_manager.filename_entry.insert(tk.END, event.char)
self.widget_manager.filename_entry.bind("<Return>", self.execute_search)
self.widget_manager.filename_entry.bind("<Escape>", self.hide_search_bar)
self.widget_manager.filename_entry.focus_set()
# Clear the field before inserting the new character to start a fresh search
self.widget_manager.filename_entry.delete(0, tk.END)
self.widget_manager.filename_entry.insert(0, event.char)
self.widget_manager.filename_entry.bind("<Return>", self.execute_search)
self.widget_manager.filename_entry.bind("<Escape>", self.hide_search_bar)
def hide_search_bar(self, event=None):
self.search_mode = False
if self.dialog_mode == "open":
self.widget_manager.search_entry.grid_forget()
self.widget_manager.status_bar.grid(row=1, column=0, sticky="ew", in_=self.widget_manager.center_container)
self.widget_manager.center_container.grid_rowconfigure(1, weight=0)
self.widget_manager.search_entry.delete(0, tk.END)
else: # save mode
self.widget_manager.filename_entry.delete(0, tk.END)
self.widget_manager.filename_entry.delete(0, tk.END)
self.widget_manager.search_status_label.config(text="")
# Unbind search-specific events to restore normal behavior
self.widget_manager.filename_entry.unbind("<Return>")
self.widget_manager.filename_entry.unbind("<Escape>")
# Re-bind the default save action for the save dialog
if self.dialog_mode == "save":
self.widget_manager.filename_entry.bind("<Return>", lambda e: self.on_save())
self.populate_files()
def toggle_search_mode(self, event=None):
if self.search_mode:
self.hide_search_bar(event)
else:
self.show_search_bar(event)
# This method might not be needed anymore if search is always active in the entry
pass
def handle_path_entry_return(self, event):
"""Handles the Enter key in the path entry to navigate.
@@ -517,10 +508,7 @@ class CustomFileDialog(tk.Toplevel):
def execute_search(self, event=None):
if self.dialog_mode == "open":
search_term = self.widget_manager.search_entry.get().strip()
else:
search_term = self.widget_manager.filename_entry.get().strip()
search_term = self.widget_manager.filename_entry.get().strip()
if not search_term:
self.hide_search_bar()
@@ -714,20 +702,19 @@ class CustomFileDialog(tk.Toplevel):
directory = item['values'][0]
full_path = os.path.join(directory, filename)
# Update status bar
# Update status bar with details
try:
stat = os.stat(full_path)
size_str = self._format_size(stat.st_size)
self.widget_manager.status_bar.config(
self.widget_manager.search_status_label.config(
text=f"'{filename}' Größe: {size_str}")
except (FileNotFoundError, PermissionError):
self.widget_manager.status_bar.config(
self.widget_manager.search_status_label.config(
text=f"'{filename}' nicht zugänglich")
# If in save mode, update filename entry
if self.dialog_mode == "save":
self.widget_manager.filename_entry.delete(0, tk.END)
self.widget_manager.filename_entry.insert(0, filename)
# Update filename entry
self.widget_manager.filename_entry.delete(0, tk.END)
self.widget_manager.filename_entry.insert(0, filename)
search_tree.bind("<<TreeviewSelect>>", on_search_select)
@@ -909,7 +896,7 @@ class CustomFileDialog(tk.Toplevel):
widget.bind("<Button-5>", _on_mouse_wheel)
if warning:
self.widget_manager.status_bar.config(text=warning)
self.widget_manager.search_status_label.config(text=warning)
if error:
ttk.Label(container_frame, text=error).pack(pady=20)
return
@@ -1051,7 +1038,7 @@ class CustomFileDialog(tk.Toplevel):
self.tree.bind("<ButtonRelease-3>", self.on_list_context_menu)
if warning:
self.widget_manager.status_bar.config(text=warning)
self.widget_manager.search_status_label.config(text=warning)
if error:
self.tree.insert("", "end", text=error, values=())
return
@@ -1113,12 +1100,9 @@ class CustomFileDialog(tk.Toplevel):
self.selected_item_frame = item_frame
self.selected_file = path
self.update_status_bar(path) # Pass selected path
self.bind("<F2>", lambda e, p=path,
f=item_frame: self.on_rename_request(e, p, f))
if self.dialog_mode == "save" and not os.path.isdir(path):
if not os.path.isdir(path):
self.widget_manager.filename_entry.delete(0, tk.END)
self.widget_manager.filename_entry.insert(
0, os.path.basename(path))
self.widget_manager.filename_entry.insert(0, os.path.basename(path))
def on_list_select(self, event):
if not self.tree.selection():
@@ -1128,7 +1112,7 @@ class CustomFileDialog(tk.Toplevel):
path = os.path.join(self.current_dir, item_text)
self.selected_file = path
self.update_status_bar(path) # Pass selected path
if self.dialog_mode == "save" and not os.path.isdir(self.selected_file):
if not os.path.isdir(self.selected_file):
self.widget_manager.filename_entry.delete(0, tk.END)
self.widget_manager.filename_entry.insert(0, item_text)
@@ -1195,11 +1179,11 @@ class CustomFileDialog(tk.Toplevel):
real_path = os.path.realpath(
os.path.abspath(os.path.expanduser(path)))
if not os.path.isdir(real_path):
self.widget_manager.status_bar.config(
self.widget_manager.search_status_label.config(
text=f"Fehler: Verzeichnis '{os.path.basename(path)}' nicht gefunden.")
return
if not os.access(real_path, os.R_OK):
self.widget_manager.status_bar.config(
self.widget_manager.search_status_label.config(
text=f"Zugriff auf '{os.path.basename(path)}' verweigert.")
return
self.current_dir = real_path
@@ -1213,7 +1197,7 @@ class CustomFileDialog(tk.Toplevel):
self.update_status_bar()
self.update_action_buttons_state()
except Exception as e:
self.widget_manager.status_bar.config(text=f"Fehler: {e}")
self.widget_manager.search_status_label.config(text=f"Fehler: {e}")
def go_back(self):
if self.history_pos > 0:
@@ -1268,9 +1252,9 @@ class CustomFileDialog(tk.Toplevel):
size = os.path.getsize(selected_path)
size_str = self._format_size(size)
status_text = f"'{os.path.basename(selected_path)}' Größe: {size_str}"
self.widget_manager.status_bar.config(text=status_text)
self.widget_manager.search_status_label.config(text=status_text)
except FileNotFoundError:
self.widget_manager.status_bar.config(
self.widget_manager.search_status_label.config(
text="Verzeichnis nicht gefunden")
self.widget_manager.storage_label.config(
text="Freier Speicher: Unbekannt")
@@ -1325,7 +1309,7 @@ class CustomFileDialog(tk.Toplevel):
os.remove(self.selected_file)
self.populate_files()
self.widget_manager.status_bar.config(
self.widget_manager.search_status_label.config(
text=f"'{item_name}' wurde erfolgreich entfernt.")
except Exception as e:
@@ -1354,7 +1338,7 @@ class CustomFileDialog(tk.Toplevel):
open(new_path, 'a').close()
self.populate_files(item_to_rename=new_name)
except Exception as e:
self.widget_manager.status_bar.config(
self.widget_manager.search_status_label.config(
text=f"Fehler beim Erstellen: {e}")
def _get_unique_name(self, base_name):
@@ -1369,7 +1353,7 @@ class CustomFileDialog(tk.Toplevel):
def _copy_to_clipboard(self, data):
self.clipboard_clear()
self.clipboard_append(data)
self.widget_manager.status_bar.config(
self.widget_manager.search_status_label.config(
text=f"'{self.shorten_text(data, 50)}' in Zwischenablage kopiert.")
def _show_context_menu(self, event, item_path):
@@ -1427,7 +1411,7 @@ class CustomFileDialog(tk.Toplevel):
new_path = os.path.join(self.current_dir, new_name)
if new_name and new_path != item_path:
if os.path.exists(new_path):
self.widget_manager.status_bar.config(
self.widget_manager.search_status_label.config(
text=f"'{new_name}' existiert bereits.")
self.populate_files(
item_to_select=os.path.basename(item_path))
@@ -1436,7 +1420,7 @@ class CustomFileDialog(tk.Toplevel):
os.rename(item_path, new_path)
self.populate_files(item_to_select=new_name)
except Exception as e:
self.widget_manager.status_bar.config(
self.widget_manager.search_status_label.config(
text=f"Fehler beim Umbenennen: {e}")
self.populate_files()
else:
@@ -1480,7 +1464,7 @@ class CustomFileDialog(tk.Toplevel):
if new_name and new_path != old_path:
if os.path.exists(new_path):
self.widget_manager.status_bar.config(
self.widget_manager.search_status_label.config(
text=f"'{new_name}' existiert bereits.")
self.populate_files(item_to_select=item_text)
else:
@@ -1488,7 +1472,7 @@ class CustomFileDialog(tk.Toplevel):
os.rename(old_path, new_path)
self.populate_files(item_to_select=new_name)
except Exception as e:
self.widget_manager.status_bar.config(
self.widget_manager.search_status_label.config(
text=f"Fehler beim Umbenennen: {e}")
self.populate_files()
else: