2015-03-02 23:02:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Benjamin Otte <otte@gnome.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicntnse,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright noticnt and this permission noticnt shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "css-node-tree.h"
|
2015-10-27 03:37:13 +00:00
|
|
|
#include "prop-editor.h"
|
2015-03-02 23:02:25 +00:00
|
|
|
|
|
|
|
#include "gtktreemodelcssnode.h"
|
2015-10-28 04:33:14 +00:00
|
|
|
#include "gtktreeview.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkpopover.h"
|
2015-03-02 23:02:25 +00:00
|
|
|
#include "gtk/gtkwidgetprivate.h"
|
2015-10-28 04:33:14 +00:00
|
|
|
#include "gtkcssproviderprivate.h"
|
|
|
|
#include "gtkcssstylepropertyprivate.h"
|
|
|
|
#include "gtkcssstyleprivate.h"
|
|
|
|
#include "gtkcssvalueprivate.h"
|
2016-01-24 15:58:32 +00:00
|
|
|
#include "gtkcssselectorprivate.h"
|
2015-10-28 04:33:14 +00:00
|
|
|
#include "gtkliststore.h"
|
|
|
|
#include "gtksettings.h"
|
|
|
|
#include "gtktreeview.h"
|
|
|
|
#include "gtktreeselection.h"
|
2015-10-31 04:07:19 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
2015-12-07 04:06:33 +00:00
|
|
|
#include "gtkmodelbutton.h"
|
|
|
|
#include "gtkstack.h"
|
2015-03-02 23:02:25 +00:00
|
|
|
|
2019-04-10 16:40:50 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
#include <gtk/css/gtkcss.h>
|
|
|
|
|
2015-03-02 23:02:25 +00:00
|
|
|
enum {
|
2015-10-28 04:33:14 +00:00
|
|
|
COLUMN_NODE_NAME,
|
|
|
|
COLUMN_NODE_VISIBLE,
|
|
|
|
COLUMN_NODE_CLASSES,
|
|
|
|
COLUMN_NODE_ID,
|
2015-10-31 04:07:19 +00:00
|
|
|
COLUMN_NODE_STATE,
|
2015-03-02 23:02:25 +00:00
|
|
|
/* add more */
|
2015-10-28 04:33:14 +00:00
|
|
|
N_NODE_COLUMNS
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLUMN_PROP_NAME,
|
|
|
|
COLUMN_PROP_VALUE,
|
|
|
|
COLUMN_PROP_LOCATION
|
2015-03-02 23:02:25 +00:00
|
|
|
};
|
|
|
|
|
2018-10-05 20:07:07 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_NODE,
|
|
|
|
|
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
|
2015-03-02 23:02:25 +00:00
|
|
|
struct _GtkInspectorCssNodeTreePrivate
|
|
|
|
{
|
2015-10-28 04:33:14 +00:00
|
|
|
GtkWidget *node_tree;
|
|
|
|
GtkTreeModel *node_model;
|
|
|
|
GtkTreeViewColumn *node_name_column;
|
|
|
|
GtkTreeViewColumn *node_id_column;
|
|
|
|
GtkTreeViewColumn *node_classes_column;
|
|
|
|
GtkListStore *prop_model;
|
|
|
|
GtkWidget *prop_tree;
|
|
|
|
GtkTreeViewColumn *prop_name_column;
|
|
|
|
GHashTable *prop_iters;
|
2015-11-01 01:34:41 +00:00
|
|
|
GtkCssNode *node;
|
2015-03-02 23:02:25 +00:00
|
|
|
};
|
|
|
|
|
2018-10-05 20:07:07 +00:00
|
|
|
static GParamSpec *properties[N_PROPS] = { NULL, };
|
|
|
|
|
2015-03-02 23:02:25 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorCssNodeTree, gtk_inspector_css_node_tree, GTK_TYPE_BOX)
|
|
|
|
|
2015-12-07 04:06:33 +00:00
|
|
|
typedef struct {
|
|
|
|
GtkCssNode *node;
|
|
|
|
const gchar *prop_name;
|
|
|
|
GdkRectangle rect;
|
|
|
|
GtkInspectorCssNodeTree *cnt;
|
|
|
|
} NodePropEditor;
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_node_prop_editor (NodePropEditor *npe)
|
|
|
|
{
|
|
|
|
GtkWidget *popover;
|
|
|
|
GtkWidget *editor;
|
|
|
|
|
|
|
|
popover = gtk_popover_new (GTK_WIDGET (npe->cnt->priv->node_tree));
|
|
|
|
gtk_popover_set_pointing_to (GTK_POPOVER (popover), &npe->rect);
|
|
|
|
|
2019-04-12 18:34:11 +00:00
|
|
|
editor = gtk_inspector_prop_editor_new (G_OBJECT (npe->node), npe->prop_name, NULL);
|
2015-12-07 04:06:33 +00:00
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (popover), editor);
|
|
|
|
|
2016-08-10 17:18:27 +00:00
|
|
|
gtk_popover_popup (GTK_POPOVER (popover));
|
2015-12-07 04:06:33 +00:00
|
|
|
|
|
|
|
g_signal_connect (popover, "unmap", G_CALLBACK (gtk_widget_destroy), NULL);
|
|
|
|
}
|
|
|
|
|
2015-10-27 03:37:13 +00:00
|
|
|
static void
|
|
|
|
row_activated (GtkTreeView *tv,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *col,
|
|
|
|
GtkInspectorCssNodeTree *cnt)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2015-12-07 04:06:33 +00:00
|
|
|
NodePropEditor npe;
|
|
|
|
|
|
|
|
npe.cnt = cnt;
|
2015-10-27 03:37:13 +00:00
|
|
|
|
2015-10-28 04:33:14 +00:00
|
|
|
if (col == cnt->priv->node_name_column)
|
2015-12-07 04:06:33 +00:00
|
|
|
npe.prop_name = "name";
|
2015-10-28 04:33:14 +00:00
|
|
|
else if (col == cnt->priv->node_id_column)
|
2015-12-07 04:06:33 +00:00
|
|
|
npe.prop_name = "id";
|
2015-10-28 04:33:14 +00:00
|
|
|
else if (col == cnt->priv->node_classes_column)
|
2015-12-07 04:06:33 +00:00
|
|
|
npe.prop_name = "classes";
|
2015-10-27 03:37:13 +00:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2015-10-28 04:33:14 +00:00
|
|
|
gtk_tree_model_get_iter (cnt->priv->node_model, &iter, path);
|
2015-12-07 04:06:33 +00:00
|
|
|
npe.node = gtk_tree_model_css_node_get_node_from_iter (GTK_TREE_MODEL_CSS_NODE (cnt->priv->node_model), &iter);
|
|
|
|
gtk_tree_view_get_cell_area (tv, path, col, &npe.rect);
|
|
|
|
gtk_tree_view_convert_bin_window_to_widget_coords (tv, npe.rect.x, npe.rect.y, &npe.rect.x, &npe.rect.y);
|
|
|
|
|
|
|
|
show_node_prop_editor (&npe);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_css_node_tree_set_node (GtkInspectorCssNodeTree *cnt,
|
|
|
|
GtkCssNode *node);
|
2015-10-28 04:33:14 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
selection_changed (GtkTreeSelection *selection, GtkInspectorCssNodeTree *cnt)
|
|
|
|
{
|
2015-12-07 04:06:33 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkCssNode *node;
|
|
|
|
|
|
|
|
if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
|
|
|
|
return;
|
|
|
|
|
|
|
|
node = gtk_tree_model_css_node_get_node_from_iter (GTK_TREE_MODEL_CSS_NODE (cnt->priv->node_model), &iter);
|
|
|
|
gtk_inspector_css_node_tree_set_node (cnt, node);
|
2015-10-28 04:33:14 +00:00
|
|
|
}
|
|
|
|
|
2015-11-01 01:34:41 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_css_node_tree_unset_node (GtkInspectorCssNodeTree *cnt)
|
|
|
|
{
|
|
|
|
GtkInspectorCssNodeTreePrivate *priv = cnt->priv;
|
|
|
|
|
|
|
|
if (priv->node)
|
|
|
|
{
|
2015-11-01 15:45:11 +00:00
|
|
|
g_signal_handlers_disconnect_matched (priv->node,
|
|
|
|
G_SIGNAL_MATCH_DATA,
|
|
|
|
0, 0, NULL, NULL,
|
|
|
|
cnt);
|
2015-11-01 01:34:41 +00:00
|
|
|
g_object_unref (priv->node);
|
|
|
|
priv->node = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 20:07:07 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_css_node_tree_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkInspectorCssNodeTree *cnt = GTK_INSPECTOR_CSS_NODE_TREE (object);
|
|
|
|
GtkInspectorCssNodeTreePrivate *priv = cnt->priv;
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_NODE:
|
|
|
|
g_value_set_object (value, priv->node);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_css_node_tree_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 23:02:25 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_css_node_tree_finalize (GObject *object)
|
|
|
|
{
|
2015-10-28 04:33:14 +00:00
|
|
|
GtkInspectorCssNodeTree *cnt = GTK_INSPECTOR_CSS_NODE_TREE (object);
|
|
|
|
|
2015-11-01 01:34:41 +00:00
|
|
|
gtk_inspector_css_node_tree_unset_node (cnt);
|
|
|
|
|
2015-10-28 04:33:14 +00:00
|
|
|
g_hash_table_unref (cnt->priv->prop_iters);
|
2015-03-02 23:02:25 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_inspector_css_node_tree_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2015-10-28 04:33:14 +00:00
|
|
|
static void
|
|
|
|
ensure_css_sections (void)
|
|
|
|
{
|
|
|
|
GtkSettings *settings;
|
|
|
|
gchar *theme_name;
|
|
|
|
|
|
|
|
gtk_css_provider_set_keep_css_sections ();
|
|
|
|
|
|
|
|
settings = gtk_settings_get_default ();
|
|
|
|
g_object_get (settings, "gtk-theme-name", &theme_name, NULL);
|
|
|
|
g_object_set (settings, "gtk-theme-name", theme_name, NULL);
|
|
|
|
g_free (theme_name);
|
|
|
|
}
|
|
|
|
|
2015-03-02 23:02:25 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_css_node_tree_class_init (GtkInspectorCssNodeTreeClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2015-10-28 04:33:14 +00:00
|
|
|
ensure_css_sections ();
|
|
|
|
|
2018-10-05 20:07:07 +00:00
|
|
|
object_class->set_property = gtk_inspector_css_node_tree_set_property;
|
|
|
|
object_class->get_property = gtk_inspector_css_node_tree_get_property;
|
2015-03-02 23:02:25 +00:00
|
|
|
object_class->finalize = gtk_inspector_css_node_tree_finalize;
|
|
|
|
|
2018-10-05 20:07:07 +00:00
|
|
|
properties[PROP_NODE] =
|
|
|
|
g_param_spec_object ("node",
|
|
|
|
"Node",
|
|
|
|
"Currently inspected CSS node",
|
|
|
|
GTK_TYPE_CSS_NODE,
|
|
|
|
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, N_PROPS, properties);
|
|
|
|
|
2015-03-02 23:02:25 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/css-node-tree.ui");
|
2015-10-28 04:33:14 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, node_tree);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, node_name_column);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, node_id_column);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, node_classes_column);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, prop_name_column);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, prop_model);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssNodeTree, prop_name_column);
|
2015-10-27 03:37:13 +00:00
|
|
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, row_activated);
|
2015-10-28 04:33:14 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, selection_changed);
|
2015-03-02 23:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sort_strv (gconstpointer a,
|
|
|
|
gconstpointer b,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
char **ap = (char **) a;
|
|
|
|
char **bp = (char **) b;
|
|
|
|
|
2015-04-10 07:48:59 +00:00
|
|
|
return g_ascii_strcasecmp (*ap, *bp);
|
2015-03-02 23:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
strv_sort (char **strv)
|
|
|
|
{
|
|
|
|
g_qsort_with_data (strv,
|
|
|
|
g_strv_length (strv),
|
|
|
|
sizeof (char *),
|
|
|
|
sort_strv,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2015-10-31 04:07:19 +00:00
|
|
|
static gchar *
|
|
|
|
format_state_flags (GtkStateFlags state)
|
|
|
|
{
|
|
|
|
if (state)
|
|
|
|
{
|
2016-01-24 15:58:32 +00:00
|
|
|
GString *str;
|
|
|
|
gint i;
|
|
|
|
gboolean first = TRUE;
|
|
|
|
|
|
|
|
str = g_string_new ("");
|
|
|
|
|
|
|
|
for (i = 0; i < 31; i++)
|
2015-10-31 04:07:19 +00:00
|
|
|
{
|
2016-01-24 15:58:32 +00:00
|
|
|
if (state & (1 << i))
|
2015-10-31 04:07:19 +00:00
|
|
|
{
|
2016-01-24 15:58:32 +00:00
|
|
|
if (!first)
|
2015-10-31 04:07:19 +00:00
|
|
|
g_string_append (str, " | ");
|
2016-01-24 15:58:32 +00:00
|
|
|
first = FALSE;
|
|
|
|
g_string_append (str, gtk_css_pseudoclass_name (1 << i));
|
2015-10-31 04:07:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-24 15:58:32 +00:00
|
|
|
return g_string_free (str, FALSE);
|
2015-10-31 04:07:19 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 11:28:32 +00:00
|
|
|
return g_strdup ("");
|
2015-10-31 04:07:19 +00:00
|
|
|
}
|
|
|
|
|
2015-03-02 23:02:25 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_css_node_tree_get_node_value (GtkTreeModelCssNode *model,
|
|
|
|
GtkCssNode *node,
|
|
|
|
int column,
|
|
|
|
GValue *value)
|
|
|
|
{
|
|
|
|
char **strv;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
switch (column)
|
|
|
|
{
|
2015-10-28 04:33:14 +00:00
|
|
|
case COLUMN_NODE_NAME:
|
2015-10-23 00:58:08 +00:00
|
|
|
g_value_set_string (value, gtk_css_node_get_name (node));
|
|
|
|
break;
|
|
|
|
|
2015-10-28 04:33:14 +00:00
|
|
|
case COLUMN_NODE_VISIBLE:
|
2015-03-02 23:02:25 +00:00
|
|
|
g_value_set_boolean (value, gtk_css_node_get_visible (node));
|
|
|
|
break;
|
|
|
|
|
2015-10-28 04:33:14 +00:00
|
|
|
case COLUMN_NODE_CLASSES:
|
2015-03-02 23:02:25 +00:00
|
|
|
strv = gtk_css_node_get_classes (node);
|
|
|
|
strv_sort (strv);
|
|
|
|
s = g_strjoinv (" ", strv);
|
|
|
|
g_value_take_string (value, s);
|
|
|
|
g_strfreev (strv);
|
|
|
|
break;
|
|
|
|
|
2015-10-28 04:33:14 +00:00
|
|
|
case COLUMN_NODE_ID:
|
2015-03-02 23:02:25 +00:00
|
|
|
g_value_set_string (value, gtk_css_node_get_id (node));
|
|
|
|
break;
|
|
|
|
|
2015-10-31 04:07:19 +00:00
|
|
|
case COLUMN_NODE_STATE:
|
|
|
|
g_value_take_string (value, format_state_flags (gtk_css_node_get_state (node)));
|
|
|
|
break;
|
|
|
|
|
2015-03-02 23:02:25 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_css_node_tree_init (GtkInspectorCssNodeTree *cnt)
|
|
|
|
{
|
|
|
|
GtkInspectorCssNodeTreePrivate *priv;
|
2015-10-28 04:33:14 +00:00
|
|
|
gint i;
|
|
|
|
|
2015-03-02 23:02:25 +00:00
|
|
|
cnt->priv = gtk_inspector_css_node_tree_get_instance_private (cnt);
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (cnt));
|
|
|
|
priv = cnt->priv;
|
|
|
|
|
2015-10-28 04:33:14 +00:00
|
|
|
priv->node_model = gtk_tree_model_css_node_new (gtk_inspector_css_node_tree_get_node_value,
|
|
|
|
N_NODE_COLUMNS,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_BOOLEAN,
|
|
|
|
G_TYPE_STRING,
|
2015-10-31 04:07:19 +00:00
|
|
|
G_TYPE_STRING,
|
2015-10-28 04:33:14 +00:00
|
|
|
G_TYPE_STRING);
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (priv->node_tree), priv->node_model);
|
|
|
|
g_object_unref (priv->node_model);
|
|
|
|
|
|
|
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (cnt->priv->prop_model),
|
|
|
|
COLUMN_PROP_NAME,
|
|
|
|
GTK_SORT_ASCENDING);
|
|
|
|
|
|
|
|
priv->prop_iters = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
NULL, (GDestroyNotify) gtk_tree_iter_free);
|
|
|
|
|
|
|
|
for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
|
|
|
|
{
|
|
|
|
GtkCssStyleProperty *prop;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
const gchar *name;
|
|
|
|
|
|
|
|
prop = _gtk_css_style_property_lookup_by_id (i);
|
|
|
|
name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop));
|
|
|
|
|
|
|
|
gtk_list_store_append (cnt->priv->prop_model, &iter);
|
|
|
|
gtk_list_store_set (cnt->priv->prop_model, &iter, COLUMN_PROP_NAME, name, -1);
|
|
|
|
g_hash_table_insert (cnt->priv->prop_iters, (gpointer)name, gtk_tree_iter_copy (&iter));
|
|
|
|
}
|
2015-03-02 23:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_inspector_css_node_tree_set_object (GtkInspectorCssNodeTree *cnt,
|
|
|
|
GObject *object)
|
|
|
|
{
|
2019-04-02 23:24:57 +00:00
|
|
|
GtkWidget *stack;
|
|
|
|
GtkStackPage *page;
|
2015-03-02 23:02:25 +00:00
|
|
|
GtkInspectorCssNodeTreePrivate *priv;
|
2015-11-02 19:16:23 +00:00
|
|
|
GtkCssNode *node, *root;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
2015-10-25 13:20:43 +00:00
|
|
|
|
2015-03-02 23:02:25 +00:00
|
|
|
g_return_if_fail (GTK_INSPECTOR_IS_CSS_NODE_TREE (cnt));
|
|
|
|
|
|
|
|
priv = cnt->priv;
|
|
|
|
|
2019-04-02 23:24:57 +00:00
|
|
|
stack = gtk_widget_get_parent (GTK_WIDGET (cnt));
|
|
|
|
page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (cnt));
|
|
|
|
|
2015-03-02 23:02:25 +00:00
|
|
|
if (!GTK_IS_WIDGET (object))
|
|
|
|
{
|
2019-04-02 23:24:57 +00:00
|
|
|
g_object_set (page, "visible", FALSE, NULL);
|
2015-03-02 23:02:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-02 23:24:57 +00:00
|
|
|
g_object_set (page, "visible", TRUE, NULL);
|
2015-12-07 04:06:33 +00:00
|
|
|
|
2015-11-02 19:16:23 +00:00
|
|
|
root = node = gtk_widget_get_css_node (GTK_WIDGET (object));
|
|
|
|
while (gtk_css_node_get_parent (root))
|
|
|
|
root = gtk_css_node_get_parent (root);
|
|
|
|
|
|
|
|
gtk_tree_model_css_node_set_root_node (GTK_TREE_MODEL_CSS_NODE (priv->node_model), root);
|
|
|
|
|
|
|
|
gtk_tree_model_css_node_get_iter_from_node (GTK_TREE_MODEL_CSS_NODE (priv->node_model), &iter, node);
|
|
|
|
path = gtk_tree_model_get_path (priv->node_model, &iter);
|
|
|
|
|
|
|
|
gtk_tree_view_expand_to_path (GTK_TREE_VIEW (priv->node_tree), path);
|
|
|
|
gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->node_tree), path, NULL, FALSE);
|
2015-11-04 04:55:50 +00:00
|
|
|
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->node_tree), path, NULL, TRUE, 0.5, 0.0);
|
2015-11-02 19:16:23 +00:00
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
2015-03-02 23:02:25 +00:00
|
|
|
}
|
|
|
|
|
2015-10-28 04:33:14 +00:00
|
|
|
static void
|
2015-12-15 00:14:57 +00:00
|
|
|
gtk_inspector_css_node_tree_update_style (GtkInspectorCssNodeTree *cnt,
|
|
|
|
GtkCssStyle *new_style)
|
2015-10-28 04:33:14 +00:00
|
|
|
{
|
2015-11-01 01:34:41 +00:00
|
|
|
GtkInspectorCssNodeTreePrivate *priv = cnt->priv;
|
|
|
|
gint i;
|
|
|
|
|
2015-10-28 04:33:14 +00:00
|
|
|
for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
|
|
|
|
{
|
|
|
|
GtkCssStyleProperty *prop;
|
|
|
|
const gchar *name;
|
|
|
|
GtkTreeIter *iter;
|
|
|
|
GtkCssSection *section;
|
|
|
|
gchar *location;
|
|
|
|
gchar *value;
|
|
|
|
|
|
|
|
prop = _gtk_css_style_property_lookup_by_id (i);
|
|
|
|
name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop));
|
|
|
|
|
|
|
|
iter = (GtkTreeIter *)g_hash_table_lookup (priv->prop_iters, name);
|
|
|
|
|
2015-11-01 15:45:11 +00:00
|
|
|
if (new_style)
|
|
|
|
{
|
|
|
|
value = _gtk_css_value_to_string (gtk_css_style_get_value (new_style, i));
|
2015-10-28 04:33:14 +00:00
|
|
|
|
2015-11-01 15:45:11 +00:00
|
|
|
section = gtk_css_style_get_section (new_style, i);
|
|
|
|
if (section)
|
2019-04-10 15:23:14 +00:00
|
|
|
location = gtk_css_section_to_string (section);
|
2015-11-01 15:45:11 +00:00
|
|
|
else
|
|
|
|
location = NULL;
|
|
|
|
}
|
2015-10-28 04:33:14 +00:00
|
|
|
else
|
2015-11-01 15:45:11 +00:00
|
|
|
{
|
|
|
|
value = NULL;
|
|
|
|
location = NULL;
|
|
|
|
}
|
2015-10-28 04:33:14 +00:00
|
|
|
|
|
|
|
gtk_list_store_set (priv->prop_model,
|
|
|
|
iter,
|
|
|
|
COLUMN_PROP_VALUE, value,
|
|
|
|
COLUMN_PROP_LOCATION, location,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
g_free (location);
|
|
|
|
g_free (value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 00:14:57 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_css_node_tree_update_style_cb (GtkCssNode *node,
|
|
|
|
GtkCssStyleChange *change,
|
|
|
|
GtkInspectorCssNodeTree *cnt)
|
|
|
|
{
|
|
|
|
gtk_inspector_css_node_tree_update_style (cnt, gtk_css_style_change_get_new_style (change));
|
|
|
|
}
|
|
|
|
|
2015-11-01 15:45:11 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_css_node_tree_set_node (GtkInspectorCssNodeTree *cnt,
|
|
|
|
GtkCssNode *node)
|
|
|
|
{
|
|
|
|
GtkInspectorCssNodeTreePrivate *priv = cnt->priv;
|
|
|
|
|
|
|
|
if (priv->node == node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
g_object_ref (node);
|
|
|
|
|
2015-12-15 00:14:57 +00:00
|
|
|
gtk_inspector_css_node_tree_update_style (cnt, node ? gtk_css_node_get_style (node) : NULL);
|
2015-12-12 01:02:04 +00:00
|
|
|
|
2015-11-01 15:45:11 +00:00
|
|
|
gtk_inspector_css_node_tree_unset_node (cnt);
|
|
|
|
|
|
|
|
priv->node = node;
|
2018-10-05 20:07:07 +00:00
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
g_signal_connect (node, "style-changed", G_CALLBACK (gtk_inspector_css_node_tree_update_style_cb), cnt);
|
|
|
|
}
|
2015-11-01 15:45:11 +00:00
|
|
|
|
2018-10-05 20:07:07 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (cnt), properties[PROP_NODE]);
|
2015-10-31 16:14:14 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 20:07:07 +00:00
|
|
|
GtkCssNode *
|
|
|
|
gtk_inspector_css_node_tree_get_node (GtkInspectorCssNodeTree *cnt)
|
|
|
|
{
|
|
|
|
GtkInspectorCssNodeTreePrivate *priv = cnt->priv;
|
|
|
|
|
|
|
|
return priv->node;
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: set et sw=2 ts=2:
|