Do not use g_error for a few more errors, instead set the GError sent in
2008-02-29 Johan Dahlin <johan@gnome.org> * gtk/gtkbuilder.c: * gtk/gtkbuilderparser.c: * gtk/gtkbuilderprivate.h: Do not use g_error for a few more errors, instead set the GError sent in through add_from_file/add_from_string. * tests/buildertest.c: Add a couple of new parsing tests. (#519199, Pavel Syomin) svn path=/trunk/; revision=19681
This commit is contained in:
parent
9b440c1656
commit
a57b66aac2
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
2008-02-29 Johan Dahlin <johan@gnome.org>
|
||||||
|
|
||||||
|
* gtk/gtkbuilder.c:
|
||||||
|
* gtk/gtkbuilderparser.c:
|
||||||
|
* gtk/gtkbuilderprivate.h:
|
||||||
|
Do not use g_error for a few more errors, instead set
|
||||||
|
the GError sent in through add_from_file/add_from_string.
|
||||||
|
* tests/buildertest.c:
|
||||||
|
Add a couple of new parsing tests.
|
||||||
|
(#519199, Pavel Syomin)
|
||||||
|
|
||||||
2008-02-29 Federico Mena Quintero <federico@novell.com>
|
2008-02-29 Federico Mena Quintero <federico@novell.com>
|
||||||
|
|
||||||
* gtk/gtkfilesystemunix.c (gtk_file_system_unix_get_folder): When
|
* gtk/gtkfilesystemunix.c (gtk_file_system_unix_get_folder): When
|
||||||
|
@ -334,7 +334,8 @@ gtk_builder_get_parameters (GtkBuilder *builder,
|
|||||||
static GObject *
|
static GObject *
|
||||||
gtk_builder_get_internal_child (GtkBuilder *builder,
|
gtk_builder_get_internal_child (GtkBuilder *builder,
|
||||||
ObjectInfo *info,
|
ObjectInfo *info,
|
||||||
const gchar *childname)
|
const gchar *childname,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GObject *obj = NULL;
|
GObject *obj = NULL;
|
||||||
|
|
||||||
@ -359,14 +360,19 @@ gtk_builder_get_internal_child (GtkBuilder *builder,
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!obj)
|
if (!obj)
|
||||||
g_error ("Unknown internal child: %s\n", childname);
|
{
|
||||||
|
g_set_error (error,
|
||||||
|
GTK_BUILDER_ERROR,
|
||||||
|
GTK_BUILDER_ERROR_INVALID_VALUE,
|
||||||
|
"Unknown internal child: %s", childname);
|
||||||
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
GObject *
|
GObject *
|
||||||
_gtk_builder_construct (GtkBuilder *builder,
|
_gtk_builder_construct (GtkBuilder *builder,
|
||||||
ObjectInfo *info)
|
ObjectInfo *info,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GArray *parameters, *construct_parameters;
|
GArray *parameters, *construct_parameters;
|
||||||
GType object_type;
|
GType object_type;
|
||||||
@ -379,7 +385,14 @@ _gtk_builder_construct (GtkBuilder *builder,
|
|||||||
g_assert (info->class_name != NULL);
|
g_assert (info->class_name != NULL);
|
||||||
object_type = gtk_builder_get_type_from_name (builder, info->class_name);
|
object_type = gtk_builder_get_type_from_name (builder, info->class_name);
|
||||||
if (object_type == G_TYPE_INVALID)
|
if (object_type == G_TYPE_INVALID)
|
||||||
g_error ("Invalid type: %s", info->class_name);
|
{
|
||||||
|
g_set_error (error,
|
||||||
|
GTK_BUILDER_ERROR,
|
||||||
|
GTK_BUILDER_ERROR_INVALID_VALUE,
|
||||||
|
"Invalid object type `%s'",
|
||||||
|
info->class_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
gtk_builder_get_parameters (builder, object_type,
|
gtk_builder_get_parameters (builder, object_type,
|
||||||
info->id,
|
info->id,
|
||||||
@ -393,9 +406,17 @@ _gtk_builder_construct (GtkBuilder *builder,
|
|||||||
|
|
||||||
constructor = gtk_builder_get_object (builder, info->constructor);
|
constructor = gtk_builder_get_object (builder, info->constructor);
|
||||||
if (constructor == NULL)
|
if (constructor == NULL)
|
||||||
g_error ("Unknown constructor for %s: %s\n", info->id,
|
{
|
||||||
|
g_set_error (error,
|
||||||
|
GTK_BUILDER_ERROR,
|
||||||
|
GTK_BUILDER_ERROR_INVALID_VALUE,
|
||||||
|
"Unknown object constructor for %s: %s",
|
||||||
|
info->id,
|
||||||
info->constructor);
|
info->constructor);
|
||||||
|
g_array_free (parameters, TRUE);
|
||||||
|
g_array_free (construct_parameters, TRUE);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
obj = gtk_buildable_construct_child (GTK_BUILDABLE (constructor),
|
obj = gtk_buildable_construct_child (GTK_BUILDABLE (constructor),
|
||||||
builder,
|
builder,
|
||||||
info->id);
|
info->id);
|
||||||
@ -406,7 +427,13 @@ _gtk_builder_construct (GtkBuilder *builder,
|
|||||||
else if (info->parent && ((ChildInfo*)info->parent)->internal_child != NULL)
|
else if (info->parent && ((ChildInfo*)info->parent)->internal_child != NULL)
|
||||||
{
|
{
|
||||||
gchar *childname = ((ChildInfo*)info->parent)->internal_child;
|
gchar *childname = ((ChildInfo*)info->parent)->internal_child;
|
||||||
obj = gtk_builder_get_internal_child (builder, info, childname);
|
obj = gtk_builder_get_internal_child (builder, info, childname, error);
|
||||||
|
if (!obj)
|
||||||
|
{
|
||||||
|
g_array_free (parameters, TRUE);
|
||||||
|
g_array_free (construct_parameters, TRUE);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (construct_parameters->len)
|
if (construct_parameters->len)
|
||||||
g_warning ("Can't pass in construct-only parameters to %s", childname);
|
g_warning ("Can't pass in construct-only parameters to %s", childname);
|
||||||
g_object_ref (obj);
|
g_object_ref (obj);
|
||||||
|
@ -183,7 +183,8 @@ _gtk_builder_boolean_from_string (const gchar *string,
|
|||||||
|
|
||||||
static GObject *
|
static GObject *
|
||||||
builder_construct (ParserData *data,
|
builder_construct (ParserData *data,
|
||||||
ObjectInfo *object_info)
|
ObjectInfo *object_info,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GObject *object;
|
GObject *object;
|
||||||
|
|
||||||
@ -194,7 +195,10 @@ builder_construct (ParserData *data,
|
|||||||
|
|
||||||
object_info->properties = g_slist_reverse (object_info->properties);
|
object_info->properties = g_slist_reverse (object_info->properties);
|
||||||
|
|
||||||
object = _gtk_builder_construct (data->builder, object_info);
|
object = _gtk_builder_construct (data->builder, object_info, error);
|
||||||
|
if (!object)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
g_assert (G_IS_OBJECT (object));
|
g_assert (G_IS_OBJECT (object));
|
||||||
|
|
||||||
object_info->object = object;
|
object_info->object = object;
|
||||||
@ -345,7 +349,7 @@ parse_child (ParserData *data,
|
|||||||
|
|
||||||
child_info->parent = (CommonInfo*)object_info;
|
child_info->parent = (CommonInfo*)object_info;
|
||||||
|
|
||||||
object_info->object = builder_construct (data, object_info);
|
object_info->object = builder_construct (data, object_info, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -644,8 +648,13 @@ parse_custom (GMarkupParseContext *context,
|
|||||||
{
|
{
|
||||||
ObjectInfo* object_info = (ObjectInfo*)parent_info;
|
ObjectInfo* object_info = (ObjectInfo*)parent_info;
|
||||||
if (!object_info->object)
|
if (!object_info->object)
|
||||||
|
{
|
||||||
object_info->object = _gtk_builder_construct (data->builder,
|
object_info->object = _gtk_builder_construct (data->builder,
|
||||||
object_info);
|
object_info,
|
||||||
|
error);
|
||||||
|
if (!object_info->object)
|
||||||
|
return TRUE; /* A GError is already set */
|
||||||
|
}
|
||||||
g_assert (object_info->object);
|
g_assert (object_info->object);
|
||||||
object = object_info->object;
|
object = object_info->object;
|
||||||
child = NULL;
|
child = NULL;
|
||||||
@ -804,8 +813,12 @@ end_element (GMarkupParseContext *context,
|
|||||||
ObjectInfo *object_info = state_pop_info (data, ObjectInfo);
|
ObjectInfo *object_info = state_pop_info (data, ObjectInfo);
|
||||||
ChildInfo* child_info = state_peek_info (data, ChildInfo);
|
ChildInfo* child_info = state_peek_info (data, ChildInfo);
|
||||||
|
|
||||||
object_info->object = builder_construct (data, object_info);
|
object_info->object = builder_construct (data, object_info, error);
|
||||||
|
if (!object_info->object)
|
||||||
|
{
|
||||||
|
free_object_info (object_info);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (child_info)
|
if (child_info)
|
||||||
child_info->object = object_info->object;
|
child_info->object = object_info->object;
|
||||||
|
|
||||||
|
@ -103,7 +103,8 @@ void _gtk_builder_parser_parse_buffer (GtkBuilder *builder,
|
|||||||
gsize length,
|
gsize length,
|
||||||
GError **error);
|
GError **error);
|
||||||
GObject * _gtk_builder_construct (GtkBuilder *builder,
|
GObject * _gtk_builder_construct (GtkBuilder *builder,
|
||||||
ObjectInfo *info);
|
ObjectInfo *info,
|
||||||
|
GError **error);
|
||||||
void _gtk_builder_add (GtkBuilder *builder,
|
void _gtk_builder_add (GtkBuilder *builder,
|
||||||
ChildInfo *child_info);
|
ChildInfo *child_info);
|
||||||
void _gtk_builder_add_signals (GtkBuilder *builder,
|
void _gtk_builder_add_signals (GtkBuilder *builder,
|
||||||
|
@ -77,6 +77,27 @@ test_parser (void)
|
|||||||
g_assert (error->code == GTK_BUILDER_ERROR_INVALID_TAG);
|
g_assert (error->code == GTK_BUILDER_ERROR_INVALID_TAG);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
|
|
||||||
|
error = NULL;
|
||||||
|
gtk_builder_add_from_string (builder, "<interface><object class=\"Unknown\" id=\"a\"></object></interface>", -1, &error);
|
||||||
|
g_assert (error != NULL);
|
||||||
|
g_assert (error->domain == GTK_BUILDER_ERROR);
|
||||||
|
g_assert (error->code == GTK_BUILDER_ERROR_INVALID_VALUE);
|
||||||
|
g_error_free (error);
|
||||||
|
|
||||||
|
error = NULL;
|
||||||
|
gtk_builder_add_from_string (builder, "<interface><object class=\"GtkWidget\" id=\"a\" constructor=\"none\"></object></interface>", -1, &error);
|
||||||
|
g_assert (error != NULL);
|
||||||
|
g_assert (error->domain == GTK_BUILDER_ERROR);
|
||||||
|
g_assert (error->code == GTK_BUILDER_ERROR_INVALID_VALUE);
|
||||||
|
g_error_free (error);
|
||||||
|
|
||||||
|
error = NULL;
|
||||||
|
gtk_builder_add_from_string (builder, "<interface><object class=\"GtkButton\" id=\"a\"><child internal-child=\"foobar\"><object class=\"GtkButton\" id=\"int\"/></child></object></interface>", -1, &error);
|
||||||
|
g_assert (error != NULL);
|
||||||
|
g_assert (error->domain == GTK_BUILDER_ERROR);
|
||||||
|
g_assert (error->code == GTK_BUILDER_ERROR_INVALID_VALUE);
|
||||||
|
g_error_free (error);
|
||||||
|
|
||||||
g_object_unref (builder);
|
g_object_unref (builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1853,6 +1874,5 @@ main (int argc, char **argv)
|
|||||||
g_test_add_func ("/Builder/Value From String", test_value_from_string);
|
g_test_add_func ("/Builder/Value From String", test_value_from_string);
|
||||||
g_test_add_func ("/Builder/Reference Counting", test_reference_counting);
|
g_test_add_func ("/Builder/Reference Counting", test_reference_counting);
|
||||||
g_test_add_func ("/Builder/Window", test_window);
|
g_test_add_func ("/Builder/Window", test_window);
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user