[gtk+] builder: Allow 'primary' as a modifier value



commit 9c0e4c174aaae4968bc1970082fdef3183136729
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Mar 5 23:34:50 2016 -0500

    builder: Allow 'primary' as a modifier value
    
    Support aliases for flags values in GtkBuilder, and use this
    to support the special value 'primary' for GdkModifierType
    values.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=699891

 gtk/deprecated/gtkactiongroup.c |    1 +
 gtk/gtkbuilder.c                |   23 ++++++++++++++++++++---
 gtk/gtkbuilderparser.c          |    2 +-
 gtk/gtkbuilderprivate.h         |    9 +++++----
 gtk/gtkwidget.c                 |    9 ++++++++-
 5 files changed, 35 insertions(+), 9 deletions(-)
---
diff --git a/gtk/deprecated/gtkactiongroup.c b/gtk/deprecated/gtkactiongroup.c
index a08d18c..32b913c 100644
--- a/gtk/deprecated/gtkactiongroup.c
+++ b/gtk/deprecated/gtkactiongroup.c
@@ -437,6 +437,7 @@ accelerator_start_element (GMarkupParseContext *context,
       else if (strcmp (names[i], "modifiers") == 0)
        {
          if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
+                                               NULL,
                                               values[i],
                                               &modifiers,
                                               error))
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index ca51168..50375d3 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -1954,7 +1954,7 @@ gtk_builder_value_from_string_type (GtkBuilder   *builder,
       {
         guint flags_value;
 
-        if (!_gtk_builder_flags_from_string (type, string, &flags_value, error))
+        if (!_gtk_builder_flags_from_string (type, NULL, string, &flags_value, error))
           {
             ret = FALSE;
             break;
@@ -2202,13 +2202,14 @@ _gtk_builder_enum_from_string (GType         type,
 
 gboolean
 _gtk_builder_flags_from_string (GType         type,
+                                GFlagsValue  *aliases,
                                 const gchar  *string,
                                 guint        *flags_value,
                                 GError      **error)
 {
   GFlagsClass *fclass;
   gchar *endptr, *prevptr;
-  guint i, j, value;
+  guint i, j, k, value;
   gchar *flagstr;
   GFlagsValue *fv;
   const gchar *flag;
@@ -2268,7 +2269,23 @@ _gtk_builder_flags_from_string (GType         type,
           if (endptr > flag)
             {
               *endptr = '\0';
-              fv = g_flags_get_value_by_name (fclass, flag);
+
+              fv = NULL;
+
+              if (aliases)
+                {
+                  for (k = 0; aliases[k].value_nick; k++)
+                    {
+                      if (g_ascii_strcasecmp (aliases[k].value_nick, flag) == 0)
+                        {
+                          fv = &aliases[k];
+                          break;
+                        }
+                    }
+                }
+
+              if (!fv)
+                fv = g_flags_get_value_by_name (fclass, flag);
 
               if (!fv)
                 fv = g_flags_get_value_by_nick (fclass, flag);
diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c
index ca7a918..798f29f 100644
--- a/gtk/gtkbuilderparser.c
+++ b/gtk/gtkbuilderparser.c
@@ -587,7 +587,7 @@ parse_property (ParserData   *data,
 
   if (bind_flags_str)
     {
-      if (!_gtk_builder_flags_from_string (G_TYPE_BINDING_FLAGS, bind_flags_str, &bind_flags, error))
+      if (!_gtk_builder_flags_from_string (G_TYPE_BINDING_FLAGS, NULL, bind_flags_str, &bind_flags, error))
         {
           _gtk_builder_prefix_error (data->builder, data->ctx, error);
           return;
diff --git a/gtk/gtkbuilderprivate.h b/gtk/gtkbuilderprivate.h
index 6fbf996..06b9a7a 100644
--- a/gtk/gtkbuilderprivate.h
+++ b/gtk/gtkbuilderprivate.h
@@ -162,10 +162,11 @@ gboolean _gtk_builder_enum_from_string (GType         type,
                                         const gchar  *string,
                                         gint         *enum_value,
                                         GError      **error);
-gboolean  _gtk_builder_flags_from_string (GType       type,
-                                         const char *string,
-                                         guint      *value,
-                                         GError    **error);
+gboolean  _gtk_builder_flags_from_string (GType         type,
+                                          GFlagsValue  *aliases,
+                                         const char   *string,
+                                         guint        *value,
+                                         GError      **error);
 const gchar * _gtk_builder_parser_translate (const gchar *domain,
                                              const gchar *context,
                                              const gchar *text);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 508c0eb..7c76253 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -14257,7 +14257,14 @@ accel_group_start_element (GMarkupParseContext  *context,
 
       if (modifiers_str != NULL)
         {
-          if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
+          GFlagsValue aliases[2] = {
+            { 0, "primary", "primary" },
+            { 0, NULL, NULL }
+          };
+
+          aliases[0].value = _gtk_get_primary_accel_mod ();
+
+          if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE, aliases,
                                                modifiers_str, &modifiers, error))
             {
               _gtk_builder_prefix_error (data->builder, context, error);


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