[gtk+] Convert more GtkBuilder to g_markup_collect_attributes
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Convert more GtkBuilder to g_markup_collect_attributes
- Date: Thu, 30 Apr 2015 10:20:58 +0000 (UTC)
commit 287ba6b94b290357614817ce8ec5b213857a046b
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Apr 29 23:55:07 2015 -0400
Convert more GtkBuilder to g_markup_collect_attributes
The core parser itself was left, so handle it as well.
gtk/gtkbuilderparser.c | 499 +++++++++++++++++++++---------------------------
1 files changed, 215 insertions(+), 284 deletions(-)
---
diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c
index 6c1a28b..998357d 100644
--- a/gtk/gtkbuilderparser.c
+++ b/gtk/gtkbuilderparser.c
@@ -77,28 +77,11 @@ error_missing_attribute (ParserData *data,
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
- "%s:%d:%d <%s> requires attribute \"%s\"",
+ "%s:%d:%d <%s> requires attribute '%s'",
data->filename, line, col, tag, attribute);
}
static void
-error_invalid_attribute (ParserData *data,
- const gchar *tag,
- const gchar *attribute,
- GError **error)
-{
- gint line, col;
-
- g_markup_parse_context_get_position (data->ctx, &line, &col);
-
- g_set_error (error,
- GTK_BUILDER_ERROR,
- GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
- "%s:%d:%d '%s' is not a valid attribute of <%s>",
- data->filename, line, col, attribute, tag);
-}
-
-static void
error_invalid_tag (ParserData *data,
const gchar *tag,
const gchar *expected,
@@ -112,16 +95,31 @@ error_invalid_tag (ParserData *data,
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_TAG,
- "%s:%d:%d '%s' is not a valid tag here, expected a '%s' tag",
+ "%s:%d:%d <%s> is not a valid tag here, expected a <%s> tag",
data->filename, line, col, tag, expected);
else
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_TAG,
- "%s:%d:%d '%s' is not a valid tag here",
+ "%s:%d:%d <%s> is not a valid tag here",
data->filename, line, col, tag);
}
+static void
+error_unhandled_tag (ParserData *data,
+ const gchar *tag,
+ GError **error)
+{
+ gint line, col;
+
+ g_markup_parse_context_get_position (data->ctx, &line, &col);
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
+ GTK_BUILDER_ERROR_UNHANDLED_TAG,
+ "%s:%d:%d Unhandled tag: <%s>",
+ data->filename, line, col, tag);
+}
+
gboolean
_gtk_builder_boolean_from_string (const gchar *string,
gboolean *value,
@@ -162,7 +160,7 @@ _gtk_builder_boolean_from_string (const gchar *string,
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_VALUE,
- "could not parse boolean `%s'",
+ "Could not parse boolean '%s'",
string);
return retval;
@@ -231,36 +229,26 @@ parse_requires (ParserData *data,
RequiresInfo *req_info;
const gchar *library = NULL;
const gchar *version = NULL;
- gchar **split;
- gint i, version_major = 0, version_minor = 0;
-
- for (i = 0; names[i] != NULL; i++)
+ gchar **split;
+ gint version_major = 0;
+ gint version_minor = 0;
+
+ if (!g_markup_collect_attributes (element_name, names, values, error,
+ G_MARKUP_COLLECT_STRING, "lib", &library,
+ G_MARKUP_COLLECT_STRING, "version", &version,
+ G_MARKUP_COLLECT_INVALID))
{
- if (strcmp (names[i], "lib") == 0)
- library = values[i];
- else if (strcmp (names[i], "version") == 0)
- version = values[i];
- else
- error_invalid_attribute (data, element_name, names[i], error);
- }
-
- if (!library || !version)
- {
- error_missing_attribute (data, element_name,
- version ? "lib" : "version", error);
+ _gtk_builder_prefix_error (data->builder, data->ctx, error);
return;
}
if (!(split = g_strsplit (version, ".", 2)) || !split[0] || !split[1])
{
- gint line, col;
-
- g_markup_parse_context_get_position (data->ctx, &line, &col);
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_VALUE,
- "%s:%d:%d '%s' attribute has malformed value \"%s\"",
- data->filename, line, col, "version", version);
+ "'version' attribute has malformed value '%s'", version);
+ _gtk_builder_prefix_error (data->builder, data->ctx, error);
return;
}
version_major = g_ascii_strtoll (split[0], NULL, 10);
@@ -269,8 +257,8 @@ parse_requires (ParserData *data,
req_info = g_slice_new0 (RequiresInfo);
req_info->library = g_strdup (library);
- req_info->major = version_major;
- req_info->minor = version_minor;
+ req_info->major = version_major;
+ req_info->minor = version_minor;
state_push (data, req_info);
req_info->tag.name = element_name;
}
@@ -301,10 +289,12 @@ parse_object (GMarkupParseContext *context,
ObjectInfo *object_info;
ChildInfo* child_info;
GType object_type = G_TYPE_INVALID;
- const gchar *object_id = NULL;
+ const gchar *object_class = NULL;
const gchar *constructor = NULL;
+ const gchar *type_func = NULL;
+ const gchar *object_id = NULL;
gchar *internal_id = NULL;
- gint i, line, line2;
+ gint line;
child_info = state_peek_info (data, ChildInfo);
if (child_info && strcmp (child_info->tag.name, "object") == 0)
@@ -313,45 +303,43 @@ parse_object (GMarkupParseContext *context,
return;
}
- for (i = 0; names[i] != NULL; i++)
+ if (!g_markup_collect_attributes (element_name, names, values, error,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "class",
&object_class,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "constructor",
&constructor,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "type-func",
&type_func,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "id", &object_id,
+ G_MARKUP_COLLECT_INVALID))
{
- if (strcmp (names[i], "class") == 0)
- {
- object_type = gtk_builder_get_type_from_name (data->builder, values[i]);
+ _gtk_builder_prefix_error (data->builder, data->ctx, error);
+ return;
+ }
- if (object_type == G_TYPE_INVALID)
- {
- g_markup_parse_context_get_position (context, &line, NULL);
- g_set_error (error, GTK_BUILDER_ERROR,
- GTK_BUILDER_ERROR_INVALID_VALUE,
- _("Invalid object type '%s' on line %d"),
- values[i], line);
- return;
- }
- }
- else if (strcmp (names[i], "id") == 0)
- object_id = values[i];
- else if (strcmp (names[i], "constructor") == 0)
- constructor = values[i];
- else if (strcmp (names[i], "type-func") == 0)
+ if (object_class)
+ {
+ object_type = gtk_builder_get_type_from_name (data->builder, object_class);
+ if (object_type == G_TYPE_INVALID)
{
- /* Call the GType function, and return the GType, it's guaranteed afterwards
- * that g_type_from_name on the name will return our GType
- */
- object_type = _get_type_by_symbol (values[i]);
- if (object_type == G_TYPE_INVALID)
- {
- g_markup_parse_context_get_position (context, &line, NULL);
- g_set_error (error, GTK_BUILDER_ERROR,
- GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION,
- _("Invalid type function on line %d: '%s'"),
- line, values[i]);
- return;
- }
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
+ GTK_BUILDER_ERROR_INVALID_VALUE,
+ "Invalid object type '%s'", object_class);
+ _gtk_builder_prefix_error (data->builder, context, error);
+ return;
}
- else
+ }
+ else if (type_func)
+ {
+ /* Call the GType function, and return the GType, it's guaranteed afterwards
+ * that g_type_from_name on the name will return our GType
+ */
+ object_type = _get_type_by_symbol (type_func);
+ if (object_type == G_TYPE_INVALID)
{
- error_invalid_attribute (data, element_name, names[i], error);
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
+ GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION,
+ "Invalid type function '%s'", type_func);
+ _gtk_builder_prefix_error (data->builder, context, error);
return;
}
}
@@ -378,8 +366,7 @@ parse_object (GMarkupParseContext *context,
data->requested_object_level = data->cur_object_level;
GTK_NOTE (BUILDER, g_print ("requested object \"%s\" found at level %d\n",
- object_id,
- data->requested_object_level));
+ object_id, data->requested_object_level));
data->inside_requested_object = TRUE;
}
@@ -400,17 +387,19 @@ parse_object (GMarkupParseContext *context,
if (child_info)
object_info->parent = (CommonInfo*)child_info;
- g_markup_parse_context_get_position (context, &line, NULL);
- line2 = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_id));
- if (line2 != 0)
+ line = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_id));
+ if (line != 0)
{
- g_set_error (error, GTK_BUILDER_ERROR,
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_DUPLICATE_ID,
- _("Duplicate object ID '%s' on line %d (previously on line %d)"),
- object_id, line, line2);
+ "Duplicate object ID '%s' (previously on line %d)",
+ object_id, line);
+ _gtk_builder_prefix_error (data->builder, context, error);
return;
}
+ g_markup_parse_context_get_position (context, &line, NULL);
g_hash_table_insert (data->object_ids, g_strdup (object_id), GINT_TO_POINTER (line));
}
@@ -423,46 +412,31 @@ parse_template (GMarkupParseContext *context,
GError **error)
{
ObjectInfo *object_info;
- int i;
const gchar *object_class = NULL;
const gchar *parent_class = NULL;
- gint line, line2;
- GType template_type = _gtk_builder_get_template_type (data->builder);
+ gint line;
+ GType template_type;
GType parsed_type;
+ template_type = _gtk_builder_get_template_type (data->builder);
+
if (template_type == 0)
{
- g_set_error (error,
- GTK_BUILDER_ERROR,
- GTK_BUILDER_ERROR_UNHANDLED_TAG,
- "Encountered template definition but not parsing a template.");
+ error_unhandled_tag (data, "template", error);
return;
}
else if (state_peek (data) != NULL)
{
- g_set_error (error,
- GTK_BUILDER_ERROR,
- GTK_BUILDER_ERROR_UNHANDLED_TAG,
- "Encountered template definition that is not at the top level.");
+ error_invalid_tag (data, "template", NULL, error);
return;
}
- for (i = 0; names[i] != NULL; i++)
- {
- if (strcmp (names[i], "class") == 0)
- object_class = values[i];
- else if (strcmp (names[i], "parent") == 0)
- parent_class = values[i];
- else
- {
- error_invalid_attribute (data, element_name, names[i], error);
- return;
- }
- }
-
- if (!object_class)
+ if (!g_markup_collect_attributes (element_name, names, values, error,
+ G_MARKUP_COLLECT_STRING, "class", &object_class,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "parent",
&parent_class,
+ G_MARKUP_COLLECT_INVALID))
{
- error_missing_attribute (data, element_name, "class", error);
+ _gtk_builder_prefix_error (data->builder, data->ctx, error);
return;
}
@@ -472,8 +446,9 @@ parse_template (GMarkupParseContext *context,
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_TEMPLATE_MISMATCH,
- "Parsed template definition for type `%s', expected type `%s'.",
+ "Parsed template definition for type '%s', expected type '%s'",
object_class, g_type_name (template_type));
+ _gtk_builder_prefix_error (data->builder, context, error);
return;
}
@@ -486,16 +461,17 @@ parse_template (GMarkupParseContext *context,
{
g_set_error (error, GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_VALUE,
- "Invalid template parent type `%s'",
- parent_class);
+ "Invalid template parent type '%s'", parent_class);
+ _gtk_builder_prefix_error (data->builder, context, error);
return;
}
if (parent_type != expected_type)
{
g_set_error (error, GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_TEMPLATE_MISMATCH,
- "Template parent type `%s' does not match instance parent type `%s'.",
+ "Template parent type '%s' does not match instance parent type '%s'.",
parent_class, g_type_name (expected_type));
+ _gtk_builder_prefix_error (data->builder, context, error);
return;
}
}
@@ -509,17 +485,19 @@ parse_template (GMarkupParseContext *context,
state_push (data, object_info);
object_info->tag.name = element_name;
- g_markup_parse_context_get_position (context, &line, NULL);
- line2 = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_class));
- if (line2 != 0)
+ line = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_class));
+ if (line != 0)
{
- g_set_error (error, GTK_BUILDER_ERROR,
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_DUPLICATE_ID,
- _("Duplicate object ID '%s' on line %d (previously on line %d)"),
- object_class, line, line2);
+ "Duplicate object ID '%s' (previously on line %d)",
+ object_class, line);
+ _gtk_builder_prefix_error (data->builder, context, error);
return;
}
+ g_markup_parse_context_get_position (context, &line, NULL);
g_hash_table_insert (data->object_ids, g_strdup (object_class), GINT_TO_POINTER (line));
}
@@ -555,7 +533,8 @@ parse_child (ParserData *data,
{
ObjectInfo* object_info;
ChildInfo *child_info;
- guint i;
+ const gchar *type = NULL;
+ const gchar *internal_child = NULL;
object_info = state_peek_info (data, ObjectInfo);
if (!object_info ||
@@ -566,19 +545,20 @@ parse_child (ParserData *data,
return;
}
- child_info = g_slice_new0 (ChildInfo);
- state_push (data, child_info);
- child_info->tag.name = element_name;
- for (i = 0; names[i]; i++)
+ if (!g_markup_collect_attributes (element_name, names, values, error,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "type", &type,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "internal-child",
&internal_child,
+ G_MARKUP_COLLECT_INVALID))
{
- if (strcmp (names[i], "type") == 0)
- child_info->type = g_strdup (values[i]);
- else if (strcmp (names[i], "internal-child") == 0)
- child_info->internal_child = g_strdup (values[i]);
- else
- error_invalid_attribute (data, element_name, names[i], error);
+ _gtk_builder_prefix_error (data->builder, data->ctx, error);
+ return;
}
+ child_info = g_slice_new0 (ChildInfo);
+ state_push (data, child_info);
+ child_info->tag.name = element_name;
+ child_info->type = g_strdup (type);
+ child_info->internal_child = g_strdup (internal_child);
child_info->parent = (CommonInfo*)object_info;
object_info->object = builder_construct (data, object_info, error);
@@ -600,14 +580,17 @@ parse_property (ParserData *data,
GError **error)
{
PropertyInfo *info;
+ const gchar *name = NULL;
const gchar *context = NULL;
const gchar *bind_source = NULL;
const gchar *bind_property = NULL;
+ const gchar *bind_flags_str = NULL;
GBindingFlags bind_flags = G_BINDING_DEFAULT;
gboolean translatable = FALSE;
ObjectInfo *object_info;
GParamSpec *pspec = NULL;
- gint i;
+ GObjectClass *oclass;
+ gchar *canonical;
object_info = state_peek_info (data, ObjectInfo);
if (!object_info ||
@@ -618,70 +601,48 @@ parse_property (ParserData *data,
return;
}
- for (i = 0; names[i] != NULL; i++)
+ if (!g_markup_collect_attributes (element_name, names, values, error,
+ G_MARKUP_COLLECT_STRING, "name", &name,
+ G_MARKUP_COLLECT_BOOLEAN|G_MARKUP_COLLECT_OPTIONAL, "translatable",
&translatable,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "comments", NULL,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "context", &context,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "bind-source",
&bind_source,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "bind-property",
&bind_property,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "bind-flags",
&bind_flags_str,
+ G_MARKUP_COLLECT_INVALID))
{
- if (strcmp (names[i], "name") == 0)
- {
- GObjectClass *oclass = g_type_class_ref (object_info->type);
- gchar *name = g_strdelimit (g_strdup (values[i]), "_", '-');
+ _gtk_builder_prefix_error (data->builder, data->ctx, error);
+ return;
+ }
- g_assert (oclass != NULL);
- pspec = g_object_class_find_property (oclass, name);
- g_type_class_unref (oclass);
- g_free (name);
+ oclass = g_type_class_ref (object_info->type);
+ canonical = g_strdelimit (g_strdup (name), "_", '-');
- if (!pspec)
- {
- gint line;
- g_markup_parse_context_get_position (data->ctx, &line, NULL);
- g_set_error (error, GTK_BUILDER_ERROR,
- GTK_BUILDER_ERROR_INVALID_PROPERTY,
- _("Invalid property: %s.%s on line %d"),
- g_type_name (object_info->type), values[i], line);
- return;
- }
- }
- else if (strcmp (names[i], "translatable") == 0)
- {
- if (!_gtk_builder_boolean_from_string (values[i], &translatable,
- error))
- return;
- }
- else if (strcmp (names[i], "comments") == 0)
- {
- /* do nothing, comments are for translators */
- }
- else if (strcmp (names[i], "context") == 0)
- {
- context = values[i];
- }
- else if (strcmp (names[i], "bind-source") == 0)
- {
- bind_source = values[i];
- }
- else if (strcmp (names[i], "bind-property") == 0)
- {
- bind_property = values[i];
- }
- else if (strcmp (names[i], "bind-flags") == 0)
- {
- if (!_gtk_builder_flags_from_string (G_TYPE_BINDING_FLAGS, values[i],
- &bind_flags, error))
- return;
- }
- else
- {
- error_invalid_attribute (data, element_name, names[i], error);
- return;
- }
- }
+ g_assert (oclass != NULL);
+ pspec = g_object_class_find_property (oclass, canonical);
+ g_type_class_unref (oclass);
+ g_free (canonical);
if (!pspec)
{
- error_missing_attribute (data, element_name, "name", error);
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
+ GTK_BUILDER_ERROR_INVALID_PROPERTY,
+ "Invalid property: %s.%s",
+ g_type_name (object_info->type), name);
+ _gtk_builder_prefix_error (data->builder, data->ctx, error);
return;
}
+ if (bind_flags_str)
+ {
+ if (!_gtk_builder_flags_from_string (G_TYPE_BINDING_FLAGS, bind_flags_str, &bind_flags, error))
+ {
+ _gtk_builder_prefix_error (data->builder, data->ctx, error);
+ return;
+ }
+ }
+
if (bind_source && bind_property)
{
BindingInfo *binfo = g_slice_new0 (BindingInfo);
@@ -731,15 +692,14 @@ parse_signal (ParserData *data,
GError **error)
{
SignalInfo *info;
+ const gchar *name;
const gchar *handler = NULL;
const gchar *object = NULL;
gboolean after = FALSE;
- gboolean swapped = FALSE;
- gboolean swapped_set = FALSE;
+ gboolean swapped = -1;
ObjectInfo *object_info;
- guint id = 0;
+ guint id = 0;
GQuark detail = 0;
- gint i;
object_info = state_peek_info (data, ObjectInfo);
if (!object_info ||
@@ -750,61 +710,38 @@ parse_signal (ParserData *data,
return;
}
- for (i = 0; names[i] != NULL; i++)
+ if (!g_markup_collect_attributes (element_name, names, values, error,
+ G_MARKUP_COLLECT_STRING, "name", &name,
+ G_MARKUP_COLLECT_STRING, "handler", &handler,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "object", &object,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL,
"last_modification_time", NULL,
+ G_MARKUP_COLLECT_BOOLEAN|G_MARKUP_COLLECT_OPTIONAL, "after", &after,
+ G_MARKUP_COLLECT_TRISTATE|G_MARKUP_COLLECT_OPTIONAL, "swapped", &swapped,
+ G_MARKUP_COLLECT_INVALID))
{
- if (strcmp (names[i], "name") == 0)
- {
- if (!g_signal_parse_name (values[i], object_info->type,
- &id, &detail, FALSE))
- {
- gint line;
- g_markup_parse_context_get_position (data->ctx, &line, NULL);
- g_set_error (error, GTK_BUILDER_ERROR,
- GTK_BUILDER_ERROR_INVALID_SIGNAL,
- _("Invalid signal '%s' for type '%s' on line %d"),
- values[i], g_type_name (object_info->type), line);
- return;
- }
- }
- else if (strcmp (names[i], "handler") == 0)
- handler = values[i];
- else if (strcmp (names[i], "after") == 0)
- {
- if (!_gtk_builder_boolean_from_string (values[i], &after, error))
- return;
- }
- else if (strcmp (names[i], "swapped") == 0)
- {
- if (!_gtk_builder_boolean_from_string (values[i], &swapped, error))
- return;
- swapped_set = TRUE;
- }
- else if (strcmp (names[i], "object") == 0)
- object = values[i];
- else if (strcmp (names[i], "last_modification_time") == 0)
- /* parse but ignore */
- ;
- else
- {
- error_invalid_attribute (data, element_name, names[i], error);
- return;
- }
- }
-
- if (!id)
- {
- error_missing_attribute (data, element_name, "name", error);
+ _gtk_builder_prefix_error (data->builder, data->ctx, error);
return;
}
- else if (!handler)
+
+ if (!g_signal_parse_name (name, object_info->type, &id, &detail, FALSE))
{
- error_missing_attribute (data, element_name, "handler", error);
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
+ GTK_BUILDER_ERROR_INVALID_SIGNAL,
+ "Invalid signal '%s' for type '%s'",
+ name, g_type_name (object_info->type));
+ _gtk_builder_prefix_error (data->builder, data->ctx, error);
return;
}
/* Swapped defaults to FALSE except when object is set */
- if (object && !swapped_set)
- swapped = TRUE;
+ if (swapped == -1)
+ {
+ if (object)
+ swapped = TRUE;
+ else
+ swapped = FALSE;
+ }
info = g_slice_new0 (SignalInfo);
info->id = id;
@@ -846,32 +783,27 @@ parse_interface (ParserData *data,
const gchar **values,
GError **error)
{
- int i;
+ const gchar *domain = NULL;
- for (i = 0; names[i] != NULL; i++)
+ if (!g_markup_collect_attributes (element_name, names, values, error,
+ G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "domain", &domain,
+ G_MARKUP_COLLECT_INVALID))
{
- if (strcmp (names[i], "domain") == 0)
- {
- if (data->domain)
- {
- if (strcmp (data->domain, values[i]) == 0)
- continue;
- else
- g_warning ("%s: interface domain '%s' overrides "
- "programically set domain '%s'",
- data->filename,
- values[i],
- data->domain
- );
-
- g_free (data->domain);
- }
+ _gtk_builder_prefix_error (data->builder, data->ctx, error);
+ return;
+ }
- data->domain = g_strdup (values[i]);
- gtk_builder_set_translation_domain (data->builder, data->domain);
+ if (domain)
+ {
+ if (data->domain && strcmp (data->domain, domain) != 0)
+ {
+ g_warning ("%s: interface domain '%s' overrides programmatic value '%s'",
+ data->filename, domain, data->domain);
+ g_free (data->domain);
}
- else
- error_invalid_attribute (data, "interface", names[i], error);
+
+ data->domain = g_strdup (domain);
+ gtk_builder_set_translation_domain (data->builder, data->domain);
}
}
@@ -1057,10 +989,7 @@ start_element (GMarkupParseContext *context,
if (!data->last_element && strcmp (element_name, "interface") != 0)
{
- g_set_error (error, GTK_BUILDER_ERROR,
- GTK_BUILDER_ERROR_UNHANDLED_TAG,
- _("Invalid root element: <%s>"),
- element_name);
+ error_unhandled_tag (data, element_name, error);
return;
}
data->last_element = element_name;
@@ -1098,10 +1027,7 @@ start_element (GMarkupParseContext *context,
*/
}
else if (!parse_custom (context, element_name, names, values, data, error))
- g_set_error (error,
- GTK_BUILDER_ERROR,
- GTK_BUILDER_ERROR_UNHANDLED_TAG,
- _("Unhandled tag: <%s>"), element_name);
+ error_unhandled_tag (data, element_name, error);
}
const gchar *
@@ -1146,13 +1072,16 @@ end_element (GMarkupParseContext *context,
if (!strcmp (req_info->library, "gtk+"))
{
if (!GTK_CHECK_VERSION (req_info->major, req_info->minor, 0))
- g_set_error (error,
- GTK_BUILDER_ERROR,
- GTK_BUILDER_ERROR_VERSION_MISMATCH,
- "%s: required %s version %d.%d, current version is %d.%d",
- data->filename, req_info->library,
- req_info->major, req_info->minor,
- GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
+ {
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
+ GTK_BUILDER_ERROR_VERSION_MISMATCH,
+ "Required %s version %d.%d, current version is %d.%d",
+ req_info->library,
+ req_info->major, req_info->minor,
+ GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
+ _gtk_builder_prefix_error (data->builder, context, error);
+ }
}
free_requires_info (req_info, NULL);
}
@@ -1225,8 +1154,7 @@ end_element (GMarkupParseContext *context,
prop_info->data = g_string_free (prop_info->text, FALSE);
- object_info->properties =
- g_slist_prepend (object_info->properties, prop_info);
+ object_info->properties = g_slist_prepend (object_info->properties, prop_info);
}
else
g_assert_not_reached ();
@@ -1244,15 +1172,18 @@ end_element (GMarkupParseContext *context,
SignalInfo *signal_info = state_pop_info (data, SignalInfo);
ObjectInfo *object_info = (ObjectInfo*)state_peek_info (data, CommonInfo);
signal_info->object_name = g_strdup (object_info->id);
- object_info->signals =
- g_slist_prepend (object_info->signals, signal_info);
+ object_info->signals = g_slist_prepend (object_info->signals, signal_info);
}
else if (strcmp (element_name, "placeholder") == 0)
{
}
else
{
- g_assert_not_reached ();
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
+ GTK_BUILDER_ERROR_UNHANDLED_TAG,
+ "Unhandled tag: <%s>", element_name);
+ _gtk_builder_prefix_error (data->builder, context, error);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]