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"
|
2014-06-10 12:53:31 +00:00
|
|
|
#include "gtkcomboboxprivate.h"
|
2018-08-29 14:19:37 +00:00
|
|
|
#include "gtkfilterlistmodel.h"
|
|
|
|
#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"
|
2018-08-29 14:19:37 +00:00
|
|
|
#include "gtklistbox.h"
|
2019-04-29 03:25:37 +00:00
|
|
|
#include "gtkpopover.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtksettings.h"
|
2018-08-29 14:19:37 +00:00
|
|
|
#include "gtksizegroup.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtktextview.h"
|
2018-08-29 14:19:37 +00:00
|
|
|
#include "gtktogglebutton.h"
|
|
|
|
#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-25 14:00:04 +00:00
|
|
|
#include "gtkstylecontext.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
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkListBox *list;
|
|
|
|
GtkTreeListModel *tree_model;
|
2014-10-31 18:16:39 +00:00
|
|
|
GtkWidget *search_bar;
|
|
|
|
GtkWidget *search_entry;
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkSizeGroup *type_size_group;
|
|
|
|
GtkSizeGroup *name_size_group;
|
|
|
|
GtkSizeGroup *label_size_group;
|
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);
|
|
|
|
GtkFlattenListModel *flatten;
|
|
|
|
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);
|
|
|
|
|
|
|
|
flatten = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (list));
|
|
|
|
g_object_unref (list);
|
|
|
|
|
|
|
|
return G_LIST_MODEL (flatten);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
GListModel *result;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = G_LIST_MODEL (gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (concat)));
|
|
|
|
g_object_unref (concat);
|
|
|
|
return result;
|
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;
|
|
|
|
GtkFlattenListModel *result;
|
|
|
|
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);
|
|
|
|
result = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (result_list));
|
|
|
|
g_object_unref (result_list);
|
|
|
|
|
|
|
|
return G_LIST_MODEL (result);
|
2015-08-26 13:28:22 +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)
|
|
|
|
{
|
|
|
|
return list_model_for_properties (object, (const char *[3]) { "app-menu", "menubar", NULL });
|
|
|
|
}
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
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;
|
2018-08-29 14:19:37 +00:00
|
|
|
GListModel *result, *children;
|
|
|
|
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 = NULL;
|
|
|
|
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
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
if (result_list)
|
|
|
|
{
|
|
|
|
g_list_store_append (result_list, children);
|
|
|
|
g_object_unref (children);
|
|
|
|
}
|
|
|
|
else if (result == NULL)
|
|
|
|
{
|
|
|
|
result = children;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result_list = g_list_store_new (G_TYPE_LIST_MODEL);
|
|
|
|
g_list_store_append (result_list, result);
|
|
|
|
g_object_unref (result);
|
|
|
|
g_list_store_append (result_list, children);
|
|
|
|
g_object_unref (children);
|
|
|
|
}
|
|
|
|
}
|
2014-10-11 02:34:32 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
if (result_list)
|
|
|
|
{
|
|
|
|
result = G_LIST_MODEL (gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (result_list)));
|
|
|
|
g_object_unref (result_list);
|
|
|
|
}
|
2014-10-11 02:34:32 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
return result;
|
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))
|
|
|
|
{
|
|
|
|
const gchar *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))
|
|
|
|
{
|
|
|
|
const gchar *id;
|
2014-10-25 01:14:16 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
id = gtk_buildable_get_name (GTK_BUILDABLE (object));
|
|
|
|
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
|
2018-08-29 14:19:37 +00:00
|
|
|
on_row_activated (GtkListBox *box,
|
|
|
|
GtkListBoxRow *row,
|
|
|
|
GtkInspectorObjectTree *wt)
|
2014-05-09 02:58:43 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
guint pos;
|
|
|
|
GtkTreeListRow *item;
|
|
|
|
GObject *object;
|
|
|
|
|
|
|
|
pos = gtk_list_box_row_get_index (row);
|
|
|
|
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
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkListBoxRow *selected_row;
|
|
|
|
guint selected_pos;
|
|
|
|
GtkTreeListRow *selected_row_item;
|
2015-12-27 02:40:19 +00:00
|
|
|
GObject *object;
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
selected_row = gtk_list_box_get_selected_row (wt->priv->list);
|
|
|
|
if (selected_row == NULL)
|
|
|
|
return NULL;
|
2015-12-27 02:40:19 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
selected_pos = gtk_list_box_row_get_index (selected_row);
|
|
|
|
selected_row_item = g_list_model_get_item (G_LIST_MODEL (wt->priv->tree_model), selected_pos);
|
2015-12-27 02:40:19 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
object = gtk_tree_list_row_get_item (selected_row_item);
|
|
|
|
g_object_unref (selected_row_item);
|
|
|
|
|
|
|
|
g_object_unref (object); /* ahem */
|
|
|
|
return object;
|
2015-12-27 02:40:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-08-29 14:19:37 +00:00
|
|
|
widget_mapped (GtkWidget *widget,
|
|
|
|
GtkListBoxRow *row)
|
2015-12-27 02:40:19 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (row));
|
2015-12-27 02:40:19 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
gtk_style_context_remove_class (context, "dim-label");
|
2014-05-21 02:38:38 +00:00
|
|
|
}
|
|
|
|
|
2014-10-31 18:16:39 +00:00
|
|
|
static void
|
2018-08-29 14:19:37 +00:00
|
|
|
widget_unmapped (GtkWidget *widget,
|
|
|
|
GtkListBoxRow *row)
|
2014-10-31 18:16:39 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (row));
|
|
|
|
|
|
|
|
gtk_style_context_add_class (context, "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));
|
|
|
|
default_accel = gtk_widget_get_modifier_mask (GTK_WIDGET (wt), GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
|
|
|
|
|
|
|
|
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
|
|
|
|
match_string (const gchar *string,
|
|
|
|
const gchar *text)
|
|
|
|
{
|
|
|
|
gchar *lower;
|
|
|
|
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
|
|
|
{
|
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);
|
|
|
|
else
|
|
|
|
return FALSE;
|
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));
|
2018-08-29 14:19:37 +00:00
|
|
|
if (gtk_list_box_get_selected_row (priv->list))
|
|
|
|
{
|
|
|
|
selected = gtk_list_box_row_get_index (gtk_list_box_get_selected_row (priv->list));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selected = 0;
|
|
|
|
force_progress = FALSE;
|
|
|
|
}
|
|
|
|
n = g_list_model_get_n_items (model);
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
gtk_list_box_select_row (priv->list, gtk_list_box_get_row_at_index (priv->list, row));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
static GtkWidget *
|
|
|
|
gtk_inspector_object_tree_create_list_widget (gpointer row_item,
|
|
|
|
gpointer user_data)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2018-08-29 14:19:37 +00:00
|
|
|
GtkInspectorObjectTree *wt = user_data;
|
|
|
|
gpointer item;
|
|
|
|
GtkWidget *row, *box, *column, *child;
|
|
|
|
guint depth;
|
2014-05-21 02:38:38 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
item = gtk_tree_list_row_get_item (row_item);
|
2014-05-04 23:53:04 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
row = gtk_list_box_row_new ();
|
|
|
|
g_object_set_data_full (G_OBJECT (row), "make-sure-its-not-unreffed", g_object_ref (row_item), g_object_unref);
|
|
|
|
if (GTK_IS_WIDGET (item))
|
|
|
|
{
|
|
|
|
g_signal_connect_object (item, "map", G_CALLBACK (widget_mapped), row, 0);
|
|
|
|
g_signal_connect_object (item, "unmap", G_CALLBACK (widget_unmapped), row, 0);
|
|
|
|
if (!gtk_widget_get_mapped (item))
|
|
|
|
widget_unmapped (item, GTK_LIST_BOX_ROW (row));
|
|
|
|
}
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (row), box);
|
|
|
|
|
|
|
|
column = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_size_group_add_widget (wt->priv->type_size_group, column);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), column);
|
|
|
|
|
|
|
|
/* expander */
|
|
|
|
depth = gtk_tree_list_row_get_depth (row_item);
|
|
|
|
if (depth > 0)
|
|
|
|
{
|
|
|
|
child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_widget_set_size_request (child, 16 * depth, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (column), child);
|
|
|
|
}
|
|
|
|
if (gtk_tree_list_row_is_expandable (row_item))
|
|
|
|
{
|
|
|
|
GtkWidget *title, *arrow;
|
|
|
|
|
|
|
|
child = g_object_new (GTK_TYPE_BOX, "css-name", "expander", NULL);
|
2019-10-20 14:34:24 +00:00
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
title = g_object_new (GTK_TYPE_TOGGLE_BUTTON, "css-name", "title", NULL);
|
|
|
|
gtk_button_set_relief (GTK_BUTTON (title), GTK_RELIEF_NONE);
|
|
|
|
g_object_bind_property (row_item, "expanded", title, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (child), title);
|
|
|
|
|
2020-01-28 14:03:42 +00:00
|
|
|
arrow = gtk_builtin_icon_new ("expander");
|
2018-08-29 14:19:37 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (title), arrow);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
child = gtk_image_new (); /* empty whatever */
|
|
|
|
}
|
|
|
|
gtk_container_add (GTK_CONTAINER (column), child);
|
|
|
|
|
|
|
|
/* 1st column: type name */
|
|
|
|
child = gtk_label_new (G_OBJECT_TYPE_NAME (item));
|
|
|
|
gtk_label_set_width_chars (GTK_LABEL (child), 30);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (child), 0.0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (column), child);
|
|
|
|
|
|
|
|
/* 2nd column: name */
|
|
|
|
child = gtk_label_new (gtk_inspector_get_object_name (item));
|
|
|
|
gtk_label_set_width_chars (GTK_LABEL (child), 15);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (child), 0.0);
|
|
|
|
gtk_size_group_add_widget (wt->priv->name_size_group, child);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), child);
|
|
|
|
|
|
|
|
/* 3rd column: label */
|
|
|
|
child = gtk_label_new (NULL);
|
|
|
|
if (GTK_IS_LABEL (item))
|
|
|
|
g_object_bind_property (item, "label", child, "label", G_BINDING_SYNC_CREATE);
|
|
|
|
else if (GTK_IS_BUTTON (item))
|
|
|
|
g_object_bind_property (item, "label", child, "label", G_BINDING_SYNC_CREATE);
|
|
|
|
else if (GTK_IS_WINDOW (item))
|
|
|
|
g_object_bind_property (item, "title", child, "label", G_BINDING_SYNC_CREATE);
|
|
|
|
else if (GTK_IS_TREE_VIEW_COLUMN (item))
|
|
|
|
g_object_bind_property (item, "title", child, "label", G_BINDING_SYNC_CREATE);
|
|
|
|
gtk_label_set_width_chars (GTK_LABEL (child), 15);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (child), 0.0);
|
|
|
|
gtk_size_group_add_widget (wt->priv->label_size_group, child);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), child);
|
|
|
|
|
|
|
|
g_object_unref (item);
|
|
|
|
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
GtkFilterListModel *filter;
|
|
|
|
GtkFlattenListModel *flatten;
|
|
|
|
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);
|
|
|
|
|
|
|
|
filter = gtk_filter_list_model_new_for_type (G_TYPE_OBJECT);
|
|
|
|
gtk_filter_list_model_set_filter_func (filter,
|
|
|
|
toplevel_filter_func,
|
2019-12-07 16:49:30 +00:00
|
|
|
display, NULL);
|
2018-08-29 14:19:37 +00:00
|
|
|
gtk_filter_list_model_set_model (filter, gtk_window_get_toplevels ());
|
|
|
|
g_list_store_append (list, filter);
|
|
|
|
g_object_unref (filter);
|
|
|
|
|
|
|
|
flatten = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (list));
|
|
|
|
g_object_unref (list);
|
|
|
|
return G_LIST_MODEL (flatten);
|
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);
|
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);
|
2018-08-29 14:19:37 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorObjectTree, type_size_group);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorObjectTree, name_size_group);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorObjectTree, label_size_group);
|
2014-10-31 18:16:39 +00:00
|
|
|
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);
|
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;
|
|
|
|
GtkListBoxRow *row_widget;
|
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
|
|
|
|
2018-08-29 14:19:37 +00:00
|
|
|
row_widget = gtk_list_box_get_row_at_index (wt->priv->list,
|
|
|
|
gtk_tree_list_row_get_position (row_item));
|
|
|
|
g_return_if_fail (row_widget != NULL);
|
|
|
|
gtk_list_box_select_row (wt->priv->list, row_widget);
|
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)
|
|
|
|
{
|
|
|
|
GListModel *root_model;
|
|
|
|
|
|
|
|
root_model = create_root_model (display);
|
|
|
|
wt->priv->tree_model = gtk_tree_list_model_new (FALSE,
|
|
|
|
root_model,
|
|
|
|
FALSE,
|
|
|
|
create_model_for_object,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
g_object_unref (root_model);
|
|
|
|
|
|
|
|
gtk_list_box_bind_model (wt->priv->list,
|
|
|
|
G_LIST_MODEL (wt->priv->tree_model),
|
|
|
|
gtk_inspector_object_tree_create_list_widget,
|
|
|
|
wt,
|
|
|
|
NULL);
|
|
|
|
}
|