From 7784aa38364411b66ad37f2fbbe89e57e60ef3d2 Mon Sep 17 00:00:00 2001 From: Johannes Schmid Date: Mon, 31 Jan 2011 00:04:51 +0100 Subject: [PATCH] language-support-cpp-java: Load files for packages asynchronous --- plugins/language-support-cpp-java/Makefile.am | 4 +- .../cpp-package-scanner.c | 212 ++++++++++ .../cpp-package-scanner.h | 62 +++ plugins/language-support-cpp-java/cpp-packages.c | 468 ++++++++++++--------- plugins/language-support-cpp-java/cpp-packages.h | 85 ++-- plugins/language-support-cpp-java/plugin.c | 13 +- plugins/language-support-cpp-java/plugin.h | 4 + 7 files changed, 612 insertions(+), 236 deletions(-) create mode 100644 plugins/language-support-cpp-java/cpp-package-scanner.c create mode 100644 plugins/language-support-cpp-java/cpp-package-scanner.h rewrite plugins/language-support-cpp-java/cpp-packages.c (62%) rewrite plugins/language-support-cpp-java/cpp-packages.h (79%) diff --git a/plugins/language-support-cpp-java/Makefile.am b/plugins/language-support-cpp-java/Makefile.am index 2d4fb7f0c..fe5024c0d 100644 --- a/plugins/language-support-cpp-java/Makefile.am +++ b/plugins/language-support-cpp-java/Makefile.am @@ -55,7 +55,9 @@ libanjuta_language_cpp_java_la_SOURCES = \ cpp-java-indentation.c \ cpp-java-indentation.h \ cpp-packages.c \ - cpp-packages.h + cpp-packages.h \ + cpp-package-scanner.h \ + cpp-package-scanner.c libanjuta_language_cpp_java_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS) diff --git a/plugins/language-support-cpp-java/cpp-package-scanner.c b/plugins/language-support-cpp-java/cpp-package-scanner.c new file mode 100644 index 000000000..cb10bd7fd --- /dev/null +++ b/plugins/language-support-cpp-java/cpp-package-scanner.c @@ -0,0 +1,212 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) Johannes Schmid 2011 + * + * anjuta is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * anjuta is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "cpp-package-scanner.h" +#include +#include +#include + +enum +{ + PROP_0, + PROP_PACKAGE, + PROP_VERSION +}; + +G_DEFINE_TYPE (CppPackageScanner, cpp_package_scanner, ANJUTA_TYPE_ASYNC_COMMAND); + +static void +cpp_package_scanner_init (CppPackageScanner *object) +{ + object->files = NULL; +} + +static void +cpp_package_scanner_finalize (GObject *object) +{ + CppPackageScanner* scanner = CPP_PACKAGE_SCANNER (object); + g_free (scanner->package); + g_free (scanner->version); + anjuta_util_glist_strings_free (scanner->files); + + G_OBJECT_CLASS (cpp_package_scanner_parent_class)->finalize (object); +} + +static void +cpp_package_scanner_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + CppPackageScanner* scanner; + + g_return_if_fail (CPP_IS_PACKAGE_SCANNER (object)); + + scanner = CPP_PACKAGE_SCANNER(object); + + switch (prop_id) + { + case PROP_PACKAGE: + scanner->package = g_value_dup_string (value); + break; + case PROP_VERSION: + scanner->version = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +cpp_package_scanner_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + CppPackageScanner* scanner; + + g_return_if_fail (CPP_IS_PACKAGE_SCANNER (object)); + + scanner = CPP_PACKAGE_SCANNER(object); + + switch (prop_id) + { + case PROP_PACKAGE: + g_value_set_string (value, scanner->package); + break; + case PROP_VERSION: + g_value_set_string (value, scanner->version); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +cpp_package_scanner_list_files (GList **children, GFile *dir) +{ + GFileEnumerator *list; + + list = g_file_enumerate_children (dir, + G_FILE_ATTRIBUTE_STANDARD_NAME, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL, + NULL); + + if (list != NULL) + { + GFileInfo *info; + + while ((info = g_file_enumerator_next_file (list, NULL, NULL)) != NULL) + { + const gchar *name; + GFile *file; + + name = g_file_info_get_name (info); + file = g_file_get_child (dir, name); + g_object_unref (info); + + if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY) + { + cpp_package_scanner_list_files (children, file); + } + else + { + gchar* filename = g_file_get_path (file); + *children = g_list_prepend (*children, filename); + } + g_object_unref (file); + } + g_file_enumerator_close (list, NULL, NULL); + g_object_unref (list); + } +} + +static guint +cpp_package_scanner_run (AnjutaCommand* command) +{ + CppPackageScanner* scanner = CPP_PACKAGE_SCANNER (command); + GList* dirs = anjuta_pkg_config_get_directories (scanner->package, TRUE, NULL); + GList* dir; + + g_message ("Scanning package: %s", scanner->package); + + for (dir = dirs; dir != NULL; dir = g_list_next (dir)) + { + GFile* file = g_file_new_for_path (dir->data); + cpp_package_scanner_list_files (&scanner->files, file); + } + anjuta_util_glist_strings_free (dirs); + return 0; +} + +static void +cpp_package_scanner_class_init (CppPackageScannerClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + AnjutaCommandClass* command_class = ANJUTA_COMMAND_CLASS (klass); + + object_class->finalize = cpp_package_scanner_finalize; + object_class->set_property = cpp_package_scanner_set_property; + object_class->get_property = cpp_package_scanner_get_property; + + g_object_class_install_property (object_class, + PROP_PACKAGE, + g_param_spec_string ("package", + "package", + "Name of the package", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + + g_object_class_install_property (object_class, + PROP_VERSION, + g_param_spec_string ("version", + "version", + "Version of the package", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + + command_class->run = cpp_package_scanner_run; +} + + +AnjutaCommand* +cpp_package_scanner_new (const gchar* package, const gchar* version) +{ + GObject* object = + g_object_new (CPP_TYPE_PACKAGE_SCANNER, + "package", package, + "version", version, + NULL); + + return ANJUTA_COMMAND (object); +} + +const gchar* +cpp_package_scanner_get_package (CppPackageScanner* scanner) +{ + return scanner->package; +} +const gchar* +cpp_package_scanner_get_version (CppPackageScanner* scanner) +{ + return scanner->version; +} + +GList* +cpp_package_scanner_get_files (CppPackageScanner* scanner) +{ + return scanner->files; +} diff --git a/plugins/language-support-cpp-java/cpp-package-scanner.h b/plugins/language-support-cpp-java/cpp-package-scanner.h new file mode 100644 index 000000000..62fa1b60a --- /dev/null +++ b/plugins/language-support-cpp-java/cpp-package-scanner.h @@ -0,0 +1,62 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) Johannes Schmid 2011 + * + * anjuta is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * anjuta is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef _CPP_PACKAGE_SCANNER_H_ +#define _CPP_PACKAGE_SCANNER_H_ + +#include + +G_BEGIN_DECLS + +#define CPP_TYPE_PACKAGE_SCANNER (cpp_package_scanner_get_type ()) +#define CPP_PACKAGE_SCANNER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPP_TYPE_PACKAGE_SCANNER, CppPackageScanner)) +#define CPP_PACKAGE_SCANNER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CPP_TYPE_PACKAGE_SCANNER, CppPackageScannerClass)) +#define CPP_IS_PACKAGE_SCANNER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CPP_TYPE_PACKAGE_SCANNER)) +#define CPP_IS_PACKAGE_SCANNER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CPP_TYPE_PACKAGE_SCANNER)) +#define CPP_PACKAGE_SCANNER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CPP_TYPE_PACKAGE_SCANNER, CppPackageScannerClass)) + +typedef struct _CppPackageScannerClass CppPackageScannerClass; +typedef struct _CppPackageScanner CppPackageScanner; + +struct _CppPackageScannerClass +{ + AnjutaAsyncCommandClass parent_class; + +}; + +struct _CppPackageScanner +{ + AnjutaAsyncCommand parent_instance; + + gchar* package; + gchar* version; + GList* files; + +}; + +GType cpp_package_scanner_get_type (void) G_GNUC_CONST; +AnjutaCommand* cpp_package_scanner_new (const gchar* package, const gchar* version); +const gchar* cpp_package_scanner_get_package (CppPackageScanner* scanner); +const gchar* cpp_package_scanner_get_version (CppPackageScanner* scanner); +GList* cpp_package_scanner_get_files (CppPackageScanner* scanner); + + +G_END_DECLS + +#endif /* _CPP_PACKAGE_SCANNER_H_ */ diff --git a/plugins/language-support-cpp-java/cpp-packages.c b/plugins/language-support-cpp-java/cpp-packages.c dissimilarity index 62% index cf971be9f..4ec75eeb6 100644 --- a/plugins/language-support-cpp-java/cpp-packages.c +++ b/plugins/language-support-cpp-java/cpp-packages.c @@ -1,202 +1,266 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ -/* - * cpp-packages.c - * - * Copyright (C) 2011 - Johannes Schmid - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "cpp-packages.h" - -#include -#include -#include -#include - -typedef struct -{ - gchar* pkg; - gchar* version; -} PackageData; - -static int -pkg_data_compare (gpointer data1, gpointer pkg2) -{ - PackageData* pkg_data1 = data1; - - return strcmp (pkg_data1->pkg, (const gchar*) pkg2); -} - -static void -pkg_data_free (PackageData* data) -{ - g_free (data->pkg); - g_free (data->version); - g_free (data); -} - -static void -list_all_children (GList **children, GFile *dir) -{ - GFileEnumerator *list; - - list = g_file_enumerate_children (dir, - G_FILE_ATTRIBUTE_STANDARD_NAME, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - NULL, - NULL); - - if (list != NULL) - { - GFileInfo *info; - - while ((info = g_file_enumerator_next_file (list, NULL, NULL)) != NULL) - { - const gchar *name; - GFile *file; - - name = g_file_info_get_name (info); - file = g_file_get_child (dir, name); - g_object_unref (info); - - if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY) - { - list_all_children (children, file); - } - else - { - gchar* filename = g_file_get_path (file); - *children = g_list_prepend (*children, filename); - } - g_object_unref (file); - } - g_file_enumerator_close (list, NULL, NULL); - g_object_unref (list); - } -} - -static void -cpp_packages_add_package (IAnjutaSymbolManager* sm, - const gchar* pkg, - const gchar* version) -{ - GList* dirs = anjuta_pkg_config_get_directories (pkg, TRUE, NULL); - GList* dir; - GList* children = NULL; - for (dir = dirs; dir != NULL; dir = g_list_next (dir)) - { - GFile* file = g_file_new_for_path (dir->data); - list_all_children (&children, file); - } - g_message ("Adding package: %s", pkg); - if (children) - ianjuta_symbol_manager_add_package (sm, pkg, version, children, NULL); - anjuta_util_glist_strings_free (children); - anjuta_util_glist_strings_free (dirs); -} - -static GList* -cpp_packages_activate_package (IAnjutaSymbolManager* sm, const gchar* pkg, const gchar* version, - GList** packages_to_add) -{ - g_message ("Activate package: %s", pkg); - /* Only query each package once */ - if (g_list_find_custom (*packages_to_add, - pkg, (GCompareFunc) pkg_data_compare)) - return *packages_to_add; - if (!ianjuta_symbol_manager_activate_package (sm, pkg, version, NULL)) - { - GList* deps = anjuta_pkg_config_list_dependencies (pkg, NULL); - GList* dep; - PackageData* data = g_new0 (PackageData, 1); - for (dep = deps; dep != NULL; dep = g_list_next (dep)) - { - g_message ("Adding dependency: %s", dep->data); - gchar* dep_version = - anjuta_pkg_config_get_version (dep->data); - if (dep_version) - cpp_packages_activate_package (sm, dep->data, dep_version, packages_to_add); - g_free (dep_version); - } - anjuta_util_glist_strings_free (deps); - data->pkg = g_strdup(pkg); - data->version = g_strdup (version); - *packages_to_add = g_list_prepend (*packages_to_add, - data); - } - return *packages_to_add; -} - -static void -cpp_packages_load_real (AnjutaShell* shell, GError* error, IAnjutaProjectManager* pm) -{ - IAnjutaSymbolManager* sm = - anjuta_shell_get_interface (shell, IAnjutaSymbolManager, NULL); - GList* packages; - GList* pkg; - GList* packages_to_add = NULL; - - g_message ("Project loaded"); - - if (!pm || !sm) - return; - - packages = ianjuta_project_manager_get_packages (pm, NULL); - for (pkg = packages; pkg != NULL; pkg = g_list_next (pkg)) - { - gchar* version = - anjuta_pkg_config_get_version (pkg->data); - if (version) - { - cpp_packages_activate_package (sm, pkg->data, version, &packages_to_add); - } - g_free (version); - } - g_list_free (packages); - for (pkg = packages_to_add; pkg != NULL; pkg = g_list_next (pkg)) - { - PackageData* pkg_data = pkg->data; - cpp_packages_add_package (sm, pkg_data->pkg, pkg_data->version); - } - g_list_foreach (packages_to_add, (GFunc) pkg_data_free, NULL); - g_list_free (packages_to_add); -} - -void -cpp_packages_load (CppJavaPlugin* plugin) -{ - static gboolean init = FALSE; - AnjutaShell* shell = ANJUTA_PLUGIN (plugin)->shell; - IAnjutaProjectManager* pm = - anjuta_shell_get_interface (shell, IAnjutaProjectManager, NULL); - IAnjutaProject* project; - - if (init) - return; - init = TRUE; - - if (!pm) - return; - - g_message ("Connecting signal"); - - g_signal_connect_swapped (pm, "project-loaded", G_CALLBACK (cpp_packages_load_real), shell); - - project = ianjuta_project_manager_get_current_project (pm, NULL); - if (project && ianjuta_project_is_loaded (project, NULL)) - { - cpp_packages_load_real (shell, NULL, pm); - } -} +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) Johannes Schmid 2011 + * + * anjuta is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * anjuta is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "cpp-packages.h" +#include "cpp-package-scanner.h" + +#include +#include +#include +#include + +enum +{ + PROP_0, + PROP_PLUGIN +}; + +typedef struct +{ + gchar* pkg; + gchar* version; +} PackageData; + +static int +pkg_data_compare (gpointer data1, gpointer pkg2) +{ + PackageData* pkg_data1 = data1; + + return strcmp (pkg_data1->pkg, (const gchar*) pkg2); +} + +static void +pkg_data_free (PackageData* data) +{ + g_free (data->pkg); + g_free (data->version); + g_free (data); +} + + +G_DEFINE_TYPE (CppPackages, cpp_packages, G_TYPE_OBJECT); + +static GList* +cpp_packages_activate_package (IAnjutaSymbolManager* sm, const gchar* pkg, + GList** packages_to_add) +{ + gchar* name = g_strdup (pkg); + gchar* version; + gchar* c; + + /* Clean package name */ + for (c = name; *c != '\0'; c++) + { + if (g_ascii_isspace (*c)) + { + *c = '\0'; + break; + } + } + + version = anjuta_pkg_config_get_version (name); + if (!version) + { + g_free (name); + return *packages_to_add; + } + + /* Only query each package once */ + if (g_list_find_custom (*packages_to_add, + name, (GCompareFunc) pkg_data_compare)) + return *packages_to_add; + if (!ianjuta_symbol_manager_activate_package (sm, name, version, NULL)) + { + GList* deps = anjuta_pkg_config_list_dependencies (name, NULL); + GList* dep; + PackageData* data = g_new0 (PackageData, 1); + for (dep = deps; dep != NULL; dep = g_list_next (dep)) + { + cpp_packages_activate_package (sm, dep->data, packages_to_add); + } + anjuta_util_glist_strings_free (deps); + data->pkg = g_strdup (name); + data->version = g_strdup (version); + *packages_to_add = g_list_prepend (*packages_to_add, + data); + } + g_free (name); + return *packages_to_add; +} + +static void +on_package_ready (AnjutaCommand* command, + gint return_code, + IAnjutaSymbolManager* sm) +{ + CppPackageScanner* scanner = CPP_PACKAGE_SCANNER (command); + if (g_list_length (cpp_package_scanner_get_files (scanner))) + { + g_message ("Adding package: %s", cpp_package_scanner_get_package (scanner)); + ianjuta_symbol_manager_add_package (sm, + cpp_package_scanner_get_package (scanner), + cpp_package_scanner_get_version (scanner), + cpp_package_scanner_get_files (scanner), + NULL); + } + g_object_unref (command); +} + +static void +cpp_packages_load_real (CppPackages* packages, GError* error, IAnjutaProjectManager* pm) +{ + IAnjutaSymbolManager* sm = + anjuta_shell_get_interface (packages->plugin->shell, IAnjutaSymbolManager, NULL); + GList* pkgs; + GList* pkg; + GList* packages_to_add = NULL; + + if (!pm || !sm) + return; + + pkgs = ianjuta_project_manager_get_packages (pm, NULL); + for (pkg = pkgs; pkg != NULL; pkg = g_list_next (pkg)) + { + cpp_packages_activate_package (sm, pkg->data, &packages_to_add); + } + g_list_free (pkgs); + for (pkg = packages_to_add; pkg != NULL; pkg = g_list_next (pkg)) + { + PackageData* pkg_data = pkg->data; + AnjutaCommand* command = + cpp_package_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); + + anjuta_command_queue_start (packages->queue); +} + +void +cpp_packages_load (CppPackages* 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")); + if (!loaded) + { + cpp_packages_load_real (packages, NULL, pm); + g_object_set_data (G_OBJECT (project), "__cpp_packages_loaded", GINT_TO_POINTER (TRUE)); + } + } +} + +static void +cpp_packages_init (CppPackages *packages) +{ + packages->queue = anjuta_command_queue_new (ANJUTA_COMMAND_QUEUE_EXECUTE_MANUAL); +} + +static void +cpp_packages_finalize (GObject* object) +{ + CppPackages *packages = CPP_PACKAGES (object); + AnjutaShell* shell = packages->plugin->shell; + IAnjutaProjectManager* pm = + anjuta_shell_get_interface (shell, IAnjutaProjectManager, NULL); + + g_object_unref (packages->queue); + g_signal_handlers_disconnect_by_func (pm, cpp_packages_load_real, packages); + + G_OBJECT_CLASS (cpp_packages_parent_class)->finalize (object); +} + +static void +cpp_packages_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + CppPackages* packages; + + g_return_if_fail (CPP_IS_PACKAGES (object)); + + packages = CPP_PACKAGES (object); + + switch (prop_id) + { + case PROP_PLUGIN: + packages->plugin = ANJUTA_PLUGIN (g_value_get_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +cpp_packages_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + CppPackages* packages; + + g_return_if_fail (CPP_IS_PACKAGES (object)); + + packages = CPP_PACKAGES (object); + + switch (prop_id) + { + case PROP_PLUGIN: + g_value_set_object (value, G_OBJECT (packages->plugin)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +cpp_packages_class_init (CppPackagesClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = cpp_packages_finalize; + object_class->set_property = cpp_packages_set_property; + object_class->get_property = cpp_packages_get_property; + + g_object_class_install_property (object_class, + PROP_PLUGIN, + g_param_spec_object ("plugin", + "CppJavaPlugin", + "CppJavaPlugin", + ANJUTA_TYPE_PLUGIN, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); +} + +CppPackages* +cpp_packages_new (AnjutaPlugin* plugin) +{ + GObject* object = + g_object_new (CPP_TYPE_PACKAGES, + "plugin", plugin, + NULL); + return CPP_PACKAGES (object); +} diff --git a/plugins/language-support-cpp-java/cpp-packages.h b/plugins/language-support-cpp-java/cpp-packages.h dissimilarity index 79% index b176b0c74..84644bcf8 100644 --- a/plugins/language-support-cpp-java/cpp-packages.h +++ b/plugins/language-support-cpp-java/cpp-packages.h @@ -1,28 +1,57 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ -/* - * cpp-packages.h - * - * Copyright (C) 2011 - Johannes Schmid - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef CPP_PACKAGES_H -#define CPP_PACKAGES_H - -#include "plugin.h" - -void cpp_packages_load (CppJavaPlugin* plugin); - -#endif +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) Johannes Schmid 2011 + * + * anjuta is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * anjuta is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef _CPP_PACKAGES_H_ +#define _CPP_PACKAGES_H_ + +#include +#include + +G_BEGIN_DECLS + +#define CPP_TYPE_PACKAGES (cpp_packages_get_type ()) +#define CPP_PACKAGES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPP_TYPE_PACKAGES, CppPackages)) +#define CPP_PACKAGES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CPP_TYPE_PACKAGES, CppPackagesClass)) +#define CPP_IS_PACKAGES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CPP_TYPE_PACKAGES)) +#define CPP_IS_PACKAGES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CPP_TYPE_PACKAGES)) +#define CPP_PACKAGES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CPP_TYPE_PACKAGES, CppPackagesClass)) + +typedef struct _CppPackagesClass CppPackagesClass; +typedef struct _CppPackages CppPackages; + +struct _CppPackagesClass +{ + GObjectClass parent_class; +}; + +struct _CppPackages +{ + GObject parent_instance; + + AnjutaPlugin* plugin; + AnjutaCommandQueue* queue; +}; + +GType cpp_packages_get_type (void) G_GNUC_CONST; +CppPackages* cpp_packages_new (AnjutaPlugin* plugin); +void cpp_packages_load (CppPackages* packages); + +G_END_DECLS + +#endif /* _CPP_PACKAGES_H_ */ diff --git a/plugins/language-support-cpp-java/plugin.c b/plugins/language-support-cpp-java/plugin.c index 39996930f..33309d069 100644 --- a/plugins/language-support-cpp-java/plugin.c +++ b/plugins/language-support-cpp-java/plugin.c @@ -577,7 +577,10 @@ install_support (CppJavaPlugin *lang_plugin) lang_plugin); } } - + + lang_plugin->packages = cpp_packages_new (ANJUTA_PLUGIN (lang_plugin)); + cpp_packages_load (lang_plugin->packages); + lang_plugin->support_installed = TRUE; } @@ -614,8 +617,9 @@ uninstall_support (CppJavaPlugin *lang_plugin) on_glade_drop_possible, lang_plugin); g_signal_handlers_disconnect_by_func (lang_plugin->current_editor, on_glade_drop, lang_plugin); - - + + g_object_unref (lang_plugin->packages); + lang_plugin->packages = NULL; lang_plugin->support_installed = FALSE; } @@ -1033,8 +1037,6 @@ cpp_java_plugin_activate_plugin (AnjutaPlugin *plugin) on_value_removed_current_editor, plugin); - cpp_packages_load (lang_plugin); - initialized = FALSE; return TRUE; } @@ -1091,6 +1093,7 @@ cpp_java_plugin_instance_init (GObject *obj) plugin->uiid = 0; plugin->assist = NULL; plugin->settings = g_settings_new (PREF_SCHEMA); + plugin->packages = NULL; } static void diff --git a/plugins/language-support-cpp-java/plugin.h b/plugins/language-support-cpp-java/plugin.h index ed9ac3cc1..0060c5bf4 100644 --- a/plugins/language-support-cpp-java/plugin.h +++ b/plugins/language-support-cpp-java/plugin.h @@ -25,6 +25,7 @@ #include #include #include "cpp-java-assist.h" +#include "cpp-packages.h" extern GType cpp_java_plugin_get_type (GTypeModule *module); #define ANJUTA_TYPE_PLUGIN_CPP_JAVA (cpp_java_plugin_get_type (NULL)) @@ -71,6 +72,9 @@ struct _CppJavaPlugin { CppJavaAssist *assist; CppFileType filetype; + /* Packages */ + CppPackages* packages; + /* Preferences */ GtkBuilder* bxml; }; -- 2.11.4.GIT