Commit b399c255 authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte
Browse files

Added a composite templates widget group in palette.

Replace template widget with new type.
parent 1510d1a0
......@@ -20,6 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <glib/gi18n-lib.h>
#include "glade-composite-template.h"
#include "glade-app.h"
#include "glade-utils.h"
......@@ -90,9 +93,36 @@ composite_template_derived_init (GTypeInstance *instance, gpointer g_class)
{
}
#if !HAVE_GTK_CONTAINER_CLASS_SET_TEMPLATE_FROM_STRING
static GObject *
composite_template_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{
GladeWidgetAdaptor *adaptor;
GObjectClass *parent_class;
GObject *obj;
parent_class = g_type_class_peek (g_type_parent (type));
obj = parent_class->constructor (type,
n_construct_properties,
construct_properties);
/*
adaptor = glade_widget_adaptor_get_by_type (type);
glade_widget_adaptor_get_*/
return obj;
}
#endif
static void
composite_template_derived_class_init (gpointer g_class, gpointer class_data)
{
#if !HAVE_GTK_CONTAINER_CLASS_SET_TEMPLATE_FROM_STRING
GObjectClass *object_class = g_class;
object_class->constructor = composite_template_constructor;
#endif
}
static inline GType
......@@ -226,6 +256,7 @@ glade_composite_template_load_directory (const gchar *directory)
* @gwidget: a #GladeWidget
* @template_class: the name of the new composite template class
* @filename: a file name to save the template
* @replace: True if you want to replace @gwidget with a new widget of type @template_class
*
* Saves a copy of @gwidget as a composite template in @filename with @template_class
* as the class name
......@@ -233,7 +264,8 @@ glade_composite_template_load_directory (const gchar *directory)
void
glade_composite_template_save_from_widget (GladeWidget *gwidget,
const gchar *template_class,
const gchar *filename)
const gchar *filename,
gboolean replace)
{
GladeProject *project;
gchar *template_xml;
......@@ -255,6 +287,24 @@ glade_composite_template_save_from_widget (GladeWidget *gwidget,
g_file_set_contents (filename, template_xml, -1, NULL);
if (replace)
{
GladeProject *project = glade_widget_get_project (gwidget);
GladeWidget *parent = glade_widget_get_parent (gwidget);
GladeWidgetAdaptor *new_adaptor;
GList widgets = {0, };
/* Create it at run time */
if ((new_adaptor = glade_composite_template_load_from_string (template_xml)))
g_object_set (new_adaptor, "template-path", filename, NULL);
glade_command_push_group (_("Create new composite type %s"), template_class);
widgets.data = gwidget;
glade_command_cut (&widgets);
glade_command_create (new_adaptor, parent, NULL, project);
glade_command_pop_group ();
}
g_free (template_xml);
g_object_unref (project);
}
......@@ -35,7 +35,8 @@ void glade_composite_template_load_directory (const gchar *directory);
void glade_composite_template_save_from_widget (GladeWidget *gwidget,
const gchar *template_class,
const gchar *filename);
const gchar *filename,
gboolean replace);
G_END_DECLS
......
......@@ -69,6 +69,8 @@ struct _GladePalettePrivate
GladeWidgetAdaptor *local_selection;
GHashTable *button_table;
GtkWidget *composite_templates;
};
enum
......@@ -335,13 +337,12 @@ glade_palette_new_item (GladePalette * palette, GladeWidgetAdaptor * adaptor)
}
static GtkWidget *
glade_palette_new_item_group (GladePalette * palette, GladeWidgetGroup * group)
tool_item_group_new (const gchar *name)
{
GtkWidget *item_group, *item, *label;
GList *l;
GtkWidget *item_group, *label;
/* Give the item group a left aligned label */
label = gtk_label_new (glade_widget_group_get_title (group));
label = gtk_label_new (name);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_widget_show (label);
......@@ -353,6 +354,17 @@ glade_palette_new_item_group (GladePalette * palette, GladeWidgetGroup * group)
gtk_tool_item_group_set_ellipsize (GTK_TOOL_ITEM_GROUP (item_group),
PANGO_ELLIPSIZE_END);
return item_group;
}
static GtkWidget *
glade_palette_new_item_group (GladePalette * palette, GladeWidgetGroup * group)
{
GtkWidget *item_group, *item;
GList *l;
item_group = tool_item_group_new (glade_widget_group_get_title (group));
gtk_widget_set_tooltip_text (item_group,
glade_widget_group_get_title (group));
......@@ -387,6 +399,45 @@ glade_palette_append_item_group (GladePalette * palette,
gtk_container_add (GTK_CONTAINER (priv->toolpalette), item_group);
}
static void
glade_palette_update_templates (GladePalette *palette)
{
GList *l, *adaptors = glade_widget_adaptor_list_adaptors ();
GladePalettePrivate *priv = palette->priv;
if (priv->composite_templates == NULL)
{
priv->composite_templates = tool_item_group_new (_("Composite Templates"));
gtk_container_add (GTK_CONTAINER (priv->toolpalette), priv->composite_templates);
gtk_widget_show (priv->composite_templates);
}
else
{
GtkContainer *container = GTK_CONTAINER (priv->composite_templates);
GList *l, *children = gtk_container_get_children (container);
for (l = children; l; l = g_list_next (l))
gtk_container_remove (container, l->data);
g_list_free (children);
}
for (l = adaptors; l; l = g_list_next (l))
{
GladeWidgetAdaptor *adaptor = l->data;
/* Create/append new item */
if (glade_widget_adaptor_get_template (adaptor))
{
GtkWidget *item = glade_palette_new_item (palette, adaptor);
gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (priv->composite_templates),
GTK_TOOL_ITEM (item), -1);
}
}
g_list_free (adaptors);
}
static void
glade_palette_populate (GladePalette * palette)
{
......@@ -394,6 +445,8 @@ glade_palette_populate (GladePalette * palette)
g_return_if_fail (GLADE_IS_PALETTE (palette));
glade_palette_update_templates (palette);
for (l = (GList *) glade_app_get_catalogs (); l; l = l->next)
{
GList *groups = glade_catalog_get_widget_groups (GLADE_CATALOG (l->data));
......@@ -665,6 +718,10 @@ glade_palette_init (GladePalette * palette)
gtk_widget_set_no_show_all (GTK_WIDGET (palette), TRUE);
glade_palette_populate (palette);
g_signal_connect_swapped (glade_app_get (), "widget-adaptor-registered",
G_CALLBACK (glade_palette_update_templates),
palette);
}
......
......@@ -1956,6 +1956,8 @@ glade_widget_adaptor_register (GladeWidgetAdaptor *adaptor)
g_hash_table_insert (adaptor_hash,
g_memdup (&adaptor->priv->type, sizeof (GType)), adaptor);
g_signal_emit_by_name (glade_app_get (), "widget-adaptor-registered", adaptor);
}
static GladePackingDefault *
......
......@@ -1422,7 +1422,7 @@ glade_gtk_container_action_activate (GladeWidgetAdaptor *adaptor,
filename = tmp;
}
glade_composite_template_save_from_widget (gwidget, basename, filename);
glade_composite_template_save_from_widget (gwidget, basename, filename, TRUE);
g_free (basename);
g_free (filename);
......
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