[anjuta/newproject] Improve the import project plugin to allow choosing the project backend



commit bdf09fcbe79b1e6a25965e775dee9379c5335f5f
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Mon Dec 21 11:25:33 2009 +0100

    Improve the import project plugin to allow choosing the project backend

 configure.in                                       |    1 +
 plugins/dir-project/dir-project.plugin.in          |    2 +-
 plugins/mk-project/mk-project.plugin.in            |    2 +-
 plugins/project-import/plugin.c                    |   63 ++++++++++++-------
 plugins/project-manager/plugin.c                   |   63 ++++++++++++--------
 plugins/project-wizard/templates/Makefile.am       |    2 +-
 .../project-wizard/templates/directory/Makefile.am |    8 +++
 .../templates/directory/project.anjuta             |   51 ++++++++++++++++
 .../project-wizard/templates/mkfile/project.anjuta |   11 +++-
 .../templates/terminal/project.anjuta              |    9 +++-
 10 files changed, 159 insertions(+), 53 deletions(-)
---
diff --git a/configure.in b/configure.in
index 5721780..024d3a4 100644
--- a/configure.in
+++ b/configure.in
@@ -797,6 +797,7 @@ plugins/project-wizard/templates/gnome-applet/po/Makefile
 plugins/project-wizard/templates/library/Makefile
 plugins/project-wizard/templates/library/src/Makefile
 plugins/project-wizard/templates/library/po/Makefile
+plugins/project-wizard/templates/directory/Makefile
 plugins/project-wizard/templates/m4/Makefile
 plugins/am-project/Makefile
 plugins/mk-project/Makefile
diff --git a/plugins/dir-project/dir-project.plugin.in b/plugins/dir-project/dir-project.plugin.in
index 52f46c1..00cea2a 100644
--- a/plugins/dir-project/dir-project.plugin.in
+++ b/plugins/dir-project/dir-project.plugin.in
@@ -1,6 +1,6 @@
 [Anjuta Plugin]
 _Name=Directory backend
-_Description=Directory backend for project manager
+_Description=Directory project backend, read only source files, use it when other backend fails
 Location=dir-project:DirProjectPlugin
 Icon=dir-project-plugin-48.png
 Interfaces=IAnjutaProjectBackend
diff --git a/plugins/mk-project/mk-project.plugin.in b/plugins/mk-project/mk-project.plugin.in
index 543fc4c..45790c3 100644
--- a/plugins/mk-project/mk-project.plugin.in
+++ b/plugins/mk-project/mk-project.plugin.in
@@ -1,6 +1,6 @@
 [Anjuta Plugin]
 _Name=Makefile backend
-_Description=Makefile backend for project manager
+_Description=Makefile project backend, allowing only to read the project
 Location=mk-project:MkpPlugin
 Icon=mk-project-plugin-48.png
 Interfaces=IAnjutaProjectBackend
diff --git a/plugins/project-import/plugin.c b/plugins/project-import/plugin.c
index 44d9c21..6da9762 100644
--- a/plugins/project-import/plugin.c
+++ b/plugins/project-import/plugin.c
@@ -27,7 +27,6 @@
 #include <libanjuta/interfaces/ianjuta-file-loader.h>
 #include <libanjuta/interfaces/ianjuta-project-backend.h>
 #include <libanjuta/interfaces/ianjuta-vcs.h>
-#include <libanjuta/gbf-project.h>
 #include <libanjuta/anjuta-async-notify.h>
 
 #include "plugin.h"
@@ -37,6 +36,7 @@
 
 #define AM_PROJECT_FILE PACKAGE_DATA_DIR"/project/terminal/project.anjuta"
 #define MKFILE_PROJECT_FILE PACKAGE_DATA_DIR"/project/mkfile/project.anjuta"
+#define DIRECTORY_PROJECT_FILE PACKAGE_DATA_DIR"/project/directory/project.anjuta"
 
 static gpointer parent_class;
 
@@ -54,6 +54,8 @@ project_import_generate_file (AnjutaProjectImportPlugin* import_plugin, ProjectI
 		source_file = g_file_new_for_path (AM_PROJECT_FILE);
 	else if (!strcmp (import_plugin->backend_id, "make"))
 		source_file = g_file_new_for_path (MKFILE_PROJECT_FILE);
+	else if (!strcmp (import_plugin->backend_id, "directory"))
+		source_file = g_file_new_for_path (DIRECTORY_PROJECT_FILE);
 	else
 	{
 		/* We shouldn't get here, unless someone has upgraded their GBF */
@@ -153,47 +155,62 @@ project_import_import_project (AnjutaProjectImportPlugin *import_plugin, Project
 	GList *desc;
 	AnjutaPluginDescription *backend;
 	gchar *name, *project_file_name;
-	
+
+	/* Search for all valid project backend */
 	plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN(import_plugin)->shell, NULL);
 	descs = anjuta_plugin_manager_query (plugin_manager,
 										 "Anjuta Plugin",
 										 "Interfaces",
 										 "IAnjutaProjectBackend",
 										 NULL);	
-	for (desc = g_list_first (descs); desc != NULL; desc = g_list_next (desc)) {
+	for (desc = g_list_first (descs); desc != NULL;) {
 		IAnjutaProjectBackend *plugin;
 		gchar *location = NULL;
-		GbfProject* proj;	
+		GList *next;
 		
 		backend = (AnjutaPluginDescription *)desc->data;
 		anjuta_plugin_description_get_string (backend, "Anjuta Plugin", "Location", &location);
 		plugin = (IAnjutaProjectBackend *)anjuta_plugin_manager_get_plugin_by_id (plugin_manager, location);
+		g_message ("project probe location =%s=", location);
 		g_free (location);
 
-		/* Probe the backend to find out if the project directory is OK */
-		/* If probe() returns TRUE then we have a valid backend */
+		next = g_list_next (desc);
 		
-		proj= ianjuta_project_backend_new_project (plugin, NULL);
-		if (proj)
+		/* Probe the project directory to find if the backend can handle it */
+		if (ianjuta_project_backend_probe (plugin, source_dir, NULL) <= 0)
 		{
-			gchar *path;
-
-			path = g_file_get_path (source_dir);
-			if (gbf_project_probe (proj, path, NULL))
-			{
-				/* This is a valid backend for this root directory */
-				/* FIXME: Possibility of more than one valid backend? */
-				break;
-			}
-			g_object_unref (proj);
-			g_free (path);
+			/* Remove invalid backend */
+			descs = g_list_delete_link (descs, desc);
 		}
-		plugin = NULL;
+
+		desc = next;
+	}
+
+	if (descs == NULL)
+	{
 		backend = NULL;
 	}
+	else if (g_list_next (descs) == NULL)
+	{
+		backend =  (AnjutaPluginDescription *)descs->data;
+	}
+	else
+	{
+		/* Several backend are possible, ask the user to select one */
+		gchar *path = project_import_dialog_get_name (import_dialog);
+		gchar* message = g_strdup_printf (_("Please select a project backend to open %s."), path);
+		
+		g_free (path);
+		
+        backend = anjuta_plugin_manager_select (plugin_manager,
+		    _("Open With"),
+		    message,
+		    descs);
+		g_free (message);
+	}
 	g_list_free (descs);
-	
-	if (!backend)
+
+	if (backend == NULL)
 	{
 		gchar *path = project_import_dialog_get_name (import_dialog);
 
@@ -210,7 +227,7 @@ project_import_import_project (AnjutaProjectImportPlugin *import_plugin, Project
 
 		return FALSE;
 	}
-
+	
 	if (!anjuta_plugin_description_get_string (backend, "Project", "Supported-Project-Types", &import_plugin->backend_id))
 	{
 		import_plugin->backend_id = g_strdup ("unknown");
diff --git a/plugins/project-manager/plugin.c b/plugins/project-manager/plugin.c
index 171e6ac..f4d0d7e 100644
--- a/plugins/project-manager/plugin.c
+++ b/plugins/project-manager/plugin.c
@@ -1173,9 +1173,9 @@ project_manager_load_gbf (ProjectManagerPlugin *pm_plugin)
 	gchar *basename;
 	const gchar *root_uri;
 	GError *error = NULL;
-	GList *descs = NULL;
 	GList *desc;
 	IAnjutaProjectBackend *backend;
+	gint found = 0;
 	
 	root_uri = pm_plugin->project_root_uri;
 	
@@ -1189,32 +1189,47 @@ project_manager_load_gbf (ProjectManagerPlugin *pm_plugin)
 	
 	DEBUG_PRINT ("loading gbf backendâ?¦\n");
 	plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN(pm_plugin)->shell, NULL);
-	descs = anjuta_plugin_manager_query (plugin_manager,
-										 "Anjuta Plugin",
-										 "Interfaces",
-										 "IAnjutaProjectBackend",
-										 NULL);
-	backend = NULL;
-	for (desc = g_list_first (descs); desc != NULL; desc = g_list_next (desc)) {
-		AnjutaPluginDescription *backend_desc;
-		gchar *location = NULL;
-		IAnjutaProjectBackend *plugin;
-				
-		backend_desc = (AnjutaPluginDescription *)desc->data;
-		anjuta_plugin_description_get_string (backend_desc, "Anjuta Plugin", "Location", &location);
-		plugin = (IAnjutaProjectBackend *)anjuta_plugin_manager_get_plugin_by_id (plugin_manager, location);
-		g_message ("search plugin %s", location);
-		g_free (location);
 
-		if (ianjuta_project_backend_probe (plugin, dirfile, NULL))
-		{
-			/* Backend found */;
-			backend = plugin;
-			g_message ("Find backend");
-			break;
+	if (!anjuta_plugin_manager_is_active_plugin (plugin_manager, "IAnjutaProjectBackend"))
+	{
+		GList *descs = NULL;
+		
+		descs = anjuta_plugin_manager_query (plugin_manager,
+											 "Anjuta Plugin",
+											 "Interfaces",
+											 "IAnjutaProjectBackend",
+											 NULL);
+		backend = NULL;
+		for (desc = g_list_first (descs); desc != NULL; desc = g_list_next (desc)) {
+			AnjutaPluginDescription *backend_desc;
+			gchar *location = NULL;
+			IAnjutaProjectBackend *plugin;
+			gint backend_val;
+				
+			backend_desc = (AnjutaPluginDescription *)desc->data;
+			anjuta_plugin_description_get_string (backend_desc, "Anjuta Plugin", "Location", &location);
+			plugin = (IAnjutaProjectBackend *)anjuta_plugin_manager_get_plugin_by_id (plugin_manager, location);
+			g_message ("search plugin %s", location);
+			g_free (location);
+
+			backend_val = ianjuta_project_backend_probe (plugin, dirfile, NULL);
+			if (backend_val > found)
+			{
+				/* Backend found */;
+				backend = plugin;
+				found = backend_val;
+			}
 		}
+		g_list_free (descs);
+	}
+	else
+	{
+		/* A backend is already loaded, use it */
+		backend = IANJUTA_PROJECT_BACKEND (anjuta_shell_get_object (ANJUTA_PLUGIN (pm_plugin)->shell,
+                                        "IAnjutaProjectBackend", NULL));
+
+        g_object_ref (backend);
 	}
-	g_list_free (descs);
 	
 	if (!backend)
 	{
diff --git a/plugins/project-wizard/templates/Makefile.am b/plugins/project-wizard/templates/Makefile.am
index 3e0971b..a36c6f8 100644
--- a/plugins/project-wizard/templates/Makefile.am
+++ b/plugins/project-wizard/templates/Makefile.am
@@ -1,7 +1,7 @@
 
 SUBDIRS = minimal terminal cpp gtk anjuta-plugin \
 	gtkmm wxwin xlib xlib-dock gcj java gnome-applet\
-	python mkfile sdl library licenses m4
+	python mkfile sdl library directory licenses m4
 
 wizard_filesdir = $(anjuta_data_dir)/project
 wizard_files_DATA = \
diff --git a/plugins/project-wizard/templates/directory/Makefile.am b/plugins/project-wizard/templates/directory/Makefile.am
new file mode 100644
index 0000000..ffb141a
--- /dev/null
+++ b/plugins/project-wizard/templates/directory/Makefile.am
@@ -0,0 +1,8 @@
+
+wizard_filesdir = $(anjuta_data_dir)/project/directory
+wizard_files_DATA = \
+	project.anjuta
+
+EXTRA_DIST = $(wizard_files_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/project-wizard/templates/directory/project.anjuta b/plugins/project-wizard/templates/directory/project.anjuta
new file mode 100644
index 0000000..dd12c27
--- /dev/null
+++ b/plugins/project-wizard/templates/directory/project.anjuta
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<anjuta>
+	<plugin name="GBF Project Manager"
+            url="http://anjuta.org/plugins/";
+            mandatory="yes">
+		<require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaProjectManager"/>
+	</plugin>
+	<plugin name="Directory Project Backend"
+            url="http://anjuta.org/plugins/";
+            mandatory="yes">
+		<require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaProjectBackend"/>
+		<require group="Project"
+                 attribute="Supported-Project-Types"
+                 value="directory"/>
+	</plugin>
+	<plugin name="Symbol Browser"
+            url="http://anjuta.org/plugins/";
+            mandatory="yes">
+		<require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaSymbolManager"/>
+	</plugin>
+	<plugin name="Make Build System"
+            url="http://anjuta.org/plugins/";
+            mandatory="yes">
+		<require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaBuildable"/>
+		<require group="Build"
+                 attribute="Supported-Build-Types"
+                 value="make"/>
+	</plugin>
+	<plugin name="Task Manager"
+            url="http://anjuta.org/plugins/";
+            mandatory="no">
+		<require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaTodo"/>
+	</plugin>
+	<plugin name="Debug Manager"
+            url="http://anjuta.org/plugins/";
+            mandatory="no">
+		<require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaDebugManager"/>
+	</plugin>
+</anjuta>
diff --git a/plugins/project-wizard/templates/mkfile/project.anjuta b/plugins/project-wizard/templates/mkfile/project.anjuta
index 471e6e1..390fe09 100644
--- a/plugins/project-wizard/templates/mkfile/project.anjuta
+++ b/plugins/project-wizard/templates/mkfile/project.anjuta
@@ -6,9 +6,16 @@
 		<require group="Anjuta Plugin"
 		 attribute="Interfaces"
 		 value="IAnjutaProjectManager"/>
+	</plugin>
+	<plugin name="Makefile Project Backend"
+            url="http://anjuta.org/plugins/";
+            mandatory="yes">
+		<require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaProjectBackend"/>
 		<require group="Project"
-		 attribute="Supported-Project-Types"
-		 value="make"/>
+                 attribute="Supported-Project-Types"
+                 value="make"/>
 	</plugin>
 	<plugin name="Symbol Browser"
             url="http://anjuta.org/plugins/";
diff --git a/plugins/project-wizard/templates/terminal/project.anjuta b/plugins/project-wizard/templates/terminal/project.anjuta
index 2389e4c..68c60e6 100644
--- a/plugins/project-wizard/templates/terminal/project.anjuta
+++ b/plugins/project-wizard/templates/terminal/project.anjuta
@@ -1,11 +1,18 @@
 <?xml version="1.0"?>
 <anjuta>
-    <plugin name="GBF Project Manager"
+	<plugin name="GBF Project Manager"
             url="http://anjuta.org/plugins/";
             mandatory="yes">
 		<require group="Anjuta Plugin"
                  attribute="Interfaces"
                  value="IAnjutaProjectManager"/>
+	</plugin>
+	<plugin name="AutoTools Project Backend"
+            url="http://anjuta.org/plugins/";
+            mandatory="yes">
+		<require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaProjectBackend"/>
 		<require group="Project"
                  attribute="Supported-Project-Types"
                  value="automake"/>



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