fix all search problems

This commit is contained in:
2025-08-09 10:16:51 +02:00
parent f47f18d48c
commit f06d1b6652
3 changed files with 42 additions and 29 deletions

View File

@@ -337,39 +337,40 @@ class CustomFileDialog(tk.Toplevel):
raise InterruptedError("Search cancelled by user")
if not search_hidden:
# Exclude hidden directories from traversal
dirs[:] = [d for d in dirs if not d.startswith('.')]
# Exclude hidden files from results
files = [f for f in files if not f.startswith('.')]
for name in files + dirs:
for name in files:
if search_term_lower in name.lower() and self._matches_filetype(name):
all_files.append(os.path.join(root, name))
for name in dirs:
if search_term_lower in name.lower():
all_files.append(os.path.join(root, name))
else: # Non-recursive search
else:
for name in os.listdir(search_dir):
if not (self.search_thread and self.search_thread.is_alive()):
raise InterruptedError("Search cancelled by user")
if not search_hidden and name.startswith('.'):
continue
path = os.path.join(search_dir, name)
is_dir = os.path.isdir(path)
if search_term_lower in name.lower():
all_files.append(os.path.join(search_dir, name))
if is_dir:
all_files.append(path)
elif self._matches_filetype(name):
all_files.append(path)
if is_recursive:
break # Only search the first directory recursively
break
if not (self.search_thread and self.search_thread.is_alive()):
raise InterruptedError("Search cancelled by user")
seen = set()
unique_files = [x for x in all_files if not (x in seen or seen.add(x))]
# Final filtering based on file type
self.search_results = [
p for p in unique_files
if self._matches_filetype(os.path.basename(p)) or os.path.isdir(p)
]
self.search_results = [x for x in all_files if not (x in seen or seen.add(x))]
def update_ui():
if self.search_results:
@@ -451,12 +452,12 @@ class CustomFileDialog(tk.Toplevel):
self.update_idletasks()
self._handle_responsive_buttons(self.winfo_width())
# If search was active, reset it to avoid inconsistent state
if self.search_mode:
self.hide_search_bar() # This will correctly reset the UI
self.update_animation_settings() # Add this line
self.navigate_to(self.current_dir)
if self.search_mode:
self.show_search_results_treeview()
else:
self.navigate_to(self.current_dir)
def open_settings_dialog(self):
SettingsDialog(self, dialog_mode=self.dialog_mode)
@@ -1445,10 +1446,9 @@ class CustomFileDialog(tk.Toplevel):
self.context_menu.add_command(
label="Pfad in Zwischenablage", command=lambda: self._copy_to_clipboard(item_path))
if self.search_mode:
self.context_menu.add_separator()
self.context_menu.add_command(
label="Speicherort öffnen", command=lambda: self._open_file_location_from_context(item_path))
self.context_menu.add_separator()
self.context_menu.add_command(
label="Speicherort öffnen", command=lambda: self._open_file_location_from_context(item_path))
self.context_menu.tk_popup(event.x_root, event.y_root)
return "break"
@@ -1587,12 +1587,24 @@ class CustomFileDialog(tk.Toplevel):
def _matches_filetype(self, filename):
if self.current_filter_pattern == "*.*":
return True
patterns = self.current_filter_pattern.replace(
"*.", "").lower().split()
# Split the pattern string by spaces to handle multiple patterns
patterns = self.current_filter_pattern.lower().split()
fn_lower = filename.lower()
for p in patterns:
if fn_lower.endswith(p):
return True
# Handle patterns like *.txt
if p.startswith('*.'):
if fn_lower.endswith(p[1:]):
return True
# Handle patterns like .conf
elif p.startswith('.'):
if fn_lower.endswith(p):
return True
# Handle exact match
else:
if fn_lower == p:
return True
return False
def _format_size(self, size_bytes):

View File

@@ -32,8 +32,9 @@ class GlotzMol(tk.Tk):
dialog = CustomFileDialog(self,
initial_dir=os.path.expanduser("~"),
filetypes=[("All Files", "*.*")
], dialog_mode="save")
filetypes=[("All Files", "*.*"),
("Wireguard config Files", "*.conf")
])
# This is the crucial part: wait for the dialog to be closed
self.wait_window(dialog)