[gtk/matthiasc/for-master: 18/19] shortcutcontroller: Fix builder support



commit ace183f38f030e1795594bda5666bf053f823286
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Mar 30 19:02:35 2020 -0400

    shortcutcontroller: Fix builder support
    
    The GtkBuilder support was not working anymore after
    triggers and actions have been turned into objects.
    
    Fix this.

 gtk/gtkbuilder.c            | 48 +++++++++++++++++++++++----------------------
 gtk/gtkshortcutcontroller.c |  2 +-
 2 files changed, 26 insertions(+), 24 deletions(-)
---
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index c444e15036..a4351bade1 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -531,6 +531,8 @@ gtk_builder_get_parameters (GtkBuilder         *builder,
           (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GDK_TYPE_PIXBUF) &&
           (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GDK_TYPE_TEXTURE) &&
           (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GDK_TYPE_PAINTABLE) &&
+          (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GTK_TYPE_SHORTCUT_TRIGGER) &&
+          (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GTK_TYPE_SHORTCUT_ACTION) &&
           (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != G_TYPE_FILE))
         {
           GObject *object = g_hash_table_lookup (priv->objects,
@@ -2097,29 +2099,6 @@ gtk_builder_value_from_string_type (GtkBuilder   *builder,
               ret = FALSE;
             }
         }
-      else if (G_VALUE_HOLDS (value, GTK_TYPE_SHORTCUT_TRIGGER))
-        {
-          GtkShortcutTrigger *trigger = gtk_shortcut_trigger_parse_string (string);
-
-          if (trigger)
-            g_value_take_object (value, trigger);
-          else
-            {
-              g_set_error (error,
-                           GTK_BUILDER_ERROR,
-                           GTK_BUILDER_ERROR_INVALID_VALUE,
-                           "Could not parse shortcut trigger '%s'",
-                           string);
-              ret = FALSE;
-            }
-        }
-      else if (G_VALUE_HOLDS (value, GTK_TYPE_SHORTCUT_ACTION))
-        {
-          GtkShortcutAction *action = gtk_shortcut_action_parse_builder (builder, string, error);
-
-          /* Works for success and failure (NULL) case */
-          g_value_take_object (value, action);
-        }
       else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
         {
           gchar **vector = g_strsplit (string, "\n", 0);
@@ -2237,6 +2216,29 @@ gtk_builder_value_from_string_type (GtkBuilder   *builder,
 
           ret = TRUE;
         }
+      else if (G_VALUE_HOLDS (value, GTK_TYPE_SHORTCUT_TRIGGER))
+        {
+          GtkShortcutTrigger *trigger = gtk_shortcut_trigger_parse_string (string);
+
+          if (trigger)
+            g_value_take_object (value, trigger);
+          else
+            {
+              g_set_error (error,
+                           GTK_BUILDER_ERROR,
+                           GTK_BUILDER_ERROR_INVALID_VALUE,
+                           "Could not parse shortcut trigger '%s'",
+                           string);
+              ret = FALSE;
+            }
+        }
+      else if (G_VALUE_HOLDS (value, GTK_TYPE_SHORTCUT_ACTION))
+        {
+          GtkShortcutAction *action = gtk_shortcut_action_parse_builder (builder, string, error);
+
+          /* Works for success and failure (NULL) case */
+          g_value_take_object (value, action);
+        }
       else
         {
           GObject *object = g_hash_table_lookup (priv->objects, string);
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
index 8123d796e6..d18b6902f2 100644
--- a/gtk/gtkshortcutcontroller.c
+++ b/gtk/gtkshortcutcontroller.c
@@ -127,7 +127,7 @@ gtk_shortcut_controller_buildable_add_child (GtkBuildable  *buildable,
     }
   if (GTK_IS_SHORTCUT (child))
     {
-      gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (buildable), GTK_SHORTCUT (child));
+      gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (buildable), g_object_ref (GTK_SHORTCUT 
(child)));
     }
   else
     {


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