Commit 1ce0de4d authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

Properly convert toolbutton:icon both ways.


	* gladeui/glade-convert.c: Properly convert toolbutton:icon both ways.

	* plugins/gtk+/glade-gtk.c: Undid a little toolbutton support so that
	stock-id remains untouched and is accessible in builder format, TODO
	rework toolbars and menus (will be simpler) with GladeEditable.


svn path=/trunk/; revision=2001
parent d8370a0b
......@@ -33,6 +33,12 @@
Removed hack for GtkToolButton:icon --> iconfactory (will do in glade-convert.c
properly).
* gladeui/glade-convert.c: Properly convert toolbutton:icon both ways.
* plugins/gtk+/glade-gtk.c: Undid a little toolbutton support so that
stock-id remains untouched and is accessible in builder format, TODO
rework toolbars and menus (will be simpler) with GladeEditable.
2008-10-24 Tristan Van Berkom <tvb@gnome.org>
* plugins/gtk+/Makefile.am, plugins/gtk+/glade-button-editor.[ch]:
......
......@@ -2260,41 +2260,55 @@ glade_command_convert_cleanup_props (GList *properties,
}
static gint
find_format_only_object (GObject *object, gpointer fmtptr)
{
GladeWidget *widget = glade_widget_get_from_gobject (object);
GladeProjectFormat fmt = GPOINTER_TO_INT (fmtptr);
if ((fmt == GLADE_PROJECT_FORMAT_GTKBUILDER &&
GWA_LIBGLADE_ONLY (widget->adaptor)) ||
/* If going in libglade format... */
(fmt == GLADE_PROJECT_FORMAT_LIBGLADE &&
/* ... and widget is unsupported by libglade */
(GWA_LIBGLADE_UNSUPPORTED (widget->adaptor) ||
/* ... and widget is a non GtkWidget object */
!GTK_IS_WIDGET (widget->object) ||
/* ... and its a non-window toplevel */
(!widget->parent && !GTK_IS_WINDOW (widget->object)))))
return 0;
return -1;
}
static void
glade_command_convert_cleanup (GladeProject *project,
GladeProjectFormat fmt)
{
GladeWidget *widget;
const GList *objects, *list;
GList *l;
objects = glade_project_get_objects (project);
/* List safely delete widgets */
while ((l =
g_list_find_custom ((GList *)glade_project_get_objects (project), GINT_TO_POINTER (fmt),
(GCompareFunc)find_project_only_object)) != NULL)
{
GList delete = { 0, };
delete.data = l->data;
glade_command_delete (&delete);
}
/* Deal with properties of remaining widgets */
objects = glade_project_get_objects (project);
for (list = objects; list; list = list->next)
{
widget = glade_widget_get_from_gobject (list->data);
/* If libglade-only widget going in builder format ... */
if ((fmt == GLADE_PROJECT_FORMAT_GTKBUILDER &&
GWA_LIBGLADE_ONLY (widget->adaptor)) ||
/* If going in libglade format... */
(fmt == GLADE_PROJECT_FORMAT_LIBGLADE &&
/* ... and widget is unsupported by libglade */
(GWA_LIBGLADE_UNSUPPORTED (widget->adaptor) ||
/* ... and widget is a non GtkWidget object */
!GTK_IS_WIDGET (widget->object) ||
/* ... and its a non-window toplevel */
(!widget->parent && !GTK_IS_WINDOW (widget->object)))))
{
GList delete = { 0, };
delete.data = widget;
glade_command_delete (&delete);
}
else
{
glade_command_convert_cleanup_props (widget->properties, fmt);
glade_command_convert_cleanup_props (widget->packing_properties, fmt);
}
glade_command_convert_cleanup_props (widget->properties, fmt);
glade_command_convert_cleanup_props (widget->packing_properties, fmt);
}
g_list_free (objects);
}
......
......@@ -1046,7 +1046,7 @@ glade_project_read_comment (GladeProject *project, GladeXmlDoc *doc)
*/
}
gboolean
static gboolean
glade_project_load_from_file (GladeProject *project, const gchar *path)
{
GladeXmlContext *context;
......@@ -1075,9 +1075,9 @@ glade_project_load_from_file (GladeProject *project, const gchar *path)
root = glade_xml_doc_get_root (doc);
if (glade_xml_node_verify_silent (root, GLADE_XML_TAG_LIBGLADE_PROJECT))
project->priv->format = GLADE_PROJECT_FORMAT_LIBGLADE;
glade_project_set_format (project, GLADE_PROJECT_FORMAT_LIBGLADE);
else if (glade_xml_node_verify_silent (root, GLADE_XML_TAG_BUILDER_PROJECT))
project->priv->format = GLADE_PROJECT_FORMAT_GTKBUILDER;
glade_project_set_format (project, GLADE_PROJECT_FORMAT_GTKBUILDER);
else
{
g_warning ("Couldnt determine project format, skipping %s", path);
......@@ -1088,7 +1088,6 @@ glade_project_load_from_file (GladeProject *project, const gchar *path)
/* XXX Need to load project->priv->comment ! */
glade_project_read_comment (project, doc);
if (glade_project_read_requires (project, root, path) == FALSE)
{
glade_xml_context_free (context);
......
......@@ -69,8 +69,6 @@ GType glade_project_get_type (void) G_GNUC_CONST;
GladeProject *glade_project_new (void);
gboolean glade_project_load_from_file (GladeProject *project, const gchar *path);
GladeProject *glade_project_load (const gchar *path);
gboolean glade_project_save (GladeProject *project,
......
......@@ -31,6 +31,7 @@
#include "glade-gtk.h"
#include "glade-column-types.h"
#include "glade-model-data.h"
#include "glade-icon-sources.h"
#include <gladeui/glade.h>
......@@ -55,6 +56,7 @@ typedef struct {
GList *textviews;
GList *tooltips;
GList *combos;
GList *toolbuttons;
} ConvertData;
/*****************************************
......@@ -297,7 +299,7 @@ convert_textviews (GladeProject *project,
}
/*****************************************
* GtkWidget:tooltips *
* GtkWidget:tooltip *
*****************************************/
static void
convert_tooltips_finished (GladeProject *project,
......@@ -536,6 +538,187 @@ convert_combos_finished (GladeProject *project,
g_list_free (data->combos);
}
/******************************
* ToolButton:icon *
******************************/
static void
convert_toolbuttons_finished (GladeProject *project,
ConvertData *data)
{
GladeProjectFormat new_format = glade_project_get_format (project);
GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_ICON_FACTORY);
GladeWidget *icon_factory = NULL;
GladeIconSources *icon_sources = NULL;
GladeProperty *property;
TextData *tdata;
GtkIconSource *source;
GList *list, *source_list;
gchar *filename;
GValue *value;
GdkPixbuf *pixbuf;
if (new_format == GLADE_PROJECT_FORMAT_GTKBUILDER)
{
/* Generate icon_sources first... */
for (list = data->toolbuttons; list; list = list->next)
{
tdata = list->data;
filename = g_strdup_printf ("generated-icon-%s", tdata->text);
glade_util_replace (filename, '.', '-');
/* get icon source with pixbuf from tdata->text */
value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, tdata->text,
project, tdata->widget);
pixbuf = g_value_get_object (value);
source = gtk_icon_source_new ();
gtk_icon_source_set_pixbuf (source, pixbuf);
g_value_unset (value);
g_free (value);
/* Add to the icon source (only one icon set list per icon) */
if (!icon_sources)
icon_sources = glade_icon_sources_new ();
source_list = g_list_append (NULL, source);
g_hash_table_insert (icon_sources->sources, g_strdup (filename), source_list);
g_free (filename);
}
if (icon_sources)
{
icon_factory = glade_command_create (adaptor, NULL, NULL, project);
property = glade_widget_get_property (icon_factory, "sources");
glade_command_set_property (property, icon_sources);
glade_icon_sources_free (icon_sources);
}
for (list = data->toolbuttons; list; list = list->next)
{
tdata = list->data;
filename = g_strdup_printf ("generated-icon-%s", tdata->text);
glade_util_replace (filename, '.', '-');
/* Set stock-id for newly generated icon */
property = glade_widget_get_property (tdata->widget, "stock-id");
glade_command_set_property (property, filename);
g_free (filename);
g_free (tdata->text);
g_free (tdata);
}
}
else
{
/* Set "icon" property */
for (list = data->toolbuttons; list; list = list->next)
{
tdata = list->data;
value = glade_utils_value_from_string (GDK_TYPE_PIXBUF,
tdata->text,
project, tdata->widget);
pixbuf = g_value_get_object (value);
property = glade_widget_get_property (tdata->widget, "icon");
glade_command_set_property (property, pixbuf);
g_value_unset (value);
g_free (value);
g_free (tdata->text);
g_free (tdata);
}
}
g_list_free (data->toolbuttons);
}
static gint
find_icon_factory (GObject *object, gpointer blah)
{
if (GTK_IS_ICON_FACTORY (object))
return 0;
return -1;
}
static void
convert_toolbuttons (GladeProject *project,
GladeProjectFormat new_format,
ConvertData *data)
{
GladeIconSources *icon_sources = NULL;
GladeWidget *widget, *gfactory;
GladeProperty *property;
GtkIconSource *source;
const GList *objects, *element;
TextData *tdata;
GdkPixbuf *pixbuf;
gchar *filename = NULL, *stock_id = NULL;
for (objects = glade_project_get_objects (project); objects; objects = objects->next)
{
widget = glade_widget_get_from_gobject (objects->data);
if (!GTK_IS_TOOL_BUTTON (widget->object))
continue;
if (new_format == GLADE_PROJECT_FORMAT_GTKBUILDER)
{
pixbuf = NULL;
property = glade_widget_get_property (widget, "icon");
glade_property_get (property, &pixbuf);
if (pixbuf)
{
filename = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName");
tdata = g_new0 (TextData, 1);
tdata->widget = widget;
tdata->text = g_strdup (filename);
data->toolbuttons = g_list_prepend (data->toolbuttons, tdata);
glade_command_set_property (property, NULL);
}
}
else
{
/* If any stock's are provided in the icon factory, convert
* them to the "icon" property
*/
property = glade_widget_get_property (widget, "stock-id");
glade_property_get (property, &stock_id);
if (!stock_id)
continue;
if ((element =
g_list_find_custom ((GList *)objects, NULL,
(GCompareFunc)find_icon_factory)) != NULL)
{
gfactory = glade_widget_get_from_gobject (element->data);
property = glade_widget_get_property (gfactory, "sources");
glade_property_get (property, &icon_sources);
if (icon_sources &&
(element = g_hash_table_lookup (icon_sources->sources, stock_id)))
{
source = element->data;
pixbuf = gtk_icon_source_get_pixbuf (source);
filename = g_object_get_data (G_OBJECT (pixbuf),
"GladeFileName");
if (filename)
{
tdata = g_new0 (TextData, 1);
tdata->widget = widget;
tdata->text = g_strdup (filename);
data->toolbuttons = g_list_prepend (data->toolbuttons, tdata);
}
}
}
}
}
}
/*****************************************
* Main entry point *
......@@ -548,6 +731,7 @@ glade_gtk_project_convert_finished (GladeProject *project,
convert_textviews_finished (project, data);
convert_tooltips_finished (project, data);
convert_combos_finished (project, data);
convert_toolbuttons_finished (project, data);
/* Once per conversion */
g_signal_handlers_disconnect_by_func (G_OBJECT (project),
......@@ -566,6 +750,7 @@ glade_gtk_project_convert (GladeProject *project,
convert_textviews (project, new_format, data);
convert_tooltips (project, new_format, data);
convert_combos (project, new_format, data);
convert_toolbuttons (project, new_format, data);
/* Clean up after the new_format is in effect */
g_signal_connect (G_OBJECT (project), "convert-finished",
......
......@@ -6857,31 +6857,11 @@ glade_gtk_tool_button_set_label (GObject *object, const GValue *value)
static void
glade_gtk_tool_button_set_stock_id (GObject *object, const GValue *value)
{
GladeWidget *gbutton;
GEnumClass *eclass;
GEnumValue *eval;
const gchar *stock_id;
g_return_if_fail (GTK_IS_TOOL_BUTTON (object));
gbutton = glade_widget_get_from_gobject (object);
if ((stock_id = g_value_get_string (value)))
{
eclass = g_type_class_ref (GLADE_TYPE_STOCK_IMAGE);
if ((eval = g_enum_get_value_by_nick (eclass, stock_id)) != NULL)
glade_widget_property_set (gbutton, "glade-stock", eval->value);
else
{
glade_widget_property_set (gbutton, "glade-stock",
"gtk-missing-image");
g_warning ("Invalid stock-id '%s' found in toolbutton", stock_id);
}
glade_widget_property_set (gbutton, "glade-type", GLADEGTK_IMAGE_STOCK);
g_type_class_unref (eclass);
}
stock_id = g_value_get_string (value);
if (stock_id && strlen (stock_id) == 0) stock_id = NULL;
......@@ -6907,11 +6887,6 @@ glade_gtk_tool_button_set_glade_stock (GObject *object, const GValue *value)
if ((eval = g_enum_get_value (eclass, val)) != NULL)
glade_widget_property_set (gbutton, "stock-id", eval->value_nick);
else
{
glade_widget_property_set (gbutton, "stock-id", "gtk-missing-image");
g_warning ("Invalid glade stock id '%d' found in toolbutton", val);
}
g_type_class_unref (eclass);
}
else
......
......@@ -312,6 +312,9 @@ populate_store (GladeEPropIconSources *eprop_sources)
gtk_tree_store_clear (eprop_sources->store);
gtk_list_store_clear (eprop_sources->icon_names_store);
if (!GLADE_EDITOR_PROPERTY (eprop_sources)->property)
return;
glade_property_get (GLADE_EDITOR_PROPERTY (eprop_sources)->property, &sources);
if (sources)
......
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