[gtk/wip/matthiasc/shortcut-4: 100/149] Only create a class shortcut controller if we have shortcuts



commit 941932c24bfe243b3d3ce803a918e69b01478454
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Mar 15 18:24:52 2020 -0400

    Only create a class shortcut controller if we have shortcuts
    
    No point in creating objects that just hold empty lists.

 gtk/gtkwidget.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 1eb12c0806..ee1a38c5b9 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2450,9 +2450,12 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
   if (layout_manager_type != G_TYPE_INVALID)
     gtk_widget_set_layout_manager (widget, g_object_new (layout_manager_type, NULL));
 
-  controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (GTK_WIDGET_CLASS 
(g_class)->priv->shortcuts));
-  gtk_event_controller_set_name (controller, "gtk-widget-class-shortcuts");
-  gtk_widget_add_controller (widget, controller);
+  if (g_list_model_get_n_items (G_LIST_MODEL (GTK_WIDGET_CLASS (g_class)->priv->shortcuts)) > 0)
+    {
+      controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (GTK_WIDGET_CLASS 
(g_class)->priv->shortcuts));
+      gtk_event_controller_set_name (controller, "gtk-widget-class-shortcuts");
+      gtk_widget_add_controller (widget, controller);
+    }
 }
 
 /**


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