[nautilus/wip/coreyberla/window-dispose: 107/107] toolbar: Clear references to NautilusWindow before closing window




commit 3957c614bbb378e0fb186424bd9186a61ca9b662
Author: Corey Berla <corey berla me>
Date:   Fri Aug 5 09:14:44 2022 -0700

    toolbar: Clear references to NautilusWindow before closing window
    
    Toolbar gets a references to the window after the window is created.
    We want the window to be able to destroy properly so it can
    release all of its references.

 src/nautilus-toolbar.c | 14 ++++++++++++--
 src/nautilus-toolbar.h |  1 +
 src/nautilus-window.c  |  1 +
 3 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 555435e6c..4ee56e9e1 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -89,6 +89,10 @@ G_DEFINE_TYPE (NautilusToolbar, nautilus_toolbar, ADW_TYPE_BIN);
 
 static void nautilus_toolbar_set_window_slot_real (NautilusToolbar    *self,
                                                    NautilusWindowSlot *slot);
+static void on_window_focus_changed (GObject    *object,
+                                     GParamSpec *pspec,
+                                     gpointer    user_data);
+
 static void
 toolbar_update_appearance (NautilusToolbar *self)
 {
@@ -209,6 +213,14 @@ on_location_entry_focus_changed (GObject    *object,
     }
 }
 
+void
+nautilus_toolbar_unset_window (NautilusToolbar *self)
+{
+    g_signal_handlers_disconnect_by_func (self->window,
+                                          on_window_focus_changed, self);
+    g_clear_object (&self->window);
+}
+
 static void
 nautilus_toolbar_constructed (GObject *object)
 {
@@ -467,8 +479,6 @@ nautilus_toolbar_finalize (GObject *obj)
         self->window_slot = NULL;
     }
 
-    g_signal_handlers_disconnect_by_func (self->window,
-                                          on_window_focus_changed, self);
 
     G_OBJECT_CLASS (nautilus_toolbar_parent_class)->finalize (obj);
 }
diff --git a/src/nautilus-toolbar.h b/src/nautilus-toolbar.h
index a61a3cb9f..592e99e6f 100644
--- a/src/nautilus-toolbar.h
+++ b/src/nautilus-toolbar.h
@@ -51,4 +51,5 @@ void       nautilus_toolbar_on_window_constructed       (NautilusToolbar *toolba
 
 void nautilus_toolbar_set_window_slot (NautilusToolbar    *self,
                                        NautilusWindowSlot *window_slot);
+void nautilus_toolbar_unset_window (NautilusToolbar *self);
 G_END_DECLS
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index e3ad8fc2c..3aaa740b7 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -1919,6 +1919,7 @@ static gboolean
 nautilus_window_close_request (GtkWindow *window)
 {
     nautilus_window_close (NAUTILUS_WINDOW (window));
+    nautilus_toolbar_unset_window (NAUTILUS_TOOLBAR (NAUTILUS_WINDOW (window)->toolbar));
     return FALSE;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]