[gtk/wip/matthiasc/shortcut-4: 82/139] shortcutcontroller: Use a list model for shortcuts



commit c3abdb1fb8616c86d5afb43de9b8d964a0ee0365
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Mar 25 17:28:01 2020 -0400

    shortcutcontroller: Use a list model for shortcuts

 gtk/gtkshortcutcontroller.c        | 46 ++++++++++++++++----------------------
 gtk/gtkshortcutcontrollerprivate.h |  3 ---
 2 files changed, 19 insertions(+), 30 deletions(-)
---
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
index f2afe0354c..cd5a17bb56 100644
--- a/gtk/gtkshortcutcontroller.c
+++ b/gtk/gtkshortcutcontroller.c
@@ -34,6 +34,7 @@
 
 #include "gtkshortcutcontrollerprivate.h"
 
+#include "gtkflattenlistmodel.h"
 #include "gtkeventcontrollerprivate.h"
 #include "gtkintl.h"
 #include "gtkshortcut.h"
@@ -53,7 +54,6 @@ struct _GtkShortcutController
   GdkModifierType mnemonics_modifiers;
 
   guint custom_shortcuts : 1;
-  guint run_managed : 1;
 };
 
 struct _GtkShortcutControllerClass
@@ -212,15 +212,27 @@ gtk_shortcut_controller_finalize (GObject *object)
 static gboolean
 gtk_shortcut_controller_trigger_shortcut (GtkShortcutController *self,
                                           GtkShortcut           *shortcut,
+                                          guint                  position,
                                           GdkEvent              *event,
                                           gboolean               enable_mnemonics)
 {
+  GtkWidget *widget;
+
   if (!gtk_shortcut_trigger_trigger (gtk_shortcut_get_trigger (shortcut), event, enable_mnemonics))
     return FALSE;
 
+  widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self));
+  if (!self->custom_shortcuts &&
+      GTK_IS_FLATTEN_LIST_MODEL (self->shortcuts))
+    {
+      GListModel *model = gtk_flatten_list_model_get_model_for_item (GTK_FLATTEN_LIST_MODEL 
(self->shortcuts), position);
+      if (GTK_IS_SHORTCUT_CONTROLLER (model))
+        widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (model));
+    }
+
   return gtk_shortcut_action_activate (gtk_shortcut_get_action (shortcut),
                                        GTK_SHORTCUT_ACTION_EXCLUSIVE, /* FIXME */
-                                       gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self)),
+                                       widget,
                                        gtk_shortcut_get_arguments (shortcut));
 }
 
@@ -232,34 +244,21 @@ gtk_shortcut_controller_run_controllers (GtkEventController *controller,
                                          gboolean            enable_mnemonics)
 {
   GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
-  GtkWidget *widget;
-  const GSList *l;
   guint i;
 
   for (i = 0; i < g_list_model_get_n_items (self->shortcuts); i++)
     {
+      GtkShortcut *shortcut = g_list_model_get_item (self->shortcuts, i);
+      g_object_unref (shortcut);
+
       if (gtk_shortcut_controller_trigger_shortcut (self, 
-                                                    g_list_model_get_item (self->shortcuts, i),
+                                                    shortcut,
+                                                    i,
                                                     event,
                                                     enable_mnemonics))
         return TRUE;
     }
 
-  if (self->run_managed)
-    {
-      GtkPropagationPhase current_phase = gtk_event_controller_get_propagation_phase (controller);
-      widget = gtk_event_controller_get_widget (controller); 
-      
-      for (l = g_object_get_data (G_OBJECT (widget), "gtk-shortcut-controllers"); l; l = l->next)
-        {
-          if (gtk_event_controller_get_propagation_phase (l->data) != current_phase)
-            continue;
-
-          if (gtk_shortcut_controller_run_controllers (l->data, event, x, y, enable_mnemonics))
-            return TRUE;
-        }
-    }
-
   return FALSE;
 }
 
@@ -483,13 +482,6 @@ gtk_shortcut_controller_new_for_model (GListModel *model)
                        NULL);
 }
 
-void
-gtk_shortcut_controller_set_run_managed (GtkShortcutController  *controller,
-                                         gboolean                run_managed)
-{
-  controller->run_managed = run_managed;
-}
-
 /**
  * gtk_shortcut_controller_add_shortcut:
  * @self: the controller
diff --git a/gtk/gtkshortcutcontrollerprivate.h b/gtk/gtkshortcutcontrollerprivate.h
index a7086cd678..db1b52cecc 100644
--- a/gtk/gtkshortcutcontrollerprivate.h
+++ b/gtk/gtkshortcutcontrollerprivate.h
@@ -22,9 +22,6 @@
 
 #include "gtkshortcutcontroller.h"
 
-void                    gtk_shortcut_controller_set_run_managed         (GtkShortcutController  *controller,
-                                                                         gboolean                
run_managed);
-
 void                    gtk_shortcut_controller_root                    (GtkShortcutController  *controller);
 void                    gtk_shortcut_controller_unroot                  (GtkShortcutController  *controller);
 


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