diff --git a/__pycache__/custom_file_dialog.cpython-312.pyc b/__pycache__/custom_file_dialog.cpython-312.pyc index 3cc7c5a..c320811 100644 Binary files a/__pycache__/custom_file_dialog.cpython-312.pyc and b/__pycache__/custom_file_dialog.cpython-312.pyc differ diff --git a/custom_file_dialog.py b/custom_file_dialog.py index 6d873fd..e14962b 100644 --- a/custom_file_dialog.py +++ b/custom_file_dialog.py @@ -406,15 +406,24 @@ class CustomFileDialog(tk.Toplevel): self.search_process = None def handle_path_entry_return(self, event): - """Handles the Enter key in the path entry to navigate. - Search is handled by on_path_entry_key_release. + """ + Handles the Enter key in the path entry. + - If the path is a directory, it navigates into it. + - If the path is a file, it navigates to the containing directory + and selects the file. """ path_text = self.widget_manager.path_entry.get().strip() potential_path = os.path.realpath(os.path.expanduser(path_text)) if os.path.isdir(potential_path): self.navigate_to(potential_path) - # If not a directory, do nothing on Enter. Search is triggered on key release. + elif os.path.isfile(potential_path): + directory = os.path.dirname(potential_path) + filename = os.path.basename(potential_path) + self.navigate_to(directory, file_to_select=filename) + else: + self.widget_manager.search_status_label.config( + text=f"Pfad nicht gefunden: {self.shorten_text(path_text, 50)}") def load_settings(self): self.settings = CfdConfigManager.load() @@ -811,10 +820,32 @@ class CustomFileDialog(tk.Toplevel): self.tree.focus(item_id) self.tree.see(item_id) break - else: # icon view - # This is more complex as items are in a grid. A simple selection is not straightforward. - # For now, we just navigate to the folder. - pass + elif self.view_mode.get() == "icons": + if not hasattr(self, 'icon_canvas') or not self.icon_canvas.winfo_exists(): + return + + container_frame = self.icon_canvas.winfo_children()[0] + target_path = os.path.join(self.current_dir, filename) + + for widget in container_frame.winfo_children(): + if hasattr(widget, 'item_path') and widget.item_path == target_path: + self.on_item_select(widget.item_path, widget) + + def scroll_to_widget(): + self.update_idletasks() + if not widget.winfo_exists(): return + y = widget.winfo_y() + canvas_height = self.icon_canvas.winfo_height() + scroll_region = self.icon_canvas.bbox("all") + if not scroll_region: return + + scroll_height = scroll_region[3] + if scroll_height > canvas_height: + fraction = y / scroll_height + self.icon_canvas.yview_moveto(fraction) + + self.after(100, scroll_to_widget) + break def _unbind_mouse_wheel_events(self): # Unbind all mouse wheel events from the root window @@ -992,6 +1023,7 @@ class CustomFileDialog(tk.Toplevel): container, width=item_width, height=item_height, style="Item.TFrame") item_frame.grid(row=row, column=col, padx=5, ipadx=25, pady=5) item_frame.grid_propagate(False) + item_frame.item_path = path # Store path for later reference if name == item_to_rename: self.start_rename(item_frame, path)