inspector: Turn object tree into a GtkListBox

The code gets rid of the GtkTreeView and replaces it with a GtkListBox.

Most of the logic is now done via GListModel subclasses.

A big change is that this new list is now tracking updates itself and
doesn't need to be manually updated. All code that used to cause rescans
or add forgotten objects to the tree has been removed.

If objects are missing from the object tree, the logic for tracking them
needs to be added.
This commit is contained in:
Benjamin Otte 2018-08-29 16:19:37 +02:00
parent 2237009983
commit 05e752e096
11 changed files with 772 additions and 914 deletions

View File

@ -10797,7 +10797,6 @@ warn_response (GtkDialog *dialog,
static gboolean
update_debugging (gpointer data)
{
gtk_inspector_window_rescan (inspector_window);
gtk_window_update_debugging_id = 0;
return G_SOURCE_REMOVE;
}

View File

@ -20,6 +20,8 @@
#include "data-list.h"
#include "object-tree.h"
#include "gtktreeview.h"
#include "gtkcellrenderertext.h"
#include "gtktogglebutton.h"
@ -114,7 +116,7 @@ void
gtk_inspector_data_list_set_object (GtkInspectorDataList *sl,
GObject *object)
{
const gchar *title;
gchar *title;
clear_view (sl);
sl->priv->object = NULL;
@ -126,8 +128,9 @@ gtk_inspector_data_list_set_object (GtkInspectorDataList *sl,
return;
}
title = (const gchar *)g_object_get_data (object, "gtk-inspector-object-title");
title = gtk_inspector_get_object_title (object);
gtk_label_set_label (GTK_LABEL (sl->priv->object_title), title);
g_free (title);
gtk_widget_show (GTK_WIDGET (sl));

View File

@ -157,11 +157,7 @@ select_widget (GtkInspectorWindow *iw,
iw->selected_widget = widget;
if (!gtk_inspector_object_tree_select_object (wt, G_OBJECT (widget)))
{
gtk_inspector_object_tree_scan (wt, gtk_widget_get_toplevel (widget));
gtk_inspector_object_tree_select_object (wt, G_OBJECT (widget));
}
gtk_inspector_object_tree_select_object (wt, G_OBJECT (widget));
}
static void

View File

@ -180,24 +180,8 @@ show_object (GtkInspectorMiscInfo *sl,
GObject *object,
const gchar *tab)
{
GtkTreeIter iter;
g_object_set_data (G_OBJECT (sl->priv->object_tree), "next-tab", (gpointer)tab);
if (gtk_inspector_object_tree_find_object (sl->priv->object_tree, object, &iter))
{
gtk_inspector_object_tree_select_object (sl->priv->object_tree, object);
}
else if (GTK_IS_WIDGET (object) &&
gtk_inspector_object_tree_find_object (sl->priv->object_tree, G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (object))), &iter))
{
gtk_inspector_object_tree_append_object (sl->priv->object_tree, object, &iter, NULL);
gtk_inspector_object_tree_select_object (sl->priv->object_tree, object);
}
else
{
g_warning ("GtkInspector: couldn't find the object in the tree");
}
gtk_inspector_object_tree_select_object (sl->priv->object_tree, object);
}
static void

File diff suppressed because it is too large Load Diff

View File

@ -58,17 +58,10 @@ G_BEGIN_DECLS
GType gtk_inspector_object_tree_get_type (void);
void gtk_inspector_object_tree_scan (GtkInspectorObjectTree *wt,
GtkWidget *window);
gboolean gtk_inspector_object_tree_select_object (GtkInspectorObjectTree *wt,
char * gtk_inspector_get_object_title (GObject *object);
void gtk_inspector_object_tree_select_object (GtkInspectorObjectTree *wt,
GObject *object);
void gtk_inspector_object_tree_append_object (GtkInspectorObjectTree *wt,
GObject *object,
GtkTreeIter *parent_iter,
const gchar *name);
gboolean gtk_inspector_object_tree_find_object (GtkInspectorObjectTree *wt,
GObject *object,
GtkTreeIter *iter);
GObject *gtk_inspector_object_tree_get_selected (GtkInspectorObjectTree *wt);

View File

@ -1,15 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk40">
<object class="GtkTreeStore" id="model">
<columns>
<column type="gpointer"/>
<column type="gchararray"/>
<column type="gchararray"/>
<column type="gchararray"/>
<column type="gchararray"/>
<column type="gboolean"/>
</columns>
</object>
<template class="GtkInspectorObjectTree" parent="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
@ -52,81 +42,20 @@
<property name="hscrollbar-policy">never</property>
<property name="expand">1</property>
<child>
<object class="GtkTreeView" id="tree">
<property name="model">model</property>
<property name="enable-search">0</property>
<property name="enable-grid-lines">vertical</property>
<object class="GtkListBox" id="list">
<signal name="row-activated" handler="on_row_activated"/>
<child internal-child="selection">
<object class="GtkTreeSelection">
<signal name="changed" handler="on_selection_changed"/>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="object_column">
<property name="title" translatable="yes">Object</property>
<property name="resizable">1</property>
<child>
<object class="GtkCellRendererText">
<property name="scale">0.8</property>
</object>
<attributes>
<attribute name="text">1</attribute>
<attribute name="sensitive">5</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Name</property>
<property name="resizable">1</property>
<child>
<object class="GtkCellRendererText">
<property name="scale">0.8</property>
</object>
<attributes>
<attribute name="text">2</attribute>
<attribute name="sensitive">5</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Label</property>
<property name="resizable">1</property>
<child>
<object class="GtkCellRendererText">
<property name="scale">0.8</property>
<property name="ellipsize">end</property>
<property name="max-width-chars">30</property>
</object>
<attributes>
<attribute name="text">3</attribute>
<attribute name="sensitive">5</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Style Classes</property>
<property name="resizable">1</property>
<child>
<object class="GtkCellRendererText">
<property name="scale">0.8</property>
</object>
<attributes>
<attribute name="text">4</attribute>
<attribute name="sensitive">5</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
<object class="GtkSizeGroup" id="type_size_group">
<property name="mode">both</property>
</object>
<object class="GtkSizeGroup" id="name_size_group">
<property name="mode">both</property>
</object>
<object class="GtkSizeGroup" id="label_size_group">
<property name="mode">both</property>
</object>
</interface>

View File

@ -207,26 +207,13 @@ show_object (GtkInspectorPropEditor *editor,
const gchar *tab,
GtkInspectorPropList *pl)
{
GtkTreeIter iter;
GtkWidget *popover;
popover = gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_POPOVER);
gtk_widget_hide (popover);
g_object_set_data (G_OBJECT (pl->priv->object_tree), "next-tab", (gpointer)tab);
if (gtk_inspector_object_tree_find_object (pl->priv->object_tree, object, &iter))
{
gtk_inspector_object_tree_select_object (pl->priv->object_tree, object);
}
else if (gtk_inspector_object_tree_find_object (pl->priv->object_tree, pl->priv->object, &iter))
{
gtk_inspector_object_tree_append_object (pl->priv->object_tree, object, &iter, name);
gtk_inspector_object_tree_select_object (pl->priv->object_tree, object);
}
else
{
g_warning ("GtkInspector: couldn't find the widget in the tree");
}
gtk_inspector_object_tree_select_object (pl->priv->object_tree, object);
}
static void

View File

@ -402,6 +402,8 @@ recordings_list_row_selected (GtkListBox *box,
gtk_picture_set_paintable (GTK_PICTURE (priv->render_node_view), NULL);
}
g_print ("%u render nodes\n", g_list_model_get_n_items (G_LIST_MODEL (priv->render_node_model)));
gtk_list_box_bind_model (GTK_LIST_BOX (priv->render_node_list),
G_LIST_MODEL (priv->render_node_model),
create_widget_for_render_node,

View File

@ -62,13 +62,14 @@ set_selected_object (GtkInspectorWindow *iw,
GObject *selected)
{
GList *l;
const char *title;
char *title;
if (!gtk_inspector_prop_list_set_object (GTK_INSPECTOR_PROP_LIST (iw->prop_list), selected))
return FALSE;
title = (const char *)g_object_get_data (selected, "gtk-inspector-object-title");
title = gtk_inspector_get_object_title (selected);
gtk_label_set_label (GTK_LABEL (iw->object_title), title);
g_free (title);
gtk_inspector_prop_list_set_object (GTK_INSPECTOR_PROP_LIST (iw->child_prop_list), selected);
gtk_inspector_signals_list_set_object (GTK_INSPECTOR_SIGNALS_LIST (iw->signals_list), selected);
@ -92,7 +93,6 @@ set_selected_object (GtkInspectorWindow *iw,
static void
on_object_activated (GtkInspectorObjectTree *wt,
GObject *selected,
const gchar *name,
GtkInspectorWindow *iw)
{
const gchar *tab;
@ -232,8 +232,6 @@ gtk_inspector_window_constructed (GObject *object)
G_OBJECT_CLASS (gtk_inspector_window_parent_class)->constructed (object);
g_object_set_data (G_OBJECT (gdk_display_get_default ()), "-gtk-inspector", iw);
gtk_inspector_object_tree_scan (GTK_INSPECTOR_OBJECT_TREE (iw->object_tree), NULL);
}
static void
@ -379,14 +377,6 @@ gtk_inspector_window_remove_overlay (GtkInspectorWindow *iw,
iw->overlays = g_list_delete_link (iw->overlays, item);
}
void
gtk_inspector_window_rescan (GtkWidget *widget)
{
GtkInspectorWindow *iw = GTK_INSPECTOR_WINDOW (widget);
gtk_inspector_object_tree_scan (GTK_INSPECTOR_OBJECT_TREE (iw->object_tree), NULL);
}
static GtkInspectorWindow *
gtk_inspector_window_get_for_display (GdkDisplay *display)
{

View File

@ -111,8 +111,6 @@ void gtk_inspector_window_remove_overlay
void gtk_inspector_window_select_widget_under_pointer (GtkInspectorWindow *iw);
void gtk_inspector_window_rescan (GtkWidget *iw);
gboolean gtk_inspector_is_recording (GtkWidget *widget);
GskRenderNode * gtk_inspector_prepare_render (GtkWidget *widget,
GskRenderer *renderer,