Commit 21605e92 authored by Tristan Van Berkom's avatar Tristan Van Berkom

Added editor support for Icon View.


	* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: Added editor support for Icon View.

	* plugins/gtk+/glade-cell-renderer-editor.c: Export a new function to get the model from
	the renderer regardless of the layout type.

	* plugins/gtk+/glade-treeview-editor.c: Now supports editing any view that can have a model,
	and pops up the store editor automatically on the right of the normal widget editor.


svn path=/trunk/; revision=2051
parent 0b940e4d
......@@ -8,6 +8,14 @@
* gladeui/glade-command.c: Fixed check for wrapperless objects returned by adaptor_get_children().
* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: Added editor support for Icon View.
* plugins/gtk+/glade-cell-renderer-editor.c: Export a new function to get the model from
the renderer regardless of the layout type.
* plugins/gtk+/glade-treeview-editor.c: Now supports editing any view that can have a model,
and pops up the store editor automatically on the right of the normal widget editor.
2008-11-23 Tristan Van Berkom <tvb@gnome.org>
* gladeui/glade-widget.c:
......
......@@ -942,10 +942,12 @@ get_all_parentless_reffed_widgets (GList *reffed, GladeWidget *widget)
for (l = children; l; l = l->next)
{
if ((child = glade_widget_get_from_gobject (l->data)) != NULL)
{
if ((list = glade_widget_get_parentless_reffed_widgets (child)) != NULL)
reffed = g_list_concat (reffed, list);
reffed = get_all_parentless_reffed_widgets (reffed, child);
reffed = get_all_parentless_reffed_widgets (reffed, child);
}
}
return reffed;
......
......@@ -521,11 +521,9 @@ glade_eprop_cell_attribute_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static GladeWidget *
get_model (GladeProperty *property)
GladeWidget *
glade_cell_renderer_get_model (GladeWidget *renderer)
{
GladeWidget *renderer = property->widget;
GladeWidget *model = NULL;
/* Keep inline with all new cell layouts !!! */
......@@ -542,6 +540,15 @@ get_model (GladeProperty *property)
model = glade_widget_get_from_gobject (real_model);
}
}
else if (renderer->parent && GTK_IS_ICON_VIEW (renderer->parent->object))
{
GladeWidget *view = renderer->parent;
GtkTreeModel *real_model = NULL;
glade_widget_property_get (view, "model", &real_model);
if (real_model)
model = glade_widget_get_from_gobject (real_model);
}
return model;
}
......@@ -565,7 +572,7 @@ glade_eprop_cell_attribute_load (GladeEditorProperty *eprop,
gtk_list_store_clear (store);
/* Generate model and set active iter */
if ((gmodel = get_model (property)) != NULL)
if ((gmodel = glade_cell_renderer_get_model (property->widget)) != NULL)
{
GList *columns = NULL, *l;
......
......@@ -67,6 +67,8 @@ GtkWidget *glade_cell_renderer_editor_new (GladeWidgetAdaptor *adapt
GladeEditorPageType type,
GladeEditable *editable);
GladeWidget *glade_cell_renderer_get_model (GladeWidget *renderer);
G_END_DECLS
#endif /* _GLADE_CELL_RENDERER_EDITOR_H_ */
......@@ -10045,8 +10045,8 @@ glade_gtk_cell_renderer_sync_attributes (GObject *object)
GtkCellLayout *layout;
GtkCellRenderer *cell;
GladeWidget *widget = glade_widget_get_from_gobject (object), *glayout;
GladeWidget *gmodel = NULL;
GladeWidget *widget = glade_widget_get_from_gobject (object);
GladeWidget *gmodel;
GladeProperty *property;
gchar *attr_prop_name;
GList *l;
......@@ -10066,26 +10066,15 @@ glade_gtk_cell_renderer_sync_attributes (GObject *object)
*/
layout = GTK_CELL_LAYOUT (widget->parent->object);
cell = GTK_CELL_RENDERER (object);
glayout = glade_widget_get_from_gobject (layout);
if (!glade_gtk_cell_layout_has_renderer (layout, cell))
return;
if (glayout->parent && GTK_IS_TREE_VIEW (glayout->parent->object))
{
GtkTreeModel *model = NULL;
glade_widget_property_get (glayout->parent, "model", &model);
if (model)
gmodel = glade_widget_get_from_gobject (model);
}
if (gmodel)
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);
......@@ -10099,6 +10088,8 @@ glade_gtk_cell_renderer_sync_attributes (GObject *object)
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 */
......@@ -10214,8 +10205,18 @@ glade_gtk_cell_layout_add_child (GladeWidgetAdaptor *adaptor,
GObject *container,
GObject *child)
{
GladeWidget *gmodel = NULL;
GladeWidget *grenderer = glade_widget_get_from_gobject (child);
if (GTK_IS_ICON_VIEW (container) &&
(gmodel = glade_cell_renderer_get_model (grenderer)) != NULL)
gtk_icon_view_set_model (GTK_ICON_VIEW (container), NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (container), GTK_CELL_RENDERER (child), TRUE);
if (gmodel)
gtk_icon_view_set_model (GTK_ICON_VIEW (container), GTK_TREE_MODEL (gmodel->object));
glade_gtk_cell_renderer_sync_attributes (child);
}
......@@ -10457,38 +10458,10 @@ glade_gtk_cell_layout_sync_attributes (GObject *layout)
g_list_free (children);
}
/*--------------------------- GtkTreeViewColumn ---------------------------------*/
void
glade_gtk_treeview_column_action_activate (GladeWidgetAdaptor *adaptor,
GObject *object,
const gchar *action_path)
{
if (strcmp (action_path, "launch_editor") == 0)
{
GladeWidget *w = glade_widget_get_from_gobject (object);
while ((w = glade_widget_get_parent (w)))
{
if (GTK_IS_TREE_VIEW (w->object))
{
glade_gtk_treeview_launch_editor (w->object);
break;
}
}
}
else
GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor,
object,
action_path);
}
/*--------------------------- GtkTreeView ---------------------------------*/
static gchar *
glade_gtk_treeview_get_display_name (GladeBaseEditor *editor,
GladeWidget *gchild,
gpointer user_data)
glade_gtk_cell_layout_get_display_name (GladeBaseEditor *editor,
GladeWidget *gchild,
gpointer user_data)
{
GObject *child = glade_widget_get_object (gchild);
gchar *name;
......@@ -10502,9 +10475,9 @@ glade_gtk_treeview_get_display_name (GladeBaseEditor *editor,
}
static void
glade_gtk_treeview_child_selected (GladeBaseEditor *editor,
GladeWidget *gchild,
gpointer data)
glade_gtk_cell_layout_child_selected (GladeBaseEditor *editor,
GladeWidget *gchild,
gpointer data)
{
GObject *child = glade_widget_get_object (gchild);
......@@ -10525,10 +10498,10 @@ glade_gtk_treeview_child_selected (GladeBaseEditor *editor,
}
static gboolean
glade_gtk_treeview_move_child (GladeBaseEditor *editor,
GladeWidget *gparent,
GladeWidget *gchild,
gpointer data)
glade_gtk_cell_layout_move_child (GladeBaseEditor *editor,
GladeWidget *gparent,
GladeWidget *gchild,
gpointer data)
{
GObject *parent = glade_widget_get_object (gparent);
GObject *child = glade_widget_get_object (gchild);
......@@ -10536,7 +10509,7 @@ glade_gtk_treeview_move_child (GladeBaseEditor *editor,
if (GTK_IS_TREE_VIEW (parent) && !GTK_IS_TREE_VIEW_COLUMN (child))
return FALSE;
if (GTK_IS_TREE_VIEW_COLUMN (parent) && !GTK_IS_CELL_RENDERER (child))
if (GTK_IS_CELL_LAYOUT (parent) && !GTK_IS_CELL_RENDERER (child))
return FALSE;
if (GTK_IS_CELL_RENDERER (parent))
return FALSE;
......@@ -10550,6 +10523,81 @@ glade_gtk_treeview_move_child (GladeBaseEditor *editor,
return TRUE;
}
static void
glade_gtk_cell_layout_launch_editor (GObject *layout)
{
GladeWidget *widget = glade_widget_get_from_gobject (layout);
GladeBaseEditor *editor;
GladeEditable *layout_editor;
GtkWidget *window;
layout_editor = glade_widget_adaptor_create_editable (widget->adaptor, GLADE_PAGE_GENERAL);
layout_editor = (GladeEditable *)glade_tree_view_editor_new (widget->adaptor, layout_editor);
/* Editor */
editor = glade_base_editor_new (layout, layout_editor,
_("Text"), GTK_TYPE_CELL_RENDERER_TEXT,
_("Accelerator"), GTK_TYPE_CELL_RENDERER_ACCEL,
_("Combo"), GTK_TYPE_CELL_RENDERER_COMBO,
_("Spin"), GTK_TYPE_CELL_RENDERER_SPIN,
_("Pixbuf"), GTK_TYPE_CELL_RENDERER_PIXBUF,
_("Progress"), GTK_TYPE_CELL_RENDERER_PROGRESS,
_("Toggle"), GTK_TYPE_CELL_RENDERER_TOGGLE,
NULL);
g_signal_connect (editor, "get-display-name", G_CALLBACK (glade_gtk_cell_layout_get_display_name), NULL);
g_signal_connect (editor, "child-selected", G_CALLBACK (glade_gtk_cell_layout_child_selected), NULL);
g_signal_connect (editor, "move-child", G_CALLBACK (glade_gtk_cell_layout_move_child), NULL);
gtk_widget_show (GTK_WIDGET (editor));
window = glade_base_editor_pack_new_window (editor,
GTK_IS_ICON_VIEW (layout) ?
_("Icon View Editor") : _("Combo Editor"),
NULL);
gtk_widget_show (window);
}
void
glade_gtk_cell_layout_action_activate (GladeWidgetAdaptor *adaptor,
GObject *object,
const gchar *action_path)
{
if (strcmp (action_path, "launch_editor") == 0)
{
GladeWidget *w = glade_widget_get_from_gobject (object);
do
{
if (GTK_IS_TREE_VIEW (w->object))
{
glade_gtk_treeview_launch_editor (w->object);
break;
}
else if (GTK_IS_ICON_VIEW (w->object))
{
glade_gtk_cell_layout_launch_editor (w->object);
break;
}
else if (GTK_IS_COMBO_BOX (w->object))
{
glade_gtk_cell_layout_launch_editor (w->object);
break;
}
} while ((w = glade_widget_get_parent (w)));
}
else
GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor,
object,
action_path);
}
/*--------------------------- GtkTreeView ---------------------------------*/
static void
glade_gtk_treeview_launch_editor (GObject *treeview)
{
......@@ -10577,9 +10625,9 @@ glade_gtk_treeview_launch_editor (GObject *treeview)
_("Toggle"), GTK_TYPE_CELL_RENDERER_TOGGLE,
NULL);
g_signal_connect (editor, "get-display-name", G_CALLBACK (glade_gtk_treeview_get_display_name), NULL);
g_signal_connect (editor, "child-selected", G_CALLBACK (glade_gtk_treeview_child_selected), NULL);
g_signal_connect (editor, "move-child", G_CALLBACK (glade_gtk_treeview_move_child), NULL);
g_signal_connect (editor, "get-display-name", G_CALLBACK (glade_gtk_cell_layout_get_display_name), NULL);
g_signal_connect (editor, "child-selected", G_CALLBACK (glade_gtk_cell_layout_child_selected), NULL);
g_signal_connect (editor, "move-child", G_CALLBACK (glade_gtk_cell_layout_move_child), NULL);
gtk_widget_show (GTK_WIDGET (editor));
......
......@@ -83,8 +83,15 @@ project_finalized (GladeTreeViewEditor *view_editor,
static GladeWidget *
get_model_widget (GladeWidget *view)
{
GtkTreeView *treeview = GTK_TREE_VIEW (view->object);
GtkTreeModel *model = gtk_tree_view_get_model (treeview);
GtkTreeModel *model = NULL;
if (GTK_IS_TREE_VIEW (view->object))
model = gtk_tree_view_get_model (GTK_TREE_VIEW (view->object));
else if (GTK_IS_ICON_VIEW (view->object))
model = gtk_icon_view_get_model (GTK_ICON_VIEW (view->object));
else if (GTK_IS_COMBO_BOX (view->object))
model = gtk_combo_box_get_model (GTK_COMBO_BOX (view->object));
if (model)
return glade_widget_get_from_gobject (model);
......@@ -232,7 +239,7 @@ glade_tree_view_editor_new (GladeWidgetAdaptor *adaptor,
vbox = gtk_vbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (view_editor), vbox, FALSE, FALSE, 8);
str = g_strdup_printf ("<b>%s</b>", _("Choose a Tree Model and define some\n"
str = g_strdup_printf ("<b>%s</b>", _("Choose a Data Model and define some\n"
"columns in the data store first"));
view_editor->no_model_message = gtk_label_new (str);
gtk_label_set_use_markup (GTK_LABEL (view_editor->no_model_message), TRUE);
......
......@@ -1668,7 +1668,7 @@ embedded in another object</_tooltip>
<value id="GTK_ASSISTANT_PAGE_PROGRESS" _name="Progress"/>
</displayable-values>
</property>
<property save="False" id="position" name="Position">
<property save="False" id="position" _name="Position">
<parameter-spec>
<type>GParamInt</type>
</parameter-spec>
......@@ -1791,48 +1791,6 @@ embedded in another object</_tooltip>
</properties>
</glade-widget-class>
<glade-widget-class name="GtkTreeView" generic-name="treeview" _title="Tree View">
<post-create-function>empty</post-create-function>
<child-set-property-function>glade_gtk_treeview_set_child_property</child-set-property-function>
<child-get-property-function>glade_gtk_treeview_get_child_property</child-get-property-function>
<get-children-function>glade_gtk_treeview_get_children</get-children-function>
<add-child-function>glade_gtk_treeview_add_child</add-child-function>
<remove-child-function>glade_gtk_treeview_remove_child</remove-child-function>
<action-activate-function>glade_gtk_treeview_action_activate</action-activate-function>
<depends-function>glade_gtk_treeview_depends</depends-function>
<actions>
<action id="launch_editor" _name="Edit&#8230;" stock="gtk-edit" important="True"/>
</actions>
<properties>
<property id="level-indentation" since="2.12"/>
<property id="show-expanders" since="2.12"/>
<property id="enable-grid-lines" ignore="True">
<displayable-values>
<value id="GTK_TREE_VIEW_GRID_LINES_NONE" _name="None"/>
<value id="GTK_TREE_VIEW_GRID_LINES_HORIZONTAL" _name="Horizontal"/>
<value id="GTK_TREE_VIEW_GRID_LINES_VERTICAL" _name="Vertical"/>
<value id="GTK_TREE_VIEW_GRID_LINES_BOTH" _name="Horizontal and Vertical"/>
</displayable-values>
</property>
<property id="hadjustment" libglade-unsupported="True"/>
<property id="vadjustment" libglade-unsupported="True"/>
<property id="model" create-type="GtkListStore" query="True" libglade-unsupported="True"/>
</properties>
<packing-properties>
<property save="False" id="position" name="Position" visible="False">
<parameter-spec>
<type>GParamInt</type>
</parameter-spec>
<_tooltip>The column position in the Tree View</_tooltip>
</property>
</packing-properties>
</glade-widget-class>
<glade-widget-class name="GtkIconView" generic-name="iconview" _title="Icon View"/>
<glade-widget-class name="GtkListStore" generic-name="liststore" _title="List Store"
libglade-unsupported="True" toplevel="True">
<set-property-function>glade_gtk_store_set_property</set-property-function>
......@@ -1893,6 +1851,45 @@ embedded in another object</_tooltip>
libglade-unsupported="True" toplevel="True"/>
<glade-widget-class name="GtkTreeView" generic-name="treeview" _title="Tree View">
<post-create-function>empty</post-create-function>
<child-set-property-function>glade_gtk_treeview_set_child_property</child-set-property-function>
<child-get-property-function>glade_gtk_treeview_get_child_property</child-get-property-function>
<get-children-function>glade_gtk_treeview_get_children</get-children-function>
<add-child-function>glade_gtk_treeview_add_child</add-child-function>
<remove-child-function>glade_gtk_treeview_remove_child</remove-child-function>
<action-activate-function>glade_gtk_treeview_action_activate</action-activate-function>
<depends-function>glade_gtk_treeview_depends</depends-function>
<actions>
<action id="launch_editor" _name="Edit&#8230;" stock="gtk-edit" important="True"/>
</actions>
<properties>
<property id="level-indentation" since="2.12"/>
<property id="show-expanders" since="2.12"/>
<property id="enable-grid-lines" ignore="True">
<displayable-values>
<value id="GTK_TREE_VIEW_GRID_LINES_NONE" _name="None"/>
<value id="GTK_TREE_VIEW_GRID_LINES_HORIZONTAL" _name="Horizontal"/>
<value id="GTK_TREE_VIEW_GRID_LINES_VERTICAL" _name="Vertical"/>
<value id="GTK_TREE_VIEW_GRID_LINES_BOTH" _name="Horizontal and Vertical"/>
</displayable-values>
</property>
<property id="hadjustment" libglade-unsupported="True"/>
<property id="vadjustment" libglade-unsupported="True"/>
<property id="model" create-type="GtkListStore" query="True" libglade-unsupported="True"/>
</properties>
<packing-properties>
<property save="False" id="position" visible="False">
<parameter-spec>
<type>GParamInt</type>
</parameter-spec>
</property>
</packing-properties>
</glade-widget-class>
<glade-widget-class name="GtkTreeViewColumn" generic-name="treeviewcolumn" _title="Tree View Column"
libglade-unsupported="True">
<add-child-function>glade_gtk_cell_layout_add_child</add-child-function>
......@@ -1913,15 +1910,46 @@ embedded in another object</_tooltip>
</properties>
<packing-properties>
<property save="False" id="position" name="Position" visible="False">
<property save="False" id="position" visible="False">
<parameter-spec>
<type>GParamInt</type>
</parameter-spec>
<_tooltip>The Cell Renderer position in the Tree View Column</_tooltip>
</property>
</packing-properties>
</glade-widget-class>
<glade-widget-class name="GtkIconView" generic-name="iconview" _title="Icon View">
<post-create-function>empty</post-create-function>
<add-child-function>glade_gtk_cell_layout_add_child</add-child-function>
<remove-child-function>glade_gtk_cell_layout_remove_child</remove-child-function>
<get-children-function>glade_gtk_cell_layout_get_children</get-children-function>
<read-child-function>glade_gtk_cell_layout_read_child</read-child-function>
<write-child-function>glade_gtk_cell_layout_write_child</write-child-function>
<action-activate-function>glade_gtk_cell_layout_action_activate</action-activate-function>
<child-set-property-function>glade_gtk_cell_layout_set_child_property</child-set-property-function>
<child-get-property-function>glade_gtk_cell_layout_get_child_property</child-get-property-function>
<actions>
<action id="launch_editor" _name="Edit&#8230;" stock="gtk-edit" important="True"/>
</actions>
<properties>
<property id="text-column" disabled="True"/>
<property id="markup-column" disabled="True"/>
<property id="pixbuf-column" disabled="True"/>
<property id="reorderable" ignore="True"/>
</properties>
<packing-properties>
<property save="False" id="position" visible="False">
<parameter-spec>
<type>GParamInt</type>
</parameter-spec>
</property>
</packing-properties>
</glade-widget-class>
<glade-widget-class name="GtkCellRenderer" _title="Cell Renderer">
<post-create-function>glade_gtk_cell_renderer_post_create</post-create-function>
<create-editor-property-function>glade_gtk_cell_renderer_create_eprop</create-editor-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