From f763e1f97cf4d47ca70ab6f964460e72206bbced Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Thu, 13 Apr 2023 15:50:41 -0700 Subject: window: Dismiss previous undo toast when undo action has changed We present a new toast every time the undo action changed which is confusing because you might have several undo toasts appearing over each other. To complicate matters, the previous undo toasts lie (undo'ing would actually undo a different action). There was a proposal in #2350 to batch undo toasts, but that's problematic because our undo manager is designed to undo exactly 1 action, we do not have an undo stack. The more straightforward solution seems to be simply dismissing the old undo toasts, when we popup a new undo toast. Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2350 --- src/nautilus-window.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/nautilus-window.c b/src/nautilus-window.c index 9424f154d..0033dcf5d 100644 --- a/src/nautilus-window.c +++ b/src/nautilus-window.c @@ -112,6 +112,7 @@ struct _NautilusWindow /* Notifications */ AdwToastOverlay *toast_overlay; + AdwToast *last_undo_toast; /* Toolbar */ GtkWidget *toolbar; @@ -1275,12 +1276,19 @@ nautilus_window_on_undo_changed (NautilusFileUndoManager *manager, } } + if (window->last_undo_toast != NULL) + { + adw_toast_dismiss (window->last_undo_toast); + g_clear_weak_pointer (&window->last_undo_toast); + } + if (popup_toast) { toast = adw_toast_new (label); adw_toast_set_button_label (toast, _("Undo")); adw_toast_set_action_name (toast, "win.undo"); adw_toast_set_priority (toast, ADW_TOAST_PRIORITY_HIGH); + g_set_weak_pointer (&window->last_undo_toast, toast); adw_toast_overlay_add_toast (window->toast_overlay, toast); } } -- cgit v1.2.1