inspector: Avoid weak ref problems
We know the objects in a size group are always widgets, so we can avoid hard-to-track down problems with weak references by just cleaning up when the object gets destroyed. There is still a chance that we show a widget as part of the group after it has been removed, but size groups simply have no signals that would let us avoid that.
This commit is contained in:
parent
d39ee6c81c
commit
11abc517f5
@ -64,6 +64,30 @@ size_group_row_get_property (GObject *object,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
size_group_row_widget_destroyed (GtkWidget *widget, SizeGroupRow *row)
|
||||||
|
{
|
||||||
|
GtkWidget *parent;
|
||||||
|
|
||||||
|
parent = gtk_widget_get_parent (GTK_WIDGET (row));
|
||||||
|
if (parent)
|
||||||
|
gtk_container_remove (GTK_CONTAINER (parent), GTK_WIDGET (row));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_widget (SizeGroupRow *row, GtkWidget *widget)
|
||||||
|
{
|
||||||
|
if (row->widget)
|
||||||
|
g_signal_handlers_disconnect_by_func (row->widget,
|
||||||
|
size_group_row_widget_destroyed, row);
|
||||||
|
|
||||||
|
row->widget = widget;
|
||||||
|
|
||||||
|
if (row->widget)
|
||||||
|
g_signal_connect (row->widget, "destroy",
|
||||||
|
G_CALLBACK (size_group_row_widget_destroyed), row);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
size_group_row_set_property (GObject *object,
|
size_group_row_set_property (GObject *object,
|
||||||
guint property_id,
|
guint property_id,
|
||||||
@ -75,11 +99,7 @@ size_group_row_set_property (GObject *object,
|
|||||||
switch (property_id)
|
switch (property_id)
|
||||||
{
|
{
|
||||||
case PROP_WIDGET:
|
case PROP_WIDGET:
|
||||||
if (row->widget)
|
set_widget (row, g_value_get_pointer (value));
|
||||||
g_object_remove_weak_pointer (G_OBJECT (row->widget), (gpointer *)&row->widget);
|
|
||||||
row->widget = g_value_get_pointer (value);
|
|
||||||
if (row->widget)
|
|
||||||
g_object_add_weak_pointer (G_OBJECT (row->widget), (gpointer *)&row->widget);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
@ -91,8 +111,7 @@ size_group_row_finalize (GObject *object)
|
|||||||
{
|
{
|
||||||
SizeGroupRow *row = (SizeGroupRow *)object;
|
SizeGroupRow *row = (SizeGroupRow *)object;
|
||||||
|
|
||||||
if (row->widget)
|
set_widget (row, NULL);
|
||||||
g_object_remove_weak_pointer (G_OBJECT (row->widget), (gpointer *)&row->widget);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (size_group_row_parent_class)->finalize (object);
|
G_OBJECT_CLASS (size_group_row_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user