Convert more GtkBuilder to g_markup_collect_attributes
The core parser itself was left, so handle it as well.
This commit is contained in:
@ -77,27 +77,10 @@ error_missing_attribute (ParserData *data,
|
|||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
GTK_BUILDER_ERROR,
|
GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
|
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);
|
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
|
static void
|
||||||
error_invalid_tag (ParserData *data,
|
error_invalid_tag (ParserData *data,
|
||||||
const gchar *tag,
|
const gchar *tag,
|
||||||
@ -112,13 +95,28 @@ error_invalid_tag (ParserData *data,
|
|||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
GTK_BUILDER_ERROR,
|
GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_INVALID_TAG,
|
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);
|
data->filename, line, col, tag, expected);
|
||||||
else
|
else
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
GTK_BUILDER_ERROR,
|
GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_INVALID_TAG,
|
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);
|
data->filename, line, col, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +160,7 @@ _gtk_builder_boolean_from_string (const gchar *string,
|
|||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
GTK_BUILDER_ERROR,
|
GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_INVALID_VALUE,
|
GTK_BUILDER_ERROR_INVALID_VALUE,
|
||||||
"could not parse boolean `%s'",
|
"Could not parse boolean '%s'",
|
||||||
string);
|
string);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
@ -232,35 +230,25 @@ parse_requires (ParserData *data,
|
|||||||
const gchar *library = NULL;
|
const gchar *library = NULL;
|
||||||
const gchar *version = NULL;
|
const gchar *version = NULL;
|
||||||
gchar **split;
|
gchar **split;
|
||||||
gint i, version_major = 0, version_minor = 0;
|
gint version_major = 0;
|
||||||
|
gint version_minor = 0;
|
||||||
|
|
||||||
for (i = 0; names[i] != NULL; i++)
|
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)
|
_gtk_builder_prefix_error (data->builder, data->ctx, error);
|
||||||
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);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(split = g_strsplit (version, ".", 2)) || !split[0] || !split[1])
|
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,
|
g_set_error (error,
|
||||||
GTK_BUILDER_ERROR,
|
GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_INVALID_VALUE,
|
GTK_BUILDER_ERROR_INVALID_VALUE,
|
||||||
"%s:%d:%d '%s' attribute has malformed value \"%s\"",
|
"'version' attribute has malformed value '%s'", version);
|
||||||
data->filename, line, col, "version", version);
|
_gtk_builder_prefix_error (data->builder, data->ctx, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
version_major = g_ascii_strtoll (split[0], NULL, 10);
|
version_major = g_ascii_strtoll (split[0], NULL, 10);
|
||||||
@ -301,10 +289,12 @@ parse_object (GMarkupParseContext *context,
|
|||||||
ObjectInfo *object_info;
|
ObjectInfo *object_info;
|
||||||
ChildInfo* child_info;
|
ChildInfo* child_info;
|
||||||
GType object_type = G_TYPE_INVALID;
|
GType object_type = G_TYPE_INVALID;
|
||||||
const gchar *object_id = NULL;
|
const gchar *object_class = NULL;
|
||||||
const gchar *constructor = NULL;
|
const gchar *constructor = NULL;
|
||||||
|
const gchar *type_func = NULL;
|
||||||
|
const gchar *object_id = NULL;
|
||||||
gchar *internal_id = NULL;
|
gchar *internal_id = NULL;
|
||||||
gint i, line, line2;
|
gint line;
|
||||||
|
|
||||||
child_info = state_peek_info (data, ChildInfo);
|
child_info = state_peek_info (data, ChildInfo);
|
||||||
if (child_info && strcmp (child_info->tag.name, "object") == 0)
|
if (child_info && strcmp (child_info->tag.name, "object") == 0)
|
||||||
@ -313,45 +303,43 @@ parse_object (GMarkupParseContext *context,
|
|||||||
return;
|
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)
|
_gtk_builder_prefix_error (data->builder, data->ctx, error);
|
||||||
{
|
return;
|
||||||
object_type = gtk_builder_get_type_from_name (data->builder, values[i]);
|
}
|
||||||
|
|
||||||
|
if (object_class)
|
||||||
|
{
|
||||||
|
object_type = gtk_builder_get_type_from_name (data->builder, object_class);
|
||||||
if (object_type == G_TYPE_INVALID)
|
if (object_type == G_TYPE_INVALID)
|
||||||
{
|
{
|
||||||
g_markup_parse_context_get_position (context, &line, NULL);
|
g_set_error (error,
|
||||||
g_set_error (error, GTK_BUILDER_ERROR,
|
GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_INVALID_VALUE,
|
GTK_BUILDER_ERROR_INVALID_VALUE,
|
||||||
_("Invalid object type '%s' on line %d"),
|
"Invalid object type '%s'", object_class);
|
||||||
values[i], line);
|
_gtk_builder_prefix_error (data->builder, context, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp (names[i], "id") == 0)
|
else if (type_func)
|
||||||
object_id = values[i];
|
|
||||||
else if (strcmp (names[i], "constructor") == 0)
|
|
||||||
constructor = values[i];
|
|
||||||
else if (strcmp (names[i], "type-func") == 0)
|
|
||||||
{
|
{
|
||||||
/* Call the GType function, and return the GType, it's guaranteed afterwards
|
/* Call the GType function, and return the GType, it's guaranteed afterwards
|
||||||
* that g_type_from_name on the name will return our GType
|
* that g_type_from_name on the name will return our GType
|
||||||
*/
|
*/
|
||||||
object_type = _get_type_by_symbol (values[i]);
|
object_type = _get_type_by_symbol (type_func);
|
||||||
if (object_type == G_TYPE_INVALID)
|
if (object_type == G_TYPE_INVALID)
|
||||||
{
|
{
|
||||||
g_markup_parse_context_get_position (context, &line, NULL);
|
g_set_error (error,
|
||||||
g_set_error (error, GTK_BUILDER_ERROR,
|
GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION,
|
GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION,
|
||||||
_("Invalid type function on line %d: '%s'"),
|
"Invalid type function '%s'", type_func);
|
||||||
line, values[i]);
|
_gtk_builder_prefix_error (data->builder, context, error);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error_invalid_attribute (data, element_name, names[i], error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -378,8 +366,7 @@ parse_object (GMarkupParseContext *context,
|
|||||||
data->requested_object_level = data->cur_object_level;
|
data->requested_object_level = data->cur_object_level;
|
||||||
|
|
||||||
GTK_NOTE (BUILDER, g_print ("requested object \"%s\" found at level %d\n",
|
GTK_NOTE (BUILDER, g_print ("requested object \"%s\" found at level %d\n",
|
||||||
object_id,
|
object_id, data->requested_object_level));
|
||||||
data->requested_object_level));
|
|
||||||
|
|
||||||
data->inside_requested_object = TRUE;
|
data->inside_requested_object = TRUE;
|
||||||
}
|
}
|
||||||
@ -400,17 +387,19 @@ parse_object (GMarkupParseContext *context,
|
|||||||
if (child_info)
|
if (child_info)
|
||||||
object_info->parent = (CommonInfo*)child_info;
|
object_info->parent = (CommonInfo*)child_info;
|
||||||
|
|
||||||
g_markup_parse_context_get_position (context, &line, NULL);
|
line = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_id));
|
||||||
line2 = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_id));
|
if (line != 0)
|
||||||
if (line2 != 0)
|
|
||||||
{
|
{
|
||||||
g_set_error (error, GTK_BUILDER_ERROR,
|
g_set_error (error,
|
||||||
|
GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_DUPLICATE_ID,
|
GTK_BUILDER_ERROR_DUPLICATE_ID,
|
||||||
_("Duplicate object ID '%s' on line %d (previously on line %d)"),
|
"Duplicate object ID '%s' (previously on line %d)",
|
||||||
object_id, line, line2);
|
object_id, line);
|
||||||
|
_gtk_builder_prefix_error (data->builder, context, error);
|
||||||
return;
|
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));
|
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)
|
GError **error)
|
||||||
{
|
{
|
||||||
ObjectInfo *object_info;
|
ObjectInfo *object_info;
|
||||||
int i;
|
|
||||||
const gchar *object_class = NULL;
|
const gchar *object_class = NULL;
|
||||||
const gchar *parent_class = NULL;
|
const gchar *parent_class = NULL;
|
||||||
gint line, line2;
|
gint line;
|
||||||
GType template_type = _gtk_builder_get_template_type (data->builder);
|
GType template_type;
|
||||||
GType parsed_type;
|
GType parsed_type;
|
||||||
|
|
||||||
|
template_type = _gtk_builder_get_template_type (data->builder);
|
||||||
|
|
||||||
if (template_type == 0)
|
if (template_type == 0)
|
||||||
{
|
{
|
||||||
g_set_error (error,
|
error_unhandled_tag (data, "template", error);
|
||||||
GTK_BUILDER_ERROR,
|
|
||||||
GTK_BUILDER_ERROR_UNHANDLED_TAG,
|
|
||||||
"Encountered template definition but not parsing a template.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (state_peek (data) != NULL)
|
else if (state_peek (data) != NULL)
|
||||||
{
|
{
|
||||||
g_set_error (error,
|
error_invalid_tag (data, "template", NULL, error);
|
||||||
GTK_BUILDER_ERROR,
|
|
||||||
GTK_BUILDER_ERROR_UNHANDLED_TAG,
|
|
||||||
"Encountered template definition that is not at the top level.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; names[i] != NULL; i++)
|
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))
|
||||||
{
|
{
|
||||||
if (strcmp (names[i], "class") == 0)
|
_gtk_builder_prefix_error (data->builder, data->ctx, error);
|
||||||
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)
|
|
||||||
{
|
|
||||||
error_missing_attribute (data, element_name, "class", error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,8 +446,9 @@ parse_template (GMarkupParseContext *context,
|
|||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
GTK_BUILDER_ERROR,
|
GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_TEMPLATE_MISMATCH,
|
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));
|
object_class, g_type_name (template_type));
|
||||||
|
_gtk_builder_prefix_error (data->builder, context, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,16 +461,17 @@ parse_template (GMarkupParseContext *context,
|
|||||||
{
|
{
|
||||||
g_set_error (error, GTK_BUILDER_ERROR,
|
g_set_error (error, GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_INVALID_VALUE,
|
GTK_BUILDER_ERROR_INVALID_VALUE,
|
||||||
"Invalid template parent type `%s'",
|
"Invalid template parent type '%s'", parent_class);
|
||||||
parent_class);
|
_gtk_builder_prefix_error (data->builder, context, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (parent_type != expected_type)
|
if (parent_type != expected_type)
|
||||||
{
|
{
|
||||||
g_set_error (error, GTK_BUILDER_ERROR,
|
g_set_error (error, GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_TEMPLATE_MISMATCH,
|
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));
|
parent_class, g_type_name (expected_type));
|
||||||
|
_gtk_builder_prefix_error (data->builder, context, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -509,17 +485,19 @@ parse_template (GMarkupParseContext *context,
|
|||||||
state_push (data, object_info);
|
state_push (data, object_info);
|
||||||
object_info->tag.name = element_name;
|
object_info->tag.name = element_name;
|
||||||
|
|
||||||
g_markup_parse_context_get_position (context, &line, NULL);
|
line = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_class));
|
||||||
line2 = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_class));
|
if (line != 0)
|
||||||
if (line2 != 0)
|
|
||||||
{
|
{
|
||||||
g_set_error (error, GTK_BUILDER_ERROR,
|
g_set_error (error,
|
||||||
|
GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_DUPLICATE_ID,
|
GTK_BUILDER_ERROR_DUPLICATE_ID,
|
||||||
_("Duplicate object ID '%s' on line %d (previously on line %d)"),
|
"Duplicate object ID '%s' (previously on line %d)",
|
||||||
object_class, line, line2);
|
object_class, line);
|
||||||
|
_gtk_builder_prefix_error (data->builder, context, error);
|
||||||
return;
|
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));
|
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;
|
ObjectInfo* object_info;
|
||||||
ChildInfo *child_info;
|
ChildInfo *child_info;
|
||||||
guint i;
|
const gchar *type = NULL;
|
||||||
|
const gchar *internal_child = NULL;
|
||||||
|
|
||||||
object_info = state_peek_info (data, ObjectInfo);
|
object_info = state_peek_info (data, ObjectInfo);
|
||||||
if (!object_info ||
|
if (!object_info ||
|
||||||
@ -566,19 +545,20 @@ parse_child (ParserData *data,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
_gtk_builder_prefix_error (data->builder, data->ctx, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
child_info = g_slice_new0 (ChildInfo);
|
child_info = g_slice_new0 (ChildInfo);
|
||||||
state_push (data, child_info);
|
state_push (data, child_info);
|
||||||
child_info->tag.name = element_name;
|
child_info->tag.name = element_name;
|
||||||
for (i = 0; names[i]; i++)
|
child_info->type = g_strdup (type);
|
||||||
{
|
child_info->internal_child = g_strdup (internal_child);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
child_info->parent = (CommonInfo*)object_info;
|
child_info->parent = (CommonInfo*)object_info;
|
||||||
|
|
||||||
object_info->object = builder_construct (data, object_info, error);
|
object_info->object = builder_construct (data, object_info, error);
|
||||||
@ -600,14 +580,17 @@ parse_property (ParserData *data,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
PropertyInfo *info;
|
PropertyInfo *info;
|
||||||
|
const gchar *name = NULL;
|
||||||
const gchar *context = NULL;
|
const gchar *context = NULL;
|
||||||
const gchar *bind_source = NULL;
|
const gchar *bind_source = NULL;
|
||||||
const gchar *bind_property = NULL;
|
const gchar *bind_property = NULL;
|
||||||
|
const gchar *bind_flags_str = NULL;
|
||||||
GBindingFlags bind_flags = G_BINDING_DEFAULT;
|
GBindingFlags bind_flags = G_BINDING_DEFAULT;
|
||||||
gboolean translatable = FALSE;
|
gboolean translatable = FALSE;
|
||||||
ObjectInfo *object_info;
|
ObjectInfo *object_info;
|
||||||
GParamSpec *pspec = NULL;
|
GParamSpec *pspec = NULL;
|
||||||
gint i;
|
GObjectClass *oclass;
|
||||||
|
gchar *canonical;
|
||||||
|
|
||||||
object_info = state_peek_info (data, ObjectInfo);
|
object_info = state_peek_info (data, ObjectInfo);
|
||||||
if (!object_info ||
|
if (!object_info ||
|
||||||
@ -618,69 +601,47 @@ parse_property (ParserData *data,
|
|||||||
return;
|
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)
|
_gtk_builder_prefix_error (data->builder, data->ctx, error);
|
||||||
{
|
return;
|
||||||
GObjectClass *oclass = g_type_class_ref (object_info->type);
|
}
|
||||||
gchar *name = g_strdelimit (g_strdup (values[i]), "_", '-');
|
|
||||||
|
oclass = g_type_class_ref (object_info->type);
|
||||||
|
canonical = g_strdelimit (g_strdup (name), "_", '-');
|
||||||
|
|
||||||
g_assert (oclass != NULL);
|
g_assert (oclass != NULL);
|
||||||
pspec = g_object_class_find_property (oclass, name);
|
pspec = g_object_class_find_property (oclass, canonical);
|
||||||
g_type_class_unref (oclass);
|
g_type_class_unref (oclass);
|
||||||
g_free (name);
|
g_free (canonical);
|
||||||
|
|
||||||
if (!pspec)
|
if (!pspec)
|
||||||
{
|
{
|
||||||
gint line;
|
g_set_error (error,
|
||||||
g_markup_parse_context_get_position (data->ctx, &line, NULL);
|
GTK_BUILDER_ERROR,
|
||||||
g_set_error (error, GTK_BUILDER_ERROR,
|
|
||||||
GTK_BUILDER_ERROR_INVALID_PROPERTY,
|
GTK_BUILDER_ERROR_INVALID_PROPERTY,
|
||||||
_("Invalid property: %s.%s on line %d"),
|
"Invalid property: %s.%s",
|
||||||
g_type_name (object_info->type), values[i], line);
|
g_type_name (object_info->type), name);
|
||||||
|
_gtk_builder_prefix_error (data->builder, data->ctx, error);
|
||||||
return;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pspec)
|
if (bind_flags_str)
|
||||||
{
|
{
|
||||||
error_missing_attribute (data, element_name, "name", error);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bind_source && bind_property)
|
if (bind_source && bind_property)
|
||||||
{
|
{
|
||||||
@ -731,15 +692,14 @@ parse_signal (ParserData *data,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
SignalInfo *info;
|
SignalInfo *info;
|
||||||
|
const gchar *name;
|
||||||
const gchar *handler = NULL;
|
const gchar *handler = NULL;
|
||||||
const gchar *object = NULL;
|
const gchar *object = NULL;
|
||||||
gboolean after = FALSE;
|
gboolean after = FALSE;
|
||||||
gboolean swapped = FALSE;
|
gboolean swapped = -1;
|
||||||
gboolean swapped_set = FALSE;
|
|
||||||
ObjectInfo *object_info;
|
ObjectInfo *object_info;
|
||||||
guint id = 0;
|
guint id = 0;
|
||||||
GQuark detail = 0;
|
GQuark detail = 0;
|
||||||
gint i;
|
|
||||||
|
|
||||||
object_info = state_peek_info (data, ObjectInfo);
|
object_info = state_peek_info (data, ObjectInfo);
|
||||||
if (!object_info ||
|
if (!object_info ||
|
||||||
@ -750,61 +710,38 @@ parse_signal (ParserData *data,
|
|||||||
return;
|
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)
|
_gtk_builder_prefix_error (data->builder, data->ctx, error);
|
||||||
{
|
|
||||||
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;
|
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)
|
if (!g_signal_parse_name (name, object_info->type, &id, &detail, FALSE))
|
||||||
{
|
{
|
||||||
error_missing_attribute (data, element_name, "name", error);
|
g_set_error (error,
|
||||||
return;
|
GTK_BUILDER_ERROR,
|
||||||
}
|
GTK_BUILDER_ERROR_INVALID_SIGNAL,
|
||||||
else if (!handler)
|
"Invalid signal '%s' for type '%s'",
|
||||||
{
|
name, g_type_name (object_info->type));
|
||||||
error_missing_attribute (data, element_name, "handler", error);
|
_gtk_builder_prefix_error (data->builder, data->ctx, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Swapped defaults to FALSE except when object is set */
|
/* Swapped defaults to FALSE except when object is set */
|
||||||
if (object && !swapped_set)
|
if (swapped == -1)
|
||||||
|
{
|
||||||
|
if (object)
|
||||||
swapped = TRUE;
|
swapped = TRUE;
|
||||||
|
else
|
||||||
|
swapped = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
info = g_slice_new0 (SignalInfo);
|
info = g_slice_new0 (SignalInfo);
|
||||||
info->id = id;
|
info->id = id;
|
||||||
@ -846,33 +783,28 @@ parse_interface (ParserData *data,
|
|||||||
const gchar **values,
|
const gchar **values,
|
||||||
GError **error)
|
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)
|
_gtk_builder_prefix_error (data->builder, data->ctx, error);
|
||||||
{
|
return;
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
|
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);
|
g_free (data->domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
data->domain = g_strdup (values[i]);
|
data->domain = g_strdup (domain);
|
||||||
gtk_builder_set_translation_domain (data->builder, data->domain);
|
gtk_builder_set_translation_domain (data->builder, data->domain);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
error_invalid_attribute (data, "interface", names[i], error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SubParser *
|
static SubParser *
|
||||||
@ -1057,10 +989,7 @@ start_element (GMarkupParseContext *context,
|
|||||||
|
|
||||||
if (!data->last_element && strcmp (element_name, "interface") != 0)
|
if (!data->last_element && strcmp (element_name, "interface") != 0)
|
||||||
{
|
{
|
||||||
g_set_error (error, GTK_BUILDER_ERROR,
|
error_unhandled_tag (data, element_name, error);
|
||||||
GTK_BUILDER_ERROR_UNHANDLED_TAG,
|
|
||||||
_("Invalid root element: <%s>"),
|
|
||||||
element_name);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
data->last_element = element_name;
|
data->last_element = element_name;
|
||||||
@ -1098,10 +1027,7 @@ start_element (GMarkupParseContext *context,
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
else if (!parse_custom (context, element_name, names, values, data, error))
|
else if (!parse_custom (context, element_name, names, values, data, error))
|
||||||
g_set_error (error,
|
error_unhandled_tag (data, element_name, error);
|
||||||
GTK_BUILDER_ERROR,
|
|
||||||
GTK_BUILDER_ERROR_UNHANDLED_TAG,
|
|
||||||
_("Unhandled tag: <%s>"), element_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *
|
const gchar *
|
||||||
@ -1146,13 +1072,16 @@ end_element (GMarkupParseContext *context,
|
|||||||
if (!strcmp (req_info->library, "gtk+"))
|
if (!strcmp (req_info->library, "gtk+"))
|
||||||
{
|
{
|
||||||
if (!GTK_CHECK_VERSION (req_info->major, req_info->minor, 0))
|
if (!GTK_CHECK_VERSION (req_info->major, req_info->minor, 0))
|
||||||
|
{
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
GTK_BUILDER_ERROR,
|
GTK_BUILDER_ERROR,
|
||||||
GTK_BUILDER_ERROR_VERSION_MISMATCH,
|
GTK_BUILDER_ERROR_VERSION_MISMATCH,
|
||||||
"%s: required %s version %d.%d, current version is %d.%d",
|
"Required %s version %d.%d, current version is %d.%d",
|
||||||
data->filename, req_info->library,
|
req_info->library,
|
||||||
req_info->major, req_info->minor,
|
req_info->major, req_info->minor,
|
||||||
GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
|
GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
|
||||||
|
_gtk_builder_prefix_error (data->builder, context, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free_requires_info (req_info, NULL);
|
free_requires_info (req_info, NULL);
|
||||||
}
|
}
|
||||||
@ -1225,8 +1154,7 @@ end_element (GMarkupParseContext *context,
|
|||||||
|
|
||||||
prop_info->data = g_string_free (prop_info->text, FALSE);
|
prop_info->data = g_string_free (prop_info->text, FALSE);
|
||||||
|
|
||||||
object_info->properties =
|
object_info->properties = g_slist_prepend (object_info->properties, prop_info);
|
||||||
g_slist_prepend (object_info->properties, prop_info);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
@ -1244,15 +1172,18 @@ end_element (GMarkupParseContext *context,
|
|||||||
SignalInfo *signal_info = state_pop_info (data, SignalInfo);
|
SignalInfo *signal_info = state_pop_info (data, SignalInfo);
|
||||||
ObjectInfo *object_info = (ObjectInfo*)state_peek_info (data, CommonInfo);
|
ObjectInfo *object_info = (ObjectInfo*)state_peek_info (data, CommonInfo);
|
||||||
signal_info->object_name = g_strdup (object_info->id);
|
signal_info->object_name = g_strdup (object_info->id);
|
||||||
object_info->signals =
|
object_info->signals = g_slist_prepend (object_info->signals, signal_info);
|
||||||
g_slist_prepend (object_info->signals, signal_info);
|
|
||||||
}
|
}
|
||||||
else if (strcmp (element_name, "placeholder") == 0)
|
else if (strcmp (element_name, "placeholder") == 0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user