inspector: Link to model for attributes

This commit is contained in:
Matthias Clasen 2014-05-19 00:13:30 -04:00
parent d260694a37
commit 9a23fd3313
3 changed files with 69 additions and 2 deletions

View File

@ -1056,6 +1056,28 @@ gtk_inspector_prop_editor_init (GtkInspectorPropEditor *editor)
NULL);
}
GtkTreeModel *
gtk_cell_layout_get_model (GtkCellLayout *layout)
{
if (GTK_IS_TREE_VIEW_COLUMN (layout))
return gtk_tree_view_get_model (GTK_TREE_VIEW (gtk_tree_view_column_get_tree_view (GTK_TREE_VIEW_COLUMN (layout))));
else if (GTK_IS_ICON_VIEW (layout))
return gtk_icon_view_get_model (GTK_ICON_VIEW (layout));
else if (GTK_IS_COMBO_BOX (layout))
return gtk_combo_box_get_model (GTK_COMBO_BOX (layout));
else
return NULL;
}
static void
model_properties (GtkButton *button, GtkInspectorPropEditor *editor)
{
GObject *model;
model = g_object_get_data (G_OBJECT (button), "model");
g_signal_emit (editor, signals[SHOW_OBJECT], 0, model, "model");
}
static void
constructed (GObject *object)
{
@ -1070,6 +1092,44 @@ constructed (GObject *object)
gtk_widget_show (label);
gtk_container_add (GTK_CONTAINER (editor), label);
if (GTK_IS_CELL_RENDERER (editor->priv->object))
{
gpointer layout;
GtkCellArea *area;
GtkTreeModel *model = NULL;
gint col = -1;
layout = g_object_get_data (editor->priv->object, "gtk-inspector-cell-layout");
if (GTK_IS_CELL_LAYOUT (layout))
{
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (layout));
col = gtk_cell_area_attribute_get_column (area,
GTK_CELL_RENDERER (editor->priv->object),
editor->priv->name);
model = gtk_cell_layout_get_model (GTK_CELL_LAYOUT (layout));
}
if (col != -1)
{
GtkWidget *box;
GtkWidget *button;
gchar *text;
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
text = g_strdup_printf (_("Mapped to column %d in %p (%s)"),
col, model, g_type_name (G_TYPE_FROM_INSTANCE (model)));
gtk_container_add (GTK_CONTAINER (box), gtk_label_new (text));
g_free (text);
button = gtk_button_new_with_label (_("Properties"));
g_object_set_data (G_OBJECT (button), "model", model);
g_signal_connect (button, "clicked", G_CALLBACK (model_properties), editor);
gtk_container_add (GTK_CONTAINER (box), button);
gtk_container_add (GTK_CONTAINER (editor), box);
gtk_widget_show_all (box);
return;
}
}
can_modify = ((spec->flags & G_PARAM_WRITABLE) != 0 &&
(spec->flags & G_PARAM_CONSTRUCT_ONLY) == 0);

View File

@ -241,10 +241,14 @@ gtk_inspector_prop_list_update_prop (GtkInspectorPropList *pl,
if (GTK_IS_CELL_RENDERER (pl->priv->object))
{
gpointer *layout;
gpointer *area;
gint column = -1;
area = g_object_get_data (pl->priv->object, "gtk-inspector-cell-area");
area = NULL;
layout = g_object_get_data (pl->priv->object, "gtk-inspector-cell-layout");
if (layout)
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (layout));
if (area)
column = gtk_cell_area_attribute_get_column (GTK_CELL_AREA (area),
GTK_CELL_RENDERER (pl->priv->object),

View File

@ -196,8 +196,10 @@ cell_callback (GtkCellRenderer *renderer,
gpointer data)
{
FindAllData *d = data;
gpointer cell_layout;
g_object_set_data (G_OBJECT (renderer), "gtk-inspector-cell-area", d->parent);
cell_layout = g_object_get_data (d->parent, "gtk-inspector-cell-layout");
g_object_set_data (G_OBJECT (renderer), "gtk-inspector-cell-layout", cell_layout);
gtk_inspector_widget_tree_append_object (d->wt, G_OBJECT (renderer), d->iter, NULL);
return FALSE;
@ -360,6 +362,7 @@ gtk_inspector_widget_tree_append_object (GtkInspectorWidgetTree *wt,
GtkCellArea *area;
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (object));
g_object_set_data (G_OBJECT (area), "gtk-inspector-cell-layout", object);
gtk_inspector_widget_tree_append_object (wt, G_OBJECT (area), &iter, "cell-area");
}