Commit 6c5e4e2a authored by Tristan Van Berkom's avatar Tristan Van Berkom

Exported glade_column_list_copy/free()


	* plugins/gtk+/glade-column-types.[ch]: Exported glade_column_list_copy/free()

	* plugins/gtk+/glade-model-data.[ch], plugins/gtk+/Makefile.am: Added model data
	  pspec, editor not compĺete yet...
	
	* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: Implemented new pspec as
	  list/treestore's "data" property with load/save support.

	* plugins/gtk+/glade-convert.c: Made combos convert correctly with new modeldata
	  pspec.

	* gladeui/glade-utils.[ch]: Added glade_utils_liststore_from_enum_type()


svn path=/trunk/; revision=1963
parent ee72eaea
2008-09-29 Tristan Van Berkom <tvb@gnome.org>
* plugins/gtk+/glade-column-types.[ch]: Exported glade_column_list_copy/free()
* plugins/gtk+/glade-model-data.[ch], plugins/gtk+/Makefile.am: Added model data
pspec, editor not compĺete yet...
* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: Implemented new pspec as
list/treestore's "data" property with load/save support.
* plugins/gtk+/glade-convert.c: Made combos convert correctly with new modeldata
pspec.
* gladeui/glade-utils.[ch]: Added glade_utils_liststore_from_enum_type()
2008-09-29 Juan Pablo Ugarte <juanpablougarte@gmail.com>
* plugins/gtk+/glade-column-types.[ch]: added missing files.
......
......@@ -14,3 +14,8 @@ Sort objects from widgets in the inspector widget.
Make popup work in workspace with no-window widgets
Take care of external object property references (sync them) at rebuild time
Liststore/Treestore data is not translatable
store data needs improvement and cant be released as is (cant even have spaces in data, needs real new structure).
IMPORTANT!!! Go over all object type properties and mark them libglade unsupported,
newly added objects need "since" versioning info updated, all around thoroughly
check catalog data before release candidate.
......@@ -1039,7 +1039,7 @@ glade_property_class_new_from_spec_full (gpointer handle,
{
GObjectClass *gtk_widget_class;
GladePropertyClass *property_class;
GladeEditorProperty *eprop;
GladeEditorProperty *eprop = NULL;
g_return_val_if_fail (spec != NULL, NULL);
gtk_widget_class = g_type_class_ref (GTK_TYPE_WIDGET);
......@@ -1065,7 +1065,8 @@ glade_property_class_new_from_spec_full (gpointer handle,
goto failed;
/* Just created it to see if it was supported.... destroy now... */
gtk_widget_destroy (GTK_WIDGET (eprop));
if (eprop)
gtk_widget_destroy (GTK_WIDGET (eprop));
/* If its on the GtkWidgetClass, it goes in "common"
* (unless stipulated otherwise in the xml file)
......@@ -1110,7 +1111,7 @@ GladePropertyClass *
glade_property_class_new_from_spec (gpointer handle,
GParamSpec *spec)
{
glade_property_class_new_from_spec_full (handle, spec, TRUE);
return glade_property_class_new_from_spec_full (handle, spec, TRUE);
}
/**
......
......@@ -1961,7 +1961,7 @@ glade_utils_enum_string_from_value (GType enum_type, gint value)
g_value_init (&gvalue, enum_type);
g_value_set_enum (&gvalue, value);
string = glade_utils_string_from_value (enum_type, &gvalue, NULL);
string = glade_utils_string_from_value (&gvalue, NULL);
g_value_unset (&gvalue);
return string;
......@@ -2100,7 +2100,6 @@ glade_utils_value_from_string (GType type,
/**
* glade_utils_string_from_value:
* @type: a #GType to convert with
* @value: the value to convert
* @project: the #GladeProject to look for formats of object names when needed
*
......@@ -2110,18 +2109,60 @@ glade_utils_value_from_string (GType type,
* Returns: A newly allocated string
*/
gchar *
glade_utils_string_from_value (GType type,
const GValue *value,
glade_utils_string_from_value (const GValue *value,
GladeProject *project)
{
GladeProjectFormat fmt;
GladePropertyClass *pclass;
g_return_val_if_fail (type != G_TYPE_INVALID, NULL);
g_return_val_if_fail (value != NULL, NULL);
if ((pclass = pclass_from_gtype (type)) != NULL)
return glade_property_class_make_string_from_gvalue (pclass, value,
glade_project_get_format (project));
fmt = project ? glade_project_get_format (project) : GLADE_PROJECT_FORMAT_GTKBUILDER;
if ((pclass = pclass_from_gtype (G_VALUE_TYPE (value))) != NULL)
return glade_property_class_make_string_from_gvalue (pclass, value, fmt);
return NULL;
}
/**
* glade_utils_liststore_from_enum_type:
* @enum_type: A #GType
* @include_empty: wheather to prepend an "Unset" slot
*
* Creates a liststore suitable for comboboxes and such to
* chose from a variety of types.
*
* Returns: A new #GtkListStore
*/
GtkListStore *
glade_utils_liststore_from_enum_type (GType enum_type,
gboolean include_empty)
{
GtkListStore *store;
GtkTreeIter iter;
GEnumClass *eclass;
guint i;
eclass = g_type_class_ref (enum_type);
store = gtk_list_store_new (1, G_TYPE_STRING);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, _("Unset"),
-1);
for (i = 0; i < eclass->n_values; i++)
{
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, eclass->values[i].value_nick,
-1);
}
g_type_class_unref (eclass);
return store;
}
......@@ -140,10 +140,11 @@ gchar *glade_utils_enum_string_from_value (GType enum_type, gint valu
GValue *glade_utils_value_from_string (GType type,
const gchar *string,
GladeProject *project);
gchar *glade_utils_string_from_value (GType type,
const GValue *value,
gchar *glade_utils_string_from_value (const GValue *value,
GladeProject *project);
GtkListStore *glade_utils_liststore_from_enum_type (GType enum_type, gboolean include_empty);
G_END_DECLS
#endif /* __GLADE_UTILS_H__ */
<glade-catalog name="bonobo"
library="gladegnome"
supports="libglade"
depends="gnome"
domain="glade3">
<glade-widget-classes>
......
<glade-catalog name="canvas"
icon-prefix="gnome"
library="gladegnome"
supports="libglade"
depends="gnome"
domain="glade3">
<glade-widget-classes>
......
......@@ -24,7 +24,7 @@ libgladegtk_la_CFLAGS = \
$(AM_CFLAGS)
libgladegtk_la_SOURCES = glade-gtk.c glade-accels.c glade-attributes.c glade-convert.c fixed-bg.xpm \
glade-column-types.c glade-column-types.h
glade-column-types.c glade-column-types.h glade-model-data.c glade-model-data.h
libgladegtk_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS)
libgladegtk_la_LIBADD = $(libgladeui) $(GTK_LIBS)
......
......@@ -240,36 +240,6 @@ typedef enum {
(type) == EDIT_SPIN ? COLUMN_SPIN_ACTIVE : \
(type) == EDIT_COMBO ? COLUMN_COMBO_ACTIVE: COLUMN_TEXT_ACTIVE)
static GtkListStore *
make_model_from_enum_type (GType enum_type)
{
GtkListStore *store;
GtkTreeIter iter;
GEnumClass *eclass;
guint i;
eclass = g_type_class_ref (enum_type);
store = gtk_list_store_new (1, G_TYPE_STRING);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, _("Unset"),
-1);
for (i = 0; i < eclass->n_values; i++)
{
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, eclass->values[i].value_nick,
-1);
}
g_type_class_unref (eclass);
return store;
}
static GtkListStore *
get_enum_model_for_combo (PangoAttrType type)
{
......@@ -282,32 +252,32 @@ get_enum_model_for_combo (PangoAttrType type)
{
case PANGO_ATTR_STYLE:
if (!style_store)
style_store = make_model_from_enum_type (PANGO_TYPE_STYLE);
style_store = glade_utils_liststore_from_enum_type (PANGO_TYPE_STYLE, TRUE);
return style_store;
case PANGO_ATTR_WEIGHT:
if (!weight_store)
weight_store = make_model_from_enum_type (PANGO_TYPE_WEIGHT);
weight_store = glade_utils_liststore_from_enum_type (PANGO_TYPE_WEIGHT, TRUE);
return weight_store;
case PANGO_ATTR_VARIANT:
if (!variant_store)
variant_store = make_model_from_enum_type (PANGO_TYPE_VARIANT);
variant_store = glade_utils_liststore_from_enum_type (PANGO_TYPE_VARIANT, TRUE);
return variant_store;
case PANGO_ATTR_STRETCH:
if (!stretch_store)
stretch_store = make_model_from_enum_type (PANGO_TYPE_STRETCH);
stretch_store = glade_utils_liststore_from_enum_type (PANGO_TYPE_STRETCH, TRUE);
return stretch_store;
case PANGO_ATTR_GRAVITY:
if (!gravity_store)
gravity_store = make_model_from_enum_type (PANGO_TYPE_GRAVITY);
gravity_store = glade_utils_liststore_from_enum_type (PANGO_TYPE_GRAVITY, TRUE);
return gravity_store;
case PANGO_ATTR_GRAVITY_HINT:
if (!gravity_hint_store)
gravity_hint_store = make_model_from_enum_type (PANGO_TYPE_GRAVITY_HINT);
gravity_hint_store = glade_utils_liststore_from_enum_type (PANGO_TYPE_GRAVITY_HINT, TRUE);
return gravity_hint_store;
default:
......
......@@ -82,8 +82,8 @@ column_types_store_populate (GtkListStore *store)
}
}
static GList *
data_list_copy (GList *list)
GList *
glade_column_list_copy (GList *list)
{
GList *l, *retval = NULL;
......@@ -101,8 +101,8 @@ data_list_copy (GList *list)
return g_list_reverse (retval);
}
static void
data_list_free (GList *list)
void
glade_column_list_free (GList *list)
{
GList *l;
......@@ -125,8 +125,8 @@ glade_column_type_list_get_type (void)
if (!type_id)
type_id = g_boxed_type_register_static
("GladeColumnTypeList",
(GBoxedCopyFunc) data_list_copy,
(GBoxedFreeFunc) data_list_free);
(GBoxedCopyFunc) glade_column_list_copy,
(GBoxedFreeFunc) glade_column_list_free);
return type_id;
}
......@@ -189,8 +189,8 @@ glade_standard_column_types_spec (void)
GladeParamSpecColumnTypes *pspec;
pspec = g_param_spec_internal (GLADE_TYPE_PARAM_COLUMN_TYPES,
"fundamental-types", _("Fundamental Types"),
_("A list of fundamental GTypes"),
"column-types", _("Column Types"),
_("A list of GTypes and thier names"),
G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
return G_PARAM_SPEC (pspec);
}
......@@ -250,10 +250,10 @@ eprop_reload_value (GladeEPropColumnTypes *eprop)
}
static void
eprop_fundamental_append (GladeEPropColumnTypes *eprop_types,
GType type,
const gchar *name,
const gchar *column_name)
eprop_column_append (GladeEPropColumnTypes *eprop_types,
GType type,
const gchar *name,
const gchar *column_name)
{
gtk_list_store_insert_with_values (eprop_types->store, NULL, -1,
COLUMN_NAME, name ? name : g_type_name (type),
......@@ -283,13 +283,13 @@ glade_eprop_column_types_load (GladeEditorProperty *eprop, GladeProperty *proper
{
GladeColumnType *data = l->data;
eprop_fundamental_append (eprop_types, data->type, NULL, data->column_name);
eprop_column_append (eprop_types, data->type, NULL, data->column_name);
}
}
static void
glade_eprop_column_types_add_clicked (GtkWidget *button,
GladeEPropColumnTypes *eprop_types)
GladeEPropColumnTypes *eprop_types)
{
GtkTreeIter iter;
GType type2add;
......@@ -303,13 +303,13 @@ glade_eprop_column_types_add_clicked (GtkWidget *button,
COLUMN_GTYPE, &type2add,
-1);
eprop_fundamental_append (eprop_types, type2add, name, NULL);
eprop_column_append (eprop_types, type2add, name, NULL);
eprop_reload_value (eprop_types);
}
static void
glade_eprop_column_types_delete_clicked (GtkWidget *button,
GladeEPropColumnTypes *eprop_types)
GladeEPropColumnTypes *eprop_types)
{
GtkTreeIter iter;
if (gtk_tree_selection_get_selected (eprop_types->selection, NULL, &iter))
......
......@@ -32,6 +32,7 @@ typedef struct
gchar *column_name;
} GladeColumnType;
#define GLADE_TYPE_COLUMN_TYPE_LIST (glade_column_type_list_get_type())
#define GLADE_TYPE_PARAM_COLUMN_TYPES (glade_param_column_types_get_type())
#define GLADE_TYPE_EPROP_COLUMN_TYPES (glade_eprop_column_types_get_type())
......@@ -47,6 +48,10 @@ GType glade_eprop_column_types_get_type (void) G_GNUC_CONST;
GParamSpec *glade_standard_column_types_spec (void);
void glade_column_list_free (GList *list);
GList *glade_column_list_copy (GList *list);
G_END_DECLS
#endif /* _GLADE_COLUMN_TYPES_H_ */
......@@ -29,6 +29,8 @@
#include <glib/gi18n-lib.h>
#include "glade-gtk.h"
#include "glade-column-types.h"
#include "glade-model-data.h"
#include <gladeui/glade.h>
......@@ -42,15 +44,21 @@ typedef struct {
gchar *text;
} TextData;
typedef struct {
GladeWidget *widget;
gchar **items;
} ComboData;
typedef struct {
/* List of newly created objects to set */
GList *adjustments;
GList *textviews;
GList *tooltips;
GList *combos;
} ConvertData;
/*****************************************
* Adjustments *
* GtkAdjustments *
*****************************************/
static void
convert_adjustments_finished (GladeProject *project,
......@@ -185,7 +193,7 @@ convert_adjustments (GladeProject *project,
}
/*****************************************
* TextViews *
* TextView:text *
*****************************************/
static void
convert_textviews_finished (GladeProject *project,
......@@ -289,7 +297,7 @@ convert_textviews (GladeProject *project,
}
/*****************************************
* Tooltips *
* GtkWidget:tooltips *
*****************************************/
static void
convert_tooltips_finished (GladeProject *project,
......@@ -355,6 +363,181 @@ convert_tooltips (GladeProject *project,
}
}
/*****************************************
* Combo:items *
*****************************************/
static GNode *
combos_data_tree_from_items (gchar **items)
{
GNode *row, *data_tree;
gint i;
if (!items)
return NULL;
data_tree = g_node_new (NULL);
for (i = 0; items[i]; i++)
{
GladeModelData *data = g_new0 (GladeModelData, 1);
g_value_init (&data->value, G_TYPE_STRING);
g_value_set_string (&data->value, items[i]);
row = g_node_new (NULL);
g_node_append (data_tree, row);
g_node_append_data (row, data);
}
return data_tree;
}
static gchar **
combos_items_from_data_tree (GNode *data_tree)
{
GNode *row, *item;
GPtrArray *array = g_ptr_array_new ();
GladeModelData *data;
gchar *string;
for (row = data_tree->children; row; row = row->next)
{
for (item = row->children; item; item = item->next)
{
data = item->data;
if (G_VALUE_TYPE (&data->value) == G_TYPE_STRING)
{
string = g_value_dup_string (&data->value);
g_ptr_array_add (array, string);
break;
}
}
}
if (array->len == 0)
return NULL;
g_ptr_array_add (array, NULL);
return (gchar **)g_ptr_array_free (array, FALSE);
}
static void
convert_combos (GladeProject *project,
GladeProjectFormat new_format,
ConvertData *data)
{
GladeWidget *widget, *gmodel;
GladeProperty *property;
ComboData *cdata;
GObject *model;
const GList *objects;
GNode *data_tree;
gchar **items;
for (objects = glade_project_get_objects (project); objects; objects = objects->next)
{
widget = glade_widget_get_from_gobject (objects->data);
if (!GTK_IS_COMBO_BOX (widget->object))
continue;
if (new_format == GLADE_PROJECT_FORMAT_GTKBUILDER)
{
items = NULL;
property = glade_widget_get_property (widget, "items");
glade_property_get (property, &items);
if (items)
{
cdata = g_new0 (ComboData, 1);
cdata->widget = widget;
cdata->items = g_strdupv (items);
data->combos = g_list_prepend (data->combos, cdata);
glade_command_set_property (property, NULL);
}
}
else
{
items = NULL;
data_tree = NULL;
gmodel = NULL;
model = NULL;
property = glade_widget_get_property (widget, "model");
glade_property_get (property, &model);
if (model && (gmodel = glade_widget_get_from_gobject (model)))
glade_widget_property_get (gmodel, "data", &data_tree);
if (data_tree)
items = combos_items_from_data_tree (data_tree);
if (items)
{
GList delete = { 0, };
delete.data = gmodel;
cdata = g_new0 (ComboData, 1);
cdata->widget = widget;
cdata->items = items;
data->combos = g_list_prepend (data->combos, cdata);
/* This will take care of unsetting the buffer property as well */
glade_command_delete (&delete);
}
}
}
}
static void
convert_combos_finished (GladeProject *project,
ConvertData *data)
{
GladeProjectFormat new_format = glade_project_get_format (project);
GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LIST_STORE);
GladeProperty *property;
GladeWidget *widget;
ComboData *cdata;
GNode *data_tree;
GList *list;
for (list = data->combos; list; list = list->next)
{
cdata = list->data;
if (new_format == GLADE_PROJECT_FORMAT_GTKBUILDER)
{
GList *columns = NULL;
GladeColumnType *column = g_new0 (GladeColumnType, 1);
column->type = G_TYPE_STRING;
columns = g_list_append (columns, column);
property = glade_widget_get_property (cdata->widget, "model");
/* Cant cancel a liststore.... */
widget = glade_command_create (adaptor, NULL, NULL, project);
glade_command_set_property (property, widget->object);
data_tree = combos_data_tree_from_items (cdata->items);
glade_widget_property_set (widget, "columns", columns);
glade_widget_property_set (widget, "data", data_tree);
glade_column_list_free (columns);
}
else
{
property = glade_widget_get_property (cdata->widget, "items");
glade_command_set_property (property, cdata->items);
}
g_strfreev (cdata->items);
g_free (cdata);
}
g_list_free (data->combos);
}
/*****************************************
* Main entry point *
*****************************************/
......@@ -365,6 +548,7 @@ glade_gtk_project_convert_finished (GladeProject *project,
convert_adjustments_finished (project, data);
convert_textviews_finished (project, data);
convert_tooltips_finished (project, data);
convert_combos_finished (project, data);
/* Once per conversion */
g_signal_handlers_disconnect_by_func (G_OBJECT (project),
......@@ -382,6 +566,7 @@ glade_gtk_project_convert (GladeProject *project,
convert_adjustments (project, new_format, data);
convert_textviews (project, new_format, data);
convert_tooltips (project, new_format, data);
convert_combos (project, new_format, data);
/* Clean up after the new_format is in effect */
g_signal_connect (G_OBJECT (project), "convert-finished",
......
......@@ -29,6 +29,7 @@
#include "glade-accels.h"
#include "glade-attributes.h"
#include "glade-column-types.h"
#include "glade-model-data.h"
#include <gladeui/glade-editor-property.h>
#include <gladeui/glade-base-editor.h>
......@@ -7631,21 +7632,31 @@ glade_gtk_text_view_set_property (GladeWidgetAdaptor *adaptor,
/* ----------------------------- GtkComboBox ------------------------------ */
static void
combo_ensure_model (GObject *combo)
{
GtkListStore *store;
if (!gtk_combo_box_get_model (GTK_COMBO_BOX (combo)))
{
/* Add store */
store = gtk_list_store_new (1, G_TYPE_STRING);
gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (store));
g_object_unref (store);
}
}
void
glade_gtk_combo_box_post_create (GladeWidgetAdaptor *adaptor,
GObject *object,
GladeCreateReason reason)
{
GtkCellRenderer *cell;
GtkListStore *store;
g_return_if_fail (GTK_IS_COMBO_BOX (object));
/* Add store */
store = gtk_list_store_new (1, G_TYPE_STRING);
gtk_combo_box_set_model (GTK_COMBO_BOX (object), GTK_TREE_MODEL (store));
g_object_unref (store);
combo_ensure_model (object);
/* Add cell renderer */
cell = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), cell, TRUE);
......@@ -7664,6 +7675,8 @@ glade_gtk_combo_box_set_items (GObject *object, const GValue *value)
combo = GTK_COMBO_BOX (object);
combo_ensure_model (object);
/* Empty the combo box */
gtk_list_store_clear (GTK_LIST_STORE (gtk_combo_box_get_model (combo)));
......@@ -8602,21 +8615,28 @@ glade_gtk_store_set_columns (GObject *object,
}
if (GTK_IS_LIST_STORE (object))
{
gtk_list_store_clear (GTK_LIST_STORE (object));
gtk_list_store_set_column_types (GTK_LIST_STORE (object), n, types);
}
else
{
gtk_tree_store_clear (GTK_TREE_STORE (object));
gtk_tree_store_set_column_types (GTK_TREE_STORE (object), n, types);
}
}
static void
glade_gtk_store_set_data (GObject *object,
const GValue *value)
{
GladeWidget *gwidget = glade_widget_get_from_gobject (object);
GList *columns = NULL, *list;
GladeWidget *gwidget = glade_widget_get_from_gobject (object);
GList *columns = NULL, *list;
GladeColumnType *column;
gchar **split, **subsplit;
gint i, j;
GtkTreeIter row_iter;
GNode *data_tree, *row, *iter;
gint colnum;
GtkTreeIter row_iter;
GladeModelData *data;
if (GTK_IS_LIST_STORE (object))
gtk_list_store_clear (GTK_LIST_STORE (object));
......@@ -8624,48 +8644,36 @@ glade_gtk_store_set_data (GObject *object,
gtk_tree_store_clear (GTK_TREE_STORE (object));
glade_widget_property_get (gwidget, "columns", &columns);
data_tree = g_value_get_boxed (value);
/* Nothing to enter without columns defined */
if (!columns) return;
split = g_value_get_boxed (value);
for (i = 0; split && split[i]; i++)
if (!data_tree || !columns)
return;
for (row = data_tree->children; row; row = row->next)
{
if ((subsplit = g_strsplit (split[i], " ", 0)) != NULL)
if (GTK_IS_LIST_STORE (object))
gtk_list_store_append (GTK_LIST_STORE (object), &row_iter);
else
/* (for now no child data... ) */
gtk_tree_store_append (GTK_TREE_STORE (object), &row_iter, NULL);
for (colnum = 0, iter = row->children; iter;
colnum++, iter = iter->next)
{
data = iter->data;
if (!g_list_nth (columns, colnum))
break;
if (GTK_IS_LIST_STORE (object))
gtk_list_store_append (GTK_LIST_STORE (object), &row_iter);
gtk_list_store_set_value (GTK_LIST_STORE (object),
&row_iter,
colnum, &data->value);
else
/* (for now no child data... ) */
gtk_tree_store_append (GTK_TREE_STORE (object), &row_iter, NULL);
for (j = 0; subsplit[j]; j++)
{
if ((list = g_list_nth (columns, j)) != NULL)