diff --git a/photo_tagger.py b/photo_tagger.py index b4108e6..80a8be5 100644 --- a/photo_tagger.py +++ b/photo_tagger.py @@ -4613,6 +4613,46 @@ class PhotoTagger: save_button = ttk.Button(bottom_frame, text="Save Tagging") save_button.pack(side=tk.RIGHT, padx=10, pady=5) + # Quit button with warning for pending changes + def quit_with_warning(): + """Quit the dialog, but warn if there are pending changes""" + # Check for pending changes + has_pending_changes = bool(pending_tag_changes or pending_tag_removals) + + if has_pending_changes: + total_additions = sum(len(tags) for tags in pending_tag_changes.values()) + total_removals = sum(len(tags) for tags in pending_tag_removals.values()) + + changes_text = [] + if total_additions > 0: + changes_text.append(f"{total_additions} tag addition(s)") + if total_removals > 0: + changes_text.append(f"{total_removals} tag removal(s)") + + changes_summary = " and ".join(changes_text) + + result = messagebox.askyesnocancel( + "Unsaved Changes", + f"You have unsaved changes: {changes_summary}.\n\n" + "Do you want to save your changes before quitting?\n\n" + "Yes = Save and quit\n" + "No = Quit without saving\n" + "Cancel = Stay in dialog" + ) + + if result is True: # Yes - Save and quit + save_tagging_changes() + root.destroy() + elif result is False: # No - Quit without saving + root.destroy() + # If result is None (Cancel), do nothing - stay in dialog + else: + # No pending changes, just quit + root.destroy() + + quit_button = ttk.Button(bottom_frame, text="Quit", command=quit_with_warning) + quit_button.pack(side=tk.RIGHT, padx=(0, 10), pady=5) + # Enable mouse scroll anywhere in the dialog def on_mousewheel(event): content_canvas.yview_scroll(int(-1*(event.delta/120)), "units") @@ -5153,7 +5193,7 @@ class PhotoTagger: # Top frame - dropdown to select tag to add ttk.Label(top_frame, text="Add tag:").grid(row=0, column=0, padx=(0, 8), sticky=tk.W) tag_var = tk.StringVar() - combo = ttk.Combobox(top_frame, textvariable=tag_var, values=available_tags, width=30) + combo = ttk.Combobox(top_frame, textvariable=tag_var, values=available_tags, width=30, state='readonly') combo.grid(row=0, column=1, padx=(0, 8), sticky=(tk.W, tk.E)) combo.focus_set()