Commit f6bee53a authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte Committed by Juan Pablo Ugarte

GladeWidget: add support for abstract classes

In order to support templates with abstract parents glade_widget_read()
will use a class with the GladeInstantiable prefix. So for a GtkBin
template it  will use GladeInstantiableGtkBin which of course has to
derive from GtkBin.

In turn glade_widget_write() will ommit GladeInstantiable prefix.
parent 44577c82
......@@ -22,6 +22,7 @@
#include <config.h>
#include <glib/gi18n-lib.h>
#include "glade.h"
#include "glade-private.h"
#include "gladeui-enum-types.h"
#include "glade-editor-table.h"
......@@ -337,7 +338,7 @@ glade_editor_table_load (GladeEditable *editable, GladeWidget *widget)
table->priv->adaptor = glade_widget_get_adaptor (widget);
if (table->priv->type == GLADE_PAGE_GENERAL)
append_name_field (table);
append_name_field (table);
append_items (table, table->priv->adaptor, table->priv->type);
}
......@@ -377,26 +378,31 @@ glade_editor_table_load (GladeEditable *editable, GladeWidget *widget)
(GWeakNotify) widget_finalized, table);
if (table->priv->composite_check)
{
GObject *object = glade_widget_get_object (table->priv->loaded_widget);
if (GTK_IS_WIDGET (object) &&
glade_widget_get_parent (table->priv->loaded_widget) == NULL)
gtk_widget_show (table->priv->composite_check);
else
gtk_widget_hide (table->priv->composite_check);
}
{
GObject *object = glade_widget_get_object (table->priv->loaded_widget);
GladeWidgetAdaptor *adaptor = glade_widget_get_adaptor (table->priv->loaded_widget);
if (GTK_IS_WIDGET (object) &&
glade_widget_get_parent (table->priv->loaded_widget) == NULL)
gtk_widget_show (table->priv->composite_check);
else
gtk_widget_hide (table->priv->composite_check);
gtk_widget_set_sensitive (table->priv->composite_check,
!g_str_has_prefix (glade_widget_adaptor_get_name (adaptor),
GLADE_WIDGET_INSTANTIABLE_PREFIX));
}
if (table->priv->name_entry)
{
if (glade_widget_has_name (widget))
gtk_entry_set_text (GTK_ENTRY (table->priv->name_entry), glade_widget_get_name (widget));
else
gtk_entry_set_text (GTK_ENTRY (table->priv->name_entry), "");
}
{
if (glade_widget_has_name (widget))
gtk_entry_set_text (GTK_ENTRY (table->priv->name_entry), glade_widget_get_name (widget));
else
gtk_entry_set_text (GTK_ENTRY (table->priv->name_entry), "");
}
if (table->priv->name_label)
widget_composite_changed (widget, NULL, table);
widget_composite_changed (widget, NULL, table);
}
else if (table->priv->name_entry)
gtk_entry_set_text (GTK_ENTRY (table->priv->name_entry), "");
......
......@@ -33,10 +33,16 @@
G_BEGIN_DECLS
#define GLADE_WIDGET_INSTANTIABLE_PREFIX "GladeInstantiable"
#define GLADE_WIDGET_INSTANTIABLE_PREFIX_LEN 17
/* glade-widget.c */
GList *_glade_widget_peek_prop_refs (GladeWidget *widget);
/* glade-widget-adaptor.c */
G_CONST_RETURN gchar *_glade_widget_adaptor_get_real_name (GladeWidgetAdaptor *adaptor);
/* glade-catalog.c */
GladeCatalog *_glade_catalog_get_catalog (const gchar *name);
......
......@@ -1787,6 +1787,17 @@ glade_widget_adaptor_get_name (GladeWidgetAdaptor *adaptor)
return adaptor->priv->name;
}
G_CONST_RETURN gchar *
_glade_widget_adaptor_get_real_name (GladeWidgetAdaptor *adaptor)
{
g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
if (g_str_has_prefix (adaptor->priv->name, GLADE_WIDGET_INSTANTIABLE_PREFIX))
return &adaptor->priv->name[GLADE_WIDGET_INSTANTIABLE_PREFIX_LEN];
return adaptor->priv->name;
}
G_CONST_RETURN gchar *
glade_widget_adaptor_get_generic_name (GladeWidgetAdaptor *adaptor)
{
......
......@@ -946,6 +946,10 @@ glade_widget_constructor (GType type,
/* Verify support warnings to start off */
glade_widget_verify (gwidget);
if (g_str_has_prefix (glade_widget_adaptor_get_name (gwidget->priv->adaptor),
GLADE_WIDGET_INSTANTIABLE_PREFIX))
glade_widget_set_is_composite (gwidget, TRUE);
return ret_obj;
}
......@@ -4008,6 +4012,13 @@ glade_widget_read_child (GladeWidget *widget, GladeXmlNode *node)
* @parent: The parent #GladeWidget or %NULL
* @node: a #GladeXmlNode
*
* Creates a new #GladeWidget from a XML node.
*
* If node is a template and its parent class is abstract/non instantiable,
* Glade will use a class with the GladeInstantiable prefix instead.
*
* For example, with a GtkBin template Glade will GladeInstantiableGtkBin class
*
* Returns: a new #GladeWidget for @project, based on @node
*/
GladeWidget *
......@@ -4060,6 +4071,26 @@ glade_widget_read (GladeProject *project,
g_warning ("Loaded widget `%s' has internal glade prefix, please rename this widget", id);
}
if (template_parent)
{
GType template_type = glade_util_get_type_from_name (template_parent, FALSE);
/* Check if there is an instantiable version for this abstract class */
if (G_TYPE_IS_ABSTRACT (template_type))
{
gchar *instantiable = g_strconcat (GLADE_WIDGET_INSTANTIABLE_PREFIX,
template_parent,
NULL);
if (glade_util_get_type_from_name (instantiable, FALSE))
{
g_free (template_parent);
template_parent = instantiable;
}
else
g_free (instantiable);
}
}
type_to_use = template_parent ? template_parent : klass;
/*
......@@ -4327,11 +4358,12 @@ glade_widget_write (GladeWidget *widget,
{
widget_node = glade_xml_node_new (context, GLADE_XML_TAG_TEMPLATE);
glade_xml_node_set_property_string (widget_node,
GLADE_XML_TAG_CLASS,
widget->priv->name);
GLADE_XML_TAG_CLASS,
widget->priv->name);
glade_xml_node_set_property_string (widget_node,
GLADE_TAG_PARENT,
glade_widget_adaptor_get_name (widget->priv->adaptor));
GLADE_TAG_PARENT,
_glade_widget_adaptor_get_real_name (widget->priv->adaptor));
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment