[anjuta/system-db-refactor] language-support-cpp-java: More fixes in user packages handling



commit 1ce4bf027050f6029823488afa14c7c17fe772a3
Author: Johannes Schmid <jhs gnome org>
Date:   Sun Feb 13 14:12:29 2011 +0100

    language-support-cpp-java: More fixes in user packages handling

 plugins/language-support-cpp-java/cpp-packages.c |   86 +++++++++++++---------
 plugins/language-support-cpp-java/cpp-packages.h |    2 +-
 plugins/language-support-cpp-java/plugin.c       |   67 +++++++++++++----
 3 files changed, 106 insertions(+), 49 deletions(-)
---
diff --git a/plugins/language-support-cpp-java/cpp-packages.c b/plugins/language-support-cpp-java/cpp-packages.c
index 4a526c7..5619e67 100644
--- a/plugins/language-support-cpp-java/cpp-packages.c
+++ b/plugins/language-support-cpp-java/cpp-packages.c
@@ -30,6 +30,9 @@
 #define PREF_PROJECT_PACKAGES "cpp-load-project-packages"
 #define PREF_USER_PACKAGES "cpp-user-packages"
 
+#define PROJECT_LOADED "__cpp_packages_loaded"
+#define USER_LOADED "__cpp_user_packages_loaded"
+
 enum
 {
 	PROP_0,
@@ -169,69 +172,84 @@ cpp_packages_load_real (CppPackages* packages, GError* error, IAnjutaProjectMana
 }
 
 static void
-cpp_packages_load_user (CppPackages* packages)
+cpp_packages_load_user (CppPackages* packages, gboolean force)
 {
-	CppJavaPlugin* plugin = (CppJavaPlugin*) packages->plugin;
+	CppJavaPlugin* plugin = ANJUTA_PLUGIN_CPP_JAVA(packages->plugin);
+	AnjutaShell* shell = anjuta_plugin_get_shell (ANJUTA_PLUGIN (plugin));
 	IAnjutaSymbolManager* sm =
-		anjuta_shell_get_interface (packages->plugin->shell, IAnjutaSymbolManager, NULL);
-	gchar* packages_str = g_settings_get_string (plugin->settings,
-	                                             PREF_USER_PACKAGES);
-	GStrv pkgs = g_strsplit (packages_str, ";", -1);
-	gchar** package;
-	GList* packages_to_add = NULL;
-	GList* pkg;
+		anjuta_shell_get_interface (shell, IAnjutaSymbolManager, NULL);
+	gboolean loaded = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (shell), 
+	                                                      USER_LOADED));
 	
-	ianjuta_symbol_manager_deactivate_all (sm, NULL);
-
-	for (package = pkgs; *package != NULL; package++)
+	if (!loaded && !force)
 	{
-		g_message ("Activating: %s", *package);
-		cpp_packages_activate_package (sm, *package, &packages_to_add);
-	}
-	g_strfreev (pkgs);
-	g_free (packages_str);
+		gchar* packages_str = g_settings_get_string (plugin->settings,
+		                                             PREF_USER_PACKAGES);
+		GStrv pkgs = g_strsplit (packages_str, ";", -1);
+		gchar** package;
+		GList* packages_to_add = NULL;
+		GList* pkg;
 
-	for (pkg = packages_to_add; pkg != NULL; pkg = g_list_next (pkg))
-	{
-		PackageData* pkg_data = pkg->data;
-		AnjutaCommand* command =
-			anjuta_pkg_scanner_new (pkg_data->pkg, pkg_data->version);
-		g_signal_connect (command, "command-finished",
-		                  G_CALLBACK (on_package_ready), sm);
-		anjuta_command_queue_push (packages->queue, command);
+		ianjuta_symbol_manager_deactivate_all (sm, NULL);
+
+		for (package = pkgs; *package != NULL; package++)
+		{
+			g_message ("Activating: %s", *package);
+			cpp_packages_activate_package (sm, *package, &packages_to_add);
+		}
+		g_strfreev (pkgs);
+		g_free (packages_str);
+
+		for (pkg = packages_to_add; pkg != NULL; pkg = g_list_next (pkg))
+		{
+			PackageData* pkg_data = pkg->data;
+			AnjutaCommand* command =
+				anjuta_pkg_scanner_new (pkg_data->pkg, pkg_data->version);
+			g_signal_connect (command, "command-finished",
+				              G_CALLBACK (on_package_ready), sm);
+			anjuta_command_queue_push (packages->queue, command);
+		}
+		g_list_foreach (packages_to_add, (GFunc) pkg_data_free, NULL);
+		g_list_free (packages_to_add);
+
+		g_object_set_data (G_OBJECT (shell), 
+		                   USER_LOADED, GINT_TO_POINTER (TRUE));
+
+		g_signal_connect (packages->queue, "finished", G_CALLBACK (on_queue_finished), NULL);
+		anjuta_command_queue_start (packages->queue);
 	}
-	g_list_foreach (packages_to_add, (GFunc) pkg_data_free, NULL);
-	g_list_free (packages_to_add);
 }
 
 void 
-cpp_packages_load (CppPackages* packages)
+cpp_packages_load (CppPackages* packages, gboolean force)
 {
 	CppJavaPlugin* plugin = (CppJavaPlugin*) packages->plugin;
-	IAnjutaProjectManager* pm =
-		anjuta_shell_get_interface (packages->plugin->shell, IAnjutaProjectManager, NULL);
-	IAnjutaProject* project;
 
 	if (g_settings_get_boolean (plugin->settings,
 	                            PREF_PROJECT_PACKAGES))
 	{
+		IAnjutaProjectManager* pm =
+			anjuta_shell_get_interface (packages->plugin->shell, IAnjutaProjectManager, NULL);
+		IAnjutaProject* project;
+		
 		g_signal_connect_swapped (pm, "project-loaded", G_CALLBACK (cpp_packages_load_real), packages);
 
 		project = ianjuta_project_manager_get_current_project (pm, NULL);
 		/* Only load the packages if necessary */
 		if (project && ianjuta_project_is_loaded (project, NULL))
 		{
-			gboolean loaded = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (project), "__cpp_packages_loaded"));
+			gboolean loaded = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (project), 
+			                                                      PROJECT_LOADED));
 			if (!loaded)
 			{
 				cpp_packages_load_real (packages, NULL, pm);
-				g_object_set_data (G_OBJECT (project), "__cpp_packages_loaded", GINT_TO_POINTER (TRUE));
+				g_object_set_data (G_OBJECT (project), PROJECT_LOADED, GINT_TO_POINTER (TRUE));
 			}
 		}
 	}
 	else
 	{
-		cpp_packages_load_user (packages);
+		cpp_packages_load_user (packages, force);
 	}
 }
 
diff --git a/plugins/language-support-cpp-java/cpp-packages.h b/plugins/language-support-cpp-java/cpp-packages.h
index 84644bc..41820f8 100644
--- a/plugins/language-support-cpp-java/cpp-packages.h
+++ b/plugins/language-support-cpp-java/cpp-packages.h
@@ -50,7 +50,7 @@ struct _CppPackages
 
 GType cpp_packages_get_type (void) G_GNUC_CONST;
 CppPackages* cpp_packages_new (AnjutaPlugin* plugin);
-void cpp_packages_load (CppPackages* packages);
+void cpp_packages_load (CppPackages* packages, gboolean force);
 
 G_END_DECLS
 
diff --git a/plugins/language-support-cpp-java/plugin.c b/plugins/language-support-cpp-java/plugin.c
index 30e53ca..02c39b7 100644
--- a/plugins/language-support-cpp-java/plugin.c
+++ b/plugins/language-support-cpp-java/plugin.c
@@ -63,6 +63,7 @@
 #define PREF_INDENT_AUTOMATIC "cpp-indent-automatic"
 #define PREF_INDENT_MODELINE "cpp-indent-modeline"
 #define PREF_USER_PACKAGES "cpp-user-packages"
+#define PREF_PROJECT_PACKAGES "cpp-load-project-packages"
 
 static gpointer parent_class;
 
@@ -578,7 +579,7 @@ install_support (CppJavaPlugin *lang_plugin)
 		}
 
 		lang_plugin->packages = cpp_packages_new (ANJUTA_PLUGIN (lang_plugin));
-		cpp_packages_load(lang_plugin->packages);
+		cpp_packages_load(lang_plugin->packages, FALSE);
 	}
 	
 	lang_plugin->support_installed = TRUE;
@@ -1119,28 +1120,61 @@ cpp_java_plugin_class_init (GObjectClass *klass)
 
 static void
 on_autocompletion_toggled (GtkToggleButton* button,
-                           GtkBuilder* bxml)
+                           CppJavaPlugin* plugin)
 {
 	GtkWidget* widget;
 	gboolean sensitive = gtk_toggle_button_get_active (button);
 
-	widget = GTK_WIDGET (gtk_builder_get_object (bxml, PREF_WIDGET_SPACE));
+	widget = GTK_WIDGET (gtk_builder_get_object (plugin->bxml, PREF_WIDGET_SPACE));
 	gtk_widget_set_sensitive (widget, sensitive);
-	widget = GTK_WIDGET (gtk_builder_get_object (bxml, PREF_WIDGET_BRACE));
+	widget = GTK_WIDGET (gtk_builder_get_object (plugin->bxml, PREF_WIDGET_BRACE));
 	gtk_widget_set_sensitive (widget, sensitive);
 }
 
+static void 
+cpp_java_plugin_select_user_packages (CppJavaPlugin* plugin,
+                                      AnjutaPkgConfigChooser* chooser)
+{
+	gchar* user_packages = g_settings_get_string (plugin->settings,
+	                                              PREF_USER_PACKAGES);
+	GStrv pkgs = g_strsplit (user_packages, ";", -1);
+	gchar** pkg;
+	GList* packages = NULL;
+	for (pkg = pkgs; *pkg != NULL; pkg++)
+	{
+		packages = g_list_append (packages, *pkg);
+	}
+	anjuta_pkg_config_chooser_set_active_packages (chooser,
+	                                               packages);
+	g_strfreev (pkgs);
+	g_free (user_packages);
+	g_list_free (packages);
+}
+
 static void
 on_project_packages_toggled (GtkToggleButton* button,
-                             GtkBuilder* bxml)
+                             CppJavaPlugin* plugin)
 {
 	GtkWidget* pkg_config;
 	gboolean sensitive = !gtk_toggle_button_get_active (button);
-	pkg_config = GTK_WIDGET (gtk_builder_get_object (bxml, PREF_WIDGET_PKG_CONFIG));
+	pkg_config = GTK_WIDGET (gtk_builder_get_object (plugin->bxml, PREF_WIDGET_PKG_CONFIG));
 
 	gtk_widget_set_sensitive (pkg_config, sensitive);
 	anjuta_pkg_config_chooser_show_active_only (ANJUTA_PKG_CONFIG_CHOOSER (pkg_config),
 	                                            !sensitive);
+
+	anjuta_pkg_config_chooser_set_active_packages (ANJUTA_PKG_CONFIG_CHOOSER (pkg_config),
+	                                               NULL);
+	if (!sensitive)
+	{
+		cpp_java_plugin_select_user_packages (plugin, ANJUTA_PKG_CONFIG_CHOOSER (pkg_config));
+		cpp_packages_load (plugin->packages, TRUE);
+	}
+	else
+	{
+		anjuta_pkg_config_chooser_set_active_packages (ANJUTA_PKG_CONFIG_CHOOSER (pkg_config),
+		                                               NULL);
+	}
 }
 
 static void
@@ -1176,7 +1210,7 @@ on_package_activated (AnjutaPkgConfigChooser *self, const gchar* package,
 	g_message ("Activate package");
 	
 	cpp_java_plugin_update_user_packages (plugin, self);
-	cpp_packages_load (plugin->packages);
+	cpp_packages_load (plugin->packages, TRUE);
 }
 
 static void
@@ -1228,25 +1262,30 @@ ipreferences_merge (IAnjutaPreferences* ipref, AnjutaPreferences* prefs,
 	                                     ICON_FILE);
 	toggle = GTK_WIDGET (gtk_builder_get_object (plugin->bxml, PREF_WIDGET_AUTO));
 	g_signal_connect (toggle, "toggled", G_CALLBACK (on_autocompletion_toggled),
-	                  plugin->bxml);
-	on_autocompletion_toggled (GTK_TOGGLE_BUTTON (toggle), plugin->bxml);
+	                  plugin);
+	on_autocompletion_toggled (GTK_TOGGLE_BUTTON (toggle), plugin);
 
 	toggle = GTK_WIDGET (gtk_builder_get_object (plugin->bxml, PREF_WIDGET_PACKAGES));
 	g_signal_connect (toggle, "toggled", G_CALLBACK (on_project_packages_toggled),
-	                  plugin->bxml);
-	on_autocompletion_toggled (GTK_TOGGLE_BUTTON (toggle), plugin->bxml);
-	on_project_packages_toggled (GTK_TOGGLE_BUTTON (toggle), plugin->bxml);
+	                  plugin);
+	on_autocompletion_toggled (GTK_TOGGLE_BUTTON (toggle), plugin);
+	on_project_packages_toggled (GTK_TOGGLE_BUTTON (toggle), plugin);
 	
 	pkg_config = GTK_WIDGET (gtk_builder_get_object (plugin->bxml, PREF_WIDGET_PKG_CONFIG));
 	anjuta_pkg_config_chooser_show_active_column (ANJUTA_PKG_CONFIG_CHOOSER (pkg_config), 
 	    										  TRUE);
+	
 	g_signal_connect (G_OBJECT (pkg_config), "package-activated",
-					  G_CALLBACK (on_package_activated), plugin);
+	                  G_CALLBACK (on_package_activated), plugin);
 
 	g_signal_connect (G_OBJECT (pkg_config), "package-deactivated",
 					  G_CALLBACK (on_package_deactivated), plugin);
 	
-	gtk_widget_show_all (pkg_config);
+	if (!g_settings_get_boolean (plugin->settings,
+	                             PREF_PROJECT_PACKAGES))
+		cpp_java_plugin_select_user_packages (plugin, ANJUTA_PKG_CONFIG_CHOOSER (pkg_config));
+	
+	gtk_widget_show (pkg_config);
 }
 
 static void



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