Commit 9c0e4c17 authored by Matthias Clasen's avatar Matthias Clasen

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
parent 27a6183b
...@@ -437,6 +437,7 @@ accelerator_start_element (GMarkupParseContext *context, ...@@ -437,6 +437,7 @@ accelerator_start_element (GMarkupParseContext *context,
else if (strcmp (names[i], "modifiers") == 0) else if (strcmp (names[i], "modifiers") == 0)
{ {
if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE, if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
NULL,
values[i], values[i],
&modifiers, &modifiers,
error)) error))
......
...@@ -1954,7 +1954,7 @@ gtk_builder_value_from_string_type (GtkBuilder *builder, ...@@ -1954,7 +1954,7 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
{ {
guint flags_value; 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; ret = FALSE;
break; break;
...@@ -2202,13 +2202,14 @@ _gtk_builder_enum_from_string (GType type, ...@@ -2202,13 +2202,14 @@ _gtk_builder_enum_from_string (GType type,
gboolean gboolean
_gtk_builder_flags_from_string (GType type, _gtk_builder_flags_from_string (GType type,
GFlagsValue *aliases,
const gchar *string, const gchar *string,
guint *flags_value, guint *flags_value,
GError **error) GError **error)
{ {
GFlagsClass *fclass; GFlagsClass *fclass;
gchar *endptr, *prevptr; gchar *endptr, *prevptr;
guint i, j, value; guint i, j, k, value;
gchar *flagstr; gchar *flagstr;
GFlagsValue *fv; GFlagsValue *fv;
const gchar *flag; const gchar *flag;
...@@ -2268,7 +2269,23 @@ _gtk_builder_flags_from_string (GType type, ...@@ -2268,7 +2269,23 @@ _gtk_builder_flags_from_string (GType type,
if (endptr > flag) if (endptr > flag)
{ {
*endptr = '\0'; *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) if (!fv)
fv = g_flags_get_value_by_nick (fclass, flag); fv = g_flags_get_value_by_nick (fclass, flag);
......
...@@ -587,7 +587,7 @@ parse_property (ParserData *data, ...@@ -587,7 +587,7 @@ parse_property (ParserData *data,
if (bind_flags_str) 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); _gtk_builder_prefix_error (data->builder, data->ctx, error);
return; return;
......
...@@ -162,10 +162,11 @@ gboolean _gtk_builder_enum_from_string (GType type, ...@@ -162,10 +162,11 @@ gboolean _gtk_builder_enum_from_string (GType type,
const gchar *string, const gchar *string,
gint *enum_value, gint *enum_value,
GError **error); GError **error);
gboolean _gtk_builder_flags_from_string (GType type, gboolean _gtk_builder_flags_from_string (GType type,
const char *string, GFlagsValue *aliases,
guint *value, const char *string,
GError **error); guint *value,
GError **error);
const gchar * _gtk_builder_parser_translate (const gchar *domain, const gchar * _gtk_builder_parser_translate (const gchar *domain,
const gchar *context, const gchar *context,
const gchar *text); const gchar *text);
......
...@@ -14257,7 +14257,14 @@ accel_group_start_element (GMarkupParseContext *context, ...@@ -14257,7 +14257,14 @@ accel_group_start_element (GMarkupParseContext *context,
if (modifiers_str != NULL) 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)) modifiers_str, &modifiers, error))
{ {
_gtk_builder_prefix_error (data->builder, context, error); _gtk_builder_prefix_error (data->builder, context, error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment