[gtk/wip/baedert/for-master: 5/5] label: Fold function into only caller



commit c13eb9e44f899ec5e88a55b182926294106807f1
Author: Timm Bäder <mail baedert org>
Date:   Sun Apr 12 10:07:15 2020 +0200

    label: Fold function into only caller
    
    This makes it more obvious that gtk_label_setup_mnemonic() depends on
    the root of the widget and it therefore makes sense to call it in
    ::root/::unroot.

 gtk/gtklabel.c | 87 +++++++++++++++++++++++++---------------------------------
 1 file changed, 37 insertions(+), 50 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 65e65b3e74..deefff139e 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -517,10 +517,6 @@ static void     gtk_label_buildable_custom_finished  (GtkBuildable       *builda
                                                       GObject            *child,
                                                       const gchar        *tagname,
                                                       gpointer            user_data);
-
-
-
-static void connect_mnemonics_visible_notify    (GtkLabel   *label);
 static gboolean      separate_uline_pattern     (const gchar  *str,
                                                  guint        *accel_key,
                                                  gchar       **new_str,
@@ -1505,13 +1501,27 @@ gtk_label_mnemonic_activate (GtkWidget *widget,
   return FALSE;
 }
 
+static void
+label_mnemonics_visible_changed (GtkWidget  *widget,
+                                 GParamSpec *pspec,
+                                 gpointer    data)
+{
+  gboolean visible;
+
+  g_object_get (widget, "mnemonics-visible", &visible, NULL);
+  _gtk_label_mnemonics_visible_apply_recursively (widget, visible);
+}
+
 static void
 gtk_label_setup_mnemonic (GtkLabel *label)
 {
   GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
   GtkWidget *widget = GTK_WIDGET (label);
   GtkShortcut *shortcut;
-  
+  GtkNative *native;
+  gboolean connected;
+  gboolean mnemonics_visible;
+
   if (priv->mnemonic_keyval == GDK_KEY_VoidSymbol)
     {
       if (priv->mnemonic_controller)
@@ -1539,7 +1549,28 @@ gtk_label_setup_mnemonic (GtkLabel *label)
       g_object_unref (shortcut);
     }
 
-  connect_mnemonics_visible_notify (GTK_LABEL (widget));
+  /* Connect to notify::mnemonics-visible of the root */
+  native = gtk_widget_get_native (GTK_WIDGET (label));
+  if (!GTK_IS_WINDOW (native) && !GTK_IS_POPOVER (native))
+    return;
+
+  /* always set up this widgets initial value */
+  g_object_get (native, "mnemonics-visible", &mnemonics_visible, NULL);
+  priv->mnemonics_visible = mnemonics_visible;
+
+  connected =
+    GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (native), quark_mnemonics_visible_connected));
+
+  if (!connected)
+    {
+      g_signal_connect (native,
+                        "notify::mnemonics-visible",
+                        G_CALLBACK (label_mnemonics_visible_changed),
+                        label);
+      g_object_set_qdata (G_OBJECT (native),
+                          quark_mnemonics_visible_connected,
+                          GINT_TO_POINTER (1));
+    }
 }
 
 static void
@@ -1650,18 +1681,6 @@ _gtk_label_mnemonics_visible_apply_recursively (GtkWidget *widget,
         }
     }
 }
-
-static void
-label_mnemonics_visible_changed (GtkWidget  *widget,
-                                 GParamSpec *pspec,
-                                 gpointer    data)
-{
-  gboolean visible;
-
-  g_object_get (widget, "mnemonics-visible", &visible, NULL);
-  _gtk_label_mnemonics_visible_apply_recursively (widget, visible);
-}
-
 static void
 label_mnemonic_widget_weak_notify (gpointer      data,
                                   GObject      *where_the_object_was)
@@ -4262,38 +4281,6 @@ gtk_label_click_gesture_released (GtkGestureClick *gesture,
     }
 }
 
-static void
-connect_mnemonics_visible_notify (GtkLabel *label)
-{
-  GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
-  GtkNative *native;
-  gboolean connected;
-  gboolean mnemonics_visible;
-
-  native = gtk_widget_get_native (GTK_WIDGET (label));
-
-  if (!GTK_IS_WINDOW (native) && !GTK_IS_POPOVER (native))
-    return;
-
-  /* always set up this widgets initial value */
-  g_object_get (native, "mnemonics-visible", &mnemonics_visible, NULL);
-  priv->mnemonics_visible = mnemonics_visible;
-
-  connected =
-    GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (native), quark_mnemonics_visible_connected));
-
-  if (!connected)
-    {
-      g_signal_connect (native,
-                        "notify::mnemonics-visible",
-                        G_CALLBACK (label_mnemonics_visible_changed),
-                        label);
-      g_object_set_qdata (G_OBJECT (native),
-                          quark_mnemonics_visible_connected,
-                          GINT_TO_POINTER (1));
-    }
-}
-
 static GdkPaintable *
 get_selection_paintable (GtkLabel *label)
 {


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