feat: Enhance preset name prompt with live status indication for overwriting or creating presets

This commit is contained in:
William Valentin
2025-08-08 12:40:08 -07:00
parent eab011b507
commit 30896e4975

View File

@@ -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"]