[anjuta] anjuta: Fix destruction of AnjutaPreferences instance.



commit c50391dc424b4fba99a118d165465ea70c7ed1c6
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date:   Tue Nov 27 18:52:22 2012 +0100

    anjuta: Fix destruction of AnjutaPreferences instance.
    
    AnjutaPreferences is not a GtkWidget so it should not be destroyed with
    gtk_widget_destroy(). Also make it not a singleton anymore since this causes
    some hard to solve problems.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=689054

 libanjuta/anjuta-preferences.c |   35 +++++++----------------------------
 plugins/terminal/terminal.c    |    2 +-
 plugins/tools/plugin.c         |    2 +-
 src/anjuta-window.c            |   20 +++++---------------
 src/shell.c                    |    2 +-
 5 files changed, 15 insertions(+), 46 deletions(-)
---
diff --git a/libanjuta/anjuta-preferences.c b/libanjuta/anjuta-preferences.c
index eafabef..5e26c0d 100644
--- a/libanjuta/anjuta-preferences.c
+++ b/libanjuta/anjuta-preferences.c
@@ -60,9 +60,6 @@
 #include <libanjuta/anjuta-debug.h>
 #include <libanjuta/interfaces/ianjuta-preferences.h>
 
-/* AnjutaPreferences is a singleton */
-static AnjutaPreferences* default_preferences = NULL;
-
 struct _AnjutaPreferencesPriv
 {
 	GtkWidget           *prefs_dialog;
@@ -575,30 +572,12 @@ anjuta_preferences_new (AnjutaPluginManager *plugin_manager, const gchar *common
 {
 	AnjutaPreferences *pr;
 
-	if (!default_preferences)
-	{
-		pr = g_object_new (ANJUTA_TYPE_PREFERENCES, NULL);
-		pr->priv->plugin_manager = g_object_ref (plugin_manager);
-		pr->priv->common_schema_id = g_strdup (common_schema_id);
-		pr->priv->common_gsettings = g_hash_table_new_full (g_str_hash, g_str_equal,
-		                                                    g_free,
-		                                                    (GDestroyNotify) g_object_unref);
-		default_preferences = pr;
-		return pr;
-	}
-	else
-		return default_preferences;
-
-}
+	pr = g_object_new (ANJUTA_TYPE_PREFERENCES, NULL);
+	pr->priv->plugin_manager = g_object_ref (plugin_manager);
+	pr->priv->common_schema_id = g_strdup (common_schema_id);
+	pr->priv->common_gsettings = g_hash_table_new_full (g_str_hash, g_str_equal,
+	                                                    g_free,
+	                                                    (GDestroyNotify) g_object_unref);
+	return pr;
 
-/**
- * anjuta_preferences_default:
- *
- * Get the default instace of anjuta preferences
- *
- * Return value: A #AnjutaPreferences object.
- */
-AnjutaPreferences *anjuta_preferences_default ()
-{
-	return default_preferences;
 }
diff --git a/plugins/terminal/terminal.c b/plugins/terminal/terminal.c
index 28edde8..184d516 100644
--- a/plugins/terminal/terminal.c
+++ b/plugins/terminal/terminal.c
@@ -913,7 +913,7 @@ ipreferences_merge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError**
 	}
 
 
-	anjuta_preferences_add_from_builder (anjuta_preferences_default (), bxml,
+	anjuta_preferences_add_from_builder (prefs, bxml,
 	                                     term_plugin->settings,
 	                                     "Terminal", _("Terminal"), ICON_FILE);
 
diff --git a/plugins/tools/plugin.c b/plugins/tools/plugin.c
index cbaefb3..6ce8d9a 100644
--- a/plugins/tools/plugin.c
+++ b/plugins/tools/plugin.c
@@ -258,7 +258,7 @@ ipreferences_merge(IAnjutaPreferences* obj, AnjutaPreferences* prefs, GError** e
 
 	atp_tool_dialog_show (&atp_plugin->dialog, bxml);
 
-	anjuta_preferences_add_from_builder (anjuta_preferences_default (), bxml,
+	anjuta_preferences_add_from_builder (prefs, bxml,
 	                                     atp_plugin->settings,
 	                                     "Tools", _("Tools"), ICON_FILE);
 	g_object_unref (bxml);
diff --git a/src/anjuta-window.c b/src/anjuta-window.c
index 7162bac..e15d16d 100644
--- a/src/anjuta-window.c
+++ b/src/anjuta-window.c
@@ -550,6 +550,11 @@ anjuta_window_dispose (GObject *widget)
 		g_object_unref (win->ui);
 		win->ui = NULL;
 	}
+	if (win->preferences)
+	{
+		g_object_unref (win->preferences);
+		win->preferences = NULL;
+	}
 	if (win->layout_manager) {
 		/* Disconnect signal handlers so we don't get any signals after we're
 		 * disposed. */
@@ -582,20 +587,6 @@ anjuta_window_dispose (GObject *widget)
 }
 
 static void
-anjuta_window_finalize (GObject *widget)
-{
-	AnjutaWindow *win;
-
-	g_return_if_fail (ANJUTA_IS_WINDOW (widget));
-
-	win = ANJUTA_WINDOW (widget);
-
-	gtk_widget_destroy (GTK_WIDGET (win->preferences));
-
-	G_OBJECT_CLASS (parent_class)->finalize (widget);
-}
-
-static void
 anjuta_window_instance_init (AnjutaWindow *win)
 {
 	GtkWidget *menubar, *about_menu;
@@ -834,7 +825,6 @@ anjuta_window_class_init (AnjutaWindowClass *class)
 	object_class = (GObjectClass*) class;
 	widget_class = (GtkWidgetClass*) class;
 
-	object_class->finalize = anjuta_window_finalize;
 	object_class->dispose = anjuta_window_dispose;
 
 	widget_class->key_press_event = anjuta_window_key_press_event;
diff --git a/src/shell.c b/src/shell.c
index b6cfa84..3487944 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -166,7 +166,7 @@ anjuta_test_shell_instance_init (AnjutaTestShell *shell)
 	plugins = anjuta_plugin_manager_get_plugins_page (shell->plugin_manager);
 	gtk_box_pack_end (GTK_BOX (shell->box), plugins, TRUE, TRUE, 0);
 
-	/* Preferencesnces */
+	/* Preferences */
 	shell->preferences = ANJUTA_PREFERENCES (anjuta_preferences_new (shell->plugin_manager, PREF_SCHEMA));
 
 	/* UI engine */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]