[anjuta] project-import: Open a directory with Anjuta
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] project-import: Open a directory with Anjuta
- Date: Wed, 16 Jan 2013 21:33:40 +0000 (UTC)
commit dbddbeba7c09b91c91c0b0d993fd172b3089db47
Author: SÃbastien Granjoux <seb sfo free fr>
Date: Wed Jan 16 22:32:59 2013 +0100
project-import: Open a directory with Anjuta
If the directory contains an anjuta project file, it opens the project.
Else it shows the import project dialog.
anjuta.desktop.in.in | 2 +-
libanjuta/anjuta-utils.c | 96 +++++++++++-------
libanjuta/anjuta-utils.h | 1 +
.../project-import/anjuta-project-import.plugin.in | 2 +-
plugins/project-import/plugin.c | 103 ++++++++++++++++----
5 files changed, 144 insertions(+), 60 deletions(-)
---
diff --git a/anjuta.desktop.in.in b/anjuta.desktop.in.in
index 6c99c45..170180f 100644
--- a/anjuta.desktop.in.in
+++ b/anjuta.desktop.in.in
@@ -10,7 +10,7 @@ X-MultipleArgs=false
Type=Application
Categories=GNOME;GTK;Development;IDE;
StartupNotify=true
-MimeType=application/x-anjuta;application/x-anjuta-project-template;x-anjuta-compressed-project-template
+MimeType=application/x-anjuta;application/x-anjuta-project-template;x-anjuta-compressed-project-template;inode/directory
X-GNOME-DocPath=anjuta/anjuta-manual.xml
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=anjuta
diff --git a/libanjuta/anjuta-utils.c b/libanjuta/anjuta-utils.c
index f8ddd26..2b6dad8 100644
--- a/libanjuta/anjuta-utils.c
+++ b/libanjuta/anjuta-utils.c
@@ -1545,6 +1545,58 @@ anjuta_util_is_template_file (const gchar *filename)
}
/**
+ * anjuta_util_get_file_info_mine_type:
+ * @info: the file information object
+ *
+ * Return the mime type corresponding to a file infor object.
+ *
+ * Returns: The mime type as a newly allocated string that must be freed with
+ * g_free() or %NULL if the mime type cannot be found.
+ */
+gchar *
+anjuta_util_get_file_info_mime_type (GFileInfo *info)
+{
+ gchar *mime_type = NULL;
+ const gchar *extension;
+ const gchar *name;
+
+ g_return_val_if_fail (info != NULL, NULL);
+
+
+ /* If Anjuta is not installed in system gnome prefix, the mime types
+ * may not have been correctly registed. In that case, we use the
+ * following mime detection
+ */
+ name = g_file_info_get_name (info);
+ extension = strrchr(name, '.');
+ if ((extension != NULL) && (extension != name))
+ {
+ const static struct {gchar *extension; gchar *type;} anjuta_types[] = {
+ {"anjuta", "application/x-anjuta"},
+ {"prj", "application/x-anjuta-old"},
+ {NULL, NULL}};
+ gint i;
+
+ for (i = 0; anjuta_types[i].extension != NULL; i++)
+ {
+ if (strcmp(extension + 1, anjuta_types[i].extension) == 0)
+ {
+ mime_type = g_strdup (anjuta_types[i].type);
+ break;
+ }
+ }
+ }
+
+ /* Use mime database if it is not an Anjuta type */
+ if (mime_type == NULL)
+ {
+ mime_type = g_content_type_get_mime_type (g_file_info_get_content_type(info));
+ }
+
+ return mime_type;
+}
+
+/**
* anjuta_util_get_file_mine_type:
* @file: the file
*
@@ -1563,47 +1615,15 @@ anjuta_util_get_file_mime_type (GFile *file)
/* Get file information, check that the file exist at the same time */
info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- G_FILE_QUERY_INFO_NONE,
- NULL,
- NULL);
+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
if (info != NULL)
{
- const gchar *extension;
- gchar *name;
-
- /* If Anjuta is not installed in system gnome prefix, the mime types
- * may not have been correctly registed. In that case, we use the
- * following mime detection
- */
- name = g_file_get_basename (file);
- extension = strrchr(name, '.');
- if (extension != NULL)
- {
- const static struct {gchar *extension; gchar *type;} anjuta_types[] = {
- {"anjuta", "application/x-anjuta"},
- {"prj", "application/x-anjuta-old"},
- {NULL, NULL}};
- gint i;
-
- for (i = 0; anjuta_types[i].extension != NULL; i++)
- {
- if (strcmp(extension + 1, anjuta_types[i].extension) == 0)
- {
- mime_type = g_strdup (anjuta_types[i].type);
- break;
- }
- }
- }
- g_free (name);
-
- /* Use mime database if it is not an Anjuta type */
- if (mime_type == NULL)
- {
- mime_type = g_content_type_get_mime_type (g_file_info_get_content_type(info));
- }
-
+ mime_type = anjuta_util_get_file_info_mime_type (info);
g_object_unref (info);
}
diff --git a/libanjuta/anjuta-utils.h b/libanjuta/anjuta-utils.h
index e2dd960..66e7a61 100644
--- a/libanjuta/anjuta-utils.h
+++ b/libanjuta/anjuta-utils.h
@@ -140,6 +140,7 @@ gchar* anjuta_util_str_middle_truncate (const gchar *string,
gboolean anjuta_util_is_project_file (const gchar *filename);
gboolean anjuta_util_is_template_file (const gchar *filename);
gchar* anjuta_util_get_file_mime_type (GFile *file);
+gchar* anjuta_util_get_file_info_mime_type (GFileInfo *info);
gchar* anjuta_util_get_local_path_from_uri (const gchar *uri);
void anjuta_util_help_display (GtkWidget *parent,
diff --git a/plugins/project-import/anjuta-project-import.plugin.in b/plugins/project-import/anjuta-project-import.plugin.in
index 365aa7e..77b3fbb 100644
--- a/plugins/project-import/anjuta-project-import.plugin.in
+++ b/plugins/project-import/anjuta-project-import.plugin.in
@@ -7,7 +7,7 @@ UserActivatable=no
Interfaces=IAnjutaWizard,IAnjutaFile
[File Loader]
-SupportedMimeTypes=application/x-anjuta-old
+SupportedMimeTypes=application/x-anjuta-old,inode/directory
[Wizard]
_Title=Project from Existing Sources
diff --git a/plugins/project-import/plugin.c b/plugins/project-import/plugin.c
index a4a3c9f..1580279 100644
--- a/plugins/project-import/plugin.c
+++ b/plugins/project-import/plugin.c
@@ -22,6 +22,7 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <libanjuta/anjuta-debug.h>
+#include <libanjuta/anjuta-utils.h>
#include <libanjuta/interfaces/ianjuta-wizard.h>
#include <libanjuta/interfaces/ianjuta-file.h>
#include <libanjuta/interfaces/ianjuta-file-loader.h>
@@ -546,31 +547,93 @@ iwizard_iface_init (IAnjutaWizardIface *iface)
static void
ifile_open (IAnjutaFile *ifile, GFile* file, GError **err)
{
- gchar *ext, *project_name;
- GFile *dir;
- ProjectImportDialog* pi;
AnjutaProjectImportPlugin* plugin = ANJUTA_PLUGIN_PROJECT_IMPORT (ifile);
- gchar* uri = g_file_get_uri (file);
- AnjutaPluginManager *plugin_manager;
-
- g_return_if_fail (uri != NULL && strlen (uri) > 0);
-
- dir = g_file_get_parent (file);
- project_name = g_path_get_basename (uri);
- ext = strrchr (project_name, '.');
- if (ext)
- *ext = '\0';
+ gchar *mime_type;
- plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN (plugin)->shell, NULL);
+ g_return_if_fail (G_IS_FILE (file));
+
+ mime_type = anjuta_util_get_file_mime_type (file);
+ if (g_strcmp0 (mime_type,"application/x-anjuta-old") == 0)
+ {
+ /* Automatically import old Anjuta project */
+ gchar *ext, *project_name;
+ GFile *dir;
+ ProjectImportDialog* pi;
+ AnjutaPluginManager *plugin_manager;
+
+ dir = g_file_get_parent (file);
+ project_name = g_file_get_basename (file);
+ ext = strrchr (project_name, '.');
+ if (ext)
+ *ext = '\0';
+
+ plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN (plugin)->shell, NULL);
- pi = project_import_dialog_new (plugin_manager, project_name, dir);
- g_signal_connect (pi, "response", G_CALLBACK (import_dialog_response), plugin);
+ pi = project_import_dialog_new (plugin_manager, project_name, dir);
+ g_signal_connect (pi, "response", G_CALLBACK (import_dialog_response), plugin);
- gtk_widget_show (GTK_WIDGET (pi));
+ gtk_widget_show (GTK_WIDGET (pi));
- g_object_unref (dir);
- g_free (project_name);
- g_free (uri);
+ g_object_unref (dir);
+ g_free (project_name);
+ }
+ else if (g_strcmp0 (mime_type,"inode/directory") == 0)
+ {
+ GFileEnumerator *dir;
+
+ dir = g_file_enumerate_children (file,
+ G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL,
+ NULL);
+ if (dir)
+ {
+ /* Look for anjuta project file in the directory */
+ GFileInfo *info;
+
+ for (info = g_file_enumerator_next_file (dir, NULL, NULL); info != NULL; info = g_file_enumerator_next_file (dir, NULL, NULL))
+ {
+ gchar *mime_type = anjuta_util_get_file_info_mime_type (info);
+
+ if (g_strcmp0 (mime_type, "application/x-anjuta") == 0)
+ {
+ /* Open the first anjuta project file */
+ IAnjutaFileLoader *loader;
+
+ loader = anjuta_shell_get_interface(ANJUTA_PLUGIN (plugin)->shell, IAnjutaFileLoader, NULL);
+ if (loader != NULL)
+ {
+ GFile* project_file = g_file_get_child (file, g_file_info_get_name(info));
+ ianjuta_file_loader_load(loader, project_file, FALSE, NULL);
+ g_object_unref (project_file);
+ }
+ g_free (mime_type);
+ g_object_unref (info);
+ break;
+ }
+ g_free (mime_type);
+ g_object_unref (info);
+ }
+ if (info == NULL)
+ {
+ /* Else import the directory */
+ ProjectImportDialog* pi;
+ AnjutaPluginManager *plugin_manager;
+ gchar *basename;
+
+ plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN (plugin)->shell, NULL);
+
+ basename = g_file_get_basename (file);
+ pi = project_import_dialog_new (plugin_manager, basename, file);
+ g_free (basename);
+ g_signal_connect (pi, "response", G_CALLBACK (import_dialog_response), plugin);
+
+ gtk_widget_show (GTK_WIDGET (pi));
+ }
+ g_object_unref (dir);
+ }
+ }
+ g_free (mime_type);
}
static GFile*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]