[gtk+/composite-templates: 12/15] Merge external object namespace with builder built objects
- From: Juan Pablo Ugarte <jpu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/composite-templates: 12/15] Merge external object namespace with builder built objects
- Date: Wed, 28 Nov 2012 16:45:29 +0000 (UTC)
commit 659e617d08db988a998abe73bd58b492728caf67
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date: Wed Nov 14 18:32:04 2012 -0300
Merge external object namespace with builder built objects
gtk/gtkbuilder.c | 64 ++++++-----------------------------------------
gtk/gtkbuilderparser.c | 57 ++++++++++++++++++++---------------------
gtk/gtkbuilderprivate.h | 4 ---
gtk/tests/builder.c | 6 ++--
4 files changed, 39 insertions(+), 92 deletions(-)
---
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index f5c4899..8e52bc9 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -125,8 +125,7 @@
* e.g. "GTK_VISIBLE|GTK_REALIZED") and colors (in a format understood by
* gdk_color_parse()). Pixbufs can be specified as a filename of an image file to load.
* Objects can be referred to by their name and by default refer to objects declared
- * in the local xml fragment, however external objects exposed via gtk_builder_expose_object()
- * can be referred to by specifying the "external-object" attribute.
+ * in the local xml fragment and objects exposed via gtk_builder_expose_object().
*
* In general, GtkBuilder allows forward references to objects &mdash declared
* in the local xml; an object doesn't have to be constructed before it can be referred to.
@@ -140,9 +139,7 @@
* a custom #GtkBuilderConnectFunc to gtk_builder_connect_signals_full(). The
* attributes "after", "swapped" and "object", have the same meaning
* as the corresponding parameters of the g_signal_connect_object() or
- * g_signal_connect_data() functions. External objects can also be referred
- * to by specifying the "external-object" attribute in the same way as described
- * with the <property> element. A "last_modification_time" attribute is also
+ * g_signal_connect_data() functions. A "last_modification_time" attribute is also
* allowed, but it does not have a meaning to the builder.
*
* Sometimes it is necessary to refer to widgets which have implicitly been
@@ -273,7 +270,6 @@ struct _GtkBuilderPrivate
{
gchar *domain;
GHashTable *objects;
- GHashTable *external_objects;
GSList *delayed_properties;
GSList *signals;
gchar *filename;
@@ -324,7 +320,6 @@ gtk_builder_init (GtkBuilder *builder)
builder->priv->domain = NULL;
builder->priv->objects = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_object_unref);
- builder->priv->external_objects = NULL;
}
@@ -342,8 +337,6 @@ gtk_builder_finalize (GObject *object)
g_free (priv->resource_prefix);
g_hash_table_destroy (priv->objects);
- if (priv->external_objects)
- g_hash_table_destroy (priv->external_objects);
g_slist_foreach (priv->signals, (GFunc) _free_signal_info, NULL);
g_slist_free (priv->signals);
@@ -501,22 +494,7 @@ gtk_builder_get_parameters (GtkBuilder *builder,
{
GObject *object;
- if (prop->external)
- {
- object = g_hash_table_lookup (builder->priv->external_objects, prop->data);
-
- if (!object)
- {
- g_warning ("Failed to get external object property "
- "%s of %s with value `%s'",
- prop->name, object_name, prop->data);
- continue;
- }
-
- g_value_init (¶meter.value, G_OBJECT_TYPE (object));
- g_value_set_object (¶meter.value, object);
- }
- else if (pspec->flags & G_PARAM_CONSTRUCT_ONLY)
+ if (pspec->flags & G_PARAM_CONSTRUCT_ONLY)
{
object = gtk_builder_get_object (builder, prop->data);
@@ -1210,21 +1188,6 @@ gtk_builder_add_objects_from_string (GtkBuilder *builder,
object_ids, error);
}
-GObject *
-_gtk_builder_get_external_object (GtkBuilder *builder,
- const gchar *name)
-{
- g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL);
-
- if (builder->priv->external_objects)
- {
- g_return_val_if_fail (name != NULL, NULL);
- return g_hash_table_lookup (builder->priv->external_objects, name);
- }
- else
- return NULL;
-}
-
/**
* gtk_builder_get_object:
* @builder: a #GtkBuilder
@@ -1332,9 +1295,8 @@ gtk_builder_get_translation_domain (GtkBuilder *builder)
* @name: the name of the object exposed to the builder
* @object: the object to expose
*
- * Adds @object to a pool of objects external to the objects built by builder.
- * Objects exposed in this pool can be referred to by xml fragments by
- * specifying the "external-object" boolean attribute.
+ * Add @object to the @builder object pool so it can be references just like any
+ * other object buiolt by builder.
*
* To make this function even more useful a new special entry point element
* <template> is defined. It is similar to <object> with the only difference
@@ -1357,15 +1319,9 @@ gtk_builder_expose_object (GtkBuilder *builder,
g_return_if_fail (G_IS_OBJECT (object));
priv = builder->priv;
-
- /* We do not create the table in _init() because this is not used very much */
- if (priv->external_objects == NULL)
- priv->external_objects = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, g_object_unref);
object_set_name (object, name);
- g_hash_table_insert (priv->external_objects,
- g_strdup (name), g_object_ref (object));
+ g_hash_table_insert (priv->objects, g_strdup (name), g_object_ref (object));
}
@@ -1508,12 +1464,8 @@ gtk_builder_connect_signals_full (GtkBuilder *builder,
if (signal->connect_object_name)
{
- if (signal->external)
- connect_object = g_hash_table_lookup (builder->priv->external_objects,
- signal->connect_object_name);
- else
- connect_object = g_hash_table_lookup (builder->priv->objects,
- signal->connect_object_name);
+ connect_object = g_hash_table_lookup (builder->priv->objects,
+ signal->connect_object_name);
if (!connect_object)
g_warning ("Could not lookup object %s on signal %s of object %s",
diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c
index bef907c..1dc7a48 100644
--- a/gtk/gtkbuilderparser.c
+++ b/gtk/gtkbuilderparser.c
@@ -316,6 +316,29 @@ is_requested_object (const gchar *object,
return FALSE;
}
+static gboolean
+parser_add_object_id (ParserData *data,
+ const gchar *object_id,
+ GError **error)
+{
+ gint line, line2;
+
+ g_markup_parse_context_get_position (data->ctx, &line, NULL);
+ line2 = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_id));
+ if (line2 != 0)
+ {
+ 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);
+ return TRUE;
+ }
+
+ g_hash_table_insert (data->object_ids, g_strdup (object_id), GINT_TO_POINTER (line));
+
+ return FALSE;
+}
+
static void
parse_object (GMarkupParseContext *context,
ParserData *data,
@@ -330,7 +353,7 @@ parse_object (GMarkupParseContext *context,
const gchar *object_class = NULL;
const gchar *object_id = NULL;
const gchar *constructor = NULL;
- gint i, line, line2;
+ gint i, line;
child_info = state_peek_info (data, ChildInfo);
if (child_info && strcmp (child_info->tag.name, "object") == 0)
@@ -430,19 +453,7 @@ 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)
- {
- 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);
- return;
- }
-
-
- g_hash_table_insert (data->object_ids, g_strdup (object_id), GINT_TO_POINTER (line));
+ parser_add_object_id (data, object_id, error);
}
static void
@@ -522,7 +533,6 @@ parse_property (ParserData *data,
gchar *name = NULL;
gchar *context = NULL;
gboolean translatable = FALSE;
- gboolean external = FALSE;
ObjectInfo *object_info;
int i;
@@ -551,11 +561,6 @@ parse_property (ParserData *data,
{
context = g_strdup (values[i]);
}
- else if (strcmp (names[i], "external-object") == 0)
- {
- if (!_gtk_builder_boolean_from_string (values[i], &external, error))
- return;
- }
else
{
error_invalid_attribute (data, element_name, names[i], error);
@@ -574,7 +579,6 @@ parse_property (ParserData *data,
info->translatable = translatable;
info->context = context;
info->text = g_string_new ("");
- info->external = external;
state_push (data, info);
info->tag.name = element_name;
@@ -603,7 +607,6 @@ parse_signal (ParserData *data,
gboolean after = FALSE;
gboolean swapped = FALSE;
gboolean swapped_set = FALSE;
- gboolean external = FALSE;
ObjectInfo *object_info;
int i;
@@ -631,11 +634,6 @@ parse_signal (ParserData *data,
return;
swapped_set = TRUE;
}
- else if (strcmp (names[i], "external-object") == 0)
- {
- if (!_gtk_builder_boolean_from_string (values[i], &external, error))
- return;
- }
else if (strcmp (names[i], "object") == 0)
object = g_strdup (values[i]);
else if (strcmp (names[i], "last_modification_time") == 0)
@@ -670,7 +668,6 @@ parse_signal (ParserData *data,
info->flags |= G_CONNECT_AFTER;
if (swapped)
info->flags |= G_CONNECT_SWAPPED;
- info->external = external;
info->connect_object_name = object;
state_push (data, info);
@@ -730,7 +727,7 @@ parse_template (ParserData *data,
}
if (data->requested_objects == NULL &&
- (parent = _gtk_builder_get_external_object (data->builder, id)))
+ (parent = gtk_builder_get_object (data->builder, id)))
{
GType class_type, parent_type = G_OBJECT_TYPE (parent);
ObjectInfo *object_info;
@@ -767,6 +764,8 @@ parse_template (ParserData *data,
object_info->tag.name = "object";
state_push (data, object_info);
+
+ parser_add_object_id (data, object_info->id, error);
}
}
diff --git a/gtk/gtkbuilderprivate.h b/gtk/gtkbuilderprivate.h
index c859159..987c5fc 100644
--- a/gtk/gtkbuilderprivate.h
+++ b/gtk/gtkbuilderprivate.h
@@ -63,7 +63,6 @@ typedef struct {
gchar *data;
gchar *context;
guint8 translatable : 1;
- guint8 external : 1;
} PropertyInfo;
typedef struct {
@@ -71,7 +70,6 @@ typedef struct {
gchar *object_name;
const gchar *name; /* Intern string */
gchar *handler;
- gboolean external;
GConnectFlags flags;
gchar *connect_object_name;
} SignalInfo;
@@ -164,8 +162,6 @@ void _gtk_builder_menu_start (ParserData *parser_data,
GError **error);
void _gtk_builder_menu_end (ParserData *parser_data);
-GObject * _gtk_builder_get_external_object (GtkBuilder *builder,
- const gchar *name);
const gchar * _gtk_builder_object_get_name (GObject *object);
#endif /* __GTK_BUILDER_PRIVATE_H__ */
diff --git a/gtk/tests/builder.c b/gtk/tests/builder.c
index a1c08b9..c39da5a 100644
--- a/gtk/tests/builder.c
+++ b/gtk/tests/builder.c
@@ -2869,9 +2869,9 @@ test_expose_object (void)
const gchar buffer[] =
"<interface>"
" <object class=\"GtkButton\" id=\"button\">"
- " <property name=\"image\" external-object=\"True\">external_image</property>"
- " <signal name=\"clicked\" handler=\"on_button_clicked\" object=\"builder\" external-object=\"yes\" swapped=\"no\"/>"
- " <signal name=\"clicked\" handler=\"on_button_clicked_swapped\" object=\"builder\" external-object=\"yes\"/>"
+ " <property name=\"image\">external_image</property>"
+ " <signal name=\"clicked\" handler=\"on_button_clicked\" object=\"builder\" swapped=\"no\"/>"
+ " <signal name=\"clicked\" handler=\"on_button_clicked_swapped\" object=\"builder\"/>"
" </object>"
"</interface>";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]