From 30896e49759a9669688dd63c7409f99a86db0378 Mon Sep 17 00:00:00 2001 From: William Valentin Date: Fri, 8 Aug 2025 12:40:08 -0700 Subject: [PATCH] feat: Enhance preset name prompt with live status indication for overwriting or creating presets --- src/search_filter_ui.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/search_filter_ui.py b/src/search_filter_ui.py index ab97fb2..f1c6962 100644 --- a/src/search_filter_ui.py +++ b/src/search_filter_ui.py @@ -542,7 +542,9 @@ class SearchFilterWidget: def _ask_preset_name(self, initial: str = "") -> str | None: """Prompt for a preset name using a themed ttk modal dialog. - Returns the entered name (stripped) or None if cancelled. + Shows a lightweight hint if the name already exists (will overwrite) + or is new (will create). Returns the entered name (stripped) or None + if cancelled. """ result: dict[str, str | None] = {"value": None} @@ -557,7 +559,22 @@ class SearchFilterWidget: ttk.Label(frame, text="Preset name:").pack(anchor="w") name_var = tk.StringVar(value=initial) entry = ttk.Entry(frame, textvariable=name_var, width=32) - entry.pack(fill="x", pady=(4, 10)) + entry.pack(fill="x", pady=(4, 6)) + + # Live status about overwrite vs create + status_var = tk.StringVar(value="") + status_label = ttk.Label(frame, textvariable=status_var) + status_label.pack(anchor="w", pady=(0, 10)) + + def _update_status(*_args: object) -> None: + presets = get_pref("filter_presets", {}) or {} + value = (name_var.get() or "").strip() + if not value: + status_var.set("") + elif value in presets: + status_var.set("Existing preset found: will overwrite") + else: + status_var.set("New preset: will create") buttons = ttk.Frame(frame) buttons.pack(anchor="e") @@ -594,6 +611,9 @@ class SearchFilterWidget: y = py + (ph // 2) - (wh // 2) top.geometry(f"+{x}+{y}") + # Initialize live status and focus + _update_status() + name_var.trace_add("write", _update_status) # update as user types entry.focus_set() top.wait_window() return result["value"]