[gtk+] search bar: Clean up weak pointer handling



commit a17d6290e404857a1f4bf021d8635a3a1eb9ee19
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Mar 22 11:46:16 2015 -0400

    search bar: Clean up weak pointer handling
    
    Break out a setter that manages the weak pointer, and
    use it in finalize. This also fixes a bug where we were
    forgetting to disconnect the right signal handler in
    some cases.

 gtk/gtksearchbar.c |   56 ++++++++++++++++++++++++++-------------------------
 1 files changed, 29 insertions(+), 27 deletions(-)
---
diff --git a/gtk/gtksearchbar.c b/gtk/gtksearchbar.c
index d1b3f3c..d098a48 100644
--- a/gtk/gtksearchbar.c
+++ b/gtk/gtksearchbar.c
@@ -350,12 +350,7 @@ gtk_search_bar_dispose (GObject *object)
   GtkSearchBar *bar = GTK_SEARCH_BAR (object);
   GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
 
-  if (priv->entry)
-    {
-      g_signal_handlers_disconnect_by_func (priv->entry, entry_key_pressed_event_cb, bar);
-      g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *) &priv->entry);
-      priv->entry = NULL;
-    }
+  gtk_search_bar_set_entry (bar, NULL);
 
   G_OBJECT_CLASS (gtk_search_bar_parent_class)->dispose (object);
 }
@@ -471,27 +466,12 @@ gtk_search_bar_new (void)
   return g_object_new (GTK_TYPE_SEARCH_BAR, NULL);
 }
 
-/**
- * gtk_search_bar_connect_entry:
- * @bar: a #GtkSearchBar
- * @entry: a #GtkEntry
- *
- * Connects the #GtkEntry widget passed as the one to be used in
- * this search bar. The entry should be a descendant of the search bar.
- * This is only required if the entry isn’t the direct child of the
- * search bar (as in our main example).
- *
- * Since: 3.10
- */
-void
-gtk_search_bar_connect_entry (GtkSearchBar *bar,
-                              GtkEntry     *entry)
+static void
+gtk_search_bar_set_entry (GtkSearchBar *bar,
+                          GtkEntry     *entry)
 {
   GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
 
-  g_return_if_fail (GTK_IS_SEARCH_BAR (bar));
-  g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
-
   if (priv->entry != NULL)
     {
       if (GTK_IS_SEARCH_ENTRY (priv->entry))
@@ -499,12 +479,12 @@ gtk_search_bar_connect_entry (GtkSearchBar *bar,
       else
         g_signal_handlers_disconnect_by_func (priv->entry, entry_key_pressed_event_cb, bar);
       g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *) &priv->entry);
-      priv->entry = NULL;
     }
 
-  if (entry != NULL)
+  priv->entry = GTK_WIDGET (entry);
+
+  if (priv->entry != NULL)
     {
-      priv->entry = GTK_WIDGET (entry);
       g_object_add_weak_pointer (G_OBJECT (priv->entry), (gpointer *) &priv->entry);
       if (GTK_IS_SEARCH_ENTRY (priv->entry))
         g_signal_connect (priv->entry, "stop-search",
@@ -516,6 +496,28 @@ gtk_search_bar_connect_entry (GtkSearchBar *bar,
 }
 
 /**
+ * gtk_search_bar_connect_entry:
+ * @bar: a #GtkSearchBar
+ * @entry: a #GtkEntry
+ *
+ * Connects the #GtkEntry widget passed as the one to be used in
+ * this search bar. The entry should be a descendant of the search bar.
+ * This is only required if the entry isn’t the direct child of the
+ * search bar (as in our main example).
+ *
+ * Since: 3.10
+ */
+void
+gtk_search_bar_connect_entry (GtkSearchBar *bar,
+                              GtkEntry     *entry)
+{
+  g_return_if_fail (GTK_IS_SEARCH_BAR (bar));
+  g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
+
+  gtk_search_bar_set_entry (bar, entry);
+}
+
+/**
  * gtk_search_bar_get_search_mode:
  * @bar: a #GtkSearchBar
  *


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