From ed00d86496dbe5aae4d5c477d311a7cbfcc6c1a2 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 26 Oct 2015 23:37:13 -0400 Subject: [PATCH] inspector: Allow editing css node properties This reuses the property editor infrastructure from the property list pages. Good that css nodes are objects. --- gtk/inspector/css-node-tree.c | 53 ++++++++++++++++++++++++++++++++++ gtk/inspector/css-node-tree.ui | 7 +++-- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/gtk/inspector/css-node-tree.c b/gtk/inspector/css-node-tree.c index 6a2e1a9221..1c894e232d 100644 --- a/gtk/inspector/css-node-tree.c +++ b/gtk/inspector/css-node-tree.c @@ -24,10 +24,12 @@ #include #include "css-node-tree.h" +#include "prop-editor.h" #include "gtktreemodelcssnode.h" #include "gtk/gtktreeview.h" #include "gtk/gtklabel.h" +#include "gtk/gtkpopover.h" #include "gtk/gtkwidgetprivate.h" enum { @@ -44,11 +46,57 @@ struct _GtkInspectorCssNodeTreePrivate { GtkWidget *tree_view; GtkTreeModel *model; + GtkTreeViewColumn *name_column; + GtkTreeViewColumn *id_column; + GtkTreeViewColumn *classes_column; GtkWidget *object_title; }; G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorCssNodeTree, gtk_inspector_css_node_tree, GTK_TYPE_BOX) +static void +row_activated (GtkTreeView *tv, + GtkTreePath *path, + GtkTreeViewColumn *col, + GtkInspectorCssNodeTree *cnt) +{ + GtkTreeIter iter; + GdkRectangle rect; + GtkWidget *editor; + GtkWidget *popover; + GtkCssNode *node; + const gchar *prop_name; + + if (col == cnt->priv->name_column) + prop_name = "name"; + else if (col == cnt->priv->id_column) + prop_name = "id"; + else if (col == cnt->priv->classes_column) + prop_name = "classes"; + else + return; + + gtk_tree_model_get_iter (cnt->priv->model, &iter, path); + node = gtk_tree_model_css_node_get_node_from_iter (GTK_TREE_MODEL_CSS_NODE (cnt->priv->model), &iter); + gtk_tree_view_get_cell_area (tv, path, col, &rect); + gtk_tree_view_convert_bin_window_to_widget_coords (tv, rect.x, rect.y, &rect.x, &rect.y); + + popover = gtk_popover_new (GTK_WIDGET (tv)); + gtk_popover_set_pointing_to (GTK_POPOVER (popover), &rect); + + editor = gtk_inspector_prop_editor_new (G_OBJECT (node), prop_name, FALSE); + gtk_widget_show (editor); + + gtk_container_add (GTK_CONTAINER (popover), editor); + + if (gtk_inspector_prop_editor_should_expand (GTK_INSPECTOR_PROP_EDITOR (editor))) + gtk_widget_set_vexpand (popover, TRUE); + + gtk_widget_show (popover); + + g_signal_connect (popover, "unmap", G_CALLBACK (gtk_widget_destroy), NULL); +} + static void gtk_inspector_css_node_tree_finalize (GObject *object) { @@ -68,6 +116,11 @@ gtk_inspector_css_node_tree_class_init (GtkInspectorCssNodeTreeClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/css-node-tree.ui"); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, tree_view); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, object_title); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, name_column); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, id_column); + gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, classes_column); + + gtk_widget_class_bind_template_callback (widget_class, row_activated); } static int diff --git a/gtk/inspector/css-node-tree.ui b/gtk/inspector/css-node-tree.ui index d82ba15d28..019d9d3088 100644 --- a/gtk/inspector/css-node-tree.ui +++ b/gtk/inspector/css-node-tree.ui @@ -21,6 +21,7 @@ True False + True @@ -35,7 +36,7 @@ - + True Name @@ -48,7 +49,7 @@ - + True ID @@ -61,7 +62,7 @@ - + True Classes