Commit ac6045c9 authored by Tristan Van Berkom's avatar Tristan Van Berkom

- Renderers watch project format changes and now sync attributes in an


	* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: 
	  - Renderers watch project format changes and now sync attributes in an idle
	    when moving into builder format (fixes renderer appearance after undo of project
	    conversions).


svn path=/trunk/; revision=2053
parent 2ed76714
......@@ -11,6 +11,9 @@
* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in:
- Added editor support for Icon View.
- Added editor support for Combo Box
- Renderers watch project format changes and now sync attributes in an idle
when moving into builder format (fixes renderer appearance after undo of project
conversions).
* plugins/gtk+/glade-cell-renderer-editor.c: Export a new function to get the model from
the renderer regardless of the layout type.
......
......@@ -1093,7 +1093,7 @@ widget_project_changed (GladeWidget *gwidget,
{
GladeProject
*project = glade_widget_get_project (gwidget),
*old_project = g_object_get_data (G_OBJECT (gwidget), "notebook-project-ptr");
*old_project = g_object_get_data (G_OBJECT (gwidget), "widget-project-ptr");
if (old_project)
g_signal_handlers_disconnect_by_func (G_OBJECT (old_project),
......@@ -1104,7 +1104,7 @@ widget_project_changed (GladeWidget *gwidget,
g_signal_connect (G_OBJECT (project), "notify::format",
G_CALLBACK (widget_format_changed), gwidget);
g_object_set_data (G_OBJECT (gwidget), "notebook-project-ptr", project);
g_object_set_data (G_OBJECT (gwidget), "widget-project-ptr", project);
}
void
......@@ -9940,10 +9940,125 @@ glade_gtk_cell_renderer_action_activate (GladeWidgetAdaptor *adaptor,
action_path);
}
static gboolean
glade_gtk_cell_layout_has_renderer (GtkCellLayout *layout,
GtkCellRenderer *renderer)
{
GList *cells = gtk_cell_layout_get_cells (layout);
gboolean has_renderer;
has_renderer = (g_list_find (cells, renderer) != NULL);
g_list_free (cells);
return has_renderer;
}
static void
glade_gtk_cell_renderer_sync_attributes (GObject *object)
{
GtkCellLayout *layout;
GtkCellRenderer *cell;
GladeWidget *widget = glade_widget_get_from_gobject (object);
GladeWidget *gmodel;
GladeProperty *property;
gchar *attr_prop_name;
GList *l;
gint columns = 0;
static gint attr_len = 0;
if (!attr_len)
attr_len = strlen ("attr-");
/* Apply attributes to renderer when bound to a model in runtime */
widget = glade_widget_get_from_gobject (object);
if (widget->parent == NULL) return;
/* When creating widgets, sometimes the parent is set before parenting happens,
* here we have to be careful for that..
*/
layout = GTK_CELL_LAYOUT (widget->parent->object);
cell = GTK_CELL_RENDERER (object);
if (!glade_gtk_cell_layout_has_renderer (layout, cell))
return;
if ((gmodel = glade_cell_renderer_get_model (widget)) != NULL)
{
GList *column_list = NULL;
glade_widget_property_get (gmodel, "columns", &column_list);
columns = g_list_length (column_list);
}
gtk_cell_layout_clear_attributes (layout, cell);
for (l = widget->properties; l; l = l->next)
{
property = l->data;
if (strncmp (property->klass->id, "attr-", attr_len) == 0)
{
attr_prop_name = &property->klass->id[attr_len];
/* XXX TODO: Check that the cell supports the data type in the indexed column.
*
* use: gtk_tree_model_get_column_type (icon_view->priv->model, column)
*/
if (g_value_get_int (property->value) >= 0 &&
/* We have to set attributes before parenting when loading */
(glade_widget_superuser () || g_value_get_int (property->value) < columns))
gtk_cell_layout_add_attribute (layout, cell,
attr_prop_name,
g_value_get_int (property->value));
}
}
}
static gboolean
sync_attributes_idle (GladeWidget *gwidget)
{
glade_gtk_cell_renderer_sync_attributes (gwidget->object);
return FALSE;
}
static void
renderer_format_changed (GladeProject *project,
GParamSpec *pspec,
GladeWidget *gwidget)
{
if (glade_project_get_format (project) == GLADE_PROJECT_FORMAT_GTKBUILDER)
g_idle_add ((GSourceFunc)sync_attributes_idle, gwidget);
}
static void
renderer_project_changed (GladeWidget *gwidget,
GParamSpec *pspec,
gpointer userdata)
{
GladeProject
*project = glade_widget_get_project (gwidget),
*old_project = g_object_get_data (G_OBJECT (gwidget), "renderer-project-ptr");
if (old_project)
g_signal_handlers_disconnect_by_func (G_OBJECT (old_project),
G_CALLBACK (renderer_format_changed),
gwidget);
if (project)
g_signal_connect (G_OBJECT (project), "notify::format",
G_CALLBACK (renderer_format_changed), gwidget);
g_object_set_data (G_OBJECT (gwidget), "renderer-project-ptr", project);
}
void
glade_gtk_cell_renderer_post_create (GladeWidgetAdaptor *adaptor,
GObject *object,
GladeCreateReason reason)
glade_gtk_cell_renderer_deep_post_create (GladeWidgetAdaptor *adaptor,
GObject *object,
GladeCreateReason reason)
{
GladePropertyClass *pclass;
GladeProperty *property;
......@@ -9962,6 +10077,12 @@ glade_gtk_cell_renderer_post_create (GladeWidgetAdaptor *adaptor,
glade_property_sync (property);
}
}
g_signal_connect (G_OBJECT (widget), "notify::project",
G_CALLBACK (renderer_project_changed), NULL);
renderer_project_changed (widget, NULL, NULL);
}
GladeEditorProperty *
......@@ -10028,82 +10149,6 @@ glade_gtk_cell_renderer_set_use_attribute (GObject *object,
g_free (attr_prop_name);
}
static gboolean
glade_gtk_cell_layout_has_renderer (GtkCellLayout *layout,
GtkCellRenderer *renderer)
{
GList *cells = gtk_cell_layout_get_cells (layout);
gboolean has_renderer;
has_renderer = (g_list_find (cells, renderer) != NULL);
g_list_free (cells);
return has_renderer;
}
static void
glade_gtk_cell_renderer_sync_attributes (GObject *object)
{
GtkCellLayout *layout;
GtkCellRenderer *cell;
GladeWidget *widget = glade_widget_get_from_gobject (object);
GladeWidget *gmodel;
GladeProperty *property;
gchar *attr_prop_name;
GList *l;
gint columns = 0;
static gint attr_len = 0;
if (!attr_len)
attr_len = strlen ("attr-");
/* Apply attributes to renderer when bound to a model in runtime */
widget = glade_widget_get_from_gobject (object);
if (widget->parent == NULL) return;
/* When creating widgets, sometimes the parent is set before parenting happens,
* here we have to be careful for that..
*/
layout = GTK_CELL_LAYOUT (widget->parent->object);
cell = GTK_CELL_RENDERER (object);
if (!glade_gtk_cell_layout_has_renderer (layout, cell))
return;
if ((gmodel = glade_cell_renderer_get_model (widget)) != NULL)
{
GList *column_list = NULL;
glade_widget_property_get (gmodel, "columns", &column_list);
columns = g_list_length (column_list);
}
gtk_cell_layout_clear_attributes (layout, cell);
for (l = widget->properties; l; l = l->next)
{
property = l->data;
if (strncmp (property->klass->id, "attr-", attr_len) == 0)
{
attr_prop_name = &property->klass->id[attr_len];
/* XXX TODO: Check that the cell supports the data type in the indexed column.
*
* use: gtk_tree_model_get_column_type (icon_view->priv->model, column)
*/
if (g_value_get_int (property->value) >= 0 &&
/* We have to set attributes before parenting when loading */
(glade_widget_superuser () || g_value_get_int (property->value) < columns))
gtk_cell_layout_add_attribute (layout, cell,
attr_prop_name,
g_value_get_int (property->value));
}
}
}
static gboolean
glade_gtk_cell_renderer_property_enabled (GObject *object,
const gchar *property_name)
......
......@@ -1964,7 +1964,7 @@ embedded in another object</_tooltip>
</glade-widget-class>
<glade-widget-class name="GtkCellRenderer" _title="Cell Renderer">
<post-create-function>glade_gtk_cell_renderer_post_create</post-create-function>
<deep-post-create-function>glade_gtk_cell_renderer_deep_post_create</deep-post-create-function>
<create-editor-property-function>glade_gtk_cell_renderer_create_eprop</create-editor-property-function>
<create-editable-function>glade_gtk_cell_renderer_create_editable</create-editable-function>
<set-property-function>glade_gtk_cell_renderer_set_property</set-property-function>
......
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