[gtk/wip/matthiasc/shortcut-4: 25/85] widget: Keep keybindings as a GListStore



commit 3cd4eb0310a1ad9c49c22585f5fd0c9e00802c32
Author: Benjamin Otte <otte redhat com>
Date:   Mon Aug 20 04:18:28 2018 +0200

    widget: Keep keybindings as a GListStore
    
    This way, we can use shortcut_controller_new_for_model() and avoid all
    the special casing about run_class.

 gtk/gtkshortcutcontroller.c        | 19 -------------------
 gtk/gtkshortcutcontrollerprivate.h |  2 --
 gtk/gtkwidget.c                    | 38 ++++++++++++++++++++++++++------------
 gtk/gtkwidgetprivate.h             |  4 +---
 4 files changed, 27 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
index d5d47b239d..f2afe0354c 100644
--- a/gtk/gtkshortcutcontroller.c
+++ b/gtk/gtkshortcutcontroller.c
@@ -53,7 +53,6 @@ struct _GtkShortcutController
   GdkModifierType mnemonics_modifiers;
 
   guint custom_shortcuts : 1;
-  guint run_class : 1;
   guint run_managed : 1;
 };
 
@@ -246,17 +245,6 @@ gtk_shortcut_controller_run_controllers (GtkEventController *controller,
         return TRUE;
     }
 
-  if (self->run_class)
-    {
-      widget = gtk_event_controller_get_widget (controller);
-
-      for (l = gtk_widget_class_get_shortcuts (GTK_WIDGET_GET_CLASS (widget)); l; l = l->next)
-        {
-          if (gtk_shortcut_controller_trigger_shortcut (self, l->data, event, enable_mnemonics))
-            return TRUE;
-        }
-    }
-
   if (self->run_managed)
     {
       GtkPropagationPhase current_phase = gtk_event_controller_get_propagation_phase (controller);
@@ -495,13 +483,6 @@ gtk_shortcut_controller_new_for_model (GListModel *model)
                        NULL);
 }
 
-void
-gtk_shortcut_controller_set_run_class (GtkShortcutController  *controller,
-                                       gboolean                run_class)
-{
-  controller->run_class = run_class;
-}
-
 void
 gtk_shortcut_controller_set_run_managed (GtkShortcutController  *controller,
                                          gboolean                run_managed)
diff --git a/gtk/gtkshortcutcontrollerprivate.h b/gtk/gtkshortcutcontrollerprivate.h
index 42594ea6eb..a7086cd678 100644
--- a/gtk/gtkshortcutcontrollerprivate.h
+++ b/gtk/gtkshortcutcontrollerprivate.h
@@ -22,8 +22,6 @@
 
 #include "gtkshortcutcontroller.h"
 
-void                    gtk_shortcut_controller_set_run_class           (GtkShortcutController  *controller,
-                                                                         gboolean                run_class);
 void                    gtk_shortcut_controller_set_run_managed         (GtkShortcutController  *controller,
                                                                          gboolean                
run_managed);
 
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index c4766a6848..b5bdd95854 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -769,9 +769,29 @@ static void
 gtk_widget_base_class_init (gpointer g_class)
 {
   GtkWidgetClass *klass = g_class;
+  GtkWidgetClassPrivate *priv;
+
+  priv = klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
+  
+  priv->template = NULL;
+
+  if (priv->shortcuts == NULL)
+    {
+      priv->shortcuts = g_list_store_new (GTK_TYPE_SHORTCUT);
+    }
+  else
+    {
+      GListModel *parent_shortcuts = G_LIST_MODEL (priv->shortcuts);
+      guint i;
 
-  klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
-  klass->priv->template = NULL;
+      priv->shortcuts = g_list_store_new (GTK_TYPE_SHORTCUT);
+      for (i = 0; i < g_list_model_get_n_items (parent_shortcuts); i++)
+        {
+          GtkShortcut *shortcut = g_list_model_get_item (parent_shortcuts, i);
+          g_list_store_append (priv->shortcuts, shortcut);
+          g_object_unref (shortcut);
+        }
+    }
 }
 
 static void
@@ -1721,8 +1741,9 @@ gtk_widget_class_init (GtkWidgetClass *klass)
 static void
 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
 {
+
   template_data_free (klass->priv->template);
-  g_slist_free_full (klass->priv->shortcuts, g_object_unref);
+  g_object_unref (klass->priv->shortcuts);
 }
 
 static void
@@ -2438,9 +2459,8 @@ 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 ();
+  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_shortcut_controller_set_run_class (GTK_SHORTCUT_CONTROLLER (controller), TRUE);
   gtk_widget_add_controller (widget, controller);
 }
 
@@ -4506,13 +4526,7 @@ gtk_widget_class_add_shortcut (GtkWidgetClass *widget_class,
 
   priv = widget_class->priv;
 
-  priv->shortcuts = g_slist_prepend (priv->shortcuts, g_object_ref (shortcut));
-}
-
-const GSList *
-gtk_widget_class_get_shortcuts (GtkWidgetClass *widget_class)
-{
-  return widget_class->priv->shortcuts;
+  g_list_store_append (priv->shortcuts, shortcut);
 }
 
 static gboolean
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index efcf1b601f..4c3954c550 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -211,7 +211,7 @@ typedef struct
 struct _GtkWidgetClassPrivate
 {
   GtkWidgetTemplate *template;
-  GSList *shortcuts;
+  GListStore *shortcuts;
   GType accessible_type;
   AtkRole accessible_role;
   GQuark css_name;
@@ -248,8 +248,6 @@ void         _gtk_widget_add_attached_window    (GtkWidget    *widget,
 void         _gtk_widget_remove_attached_window (GtkWidget    *widget,
                                                  GtkWindow    *window);
 
-const GSList *    gtk_widget_class_get_shortcuts           (GtkWidgetClass *widget_class);
-
 AtkObject *       _gtk_widget_peek_accessible              (GtkWidget *widget);
 
 void              _gtk_widget_set_has_default              (GtkWidget *widget,


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