2014-05-03 01:48:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008-2009 Christian Hammond
|
|
|
|
* Copyright (c) 2008-2009 David Trowbridge
|
|
|
|
* Copyright (c) 2013 Intel Corporation
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
#include "object-tree.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "prop-list.h"
|
2019-12-07 16:49:30 +00:00
|
|
|
#include "window.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
|
|
|
|
#include "gtkbuildable.h"
|
|
|
|
#include "gtkbutton.h"
|
|
|
|
#include "gtkcelllayout.h"
|
2019-11-05 16:10:29 +00:00
|
|
|
#include "gtkcolumnview.h"
|
2014-06-10 12:53:31 +00:00
|
|
|
#include "gtkcomboboxprivate.h"
|
2018-08-29 14:19:37 +00:00
|
|
|
#include "gtkfilterlistmodel.h"
|
2019-11-10 01:39:31 +00:00
|
|
|
#include "gtkcustomfilter.h"
|
2018-08-29 14:19:37 +00:00
|
|
|
#include "gtkflattenlistmodel.h"
|
2020-01-28 14:03:42 +00:00
|
|
|
#include "gtkbuiltiniconprivate.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkiconview.h"
|
|
|
|
#include "gtklabel.h"
|
2019-11-05 16:10:29 +00:00
|
|
|
#include "gtklistitem.h"
|
2019-04-29 03:25:37 +00:00
|
|
|
#include "gtkpopover.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtksettings.h"
|
2019-11-05 16:10:29 +00:00
|
|
|
#include "gtksingleselection.h"
|
|
|
|
#include "gtksignallistitemfactory.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtktextview.h"
|
2018-08-29 14:19:37 +00:00
|
|
|
#include "gtktogglebutton.h"
|
2019-10-14 04:22:41 +00:00
|
|
|
#include "gtktreeexpander.h"
|
2018-08-29 14:19:37 +00:00
|
|
|
#include "gtktreelistmodel.h"
|
2014-10-11 00:51:54 +00:00
|
|
|
#include "gtktreeview.h"
|
2014-07-12 03:45:18 +00:00
|
|
|
#include "gtktreeselection.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtktreestore.h"
|
2014-10-04 15:53:14 +00:00
|
|
|
#include "gtktreemodelsort.h"
|
|
|
|
#include "gtktreemodelfilter.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2014-10-31 18:16:39 +00:00
|
|
|
#include "gtksearchbar.h"
|
|
|
|
#include "gtksearchentry.h"
|
2018-02-04 08:29:44 +00:00
|
|
|
#include "gtkeventcontrollerkey.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2014-10-11 02:34:32 +00:00
|
|
|
OBJECT_SELECTED,
|
|
|
|
OBJECT_ACTIVATED,
|
2014-05-03 01:48:33 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
struct _GtkInspectorObjectTreePrivate
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2019-11-05 16:10:29 +00:00
|
|
|
GtkColumnView *list;
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkTreeListModel *tree_model;
|
2019-11-05 16:10:29 +00:00
|
|
|
GtkSingleSelection *selection;
|
2014-10-31 18:16:39 +00:00
|
|
|
GtkWidget *search_bar;
|
|
|
|
GtkWidget *search_entry;
|
2014-05-03 01:48:33 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 13:28:22 +00:00
|
|
|
typedef struct _ObjectTreeClassFuncs ObjectTreeClassFuncs;
|
|
|
|
typedef void (* ObjectTreeForallFunc) (GObject *object,
|
|
|
|
const char *name,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
struct _ObjectTreeClassFuncs {
|
|
|
|
GType (* get_type) (void);
|
|
|
|
GObject * (* get_parent) (GObject *object);
|
2018-08-29 14:19:37 +00:00
|
|
|
GListModel * (* get_children) (GObject *object);
|
2015-08-26 13:28:22 +00:00
|
|
|
};
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorObjectTree, gtk_inspector_object_tree, GTK_TYPE_BOX)
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2015-08-26 13:28:22 +00:00
|
|
|
static GObject *
|
|
|
|
object_tree_get_parent_default (GObject *object)
|
|
|
|
{
|
2015-09-14 21:32:16 +00:00
|
|
|
return g_object_get_data (object, "inspector-object-tree-parent");
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_get_children_default (GObject *object)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
return NULL;
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
object_tree_widget_get_parent (GObject *object)
|
|
|
|
{
|
|
|
|
return G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (object)));
|
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_widget_get_children (GObject *object)
|
2016-11-15 15:49:41 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (object);
|
|
|
|
GListStore *list;
|
|
|
|
GListModel *sublist;
|
2016-11-15 15:49:41 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
list = g_list_store_new (G_TYPE_LIST_MODEL);
|
2016-11-15 15:49:41 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
sublist = gtk_widget_observe_children (widget);
|
|
|
|
g_list_store_append (list, sublist);
|
|
|
|
g_object_unref (sublist);
|
|
|
|
|
|
|
|
sublist = gtk_widget_observe_controllers (widget);
|
|
|
|
g_list_store_append (list, sublist);
|
|
|
|
g_object_unref (sublist);
|
|
|
|
|
2020-07-26 14:53:55 +00:00
|
|
|
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (list)));
|
2018-08-29 14:19:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GListModel *
|
|
|
|
object_tree_tree_model_sort_get_children (GObject *object)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GListStore *store;
|
2018-01-18 04:49:17 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
store = g_list_store_new (G_TYPE_OBJECT);
|
|
|
|
g_list_store_append (store, gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (object)));
|
2018-01-18 04:49:17 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
return G_LIST_MODEL (store);
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_tree_model_filter_get_children (GObject *object)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GListStore *store;
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
store = g_list_store_new (G_TYPE_OBJECT);
|
|
|
|
g_list_store_append (store, gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (object)));
|
|
|
|
|
|
|
|
return G_LIST_MODEL (store);
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-08-29 14:19:37 +00:00
|
|
|
update_list_store (GListStore *store,
|
|
|
|
GObject *object,
|
|
|
|
const char *property)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
gpointer value;
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
g_object_get (object, property, &value, NULL);
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
g_list_store_splice (store,
|
|
|
|
0,
|
|
|
|
g_list_model_get_n_items (G_LIST_MODEL (store)),
|
|
|
|
&value,
|
|
|
|
1);
|
|
|
|
g_object_unref (value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_list_store_remove_all (store);
|
|
|
|
}
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-08-29 14:19:37 +00:00
|
|
|
list_model_for_property_notify_cb (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GListStore *store)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
update_list_store (store, object, pspec->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GListModel *
|
|
|
|
list_model_for_property (GObject *object,
|
|
|
|
const char *property)
|
|
|
|
{
|
|
|
|
GListStore *store = g_list_store_new (G_TYPE_OBJECT);
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
/* g_signal_connect_object ("notify::property") */
|
|
|
|
g_signal_connect_closure_by_id (object,
|
|
|
|
g_signal_lookup ("notify", G_OBJECT_TYPE (object)),
|
|
|
|
g_quark_from_static_string (property),
|
|
|
|
g_cclosure_new_object (G_CALLBACK (list_model_for_property_notify_cb), G_OBJECT (store)),
|
|
|
|
FALSE);
|
|
|
|
update_list_store (store, object, property);
|
|
|
|
|
|
|
|
return G_LIST_MODEL (store);
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
list_model_for_properties (GObject *object,
|
|
|
|
const char **props)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GListStore *concat;
|
|
|
|
guint i;
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
if (props[1] == NULL)
|
|
|
|
return list_model_for_property (object, props[0]);
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
concat = g_list_store_new (G_TYPE_LIST_MODEL);
|
|
|
|
for (i = 0; props[i]; i++)
|
|
|
|
{
|
|
|
|
GListModel *tmp = list_model_for_property (object, props[i]);
|
|
|
|
g_list_store_append (concat, tmp);
|
|
|
|
g_object_unref (tmp);
|
|
|
|
}
|
|
|
|
|
2020-07-26 14:53:55 +00:00
|
|
|
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (concat)));
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_combo_box_get_children (GObject *object)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
return list_model_for_properties (object, (const char *[2]) { "model", NULL });
|
|
|
|
}
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static void
|
|
|
|
treeview_columns_changed (GtkTreeView *treeview,
|
|
|
|
GListModel *store)
|
|
|
|
{
|
|
|
|
GtkTreeViewColumn *column, *item;
|
|
|
|
guint i, n_columns, n_items;
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
n_columns = gtk_tree_view_get_n_columns (treeview);
|
|
|
|
n_items = g_list_model_get_n_items (store);
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
for (i = 0; i < MAX (n_columns, n_items); i++)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
column = gtk_tree_view_get_column (treeview, i);
|
|
|
|
item = g_list_model_get_item (store, i);
|
|
|
|
g_object_unref (item);
|
|
|
|
|
|
|
|
if (column == item)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (n_columns < n_items)
|
|
|
|
{
|
|
|
|
/* column removed */
|
|
|
|
g_assert (n_columns + 1 == n_items);
|
|
|
|
g_list_store_remove (G_LIST_STORE (store), i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (n_columns > n_items)
|
|
|
|
{
|
|
|
|
/* column added */
|
|
|
|
g_assert (n_columns - 1 == n_items);
|
|
|
|
g_list_store_insert (G_LIST_STORE (store), i, column);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
guint j;
|
|
|
|
/* column reordered */
|
|
|
|
for (j = n_columns - 1; j > i; j--)
|
|
|
|
{
|
|
|
|
column = gtk_tree_view_get_column (treeview, j);
|
|
|
|
item = g_list_model_get_item (store, j);
|
|
|
|
g_object_unref (item);
|
|
|
|
|
|
|
|
if (column != item)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_assert (j > i);
|
|
|
|
column = gtk_tree_view_get_column (treeview, i);
|
|
|
|
item = g_list_model_get_item (store, j);
|
|
|
|
g_object_unref (item);
|
|
|
|
|
|
|
|
if (item == column)
|
|
|
|
{
|
|
|
|
/* column was removed from position j and put into position i */
|
|
|
|
g_list_store_remove (G_LIST_STORE (store), j);
|
|
|
|
g_list_store_insert (G_LIST_STORE (store), i, column);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* column was removed from position i and put into position j */
|
|
|
|
column = gtk_tree_view_get_column (treeview, j);
|
|
|
|
g_list_store_remove (G_LIST_STORE (store), i);
|
|
|
|
g_list_store_insert (G_LIST_STORE (store), j, column);
|
|
|
|
}
|
|
|
|
}
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_tree_view_get_children (GObject *object)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkTreeView *treeview = GTK_TREE_VIEW (object);
|
|
|
|
GListStore *columns, *selection, *result_list;
|
|
|
|
GListModel *props;
|
|
|
|
guint i;
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
props = list_model_for_properties (object, (const char *[2]) { "model", NULL });
|
|
|
|
|
|
|
|
columns = g_list_store_new (GTK_TYPE_TREE_VIEW_COLUMN);
|
|
|
|
g_signal_connect_object (treeview, "columns-changed", G_CALLBACK (treeview_columns_changed), columns, 0);
|
|
|
|
for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
|
|
|
|
g_list_store_append (columns, gtk_tree_view_get_column (treeview, i));
|
|
|
|
|
|
|
|
selection = g_list_store_new (GTK_TYPE_TREE_SELECTION);
|
|
|
|
g_list_store_append (selection, gtk_tree_view_get_selection (treeview));
|
|
|
|
|
|
|
|
result_list = g_list_store_new (G_TYPE_LIST_MODEL);
|
|
|
|
g_list_store_append (result_list, props);
|
|
|
|
g_object_unref (props);
|
|
|
|
g_list_store_append (result_list, selection);
|
|
|
|
g_object_unref (selection);
|
|
|
|
g_list_store_append (result_list, columns);
|
|
|
|
g_object_unref (columns);
|
|
|
|
|
2020-07-26 14:53:55 +00:00
|
|
|
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 04:51:11 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_column_view_get_children (GObject *object)
|
|
|
|
{
|
|
|
|
GtkColumnView *view = GTK_COLUMN_VIEW (object);
|
|
|
|
GListStore *result_list;
|
|
|
|
GListModel *columns, *sublist;
|
|
|
|
|
|
|
|
result_list = g_list_store_new (G_TYPE_LIST_MODEL);
|
|
|
|
|
|
|
|
columns = gtk_column_view_get_columns (view);
|
|
|
|
g_list_store_append (result_list, columns);
|
|
|
|
|
|
|
|
sublist = object_tree_widget_get_children (object);
|
|
|
|
g_list_store_append (result_list, sublist);
|
|
|
|
g_object_unref (sublist);
|
|
|
|
|
2020-07-26 14:53:55 +00:00
|
|
|
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
|
2019-12-18 04:51:11 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_icon_view_get_children (GObject *object)
|
|
|
|
{
|
|
|
|
return list_model_for_properties (object, (const char *[2]) { "model", NULL });
|
|
|
|
}
|
2015-08-26 13:28:22 +00:00
|
|
|
|
|
|
|
static gboolean
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_cell_area_add_child (GtkCellRenderer *renderer,
|
|
|
|
gpointer store)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
|
|
|
gpointer cell_layout;
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
cell_layout = g_object_get_data (store, "gtk-inspector-cell-layout");
|
2015-08-26 13:28:22 +00:00
|
|
|
g_object_set_data (G_OBJECT (renderer), "gtk-inspector-cell-layout", cell_layout);
|
2018-08-29 14:19:37 +00:00
|
|
|
|
|
|
|
g_list_store_append (store, renderer);
|
2015-08-26 13:28:22 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_cell_area_get_children (GObject *object)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GListStore *store;
|
|
|
|
gpointer cell_layout;
|
|
|
|
|
|
|
|
cell_layout = g_object_get_data (object, "gtk-inspector-cell-layout");
|
|
|
|
store = g_list_store_new (GTK_TYPE_CELL_RENDERER);
|
|
|
|
g_object_set_data (G_OBJECT (store), "gtk-inspector-cell-layout", cell_layout);
|
|
|
|
/* XXX: no change notification for cell areas */
|
|
|
|
gtk_cell_area_foreach (GTK_CELL_AREA (object), object_tree_cell_area_add_child, store);
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
return G_LIST_MODEL (store);
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_cell_layout_get_children (GObject *object)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GListStore *store;
|
2015-08-26 13:28:22 +00:00
|
|
|
GtkCellArea *area;
|
|
|
|
|
|
|
|
/* cell areas handle their own stuff */
|
|
|
|
if (GTK_IS_CELL_AREA (object))
|
2018-08-29 14:19:37 +00:00
|
|
|
return NULL;
|
2015-08-26 13:28:22 +00:00
|
|
|
|
|
|
|
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (object));
|
2015-12-06 22:25:31 +00:00
|
|
|
if (!area)
|
2018-08-29 14:19:37 +00:00
|
|
|
return NULL;
|
2015-12-06 22:25:31 +00:00
|
|
|
|
2015-08-26 13:28:22 +00:00
|
|
|
g_object_set_data (G_OBJECT (area), "gtk-inspector-cell-layout", object);
|
2018-08-29 14:19:37 +00:00
|
|
|
/* XXX: are cell areas immutable? */
|
|
|
|
store = g_list_store_new (G_TYPE_OBJECT);
|
|
|
|
g_list_store_append (store, area);
|
|
|
|
return G_LIST_MODEL (store);
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_text_view_get_children (GObject *object)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
return list_model_for_properties (object, (const char *[2]) { "buffer", NULL });
|
|
|
|
}
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_text_buffer_get_children (GObject *object)
|
|
|
|
{
|
|
|
|
return list_model_for_properties (object, (const char *[2]) { "tag-table", NULL });
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-08-29 14:19:37 +00:00
|
|
|
text_tag_added (GtkTextTagTable *table,
|
|
|
|
GtkTextTag *tag,
|
|
|
|
GListStore *store)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
g_list_store_append (store, tag);
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-08-29 14:19:37 +00:00
|
|
|
text_tag_removed (GtkTextTagTable *table,
|
|
|
|
GtkTextTag *tag,
|
|
|
|
GListStore *store)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (store)); i++)
|
|
|
|
{
|
|
|
|
gpointer item = g_list_model_get_item (G_LIST_MODEL (store), i);
|
|
|
|
g_object_unref (item);
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
if (tag == item)
|
|
|
|
{
|
|
|
|
g_list_store_remove (store, i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-08-29 14:19:37 +00:00
|
|
|
text_tag_foreach (GtkTextTag *tag,
|
|
|
|
gpointer store)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
g_list_store_append (store, tag);
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_text_tag_table_get_children (GObject *object)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GListStore *store = g_list_store_new (GTK_TYPE_TEXT_TAG);
|
|
|
|
|
|
|
|
g_signal_connect_object (object, "tag-added", G_CALLBACK (text_tag_added), store, 0);
|
|
|
|
g_signal_connect_object (object, "tag-removed", G_CALLBACK (text_tag_removed), store, 0);
|
|
|
|
gtk_text_tag_table_foreach (GTK_TEXT_TAG_TABLE (object), text_tag_foreach, store);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_tree_application_get_children (GObject *object)
|
|
|
|
{
|
2020-05-22 20:52:31 +00:00
|
|
|
return list_model_for_properties (object, (const char *[2]) { "menubar", NULL });
|
2018-08-29 14:19:37 +00:00
|
|
|
}
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GObject *
|
|
|
|
object_tree_event_controller_get_parent (GObject *object)
|
|
|
|
{
|
|
|
|
return G_OBJECT (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (object)));
|
2015-08-26 13:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note:
|
|
|
|
* This tree must be sorted with the most specific types first.
|
|
|
|
* We iterate over it top to bottom and return the first match
|
|
|
|
* using g_type_is_a ()
|
|
|
|
*/
|
|
|
|
static const ObjectTreeClassFuncs object_tree_class_funcs[] = {
|
|
|
|
{
|
|
|
|
gtk_application_get_type,
|
|
|
|
object_tree_get_parent_default,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_application_get_children
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
gtk_text_tag_table_get_type,
|
|
|
|
object_tree_get_parent_default,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_text_tag_table_get_children
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
gtk_text_buffer_get_type,
|
|
|
|
object_tree_get_parent_default,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_text_buffer_get_children
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
gtk_text_view_get_type,
|
|
|
|
object_tree_widget_get_parent,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_text_view_get_children
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
gtk_icon_view_get_type,
|
|
|
|
object_tree_widget_get_parent,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_icon_view_get_children
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
gtk_tree_view_get_type,
|
|
|
|
object_tree_widget_get_parent,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_tree_view_get_children
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
2019-12-18 04:51:11 +00:00
|
|
|
{
|
|
|
|
gtk_column_view_get_type,
|
|
|
|
object_tree_widget_get_parent,
|
|
|
|
object_tree_column_view_get_children
|
|
|
|
},
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
|
|
|
gtk_combo_box_get_type,
|
|
|
|
object_tree_widget_get_parent,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_combo_box_get_children
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
gtk_widget_get_type,
|
|
|
|
object_tree_widget_get_parent,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_widget_get_children
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
gtk_tree_model_filter_get_type,
|
|
|
|
object_tree_get_parent_default,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_tree_model_filter_get_children
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
gtk_tree_model_sort_get_type,
|
|
|
|
object_tree_get_parent_default,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_tree_model_sort_get_children
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
gtk_cell_area_get_type,
|
|
|
|
object_tree_get_parent_default,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_cell_area_get_children
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
gtk_cell_layout_get_type,
|
|
|
|
object_tree_get_parent_default,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_cell_layout_get_children
|
|
|
|
},
|
|
|
|
{
|
|
|
|
gtk_event_controller_get_type,
|
|
|
|
object_tree_event_controller_get_parent,
|
|
|
|
object_tree_get_children_default
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
g_object_get_type,
|
|
|
|
object_tree_get_parent_default,
|
2018-08-29 14:19:37 +00:00
|
|
|
object_tree_get_children_default
|
2015-08-26 13:28:22 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const ObjectTreeClassFuncs *
|
|
|
|
find_class_funcs (GObject *object)
|
|
|
|
{
|
|
|
|
GType object_type;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
object_type = G_OBJECT_TYPE (object);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (object_tree_class_funcs); i++)
|
|
|
|
{
|
|
|
|
if (g_type_is_a (object_type, object_tree_class_funcs[i].get_type ()))
|
|
|
|
return &object_tree_class_funcs[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-26 13:44:55 +00:00
|
|
|
static GObject *
|
2015-08-26 13:28:22 +00:00
|
|
|
object_get_parent (GObject *object)
|
|
|
|
{
|
|
|
|
const ObjectTreeClassFuncs *funcs;
|
|
|
|
|
|
|
|
funcs = find_class_funcs (object);
|
|
|
|
|
|
|
|
return funcs->get_parent (object);
|
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
|
|
|
object_get_children (GObject *object)
|
2015-08-26 13:28:22 +00:00
|
|
|
{
|
|
|
|
GType object_type;
|
2020-07-26 14:53:55 +00:00
|
|
|
GListModel *children;
|
2018-08-29 14:19:37 +00:00
|
|
|
GListStore *result_list;
|
2015-08-26 13:28:22 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
object_type = G_OBJECT_TYPE (object);
|
2018-08-29 14:19:37 +00:00
|
|
|
result_list = NULL;
|
2015-08-26 13:28:22 +00:00
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (object_tree_class_funcs); i++)
|
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
if (!g_type_is_a (object_type, object_tree_class_funcs[i].get_type ()))
|
|
|
|
continue;
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
children = object_tree_class_funcs[i].get_children (object);
|
|
|
|
if (children == NULL)
|
|
|
|
continue;
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2020-07-26 14:53:55 +00:00
|
|
|
if (!result_list)
|
|
|
|
result_list = g_list_store_new (G_TYPE_LIST_MODEL);
|
2014-10-11 02:34:32 +00:00
|
|
|
|
2020-07-26 14:53:55 +00:00
|
|
|
g_list_store_append (result_list, children);
|
|
|
|
g_object_unref (children);
|
2018-08-29 14:19:37 +00:00
|
|
|
}
|
2014-10-11 02:34:32 +00:00
|
|
|
|
2020-07-26 14:53:55 +00:00
|
|
|
if (result_list)
|
|
|
|
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
|
|
|
|
else
|
|
|
|
return NULL;
|
2014-10-11 02:34:32 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static const char *
|
|
|
|
gtk_inspector_get_object_name (GObject *object)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
if (GTK_IS_WIDGET (object))
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *id;
|
2014-10-25 01:14:16 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
id = gtk_widget_get_name (GTK_WIDGET (object));
|
|
|
|
if (id != NULL && g_strcmp0 (id, G_OBJECT_TYPE_NAME (object)) != 0)
|
|
|
|
return id;
|
|
|
|
}
|
2014-10-25 01:14:16 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
if (GTK_IS_BUILDABLE (object))
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *id;
|
2014-10-25 01:14:16 +00:00
|
|
|
|
2020-09-25 14:43:24 +00:00
|
|
|
id = gtk_buildable_get_buildable_id (GTK_BUILDABLE (object));
|
2018-08-29 14:19:37 +00:00
|
|
|
if (id != NULL && !g_str_has_prefix (id, "___object_"))
|
|
|
|
return id;
|
|
|
|
}
|
2014-10-25 01:14:16 +00:00
|
|
|
|
2019-06-19 11:11:06 +00:00
|
|
|
if (GTK_IS_EVENT_CONTROLLER (object))
|
|
|
|
{
|
|
|
|
return gtk_event_controller_get_name (GTK_EVENT_CONTROLLER (object));
|
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
return NULL;
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
char *
|
|
|
|
gtk_inspector_get_object_title (GObject *object)
|
2015-10-25 17:11:17 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
const char *name = gtk_inspector_get_object_name (object);
|
2015-10-25 17:11:17 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
if (name == NULL)
|
|
|
|
return g_strdup (G_OBJECT_TYPE_NAME (object));
|
|
|
|
else
|
|
|
|
return g_strconcat (G_OBJECT_TYPE_NAME (object), " — ", name, NULL);
|
2015-10-25 17:11:17 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 18:40:40 +00:00
|
|
|
void
|
|
|
|
gtk_inspector_object_tree_activate_object (GtkInspectorObjectTree *wt,
|
|
|
|
GObject *object)
|
|
|
|
{
|
2019-10-26 16:22:27 +00:00
|
|
|
gtk_inspector_object_tree_select_object (wt, object);
|
2019-02-13 18:40:40 +00:00
|
|
|
g_signal_emit (wt, signals[OBJECT_ACTIVATED], 0, object);
|
|
|
|
}
|
|
|
|
|
2014-05-09 02:58:43 +00:00
|
|
|
static void
|
2019-11-05 16:10:29 +00:00
|
|
|
on_row_activated (GtkColumnView *view,
|
|
|
|
guint pos,
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkInspectorObjectTree *wt)
|
2014-05-09 02:58:43 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkTreeListRow *item;
|
|
|
|
GObject *object;
|
|
|
|
|
|
|
|
item = g_list_model_get_item (G_LIST_MODEL (wt->priv->tree_model), pos);
|
|
|
|
object = gtk_tree_list_row_get_item (item);
|
2014-05-09 02:58:43 +00:00
|
|
|
|
2019-02-13 18:40:40 +00:00
|
|
|
gtk_inspector_object_tree_activate_object (wt, object);
|
2016-03-11 18:52:36 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
g_object_unref (item);
|
|
|
|
g_object_unref (object);
|
2014-05-09 00:13:34 +00:00
|
|
|
}
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
GObject *
|
|
|
|
gtk_inspector_object_tree_get_selected (GtkInspectorObjectTree *wt)
|
2015-12-27 02:40:19 +00:00
|
|
|
{
|
2019-11-05 16:10:29 +00:00
|
|
|
GtkTreeListRow *selected_item;
|
2015-12-27 02:40:19 +00:00
|
|
|
GObject *object;
|
|
|
|
|
2019-11-05 16:10:29 +00:00
|
|
|
selected_item = gtk_single_selection_get_selected_item (wt->priv->selection);
|
|
|
|
if (selected_item == NULL)
|
2018-08-29 14:19:37 +00:00
|
|
|
return NULL;
|
2015-12-27 02:40:19 +00:00
|
|
|
|
2019-11-05 16:10:29 +00:00
|
|
|
object = gtk_tree_list_row_get_item (selected_item);
|
2018-08-29 14:19:37 +00:00
|
|
|
|
|
|
|
g_object_unref (object); /* ahem */
|
|
|
|
return object;
|
2015-12-27 02:40:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-05 16:10:29 +00:00
|
|
|
widget_mapped (GtkWidget *widget,
|
|
|
|
GtkWidget *label)
|
2015-12-27 02:40:19 +00:00
|
|
|
{
|
2020-06-15 15:21:20 +00:00
|
|
|
gtk_widget_remove_css_class (label, "dim-label");
|
2014-05-21 02:38:38 +00:00
|
|
|
}
|
|
|
|
|
2014-10-31 18:16:39 +00:00
|
|
|
static void
|
2019-11-05 16:10:29 +00:00
|
|
|
widget_unmapped (GtkWidget *widget,
|
|
|
|
GtkWidget *label)
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
2020-06-15 15:21:20 +00:00
|
|
|
gtk_widget_add_css_class (label, "dim-label");
|
2014-10-31 18:16:39 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static gboolean
|
|
|
|
search (GtkInspectorObjectTree *wt,
|
|
|
|
gboolean forward,
|
|
|
|
gboolean force_progress);
|
|
|
|
|
2014-10-31 18:16:39 +00:00
|
|
|
static gboolean
|
2018-02-04 08:29:44 +00:00
|
|
|
key_pressed (GtkEventController *controller,
|
|
|
|
guint keyval,
|
|
|
|
guint keycode,
|
|
|
|
GdkModifierType state,
|
|
|
|
GtkInspectorObjectTree *wt)
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
2018-02-04 08:29:44 +00:00
|
|
|
if (gtk_widget_get_mapped (GTK_WIDGET (wt)))
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
|
|
|
GdkModifierType default_accel;
|
|
|
|
gboolean search_started;
|
|
|
|
|
|
|
|
search_started = gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (wt->priv->search_bar));
|
2020-04-05 23:52:25 +00:00
|
|
|
default_accel = GDK_CONTROL_MASK;
|
2014-10-31 18:16:39 +00:00
|
|
|
|
|
|
|
if (search_started &&
|
2017-08-25 14:57:26 +00:00
|
|
|
(keyval == GDK_KEY_Return ||
|
|
|
|
keyval == GDK_KEY_ISO_Enter ||
|
|
|
|
keyval == GDK_KEY_KP_Enter))
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
gtk_widget_activate (GTK_WIDGET (wt->priv->list));
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
2014-10-31 18:16:39 +00:00
|
|
|
}
|
|
|
|
else if (search_started &&
|
2017-08-25 14:57:26 +00:00
|
|
|
(keyval == GDK_KEY_Escape))
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
|
|
|
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (wt->priv->search_bar), FALSE);
|
|
|
|
return GDK_EVENT_STOP;
|
|
|
|
}
|
|
|
|
else if (search_started &&
|
2017-08-25 14:57:26 +00:00
|
|
|
((state & (default_accel | GDK_SHIFT_MASK)) == (default_accel | GDK_SHIFT_MASK)) &&
|
|
|
|
(keyval == GDK_KEY_g || keyval == GDK_KEY_G))
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
if (!search (wt, TRUE, TRUE))
|
2014-10-31 18:16:39 +00:00
|
|
|
gtk_widget_error_bell (GTK_WIDGET (wt));
|
|
|
|
return GDK_EVENT_STOP;
|
|
|
|
}
|
|
|
|
else if (search_started &&
|
2017-08-25 14:57:26 +00:00
|
|
|
((state & (default_accel | GDK_SHIFT_MASK)) == default_accel) &&
|
|
|
|
(keyval == GDK_KEY_g || keyval == GDK_KEY_G))
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
if (!search (wt, TRUE, TRUE))
|
2014-10-31 18:16:39 +00:00
|
|
|
gtk_widget_error_bell (GTK_WIDGET (wt));
|
|
|
|
return GDK_EVENT_STOP;
|
|
|
|
}
|
|
|
|
}
|
2018-03-11 12:54:54 +00:00
|
|
|
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
2014-10-31 18:16:39 +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);
|
|
|
|
}
|
|
|
|
|
2019-12-07 16:49:30 +00:00
|
|
|
static gboolean toplevel_filter_func (gpointer item,
|
|
|
|
gpointer data);
|
|
|
|
|
2014-10-31 18:16:39 +00:00
|
|
|
static void
|
2019-04-12 03:42:31 +00:00
|
|
|
map (GtkWidget *widget)
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
2018-03-11 12:54:54 +00:00
|
|
|
GtkInspectorObjectTree *wt = GTK_INSPECTOR_OBJECT_TREE (widget);
|
2018-02-04 08:29:44 +00:00
|
|
|
GtkEventController *controller;
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
2019-04-12 03:42:31 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_inspector_object_tree_parent_class)->map (widget);
|
2018-02-04 08:29:44 +00:00
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
|
2018-05-05 07:06:22 +00:00
|
|
|
|
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), "object-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);
|
2018-03-11 12:54:54 +00:00
|
|
|
|
2019-02-23 05:29:52 +00:00
|
|
|
gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (wt->priv->search_bar), toplevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-04-12 03:42:31 +00:00
|
|
|
unmap (GtkWidget *widget)
|
2019-02-23 05:29:52 +00:00
|
|
|
{
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
|
2019-02-23 05:29:52 +00:00
|
|
|
g_object_set_data (G_OBJECT (toplevel), "object-controller", NULL);
|
|
|
|
|
2019-04-12 03:42:31 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_inspector_object_tree_parent_class)->unmap (widget);
|
2014-10-31 18:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2020-07-24 18:40:36 +00:00
|
|
|
match_string (const char *string,
|
|
|
|
const char *text)
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *lower;
|
2014-10-31 18:16:39 +00:00
|
|
|
gboolean match = FALSE;
|
|
|
|
|
|
|
|
if (string)
|
|
|
|
{
|
|
|
|
lower = g_ascii_strdown (string, -1);
|
|
|
|
match = g_str_has_prefix (lower, text);
|
|
|
|
g_free (lower);
|
|
|
|
}
|
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-08-29 14:19:37 +00:00
|
|
|
match_object (GObject *object,
|
|
|
|
const char *text)
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
2022-02-04 17:39:56 +00:00
|
|
|
char *address;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
if (match_string (G_OBJECT_TYPE_NAME (object), text) ||
|
|
|
|
match_string (gtk_inspector_get_object_name (object), text))
|
|
|
|
return TRUE;
|
2014-10-31 18:16:39 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
if (GTK_IS_LABEL (object))
|
|
|
|
return match_string (gtk_label_get_label (GTK_LABEL (object)), text);
|
|
|
|
else if (GTK_IS_BUTTON (object))
|
|
|
|
return match_string (gtk_button_get_label (GTK_BUTTON (object)), text);
|
|
|
|
else if (GTK_IS_WINDOW (object))
|
|
|
|
return match_string (gtk_window_get_title (GTK_WINDOW (object)), text);
|
|
|
|
else if (GTK_IS_TREE_VIEW_COLUMN (object))
|
|
|
|
return match_string (gtk_tree_view_column_get_title (GTK_TREE_VIEW_COLUMN (object)), text);
|
2022-02-04 17:39:56 +00:00
|
|
|
|
|
|
|
address = g_strdup_printf ("%p", object);
|
|
|
|
ret = match_string (address, text);
|
|
|
|
g_free (address);
|
|
|
|
|
|
|
|
return ret;
|
2014-10-31 18:16:39 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GObject *
|
|
|
|
search_children (GObject *object,
|
|
|
|
const char *text,
|
|
|
|
gboolean forward)
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GListModel *children;
|
|
|
|
GObject *child, *result;
|
|
|
|
guint i, n;
|
|
|
|
|
|
|
|
children = object_get_children (object);
|
|
|
|
if (children == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
n = g_list_model_get_n_items (children);
|
|
|
|
for (i = 0; i < n; i++)
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
child = g_list_model_get_item (children, forward ? i : n - i - 1);
|
|
|
|
if (match_object (child, text))
|
|
|
|
return child;
|
|
|
|
|
|
|
|
result = search_children (child, text, forward);
|
|
|
|
g_object_unref (child);
|
|
|
|
if (result)
|
|
|
|
return result;
|
2014-10-31 18:16:39 +00:00
|
|
|
}
|
2018-08-29 14:19:37 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
search (GtkInspectorObjectTree *wt,
|
|
|
|
gboolean forward,
|
|
|
|
gboolean force_progress)
|
|
|
|
{
|
|
|
|
GtkInspectorObjectTreePrivate *priv = wt->priv;
|
|
|
|
GListModel *model = G_LIST_MODEL (priv->tree_model);
|
|
|
|
GtkTreeListRow *row_item;
|
|
|
|
GObject *child, *result;
|
|
|
|
guint i, selected, n, row;
|
|
|
|
const char *text;
|
|
|
|
|
2019-02-17 04:58:54 +00:00
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (priv->search_entry));
|
2019-11-05 16:10:29 +00:00
|
|
|
selected = gtk_single_selection_get_selected (priv->selection);
|
2018-08-29 14:19:37 +00:00
|
|
|
n = g_list_model_get_n_items (model);
|
2019-11-05 16:10:29 +00:00
|
|
|
if (selected >= n)
|
|
|
|
selected = 0;
|
2018-08-29 14:19:37 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
row = (selected + (forward ? i : n - i - 1)) % n;
|
|
|
|
row_item = g_list_model_get_item (model, row);
|
|
|
|
child = gtk_tree_list_row_get_item (row_item);
|
|
|
|
if (i > 0 || !force_progress)
|
|
|
|
{
|
|
|
|
if (match_object (child, text))
|
|
|
|
{
|
2019-11-05 16:10:29 +00:00
|
|
|
gtk_single_selection_set_selected (priv->selection, row);
|
2018-08-29 14:19:37 +00:00
|
|
|
g_object_unref (child);
|
|
|
|
g_object_unref (row_item);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_tree_list_row_get_expanded (row_item))
|
|
|
|
{
|
|
|
|
result = search_children (child, text, forward);
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
gtk_inspector_object_tree_select_object (wt, result);
|
|
|
|
g_object_unref (result);
|
|
|
|
g_object_unref (child);
|
|
|
|
g_object_unref (row_item);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_object_unref (child);
|
|
|
|
g_object_unref (row_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_search_changed (GtkSearchEntry *entry,
|
|
|
|
GtkInspectorObjectTree *wt)
|
|
|
|
{
|
|
|
|
if (!search (wt, TRUE, FALSE))
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (wt));
|
2014-10-31 18:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
next_match (GtkButton *button,
|
|
|
|
GtkInspectorObjectTree *wt)
|
|
|
|
{
|
|
|
|
if (gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (wt->priv->search_bar)))
|
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
if (!search (wt, TRUE, TRUE))
|
2014-10-31 18:16:39 +00:00
|
|
|
gtk_widget_error_bell (GTK_WIDGET (wt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
previous_match (GtkButton *button,
|
|
|
|
GtkInspectorObjectTree *wt)
|
|
|
|
{
|
|
|
|
if (gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (wt->priv->search_bar)))
|
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
if (!search (wt, FALSE, TRUE))
|
2014-10-31 18:16:39 +00:00
|
|
|
gtk_widget_error_bell (GTK_WIDGET (wt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 03:44:44 +00:00
|
|
|
static void
|
|
|
|
stop_search (GtkWidget *entry,
|
|
|
|
GtkInspectorObjectTree *wt)
|
|
|
|
{
|
2019-02-17 04:58:54 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (wt->priv->search_entry), "");
|
2014-11-25 03:44:44 +00:00
|
|
|
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (wt->priv->search_bar), FALSE);
|
|
|
|
}
|
|
|
|
|
2019-11-05 16:10:29 +00:00
|
|
|
static void
|
|
|
|
setup_type_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2019-11-05 16:10:29 +00:00
|
|
|
GtkWidget *expander, *label;
|
|
|
|
|
|
|
|
/* expander */
|
|
|
|
expander = gtk_tree_expander_new ();
|
|
|
|
gtk_list_item_set_child (list_item, expander);
|
|
|
|
|
|
|
|
/* label */
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_width_chars (GTK_LABEL (label), 30);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
gtk_tree_expander_set_child (GTK_TREE_EXPANDER (expander), label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_type_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *expander, *label;
|
|
|
|
GtkTreeListRow *list_row;
|
2018-08-29 14:19:37 +00:00
|
|
|
gpointer item;
|
2014-05-21 02:38:38 +00:00
|
|
|
|
2019-11-05 16:10:29 +00:00
|
|
|
list_row = gtk_list_item_get_item (list_item);
|
|
|
|
expander = gtk_list_item_get_child (list_item);
|
|
|
|
gtk_tree_expander_set_list_row (GTK_TREE_EXPANDER (expander), list_row);
|
|
|
|
item = gtk_tree_list_row_get_item (list_row);
|
|
|
|
expander = gtk_list_item_get_child (list_item);
|
|
|
|
label = gtk_tree_expander_get_child (GTK_TREE_EXPANDER (expander));
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), G_OBJECT_TYPE_NAME (item));
|
2014-05-04 23:53:04 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
if (GTK_IS_WIDGET (item))
|
|
|
|
{
|
2019-11-05 16:10:29 +00:00
|
|
|
g_signal_connect (item, "map", G_CALLBACK (widget_mapped), label);
|
|
|
|
g_signal_connect (item, "unmap", G_CALLBACK (widget_unmapped), label);
|
2018-08-29 14:19:37 +00:00
|
|
|
if (!gtk_widget_get_mapped (item))
|
2019-11-05 16:10:29 +00:00
|
|
|
widget_unmapped (item, label);
|
|
|
|
g_object_set_data (G_OBJECT (label), "binding", g_object_ref (item));
|
2018-08-29 14:19:37 +00:00
|
|
|
}
|
|
|
|
|
2019-11-05 16:10:29 +00:00
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unbind_type_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *expander, *label;
|
|
|
|
gpointer item;
|
|
|
|
|
|
|
|
expander = gtk_list_item_get_child (list_item);
|
|
|
|
label = gtk_tree_expander_get_child (GTK_TREE_EXPANDER (expander));
|
|
|
|
item = g_object_steal_data (G_OBJECT (label), "binding");
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (item, widget_mapped, label);
|
|
|
|
g_signal_handlers_disconnect_by_func (item, widget_unmapped, label);
|
|
|
|
|
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_name_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_width_chars (GTK_LABEL (label), 15);
|
2020-07-13 21:32:52 +00:00
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
|
2019-11-05 16:10:29 +00:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
gtk_list_item_set_child (list_item, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_name_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
gpointer item;
|
|
|
|
|
|
|
|
item = gtk_tree_list_row_get_item (gtk_list_item_get_item (list_item));
|
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), gtk_inspector_get_object_name (item));
|
|
|
|
|
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_label_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
2020-07-13 21:32:52 +00:00
|
|
|
gtk_label_set_width_chars (GTK_LABEL (label), 25);
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
|
2019-11-05 16:10:29 +00:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
gtk_list_item_set_child (list_item, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_label_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
gpointer item;
|
|
|
|
GBinding *binding = NULL;
|
|
|
|
|
|
|
|
item = gtk_tree_list_row_get_item (gtk_list_item_get_item (list_item));
|
|
|
|
label = gtk_list_item_get_child (list_item);
|
2018-08-29 14:19:37 +00:00
|
|
|
|
|
|
|
if (GTK_IS_LABEL (item))
|
2019-11-05 16:10:29 +00:00
|
|
|
binding = g_object_bind_property (item, "label", label, "label", G_BINDING_SYNC_CREATE);
|
2018-08-29 14:19:37 +00:00
|
|
|
else if (GTK_IS_BUTTON (item))
|
2019-11-05 16:10:29 +00:00
|
|
|
binding = g_object_bind_property (item, "label", label, "label", G_BINDING_SYNC_CREATE);
|
2018-08-29 14:19:37 +00:00
|
|
|
else if (GTK_IS_WINDOW (item))
|
2019-11-05 16:10:29 +00:00
|
|
|
binding = g_object_bind_property (item, "title", label, "label", G_BINDING_SYNC_CREATE);
|
2018-08-29 14:19:37 +00:00
|
|
|
else if (GTK_IS_TREE_VIEW_COLUMN (item))
|
2019-11-05 16:10:29 +00:00
|
|
|
binding = g_object_bind_property (item, "title", label, "label", G_BINDING_SYNC_CREATE);
|
|
|
|
else
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), NULL);
|
2018-08-29 14:19:37 +00:00
|
|
|
|
|
|
|
g_object_unref (item);
|
|
|
|
|
2019-11-05 16:10:29 +00:00
|
|
|
if (binding)
|
|
|
|
g_object_set_data (G_OBJECT (label), "binding", binding);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unbind_label_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
GBinding *binding;
|
|
|
|
|
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
binding = g_object_steal_data (G_OBJECT (label), "binding");
|
|
|
|
if (binding)
|
|
|
|
g_binding_unbind (binding);
|
2018-08-29 14:19:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GListModel *
|
|
|
|
create_model_for_object (gpointer object,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
return object_get_children (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
toplevel_filter_func (gpointer item,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GdkDisplay *display = data;
|
2014-10-31 18:16:39 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
if (!GTK_IS_WINDOW (item))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (g_str_equal (G_OBJECT_TYPE_NAME (item), "GtkInspectorWindow"))
|
|
|
|
return FALSE;
|
2014-10-31 18:16:39 +00:00
|
|
|
|
2020-02-14 20:13:42 +00:00
|
|
|
return gtk_widget_get_display (item) == display;
|
2018-08-29 14:19:37 +00:00
|
|
|
}
|
2014-05-21 02:38:38 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GListModel *
|
2019-12-07 16:49:30 +00:00
|
|
|
create_root_model (GdkDisplay *display)
|
2018-08-29 14:19:37 +00:00
|
|
|
{
|
2020-08-03 19:04:33 +00:00
|
|
|
GtkFilter *filter;
|
|
|
|
GtkFilterListModel *filter_model;
|
|
|
|
GListModel *model;
|
2018-08-29 14:19:37 +00:00
|
|
|
GListStore *list, *special;
|
2018-09-19 02:28:09 +00:00
|
|
|
gpointer item;
|
2018-08-29 14:19:37 +00:00
|
|
|
|
|
|
|
list = g_list_store_new (G_TYPE_LIST_MODEL);
|
|
|
|
|
|
|
|
special = g_list_store_new (G_TYPE_OBJECT);
|
2018-09-19 02:28:09 +00:00
|
|
|
item = g_application_get_default ();
|
|
|
|
if (item)
|
|
|
|
g_list_store_append (special, item);
|
2019-12-07 16:49:30 +00:00
|
|
|
g_list_store_append (special, gtk_settings_get_for_display (display));
|
2018-08-29 14:19:37 +00:00
|
|
|
g_list_store_append (list, special);
|
|
|
|
g_object_unref (special);
|
|
|
|
|
2020-08-03 19:04:33 +00:00
|
|
|
filter = GTK_FILTER (gtk_custom_filter_new (toplevel_filter_func, display, NULL));
|
|
|
|
model = gtk_window_get_toplevels ();
|
|
|
|
filter_model = gtk_filter_list_model_new (g_object_ref (model), filter);
|
|
|
|
g_list_store_append (list, filter_model);
|
|
|
|
g_object_unref (filter_model);
|
2018-08-29 14:19:37 +00:00
|
|
|
|
2020-07-26 14:53:55 +00:00
|
|
|
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (list)));
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2015-12-27 02:40:19 +00:00
|
|
|
static void
|
2018-08-29 14:19:37 +00:00
|
|
|
gtk_inspector_object_tree_init (GtkInspectorObjectTree *wt)
|
2015-12-27 02:40:19 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
wt->priv = gtk_inspector_object_tree_get_instance_private (wt);
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (wt));
|
2015-12-27 02:40:19 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
gtk_search_bar_connect_entry (GTK_SEARCH_BAR (wt->priv->search_bar),
|
2019-02-17 04:58:54 +00:00
|
|
|
GTK_EDITABLE (wt->priv->search_entry));
|
2015-12-27 02:40:19 +00:00
|
|
|
}
|
|
|
|
|
2014-05-21 02:38:38 +00:00
|
|
|
static void
|
2018-08-29 14:19:37 +00:00
|
|
|
gtk_inspector_object_tree_dispose (GObject *object)
|
2014-05-21 02:38:38 +00:00
|
|
|
{
|
2014-10-11 01:40:53 +00:00
|
|
|
GtkInspectorObjectTree *wt = GTK_INSPECTOR_OBJECT_TREE (object);
|
2014-05-21 02:38:38 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
g_clear_object (&wt->priv->tree_model);
|
2019-11-05 16:10:29 +00:00
|
|
|
g_clear_object (&wt->priv->selection);
|
2014-05-21 02:38:38 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
G_OBJECT_CLASS (gtk_inspector_object_tree_parent_class)->dispose (object);
|
2014-05-21 02:38:38 +00:00
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_class_init (GtkInspectorObjectTreeClass *klass)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-21 02:38:38 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2014-05-04 23:53:04 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2015-12-27 02:40:19 +00:00
|
|
|
object_class->dispose = gtk_inspector_object_tree_dispose;
|
2014-05-21 02:38:38 +00:00
|
|
|
|
2019-04-12 03:42:31 +00:00
|
|
|
widget_class->map = map;
|
|
|
|
widget_class->unmap = unmap;
|
2019-02-23 05:29:52 +00:00
|
|
|
|
2014-10-11 02:34:32 +00:00
|
|
|
signals[OBJECT_ACTIVATED] =
|
|
|
|
g_signal_new ("object-activated",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
|
|
|
|
G_STRUCT_OFFSET (GtkInspectorObjectTreeClass, object_activated),
|
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
2018-08-29 14:19:37 +00:00
|
|
|
G_TYPE_NONE, 1, G_TYPE_OBJECT);
|
2014-10-11 02:34:32 +00:00
|
|
|
|
|
|
|
signals[OBJECT_SELECTED] =
|
|
|
|
g_signal_new ("object-selected",
|
2014-10-11 01:13:34 +00:00
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
2014-05-04 23:53:04 +00:00
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
|
2014-10-11 02:34:32 +00:00
|
|
|
G_STRUCT_OFFSET (GtkInspectorObjectTreeClass, object_selected),
|
2014-05-04 23:53:04 +00:00
|
|
|
NULL, NULL,
|
2014-10-11 02:34:32 +00:00
|
|
|
NULL,
|
2014-10-11 01:13:34 +00:00
|
|
|
G_TYPE_NONE, 1, G_TYPE_OBJECT);
|
2014-05-04 23:53:04 +00:00
|
|
|
|
2014-11-30 20:59:53 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/object-tree.ui");
|
2018-08-29 14:19:37 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorObjectTree, list);
|
2014-10-31 18:16:39 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorObjectTree, search_bar);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorObjectTree, search_entry);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_search_changed);
|
2018-08-29 14:19:37 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_row_activated);
|
2014-10-31 18:16:39 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, next_match);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, previous_match);
|
2014-11-25 03:44:44 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, stop_search);
|
2019-11-05 16:10:29 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_type_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_type_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, unbind_type_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_name_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_name_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_label_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_label_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, unbind_label_cb);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static guint
|
|
|
|
model_get_item_index (GListModel *model,
|
|
|
|
gpointer item)
|
2014-05-04 23:53:04 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
gpointer cmp;
|
|
|
|
guint i;
|
2014-10-25 14:00:04 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
for (i = 0; (cmp = g_list_model_get_item (model, i)); i++)
|
2015-09-14 21:32:16 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
if (cmp == item)
|
2015-09-14 21:32:16 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
g_object_unref (cmp);
|
|
|
|
return i;
|
2015-09-14 21:32:16 +00:00
|
|
|
}
|
2018-08-29 14:19:37 +00:00
|
|
|
g_object_unref (cmp);
|
2015-09-14 21:32:16 +00:00
|
|
|
}
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
return G_MAXUINT;
|
|
|
|
}
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GtkTreeListRow *
|
|
|
|
find_and_expand_object (GtkTreeListModel *model,
|
|
|
|
GObject *object)
|
|
|
|
{
|
|
|
|
GtkTreeListRow *result;
|
|
|
|
GObject *parent;
|
|
|
|
guint pos;
|
2014-05-09 01:15:09 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
parent = object_get_parent (object);
|
|
|
|
if (parent)
|
2014-11-22 20:40:46 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkTreeListRow *parent_row = find_and_expand_object (model, parent);
|
|
|
|
if (parent_row == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gtk_tree_list_row_set_expanded (parent_row, TRUE);
|
|
|
|
pos = model_get_item_index (gtk_tree_list_row_get_children (parent_row), object);
|
2018-09-18 05:50:33 +00:00
|
|
|
result = gtk_tree_list_row_get_child_row (parent_row, pos);
|
2018-08-29 14:19:37 +00:00
|
|
|
g_object_unref (parent_row);
|
2014-11-22 20:40:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
pos = model_get_item_index (gtk_tree_list_model_get_model (model), object);
|
2018-09-18 05:50:33 +00:00
|
|
|
result = gtk_tree_list_model_get_child_row (model, pos);
|
2014-11-22 20:40:46 +00:00
|
|
|
}
|
2015-08-26 13:28:22 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
return result;
|
2015-08-02 19:20:17 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
void
|
2015-08-02 19:20:17 +00:00
|
|
|
gtk_inspector_object_tree_select_object (GtkInspectorObjectTree *wt,
|
|
|
|
GObject *object)
|
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkTreeListRow *row_item;
|
2014-05-09 00:13:34 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
row_item = find_and_expand_object (wt->priv->tree_model, object);
|
|
|
|
if (row_item == NULL)
|
|
|
|
return;
|
2014-05-09 02:58:43 +00:00
|
|
|
|
2019-11-05 16:10:29 +00:00
|
|
|
gtk_single_selection_set_selected (wt->priv->selection,
|
|
|
|
gtk_tree_list_row_get_position (row_item));
|
2019-02-13 18:40:40 +00:00
|
|
|
g_signal_emit (wt, signals[OBJECT_SELECTED], 0, object); // FIXME
|
2018-08-29 14:19:37 +00:00
|
|
|
g_object_unref (row_item);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2019-12-07 16:49:30 +00:00
|
|
|
void
|
|
|
|
gtk_inspector_object_tree_set_display (GtkInspectorObjectTree *wt,
|
|
|
|
GdkDisplay *display)
|
|
|
|
{
|
2020-07-26 20:38:53 +00:00
|
|
|
wt->priv->tree_model = gtk_tree_list_model_new (create_root_model (display),
|
|
|
|
FALSE,
|
2019-12-07 16:49:30 +00:00
|
|
|
FALSE,
|
|
|
|
create_model_for_object,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2020-07-26 21:16:15 +00:00
|
|
|
wt->priv->selection = gtk_single_selection_new (g_object_ref (G_LIST_MODEL (wt->priv->tree_model)));
|
2019-11-05 16:10:29 +00:00
|
|
|
gtk_column_view_set_model (GTK_COLUMN_VIEW (wt->priv->list),
|
2020-08-31 21:06:48 +00:00
|
|
|
GTK_SELECTION_MODEL (wt->priv->selection));
|
2019-12-07 16:49:30 +00:00
|
|
|
}
|