[anjuta/system-db-refactor] libanjuta: Initial work to support user packages in the preferences
- From: Johannes Schmid <jhs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta/system-db-refactor] libanjuta: Initial work to support user packages in the preferences
- Date: Thu, 10 Feb 2011 15:48:53 +0000 (UTC)
commit 6e0f4fcd8864aed1a30cadd0c677e3d23eca5f12
Author: Johannes Schmid <jhs gnome org>
Date: Thu Feb 10 16:44:20 2011 +0100
libanjuta: Initial work to support user packages in the preferences
plugins/language-support-cpp-java/Makefile.am | 4 +-
plugins/language-support-cpp-java/cpp-packages.c | 72 +++++++++++++++++---
.../language-support-cpp-java.gschema-part.xml | 3 +
plugins/language-support-cpp-java/plugin.c | 59 +++++++++++-----
4 files changed, 108 insertions(+), 30 deletions(-)
---
diff --git a/plugins/language-support-cpp-java/Makefile.am b/plugins/language-support-cpp-java/Makefile.am
index 914429e..3eda1f1 100644
--- a/plugins/language-support-cpp-java/Makefile.am
+++ b/plugins/language-support-cpp-java/Makefile.am
@@ -68,6 +68,7 @@ libanjuta_language_cpp_java_la_LIBADD = \
cxxparser/libcxxparser.la
prefs_ui_files = anjuta-language-cpp-java.ui
+prefs_keyfile = language-support-cpp-java.gschema-part.xml
prefs_name = org.gnome.anjuta.cpp
include $(top_srcdir)/scripts/build-schemas.mk
@@ -76,6 +77,7 @@ EXTRA_DIST = \
$(cpp_java_plugin_DATA) \
$(cpp_java_ui_DATA) \
$(cpp_java_pixmaps_DATA) \
- $(cpp_java_glade_DATA)
+ $(cpp_java_glade_DATA) \
+ $(prefs_keyfile)
-include $(top_srcdir)/git.mk
diff --git a/plugins/language-support-cpp-java/cpp-packages.c b/plugins/language-support-cpp-java/cpp-packages.c
index 0bdd6ad..4a526c7 100644
--- a/plugins/language-support-cpp-java/cpp-packages.c
+++ b/plugins/language-support-cpp-java/cpp-packages.c
@@ -18,12 +18,17 @@
*/
#include "cpp-packages.h"
+#include "plugin.h"
#include <libanjuta/interfaces/ianjuta-project-manager.h>
#include <libanjuta/interfaces/ianjuta-symbol-manager.h>
#include <libanjuta/anjuta-pkg-config.h>
#include <libanjuta/anjuta-pkg-scanner.h>
#include <libanjuta/anjuta-debug.h>
+#include <libanjuta/anjuta-preferences.h>
+
+#define PREF_PROJECT_PACKAGES "cpp-load-project-packages"
+#define PREF_USER_PACKAGES "cpp-user-packages"
enum
{
@@ -138,6 +143,8 @@ cpp_packages_load_real (CppPackages* packages, GError* error, IAnjutaProjectMana
if (!pm || !sm)
return;
+
+ ianjuta_symbol_manager_deactivate_all (sm, NULL);
pkgs = ianjuta_project_manager_get_packages (pm, NULL);
for (pkg = pkgs; pkg != NULL; pkg = g_list_next (pkg))
@@ -161,26 +168,71 @@ cpp_packages_load_real (CppPackages* packages, GError* error, IAnjutaProjectMana
anjuta_command_queue_start (packages->queue);
}
+static void
+cpp_packages_load_user (CppPackages* packages)
+{
+ CppJavaPlugin* plugin = (CppJavaPlugin*) packages->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;
+
+ 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);
+}
+
void
cpp_packages_load (CppPackages* packages)
{
+ CppJavaPlugin* plugin = (CppJavaPlugin*) packages->plugin;
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))
+ if (g_settings_get_boolean (plugin->settings,
+ PREF_PROJECT_PACKAGES))
{
- gboolean loaded = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (project), "__cpp_packages_loaded"));
- if (!loaded)
+ 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))
{
- cpp_packages_load_real (packages, NULL, pm);
- g_object_set_data (G_OBJECT (project), "__cpp_packages_loaded", GINT_TO_POINTER (TRUE));
+ gboolean loaded = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (project), "__cpp_packages_loaded"));
+ if (!loaded)
+ {
+ cpp_packages_load_real (packages, NULL, pm);
+ g_object_set_data (G_OBJECT (project), "__cpp_packages_loaded", GINT_TO_POINTER (TRUE));
+ }
}
- }
+ }
+ else
+ {
+ cpp_packages_load_user (packages);
+ }
}
static void
diff --git a/plugins/language-support-cpp-java/language-support-cpp-java.gschema-part.xml b/plugins/language-support-cpp-java/language-support-cpp-java.gschema-part.xml
new file mode 100644
index 0000000..33b2514
--- /dev/null
+++ b/plugins/language-support-cpp-java/language-support-cpp-java.gschema-part.xml
@@ -0,0 +1,3 @@
+<key name="cpp-user-packages" type="s">
+ <default>""</default>
+</key>
diff --git a/plugins/language-support-cpp-java/plugin.c b/plugins/language-support-cpp-java/plugin.c
index f71b47d..30e53ca 100644
--- a/plugins/language-support-cpp-java/plugin.c
+++ b/plugins/language-support-cpp-java/plugin.c
@@ -24,6 +24,7 @@
#include <libanjuta/anjuta-shell.h>
#include <libanjuta/anjuta-debug.h>
#include <libanjuta/anjuta-pkg-config-chooser.h>
+#include <libanjuta/anjuta-pkg-config.h>
#include <libanjuta/interfaces/ianjuta-iterable.h>
#include <libanjuta/interfaces/ianjuta-document.h>
#include <libanjuta/interfaces/ianjuta-document-manager.h>
@@ -56,14 +57,12 @@
#define PREFS_BUILDER PACKAGE_DATA_DIR"/glade/anjuta-language-cpp-java.ui"
#define ICON_FILE "anjuta-language-cpp-java-plugin.png"
-#define FIXME_DEFAULT_PACKAGE_VERSION "1.0"
-
/* Preferences keys */
#define PREF_SCHEMA "org.gnome.anjuta.cpp"
#define PREF_INDENT_AUTOMATIC "cpp-indent-automatic"
#define PREF_INDENT_MODELINE "cpp-indent-modeline"
-#define PREF_PROJECT_PACKAGES "cpp-load-project-packages"
+#define PREF_USER_PACKAGES "cpp-user-packages"
static gpointer parent_class;
@@ -1145,24 +1144,39 @@ on_project_packages_toggled (GtkToggleButton* button,
}
static void
+cpp_java_plugin_update_user_packages (CppJavaPlugin* plugin,
+ AnjutaPkgConfigChooser* chooser)
+{
+ GList* pkg;
+ GList* packages = anjuta_pkg_config_chooser_get_active_packages (chooser);
+ GString* pkg_string = g_string_new (NULL);
+
+ for (pkg = packages; pkg != NULL; pkg = g_list_next (pkg))
+ {
+ if (strlen (pkg_string->str))
+ {
+ pkg_string = g_string_append_c (pkg_string, ';');
+ }
+ pkg_string = g_string_append (pkg_string, pkg->data);
+ }
+ g_message ("Packages: %s", pkg_string->str);
+ g_settings_set_string (plugin->settings, PREF_USER_PACKAGES,
+ pkg_string->str);
+ g_string_free (pkg_string, TRUE);
+}
+
+static void
on_package_activated (AnjutaPkgConfigChooser *self, const gchar* package,
gpointer data)
{
CppJavaPlugin* plugin;
- IAnjutaSymbolManager *isymbol_manager;
plugin = ANJUTA_PLUGIN_CPP_JAVA (data);
- DEBUG_PRINT ("activated %s", package);
- isymbol_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
- IAnjutaSymbolManager,
- NULL);
-
- ianjuta_symbol_manager_activate_package (isymbol_manager,
- package,
- FIXME_DEFAULT_PACKAGE_VERSION,
- NULL);
+ g_message ("Activate package");
+ cpp_java_plugin_update_user_packages (plugin, self);
+ cpp_packages_load (plugin->packages);
}
static void
@@ -1171,7 +1185,8 @@ on_package_deactivated (AnjutaPkgConfigChooser *self, const gchar* package,
{
CppJavaPlugin* plugin;
IAnjutaSymbolManager *isymbol_manager;
-
+ gchar* version;
+
plugin = ANJUTA_PLUGIN_CPP_JAVA (data);
DEBUG_PRINT ("deactivated %s", package);
@@ -1179,12 +1194,18 @@ on_package_deactivated (AnjutaPkgConfigChooser *self, const gchar* package,
isymbol_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
IAnjutaSymbolManager,
NULL);
- ianjuta_symbol_manager_deactivate_package (isymbol_manager,
- package,
- FIXME_DEFAULT_PACKAGE_VERSION,
- NULL);
-}
+ version = anjuta_pkg_config_get_version (package);
+ if (version)
+ {
+ ianjuta_symbol_manager_deactivate_package (isymbol_manager,
+ package,
+ version,
+ NULL);
+ }
+ g_free (version);
+ cpp_java_plugin_update_user_packages (plugin, self);
+}
static void
ipreferences_merge (IAnjutaPreferences* ipref, AnjutaPreferences* prefs,
GError** e)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]