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
This commit is contained in:
Matthias Clasen 2016-03-05 23:34:50 -05:00
parent 27a6183b98
commit 9c0e4c174a
5 changed files with 35 additions and 9 deletions

View File

@ -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))

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);