libgimpwidgets: keep GimpColorNotebook->selectors in a consistent state

by connecting to the notebook's "remove" signal and updating the list
in the callback, so the list is consistent during the widget's
destruction.
This commit is contained in:
Michael Natterer
2011-12-11 02:41:01 +01:00
parent 8569c6e2f7
commit 12a8eec444

View File

@ -53,10 +53,9 @@
#define DEFAULT_TAB_ICON_SIZE GTK_ICON_SIZE_BUTTON
static void gimp_color_notebook_finalize (GObject *object);
static void gimp_color_notebook_style_set (GtkWidget *widget,
GtkStyle *prev_style);
static void gimp_color_notebook_togg_visible (GimpColorSelector *selector,
gboolean visible);
static void gimp_color_notebook_togg_sensitive (GimpColorSelector *selector,
@ -87,6 +86,9 @@ static void gimp_color_notebook_channel_changed (GimpColorSelector *page,
static GtkWidget * gimp_color_notebook_add_page (GimpColorNotebook *notebook,
GType page_type);
static void gimp_color_notebook_remove_selector (GtkContainer *container,
GtkWidget *widget,
GimpColorNotebook *notebook);
G_DEFINE_TYPE (GimpColorNotebook, gimp_color_notebook,
@ -98,12 +100,9 @@ G_DEFINE_TYPE (GimpColorNotebook, gimp_color_notebook,
static void
gimp_color_notebook_class_init (GimpColorNotebookClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GimpColorSelectorClass *selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
object_class->finalize = gimp_color_notebook_finalize;
widget_class->style_set = gimp_color_notebook_style_set;
selector_class->name = "Notebook";
@ -139,14 +138,16 @@ gimp_color_notebook_init (GimpColorNotebook *notebook)
guint i;
notebook->notebook = gtk_notebook_new ();
gtk_notebook_popup_enable (GTK_NOTEBOOK (notebook->notebook));
gtk_box_pack_start (GTK_BOX (notebook), notebook->notebook, TRUE, TRUE, 0);
gtk_widget_show (notebook->notebook);
gtk_notebook_popup_enable (GTK_NOTEBOOK (notebook->notebook));
g_signal_connect (notebook->notebook, "switch-page",
G_CALLBACK (gimp_color_notebook_switch_page),
notebook);
g_signal_connect (notebook->notebook, "remove",
G_CALLBACK (gimp_color_notebook_remove_selector),
notebook);
selector_types = g_type_children (GIMP_TYPE_COLOR_SELECTOR,
&n_selector_types);
@ -173,20 +174,6 @@ gimp_color_notebook_init (GimpColorNotebook *notebook)
g_free (selector_types);
}
static void
gimp_color_notebook_finalize (GObject *object)
{
GimpColorNotebook *notebook = GIMP_COLOR_NOTEBOOK (object);
if (notebook->selectors)
{
g_list_free (notebook->selectors);
notebook->selectors = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_color_notebook_style_set (GtkWidget *widget,
GtkStyle *prev_style)
@ -436,6 +423,17 @@ gimp_color_notebook_add_page (GimpColorNotebook *notebook,
return page;
}
static void
gimp_color_notebook_remove_selector (GtkContainer *container,
GtkWidget *widget,
GimpColorNotebook *notebook)
{
notebook->selectors = g_list_remove (notebook->selectors, widget);
if (! notebook->selectors)
notebook->cur_page = NULL;
}
/**
* gimp_color_notebook_set_has_page:
@ -473,10 +471,6 @@ gimp_color_notebook_set_has_page (GimpColorNotebook *notebook,
gtk_container_remove (GTK_CONTAINER (notebook->notebook),
GTK_WIDGET (page));
notebook->selectors = g_list_remove (notebook->selectors, page);
if (! notebook->selectors)
notebook->cur_page = NULL;
return NULL;
}