shortcuttrigger: Add gtk_shortcut_triger_new_parse_string()
authorBenjamin Otte <otte@redhat.com>
Thu, 23 Aug 2018 19:07:36 +0000 (21:07 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 26 Mar 2020 03:14:28 +0000 (23:14 -0400)
And hook it up into the GtkBuilder infrastructure.

docs/reference/gtk/gtk4-sections.txt
gtk/gtkbuilder.c
gtk/gtkshortcuttrigger.c
gtk/gtkshortcuttrigger.h

index a5fb8db5c388a23aecb908d0bd5f2707065f5e8e..a725215c451cd98a6c2b0e3f53ddba5aee477f6a 100644 (file)
@@ -6009,6 +6009,7 @@ gtk_shortcut_trigger_ref
 gtk_shortcut_trigger_unref
 GtkShortcutTriggerType
 gtk_shortcut_trigger_get_trigger_type
+gtk_shortcut_trigger_parse_string
 gtk_shortcut_trigger_trigger
 gtk_shortcut_trigger_hash
 gtk_shortcut_trigger_equal
index ba3f367ddc52072bf84b87f64dda4bb9d969c935..c2285dfbf9c32a7f062761b971987f6ba4be289a 100644 (file)
 #include "gtkbuilderscopeprivate.h"
 #include "gtkdebug.h"
 #include "gtkmain.h"
+#include "gtkicontheme.h"
 #include "gtkintl.h"
 #include "gtkprivate.h"
+#include "gtkshortcuttrigger.h"
+#include "gtktestutils.h"
 #include "gtktypebuiltins.h"
 #include "gtkicontheme.h"
 #include "gtkiconthemeprivate.h"
@@ -2092,6 +2095,22 @@ 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_boxed (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, G_TYPE_STRV))
         {
           gchar **vector = g_strsplit (string, "\n", 0);
index e582eb75de47da356400a0311f25e676dcbaa2a1..470a8cecc2780b1d5caed67ebac4dfa4f0b293d6 100644 (file)
@@ -181,6 +181,35 @@ gtk_shortcut_trigger_trigger (GtkShortcutTrigger *self,
   return self->trigger_class->trigger (self, event, enable_mnemonics);
 }
 
+/**
+ * gtk_shortcut_trigger_parse_string:
+ * @string: the string to parse
+ *
+ * Tries to parse the given string into a trigger. On success,
+ * the parsed trigger is returned. When parsing failed, %NULL is
+ * returned.
+ *
+ * FIXME: Document the supported format here once we've figured
+ * it out.
+ * For now, this function only supports gtk_accelerator_parse() and
+ * can only return a trigger of type %GTK_SHORTCUT_TRIGGER_KEYVAL.
+ *
+ * Returns: a new #GtkShortcutTrigger or %NULL on error
+ **/
+GtkShortcutTrigger *
+gtk_shortcut_trigger_parse_string (const char *string)
+{
+  GdkModifierType modifiers;
+  guint keyval;
+
+  g_return_val_if_fail (string != NULL, NULL);
+
+  if (gtk_accelerator_parse (string, &keyval, &modifiers))
+    return gtk_keyval_trigger_new (keyval, modifiers);
+
+  return NULL;
+}
+
 /**
  * gtk_shortcut_trigger_to_string:
  * @self: a #GtkShortcutTrigger
index 85bbd441ff9d2010de0866d454ef805284000e36..b0ab8af862103c1cd77995f9e04a5e98901f6286 100644 (file)
@@ -62,6 +62,9 @@ void                    gtk_shortcut_trigger_unref              (GtkShortcutTrig
 GDK_AVAILABLE_IN_ALL
 GtkShortcutTriggerType  gtk_shortcut_trigger_get_trigger_type   (GtkShortcutTrigger *self);
 
+GDK_AVAILABLE_IN_ALL
+GtkShortcutTrigger *    gtk_shortcut_trigger_parse_string       (const char         *string);
+
 GDK_AVAILABLE_IN_ALL
 char *                  gtk_shortcut_trigger_to_string          (GtkShortcutTrigger *self);
 GDK_AVAILABLE_IN_ALL