2014-05-03 01:48:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008-2009 Christian Hammond
|
|
|
|
* Copyright (c) 2008-2009 David Trowbridge
|
|
|
|
*
|
|
|
|
* 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, sublicense,
|
|
|
|
* 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 notice and this permission notice 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.
|
|
|
|
*/
|
2014-05-05 03:47:11 +00:00
|
|
|
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
#include "prop-list.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
#include "prop-editor.h"
|
2014-10-11 01:40:53 +00:00
|
|
|
#include "object-tree.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkcelllayout.h"
|
2014-10-11 00:51:54 +00:00
|
|
|
#include "gtktreeview.h"
|
2014-10-31 00:54:04 +00:00
|
|
|
#include "gtktreeselection.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkpopover.h"
|
2014-11-22 16:41:24 +00:00
|
|
|
#include "gtksearchentry.h"
|
|
|
|
#include "gtklabel.h"
|
2018-02-04 08:29:44 +00:00
|
|
|
#include "gtkmain.h"
|
2014-11-22 16:41:24 +00:00
|
|
|
#include "gtkstack.h"
|
2018-02-04 08:29:44 +00:00
|
|
|
#include "gtkeventcontrollerkey.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLUMN_NAME,
|
|
|
|
COLUMN_VALUE,
|
2016-03-10 01:55:46 +00:00
|
|
|
COLUMN_TYPE,
|
2014-05-03 01:48:33 +00:00
|
|
|
COLUMN_DEFINED_AT,
|
|
|
|
COLUMN_TOOLTIP,
|
2014-05-08 14:16:58 +00:00
|
|
|
COLUMN_WRITABLE,
|
|
|
|
COLUMN_ATTRIBUTE
|
2014-05-03 01:48:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2014-10-11 01:40:53 +00:00
|
|
|
PROP_OBJECT_TREE,
|
2016-03-07 01:41:28 +00:00
|
|
|
PROP_CHILD_PROPERTIES,
|
|
|
|
PROP_SEARCH_ENTRY
|
2014-05-03 01:48:33 +00:00
|
|
|
};
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
struct _GtkInspectorPropListPrivate
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
GtkListStore *model;
|
|
|
|
GHashTable *prop_iters;
|
2014-05-08 22:36:38 +00:00
|
|
|
gulong notify_handler_id;
|
2014-10-11 01:40:53 +00:00
|
|
|
GtkInspectorObjectTree *object_tree;
|
2014-05-03 19:25:43 +00:00
|
|
|
gboolean child_properties;
|
2014-10-31 00:54:04 +00:00
|
|
|
GtkTreeViewColumn *name_column;
|
2014-05-08 14:16:58 +00:00
|
|
|
GtkTreeViewColumn *attribute_column;
|
2014-05-10 03:15:34 +00:00
|
|
|
GtkWidget *tree;
|
2014-10-31 00:54:04 +00:00
|
|
|
GtkWidget *search_entry;
|
2014-11-22 16:41:24 +00:00
|
|
|
GtkWidget *search_stack;
|
2014-05-03 01:48:33 +00:00
|
|
|
};
|
|
|
|
|
2014-05-10 03:15:34 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorPropList, gtk_inspector_prop_list, GTK_TYPE_BOX)
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-11-22 16:41:24 +00:00
|
|
|
static void
|
|
|
|
search_close_clicked (GtkWidget *button,
|
|
|
|
GtkInspectorPropList *pl)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (pl->priv->search_entry), "");
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (pl->priv->search_stack), "title");
|
|
|
|
}
|
|
|
|
|
2014-10-31 00:54:04 +00:00
|
|
|
static gboolean
|
2018-02-04 08:29:44 +00:00
|
|
|
key_pressed (GtkEventController *controller,
|
|
|
|
guint keyval,
|
|
|
|
guint keycode,
|
|
|
|
GdkModifierType state,
|
|
|
|
GtkInspectorPropList *pl)
|
2014-10-31 00:54:04 +00:00
|
|
|
{
|
2014-11-22 16:41:24 +00:00
|
|
|
if (!gtk_widget_get_mapped (GTK_WIDGET (pl)))
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
|
2018-02-04 08:29:44 +00:00
|
|
|
if (gtk_search_entry_handle_event (GTK_SEARCH_ENTRY (pl->priv->search_entry),
|
|
|
|
gtk_get_current_event ()))
|
2014-11-22 16:41:24 +00:00
|
|
|
{
|
2016-03-07 01:41:28 +00:00
|
|
|
gtk_stack_set_visible_child (GTK_STACK (pl->priv->search_stack), pl->priv->search_entry);
|
2014-11-25 03:44:44 +00:00
|
|
|
return GDK_EVENT_STOP;
|
2014-11-22 16:41:24 +00:00
|
|
|
}
|
2018-02-04 08:29:44 +00:00
|
|
|
|
2014-11-25 03:44:44 +00:00
|
|
|
return GDK_EVENT_PROPAGATE;
|
2014-10-31 00:54:04 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 17:03:17 +00:00
|
|
|
static void
|
|
|
|
destroy_controller (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
gtk_widget_remove_controller (gtk_event_controller_get_widget (controller), controller);
|
|
|
|
}
|
|
|
|
|
2014-10-31 00:54:04 +00:00
|
|
|
static void
|
|
|
|
hierarchy_changed (GtkWidget *widget,
|
|
|
|
GtkWidget *previous_toplevel)
|
|
|
|
{
|
2018-02-04 08:29:44 +00:00
|
|
|
GtkEventController *controller;
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
2014-10-31 00:54:04 +00:00
|
|
|
if (previous_toplevel)
|
2018-05-05 07:02:14 +00:00
|
|
|
g_object_set_data (G_OBJECT (previous_toplevel), "prop-controller", NULL);
|
2018-02-04 08:29:44 +00:00
|
|
|
|
|
|
|
toplevel = gtk_widget_get_toplevel (widget);
|
2018-05-05 07:06:22 +00:00
|
|
|
|
|
|
|
if (!GTK_IS_WINDOW (toplevel))
|
|
|
|
return;
|
|
|
|
|
2018-04-20 17:58:06 +00:00
|
|
|
controller = gtk_event_controller_key_new ();
|
2018-05-14 17:03:17 +00:00
|
|
|
g_object_set_data_full (G_OBJECT (toplevel), "prop-controller", controller, (GDestroyNotify)destroy_controller);
|
2018-02-04 08:29:44 +00:00
|
|
|
g_signal_connect (controller, "key-pressed", G_CALLBACK (key_pressed), widget);
|
2018-04-20 17:58:06 +00:00
|
|
|
gtk_widget_add_controller (toplevel, controller);
|
2014-10-31 00:54:04 +00:00
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_prop_list_init (GtkInspectorPropList *pl)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-07 03:24:20 +00:00
|
|
|
pl->priv = gtk_inspector_prop_list_get_instance_private (pl);
|
2014-05-05 01:08:36 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (pl));
|
|
|
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (pl->priv->model),
|
|
|
|
COLUMN_NAME,
|
|
|
|
GTK_SORT_ASCENDING);
|
2014-05-03 01:48:33 +00:00
|
|
|
pl->priv->prop_iters = g_hash_table_new_full (g_str_hash,
|
|
|
|
g_str_equal,
|
|
|
|
NULL,
|
|
|
|
(GDestroyNotify) gtk_tree_iter_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_property (GObject *object,
|
2014-05-05 01:08:36 +00:00
|
|
|
guint param_id,
|
2014-05-03 01:48:33 +00:00
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2014-05-07 03:24:20 +00:00
|
|
|
GtkInspectorPropList *pl = GTK_INSPECTOR_PROP_LIST (object);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
2014-10-11 01:40:53 +00:00
|
|
|
case PROP_OBJECT_TREE:
|
|
|
|
g_value_take_object (value, pl->priv->object_tree);
|
2014-05-03 01:48:33 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-03 19:25:43 +00:00
|
|
|
case PROP_CHILD_PROPERTIES:
|
|
|
|
g_value_set_boolean (value, pl->priv->child_properties);
|
|
|
|
break;
|
|
|
|
|
2016-03-07 01:41:28 +00:00
|
|
|
case PROP_SEARCH_ENTRY:
|
|
|
|
g_value_take_object (value, pl->priv->search_entry);
|
|
|
|
break;
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_property (GObject *object,
|
2014-05-05 01:08:36 +00:00
|
|
|
guint param_id,
|
2014-05-03 01:48:33 +00:00
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2014-05-07 03:24:20 +00:00
|
|
|
GtkInspectorPropList *pl = GTK_INSPECTOR_PROP_LIST (object);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
2014-10-11 01:40:53 +00:00
|
|
|
case PROP_OBJECT_TREE:
|
|
|
|
pl->priv->object_tree = g_value_get_object (value);
|
2014-05-03 01:48:33 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-03 19:25:43 +00:00
|
|
|
case PROP_CHILD_PROPERTIES:
|
|
|
|
pl->priv->child_properties = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
|
2016-03-07 01:41:28 +00:00
|
|
|
case PROP_SEARCH_ENTRY:
|
|
|
|
pl->priv->search_entry = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
static void
|
|
|
|
show_object (GtkInspectorPropEditor *editor,
|
|
|
|
GObject *object,
|
|
|
|
const gchar *name,
|
2014-05-31 03:21:13 +00:00
|
|
|
const gchar *tab,
|
2014-05-18 05:03:24 +00:00
|
|
|
GtkInspectorPropList *pl)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkWidget *popover;
|
|
|
|
|
|
|
|
popover = gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_POPOVER);
|
|
|
|
gtk_widget_hide (popover);
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
g_object_set_data (G_OBJECT (pl->priv->object_tree), "next-tab", (gpointer)tab);
|
|
|
|
if (gtk_inspector_object_tree_find_object (pl->priv->object_tree, object, &iter))
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_select_object (pl->priv->object_tree, object);
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
2014-10-11 01:40:53 +00:00
|
|
|
else if (gtk_inspector_object_tree_find_object (pl->priv->object_tree, pl->priv->object, &iter))
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (pl->priv->object_tree, object, &iter, name);
|
|
|
|
gtk_inspector_object_tree_select_object (pl->priv->object_tree, object);
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("GtkInspector: couldn't find the widget in the tree");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
row_activated (GtkTreeView *tv,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *col,
|
|
|
|
GtkInspectorPropList *pl)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GdkRectangle rect;
|
|
|
|
gchar *name;
|
|
|
|
GtkWidget *editor;
|
|
|
|
GtkWidget *popover;
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (pl->priv->model), &iter, path);
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (pl->priv->model), &iter, COLUMN_NAME, &name, -1);
|
|
|
|
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 (pl->priv->object, name, pl->priv->child_properties);
|
|
|
|
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);
|
|
|
|
|
|
|
|
g_signal_connect (editor, "show-object", G_CALLBACK (show_object), pl);
|
|
|
|
|
2016-08-10 17:18:27 +00:00
|
|
|
gtk_popover_popup (GTK_POPOVER (popover));
|
2014-05-18 05:03:24 +00:00
|
|
|
|
2015-02-20 11:46:52 +00:00
|
|
|
g_signal_connect (popover, "unmap", G_CALLBACK (gtk_widget_destroy), NULL);
|
2014-06-05 09:56:47 +00:00
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:39:11 +00:00
|
|
|
static void cleanup_object (GtkInspectorPropList *pl);
|
|
|
|
|
|
|
|
static void
|
|
|
|
finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkInspectorPropList *pl = GTK_INSPECTOR_PROP_LIST (object);
|
|
|
|
|
|
|
|
cleanup_object (pl);
|
|
|
|
g_hash_table_unref (pl->priv->prop_iters);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_inspector_prop_list_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2016-03-07 01:41:28 +00:00
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
|
|
|
{
|
|
|
|
GtkInspectorPropList *pl = GTK_INSPECTOR_PROP_LIST (object);
|
|
|
|
|
|
|
|
pl->priv->search_stack = gtk_widget_get_parent (pl->priv->search_entry);
|
|
|
|
|
|
|
|
gtk_tree_view_set_search_entry (GTK_TREE_VIEW (pl->priv->tree),
|
|
|
|
GTK_ENTRY (pl->priv->search_entry));
|
|
|
|
|
|
|
|
g_signal_connect (pl->priv->search_entry, "stop-search",
|
|
|
|
G_CALLBACK (search_close_clicked), pl);
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_prop_list_class_init (GtkInspectorPropListClass *klass)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-05 01:08:36 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-21 10:39:11 +00:00
|
|
|
object_class->finalize = finalize;
|
2014-05-03 01:48:33 +00:00
|
|
|
object_class->get_property = get_property;
|
|
|
|
object_class->set_property = set_property;
|
2016-03-07 01:41:28 +00:00
|
|
|
object_class->constructed = constructed;
|
2014-05-05 01:08:36 +00:00
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_OBJECT_TREE,
|
|
|
|
g_param_spec_object ("object-tree", "Object Tree", "Object tree",
|
2014-05-05 01:08:36 +00:00
|
|
|
GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
2014-05-03 19:25:43 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_CHILD_PROPERTIES,
|
|
|
|
g_param_spec_boolean ("child-properties", "Child properties", "Child properties",
|
|
|
|
FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
2014-05-05 01:08:36 +00:00
|
|
|
|
2016-03-07 01:41:28 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_SEARCH_ENTRY,
|
|
|
|
g_param_spec_object ("search-entry", "Search Entry", "Search Entry",
|
|
|
|
GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2014-11-30 20:59:53 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/prop-list.ui");
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, model);
|
2014-05-08 14:16:58 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, attribute_column);
|
2014-05-10 03:15:34 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, tree);
|
2014-05-18 05:03:24 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, row_activated);
|
2014-11-22 16:41:24 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, search_close_clicked);
|
2014-11-25 01:36:00 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, hierarchy_changed);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 01:55:46 +00:00
|
|
|
/* Like g_strdup_value_contents, but keeps the type name separate */
|
|
|
|
static void
|
|
|
|
strdup_value_contents (const GValue *value,
|
|
|
|
gchar **contents,
|
|
|
|
gchar **type)
|
|
|
|
{
|
|
|
|
const gchar *src;
|
|
|
|
|
|
|
|
if (G_VALUE_HOLDS_STRING (value))
|
|
|
|
{
|
|
|
|
src = g_value_get_string (value);
|
|
|
|
|
|
|
|
*type = g_strdup ("char*");
|
|
|
|
|
|
|
|
if (!src)
|
|
|
|
{
|
|
|
|
*contents = g_strdup ("NULL");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *s = g_strescape (src, NULL);
|
|
|
|
*contents = g_strdup_printf ("\"%s\"", s);
|
|
|
|
g_free (s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING))
|
|
|
|
{
|
|
|
|
GValue tmp_value = G_VALUE_INIT;
|
|
|
|
|
|
|
|
*type = g_strdup (g_type_name (G_VALUE_TYPE (value)));
|
|
|
|
|
|
|
|
g_value_init (&tmp_value, G_TYPE_STRING);
|
|
|
|
g_value_transform (value, &tmp_value);
|
|
|
|
src = g_value_get_string (&tmp_value);
|
|
|
|
if (!src)
|
|
|
|
*contents = g_strdup ("NULL");
|
|
|
|
else
|
|
|
|
*contents = g_strescape (src, NULL);
|
|
|
|
g_value_unset (&tmp_value);
|
|
|
|
}
|
|
|
|
else if (g_value_fits_pointer (value))
|
|
|
|
{
|
|
|
|
gpointer p = g_value_peek_pointer (value);
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
*type = g_strdup (g_type_name (G_VALUE_TYPE (value)));
|
|
|
|
*contents = g_strdup ("NULL");
|
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS_OBJECT (value))
|
|
|
|
{
|
|
|
|
*type = g_strdup (G_OBJECT_TYPE_NAME (p));
|
|
|
|
*contents = g_strdup_printf ("%p", p);
|
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS_PARAM (value))
|
|
|
|
{
|
|
|
|
*type = g_strdup (G_PARAM_SPEC_TYPE_NAME (p));
|
|
|
|
*contents = g_strdup_printf ("%p", p);
|
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
|
|
|
|
{
|
|
|
|
GStrv strv = g_value_get_boxed (value);
|
|
|
|
GString *tmp = g_string_new ("[");
|
|
|
|
|
|
|
|
while (*strv != NULL)
|
|
|
|
{
|
|
|
|
gchar *escaped = g_strescape (*strv, NULL);
|
|
|
|
|
|
|
|
g_string_append_printf (tmp, "\"%s\"", escaped);
|
|
|
|
g_free (escaped);
|
|
|
|
|
|
|
|
if (*++strv != NULL)
|
|
|
|
g_string_append (tmp, ", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_append (tmp, "]");
|
|
|
|
*type = g_strdup ("char**");
|
|
|
|
*contents = g_string_free (tmp, FALSE);
|
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS_BOXED (value))
|
|
|
|
{
|
|
|
|
*type = g_strdup (g_type_name (G_VALUE_TYPE (value)));
|
|
|
|
*contents = g_strdup_printf ("%p", p);
|
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS_POINTER (value))
|
|
|
|
{
|
|
|
|
*type = g_strdup ("gpointer");
|
|
|
|
*contents = g_strdup_printf ("%p", p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*type = g_strdup ("???");
|
|
|
|
*contents = g_strdup ("???");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*type = g_strdup ("???");
|
|
|
|
*contents = g_strdup ("???");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_prop_list_update_prop (GtkInspectorPropList *pl,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GParamSpec *prop)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
|
|
|
GValue gvalue = {0};
|
2016-03-10 01:55:46 +00:00
|
|
|
gchar *value;
|
|
|
|
gchar *type;
|
2014-05-08 14:16:58 +00:00
|
|
|
gchar *attribute = NULL;
|
2016-03-10 02:42:08 +00:00
|
|
|
gboolean writable;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-08 14:16:58 +00:00
|
|
|
g_value_init (&gvalue, prop->value_type);
|
2014-05-03 19:25:43 +00:00
|
|
|
if (pl->priv->child_properties)
|
|
|
|
{
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
|
|
|
parent = gtk_widget_get_parent (GTK_WIDGET (pl->priv->object));
|
|
|
|
gtk_container_child_get_property (GTK_CONTAINER (parent),
|
|
|
|
GTK_WIDGET (pl->priv->object),
|
|
|
|
prop->name, &gvalue);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_object_get_property (pl->priv->object, prop->name, &gvalue);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2016-03-10 01:55:46 +00:00
|
|
|
strdup_value_contents (&gvalue, &value, &type);
|
2014-05-08 14:16:58 +00:00
|
|
|
|
|
|
|
if (GTK_IS_CELL_RENDERER (pl->priv->object))
|
|
|
|
{
|
2014-05-19 04:13:30 +00:00
|
|
|
gpointer *layout;
|
2014-05-20 13:45:50 +00:00
|
|
|
GtkCellArea *area;
|
2014-05-08 14:16:58 +00:00
|
|
|
gint column = -1;
|
|
|
|
|
2014-05-19 04:13:30 +00:00
|
|
|
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));
|
2014-05-08 14:16:58 +00:00
|
|
|
if (area)
|
2014-05-20 13:45:50 +00:00
|
|
|
column = gtk_cell_area_attribute_get_column (area,
|
2014-05-08 14:16:58 +00:00
|
|
|
GTK_CELL_RENDERER (pl->priv->object),
|
|
|
|
prop->name);
|
|
|
|
|
|
|
|
if (column != -1)
|
|
|
|
attribute = g_strdup_printf ("%d", column);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 02:42:08 +00:00
|
|
|
writable = ((prop->flags & G_PARAM_WRITABLE) != 0) &&
|
|
|
|
((prop->flags & G_PARAM_CONSTRUCT_ONLY) == 0);
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
gtk_list_store_set (pl->priv->model, iter,
|
|
|
|
COLUMN_NAME, prop->name,
|
2014-05-08 14:16:58 +00:00
|
|
|
COLUMN_VALUE, value ? value : "",
|
2016-03-10 01:55:46 +00:00
|
|
|
COLUMN_TYPE, type ? type : "",
|
2014-05-03 01:48:33 +00:00
|
|
|
COLUMN_DEFINED_AT, g_type_name (prop->owner_type),
|
|
|
|
COLUMN_TOOLTIP, g_param_spec_get_blurb (prop),
|
2016-03-10 02:42:08 +00:00
|
|
|
COLUMN_WRITABLE, writable,
|
2014-05-08 14:16:58 +00:00
|
|
|
COLUMN_ATTRIBUTE, attribute ? attribute : "",
|
2014-05-03 01:48:33 +00:00
|
|
|
-1);
|
|
|
|
|
|
|
|
g_free (value);
|
2016-03-10 01:55:46 +00:00
|
|
|
g_free (type);
|
2014-05-08 14:16:58 +00:00
|
|
|
g_free (attribute);
|
2014-05-03 01:48:33 +00:00
|
|
|
g_value_unset (&gvalue);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_prop_list_prop_changed_cb (GObject *pspec,
|
|
|
|
GParamSpec *prop,
|
|
|
|
GtkInspectorPropList *pl)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-21 10:39:11 +00:00
|
|
|
GtkTreeIter *iter;
|
|
|
|
|
|
|
|
if (!pl->priv->object)
|
|
|
|
return;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-21 10:39:11 +00:00
|
|
|
iter = g_hash_table_lookup (pl->priv->prop_iters, prop->name);
|
2014-05-03 01:48:33 +00:00
|
|
|
if (iter != NULL)
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_prop_list_update_prop (pl, iter, prop);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 02:58:43 +00:00
|
|
|
static void
|
|
|
|
cleanup_object (GtkInspectorPropList *pl)
|
|
|
|
{
|
2014-05-21 10:39:11 +00:00
|
|
|
if (pl->priv->object &&
|
|
|
|
g_signal_handler_is_connected (pl->priv->object, pl->priv->notify_handler_id))
|
|
|
|
g_signal_handler_disconnect (pl->priv->object, pl->priv->notify_handler_id);
|
2014-05-09 02:58:43 +00:00
|
|
|
|
|
|
|
pl->priv->object = NULL;
|
2014-05-21 10:39:11 +00:00
|
|
|
pl->priv->notify_handler_id = 0;
|
2014-05-09 02:58:43 +00:00
|
|
|
|
|
|
|
g_hash_table_remove_all (pl->priv->prop_iters);
|
2014-05-22 22:31:11 +00:00
|
|
|
if (pl->priv->model)
|
|
|
|
gtk_list_store_clear (pl->priv->model);
|
2014-05-09 02:58:43 +00:00
|
|
|
}
|
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
gboolean
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
|
|
|
|
GObject *object)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GParamSpec **props;
|
|
|
|
guint num_properties;
|
|
|
|
guint i;
|
|
|
|
|
2014-10-25 01:14:16 +00:00
|
|
|
if (!object)
|
2014-05-03 20:43:04 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2014-10-25 01:14:16 +00:00
|
|
|
if (pl->priv->object == object)
|
|
|
|
return TRUE;
|
|
|
|
|
2014-05-09 02:58:43 +00:00
|
|
|
cleanup_object (pl);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-11-22 16:41:24 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (pl->priv->search_entry), "");
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (pl->priv->search_stack), "title");
|
2016-03-07 01:41:28 +00:00
|
|
|
|
2014-05-03 19:25:43 +00:00
|
|
|
if (pl->priv->child_properties)
|
|
|
|
{
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
|
|
|
if (!GTK_IS_WIDGET (object))
|
2014-05-10 03:57:57 +00:00
|
|
|
{
|
|
|
|
gtk_widget_hide (GTK_WIDGET (pl));
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-05-03 19:25:43 +00:00
|
|
|
|
|
|
|
parent = gtk_widget_get_parent (GTK_WIDGET (object));
|
2016-11-29 17:32:43 +00:00
|
|
|
if (!parent || !GTK_IS_CONTAINER (parent))
|
2014-05-10 03:57:57 +00:00
|
|
|
{
|
|
|
|
gtk_widget_hide (GTK_WIDGET (pl));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_view_column_set_visible (pl->priv->attribute_column, FALSE);
|
2014-05-03 19:25:43 +00:00
|
|
|
|
|
|
|
props = gtk_container_class_list_child_properties (G_OBJECT_GET_CLASS (parent), &num_properties);
|
|
|
|
}
|
|
|
|
else
|
2014-05-10 03:57:57 +00:00
|
|
|
{
|
|
|
|
gtk_tree_view_column_set_visible (pl->priv->attribute_column, GTK_IS_CELL_RENDERER (object));
|
2014-05-03 19:25:43 +00:00
|
|
|
|
2014-05-10 03:57:57 +00:00
|
|
|
props = g_object_class_list_properties (G_OBJECT_GET_CLASS (object), &num_properties);
|
|
|
|
}
|
2014-05-03 19:57:16 +00:00
|
|
|
|
2014-05-21 10:39:11 +00:00
|
|
|
pl->priv->object = object;
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
for (i = 0; i < num_properties; i++)
|
|
|
|
{
|
|
|
|
GParamSpec *prop = props[i];
|
|
|
|
|
|
|
|
if (! (prop->flags & G_PARAM_READABLE))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gtk_list_store_append (pl->priv->model, &iter);
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_prop_list_update_prop (pl, &iter, prop);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
g_hash_table_insert (pl->priv->prop_iters, (gpointer) prop->name, gtk_tree_iter_copy (&iter));
|
|
|
|
}
|
2014-05-03 20:43:04 +00:00
|
|
|
|
2014-05-21 10:39:11 +00:00
|
|
|
g_free (props);
|
|
|
|
|
|
|
|
if (GTK_IS_WIDGET (object))
|
2014-09-26 03:05:15 +00:00
|
|
|
g_signal_connect_object (object, "destroy", G_CALLBACK (cleanup_object), pl, G_CONNECT_SWAPPED);
|
2014-05-21 10:39:11 +00:00
|
|
|
|
2014-05-08 22:36:38 +00:00
|
|
|
/* Listen for updates */
|
|
|
|
pl->priv->notify_handler_id =
|
2014-09-26 03:05:15 +00:00
|
|
|
g_signal_connect_object (object,
|
|
|
|
pl->priv->child_properties ? "child-notify" : "notify",
|
|
|
|
G_CALLBACK (gtk_inspector_prop_list_prop_changed_cb),
|
|
|
|
pl, 0);
|
2014-05-08 22:36:38 +00:00
|
|
|
|
2014-05-10 03:57:57 +00:00
|
|
|
gtk_widget_show (GTK_WIDGET (pl));
|
2014-05-21 10:39:11 +00:00
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
return TRUE;
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 01:08:36 +00:00
|
|
|
// vim: set et sw=2 ts=2:
|