inspector: Handle object destruction without row references

This way, we can live without row references.

A side effect is that opening the inspector on the gtk-demo list box
example now only takes 0.5s instead of the previous 3 minutes.
This commit is contained in:
Benjamin Otte 2015-08-26 16:33:52 +02:00
parent 1f2bd47965
commit bffeae6203

View File

@ -73,7 +73,6 @@ struct _GtkInspectorObjectTreePrivate
{ {
GtkTreeView *tree; GtkTreeView *tree;
GtkTreeStore *model; GtkTreeStore *model;
GHashTable *iters;
gulong map_hook; gulong map_hook;
gulong unmap_hook; gulong unmap_hook;
GtkTreeViewColumn *object_column; GtkTreeViewColumn *object_column;
@ -608,43 +607,14 @@ on_selection_changed (GtkTreeSelection *selection,
g_signal_emit (wt, signals[OBJECT_SELECTED], 0, object); g_signal_emit (wt, signals[OBJECT_SELECTED], 0, object);
} }
typedef struct
{
GtkInspectorObjectTree *wt;
GObject *object;
GtkTreeRowReference *row;
} ObjectData;
static void static void
gtk_object_tree_remove_dead_object (gpointer data, GObject *dead_object) gtk_object_tree_remove_dead_object (gpointer data, GObject *dead_object)
{ {
ObjectData *od = data; GtkInspectorObjectTree *wt = data;
if (gtk_tree_row_reference_valid (od->row))
{
GtkTreePath *path;
GtkTreeIter iter; GtkTreeIter iter;
path = gtk_tree_row_reference_get_path (od->row);
gtk_tree_model_get_iter (GTK_TREE_MODEL (od->wt->priv->model), &iter, path);
gtk_tree_store_remove (od->wt->priv->model, &iter);
gtk_tree_path_free (path);
}
od->object = NULL;
g_hash_table_remove (od->wt->priv->iters, dead_object);
}
static void if (gtk_inspector_object_tree_find_object (wt, dead_object, &iter))
object_data_free (gpointer data) gtk_tree_store_remove (wt->priv->model, &iter);
{
ObjectData *od = data;
gtk_tree_row_reference_free (od->row);
if (od->object)
g_object_weak_unref (od->object, gtk_object_tree_remove_dead_object, od);
g_free (od);
} }
static gboolean static gboolean
@ -888,10 +858,6 @@ gtk_inspector_object_tree_init (GtkInspectorObjectTree *wt)
guint signal_id; guint signal_id;
wt->priv = gtk_inspector_object_tree_get_instance_private (wt); wt->priv = gtk_inspector_object_tree_get_instance_private (wt);
wt->priv->iters = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
(GDestroyNotify) object_data_free);
gtk_widget_init_template (GTK_WIDGET (wt)); gtk_widget_init_template (GTK_WIDGET (wt));
gtk_search_bar_connect_entry (GTK_SEARCH_BAR (wt->priv->search_bar), gtk_search_bar_connect_entry (GTK_SEARCH_BAR (wt->priv->search_bar),
@ -917,8 +883,6 @@ gtk_inspector_object_tree_finalize (GObject *object)
GtkInspectorObjectTree *wt = GTK_INSPECTOR_OBJECT_TREE (object); GtkInspectorObjectTree *wt = GTK_INSPECTOR_OBJECT_TREE (object);
guint signal_id; guint signal_id;
g_hash_table_unref (wt->priv->iters);
signal_id = g_signal_lookup ("map", GTK_TYPE_WIDGET); signal_id = g_signal_lookup ("map", GTK_TYPE_WIDGET);
g_signal_remove_emission_hook (signal_id, wt->priv->map_hook); g_signal_remove_emission_hook (signal_id, wt->priv->map_hook);
signal_id = g_signal_lookup ("unmap", GTK_TYPE_WIDGET); signal_id = g_signal_lookup ("unmap", GTK_TYPE_WIDGET);
@ -997,7 +961,6 @@ gtk_inspector_object_tree_append_object (GtkInspectorObjectTree *wt,
GtkTreePath *path; GtkTreePath *path;
const gchar *class_name; const gchar *class_name;
gchar *classes; gchar *classes;
ObjectData *od;
const gchar *label; const gchar *label;
FindAllData data; FindAllData data;
@ -1074,15 +1037,10 @@ gtk_inspector_object_tree_append_object (GtkInspectorObjectTree *wt,
g_free (classes); g_free (classes);
od = g_new0 (ObjectData, 1);
od->wt = wt;
od->object = object;
path = gtk_tree_model_get_path (GTK_TREE_MODEL (wt->priv->model), &iter); path = gtk_tree_model_get_path (GTK_TREE_MODEL (wt->priv->model), &iter);
od->row = gtk_tree_row_reference_new (GTK_TREE_MODEL (wt->priv->model), path);
gtk_tree_path_free (path); gtk_tree_path_free (path);
g_hash_table_insert (wt->priv->iters, object, od); g_object_weak_ref (object, gtk_object_tree_remove_dead_object, wt);
g_object_weak_ref (object, gtk_object_tree_remove_dead_object, od);
data.wt = wt; data.wt = wt;
data.iter = &iter; data.iter = &iter;
@ -1141,7 +1099,6 @@ gtk_inspector_object_tree_scan (GtkInspectorObjectTree *wt,
selected = gtk_inspector_object_tree_get_selected (wt); selected = gtk_inspector_object_tree_get_selected (wt);
g_hash_table_remove_all (wt->priv->iters);
gtk_tree_store_clear (wt->priv->model); gtk_tree_store_clear (wt->priv->model);
gtk_inspector_object_tree_append_object (wt, G_OBJECT (gtk_settings_get_default ()), NULL, NULL); gtk_inspector_object_tree_append_object (wt, G_OBJECT (gtk_settings_get_default ()), NULL, NULL);
if (g_application_get_default ()) if (g_application_get_default ())