anjuta r4456 - in trunk: . libanjuta plugins/document-manager plugins/file-loader src



Author: sgranjoux
Date: Fri Dec 19 20:27:15 2008
New Revision: 4456
URL: http://svn.gnome.org/viewvc/anjuta?rev=4456&view=rev

Log:
	* src/anjuta.c,
	libanjuta/anjuta-utils.c,
	libanjuta/anjuta-utils.h:
	Partial fix for #511589 - Anjuta uses GNOME-VFS

	* plugins/file-loader/plugin.c:
	Do not use fragment in URI converted to GFile
	Remove recent menu item if destination cannot be opened
	Fix #309664 - Some file types impossible to open In Anjuta

	* plugins/document-manager/anjuta-docman.c:
	No need to handle fragment in URI returned by GFile

	* plugins/file-loader/Makefile.am:
	Define G_LOG_DOMAIN for file loader plugin


Modified:
   trunk/ChangeLog
   trunk/libanjuta/anjuta-utils.c
   trunk/libanjuta/anjuta-utils.h
   trunk/plugins/document-manager/anjuta-docman.c
   trunk/plugins/file-loader/Makefile.am
   trunk/plugins/file-loader/plugin.c
   trunk/src/anjuta.c

Modified: trunk/libanjuta/anjuta-utils.c
==============================================================================
--- trunk/libanjuta/anjuta-utils.c	(original)
+++ trunk/libanjuta/anjuta-utils.c	Fri Dec 19 20:27:15 2008
@@ -1118,63 +1118,89 @@
 	}
 }
 
+/**
+ * anjuta_util_is_project_file:
+ * @filename: the file name
+ *
+ * Return TRUE if the file is an anjuta project file. It is implemented by
+ * checking only the file extension. So it does not check the existence
+ * of the file. But it is working on an URI if it does not containt a
+ * fragment.
+ *
+ * Returns: TRUE if the file is a project file, else FALSE
+ */
 gboolean
-anjuta_util_path_has_extension (const gchar *path, const gchar *ext)
+anjuta_util_is_project_file (const gchar *filename)
 {
-	if (strlen (path) <= strlen (ext))
-		return FALSE;
-	if ((path[strlen (path) - strlen (ext) - 1] == '.') &&
-		(strcmp (&path[strlen (path) - strlen (ext)], ext) == 0))
-		return TRUE;
-	return FALSE;
+	gsize len = strlen (filename);
+	return (len > 8) && (strcmp (filename + len - 7, ".anjuta") == 0);
 }
 
+/**
+ * anjuta_util_get_file_mine_type:
+ * @file: the file
+ *
+ * Check if a file exists and return its mime type.
+ *
+ * Returns: NULL if the corresponding file doesn't exist or the mime type as a newly
+ * allocated string that must be freed with g_free().
+ */
 gchar *
-anjuta_util_get_uri_mime_type (const gchar *uri)
+anjuta_util_get_file_mime_type (GFile *file)
 {
-	GnomeVFSURI *vfs_uri;
-	const gchar *path;
-	gchar *mime_type;
+	GFileInfo *info;
+	gchar *mime_type = NULL;
 	
-	g_return_val_if_fail (uri != NULL, NULL);
+	g_return_val_if_fail (file != NULL, NULL);
 	
-	vfs_uri = gnome_vfs_uri_new (uri);
-	if (vfs_uri)
-		path = gnome_vfs_uri_get_path (vfs_uri);
-	else
-		path = NULL;
+	/* 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);
 	
-	/* 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
-	 */
-	if (!path)
+	if (info != NULL)
 	{
-		mime_type = gnome_vfs_get_slow_mime_type (uri);
-	}
-	else if (anjuta_util_path_has_extension (path, "anjuta"))
-	{
-		mime_type = g_strdup ("application/x-anjuta");
-	}
-	else if (anjuta_util_path_has_extension (path, "prj"))
-	{
-		mime_type = g_strdup ("application/x-anjuta-old");
-	}
-	else if (anjuta_util_path_has_extension (path, "ui"))
-	{
-		mime_type = g_strdup ("text/xml");
-	}
-	else if (anjuta_util_path_has_extension (path, "glade"))
-	{
-		mime_type = g_strdup ("application/x-glade");
-	}
-	else
-	{
-		mime_type = gnome_vfs_get_slow_mime_type (uri);
-	}
+		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"},
+									{"ui", "text/xml"},
+									{"glade", "application/x-glade"},
+									{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);
 	
-	if (vfs_uri)
-		gnome_vfs_uri_unref (vfs_uri);
+		/* 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));
+		}
+		
+		g_object_unref (info);
+	}
+
 	return mime_type;
 }
 
@@ -1520,7 +1546,7 @@
 
 	if (uri == NULL)
 	{
-		anjuta_util_dialog_error (parent, _("Unable to display help. Please make sure Anjuta "
+		anjuta_util_dialog_error (GTK_WINDOW (parent), _("Unable to display help. Please make sure Anjuta "
 								  "documentation package is install. It can be downloaded "
 								  "from http://anjuta.org";));
 

Modified: trunk/libanjuta/anjuta-utils.h
==============================================================================
--- trunk/libanjuta/anjuta-utils.h	(original)
+++ trunk/libanjuta/anjuta-utils.h	Fri Dec 19 20:27:15 2008
@@ -110,7 +110,6 @@
 
 gchar* anjuta_util_escape_quotes(const gchar* str);
 
-gboolean anjuta_util_path_has_extension (const gchar *path, const gchar *ext);
 gchar* anjuta_util_get_real_path (const gchar *path);
 
 gchar* anjuta_util_uri_get_dirname (const gchar *uri);
@@ -119,7 +118,8 @@
 gchar* anjuta_util_str_middle_truncate (const gchar *string,
 										 guint        truncate_length);
 
-gchar* anjuta_util_get_uri_mime_type (const gchar *uri);
+gboolean anjuta_util_is_project_file (const gchar *filename);
+gchar* anjuta_util_get_file_mime_type (GFile *file);
 gchar* anjuta_util_get_local_path_from_uri (const gchar *uri);
 
 void anjuta_util_help_display (GtkWidget   *parent,

Modified: trunk/plugins/document-manager/anjuta-docman.c
==============================================================================
--- trunk/plugins/document-manager/anjuta-docman.c	(original)
+++ trunk/plugins/document-manager/anjuta-docman.c	Fri Dec 19 20:27:15 2008
@@ -1252,25 +1252,11 @@
 		return NULL;
 	}
 	
-	gchar* uri = g_file_get_uri (file);
-	const gchar* line_str;
-	GFile* real_file;
-	
-	if ((line_str = strstr(uri, "#")) && line <= 0)
-	{
-		line = atoi (line_str + 1);
-		gchar* new_uri = g_strndup (uri, line_str - uri);
-		real_file = g_file_new_for_uri(new_uri);
-		g_free (new_uri);
-	}
-	else
-		real_file = g_file_dup (file);
-	
 	/* if possible, use a document that's already open */
-	doc = anjuta_docman_get_document_for_file (docman, real_file);
+	doc = anjuta_docman_get_document_for_file (docman, file);
 	if (doc == NULL)
 	{
-		te = anjuta_docman_add_editor (docman, real_file, NULL);
+		te = anjuta_docman_add_editor (docman, file, NULL);
 		doc = IANJUTA_DOCUMENT (te);
 	}
 	else if (IANJUTA_IS_EDITOR (doc))
@@ -1309,7 +1295,6 @@
 		ianjuta_document_grab_focus (IANJUTA_DOCUMENT (doc), NULL);
 	}
 	
-	g_object_unref (real_file);
 	return te;
 }
 

Modified: trunk/plugins/file-loader/Makefile.am
==============================================================================
--- trunk/plugins/file-loader/Makefile.am	(original)
+++ trunk/plugins/file-loader/Makefile.am	Fri Dec 19 20:27:15 2008
@@ -19,7 +19,8 @@
 AM_CPPFLAGS = \
 	$(WARN_CFLAGS) \
 	$(DEPRECATED_FLAGS) \
-	$(LIBANJUTA_CFLAGS)
+	$(LIBANJUTA_CFLAGS) \
+	-DG_LOG_DOMAIN=\"libanjuta-loader\"
 
 # Where to install the plugin
 plugindir = $(anjuta_plugin_dir)

Modified: trunk/plugins/file-loader/plugin.c
==============================================================================
--- trunk/plugins/file-loader/plugin.c	(original)
+++ trunk/plugins/file-loader/plugin.c	Fri Dec 19 20:27:15 2008
@@ -63,35 +63,40 @@
 		return 0;
 }
 
+/* The add argument is here to remember that recent menu items should be removed
+ * when the destination does not exist anymore */
 static void
-set_recent_file (AnjutaFileLoaderPlugin *plugin, const gchar *uri,
-				 const gchar *mime)
+update_recent_file (AnjutaFileLoaderPlugin *plugin, const gchar *uri,
+				 const gchar *mime, gboolean add)
 {
-	GtkRecentData *recent_data;
-	gchar *name;
 	
-	DEBUG_PRINT ("Adding recent item of mimi-type: %s", mime);
-	
-	name = g_path_get_basename (uri);
+	if (add)
+	{
+		GtkRecentData *recent_data;
 	
-	recent_data = g_slice_new (GtkRecentData);
+		recent_data = g_slice_new (GtkRecentData);
 
-	recent_data->display_name   = name;
-	recent_data->description    = NULL;
-	recent_data->mime_type      = (gchar *)mime;
-	recent_data->app_name       = (gchar *) g_get_application_name ();
-	recent_data->app_exec       = g_strjoin (" ", g_get_prgname (), "%u", NULL);
-	recent_data->groups         = NULL;
-	recent_data->is_private     = FALSE;
+		recent_data->display_name = NULL;
+		recent_data->description = NULL;
+		recent_data->mime_type = (gchar *)mime;
+		recent_data->app_name = (gchar *) g_get_application_name ();
+		recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
+		recent_data->groups = NULL;
+		recent_data->is_private = FALSE;
+	
+		if (!gtk_recent_manager_add_full (plugin->recent_manager, uri, recent_data))
+		{
+      		g_warning ("Unable to add '%s' to the list of recently used documents", uri);
+		}
 
-	if (!gtk_recent_manager_add_full (plugin->recent_manager, uri, recent_data))
+		g_free (recent_data->app_exec);
+		g_slice_free (GtkRecentData, recent_data);
+	}
+	else
 	{
-      		g_warning ("Unable to add '%s' to the list of recently used documents", uri);
+		gtk_recent_manager_remove_item (plugin->recent_manager, uri, NULL);
 	}
 
-	g_free (name);
-	g_free (recent_data->app_exec);
-	g_slice_free (GtkRecentData, recent_data);
 }
 
 static void
@@ -108,25 +113,8 @@
 							  g_basename (uri), errmsg);
 }
 
-static gchar *
-get_supertype_from_mime_type (const gchar *mime_type)
-{
-	gchar *supertype;
-	gchar *delim;
-	gchar *retval;
-	
-	supertype = g_strdup (mime_type);
-	delim = strchr (supertype, '/');
-	g_return_val_if_fail (delim != NULL, supertype);
-
-	*delim = '\0';
-	retval = g_strconcat (supertype, "/*", NULL);
-	g_free(supertype);
-	return retval;
-}
-
 static GList *
-get_available_plugins_for_mime (AnjutaFileLoaderPlugin* plugin,
+get_available_plugins_for_mime (AnjutaPlugin* plugin,
 							   const gchar *mime_type)
 {
 	AnjutaPluginManager *plugin_manager;
@@ -134,8 +122,10 @@
 	
 	g_return_val_if_fail (mime_type != NULL, NULL);
 	
-	plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN(plugin)->shell,
+	plugin_manager = anjuta_shell_get_plugin_manager (plugin->shell,
 													  NULL);
+	
+	/* Check an exact match */
 	plugin_descs = anjuta_plugin_manager_query (plugin_manager,
 												"Anjuta Plugin",
 												"Interfaces", "IAnjutaFile",
@@ -143,17 +133,55 @@
 												"SupportedMimeTypes",
 												mime_type,
 												NULL);
-	if (!plugin_descs);
+	
+	/* Check for plugins supporting one supertype */
+	if (plugin_descs == NULL)
 	{
-		gchar* supertype = get_supertype_from_mime_type (mime_type);
-		plugin_descs = anjuta_plugin_manager_query (plugin_manager,
+		GList *node;
+		GList *loader_descs = NULL;	
+		
+		loader_descs = anjuta_plugin_manager_query (plugin_manager,
 												"Anjuta Plugin",
 												"Interfaces", "IAnjutaFile",
-												"File Loader",
-												"SupportedMimeTypes",
-												supertype,
 												NULL);
-		g_free (supertype);
+		for (node = g_list_first (loader_descs); node != NULL; node = g_list_next (node))
+		{
+			gchar *value;
+			
+			if (anjuta_plugin_description_get_string ((AnjutaPluginDescription *)node->data,
+													  "File Loader", "SupportedMimeTypes", &value))
+			{
+				gchar **split_value;
+				
+				split_value = g_strsplit (value, ",", -1);
+				g_free (value);
+				if (split_value)
+				{
+					gchar **mime;
+					
+					for (mime = split_value; *mime != NULL; mime++)
+					{
+						/* The following line is working on unix only where
+						 * content and mime type are the same. Normally the
+						 * mime type has to be converted to a content type.
+						 * But it is a recent (glib 2.18) function, I think we can
+						 * wait a bit to fix this */
+						if (g_content_type_is_a (mime_type, *mime))
+						{
+							gchar *loc;
+							anjuta_plugin_description_get_string ((AnjutaPluginDescription *)node->data,
+													  "Anjuta Plugin", "Location", &loc);
+							
+							plugin_descs = g_list_prepend (plugin_descs, node->data);
+							break;
+						}
+					}
+				}
+				g_strfreev (split_value);
+			}
+		}
+		g_list_free (loader_descs);
+		plugin_descs = g_list_reverse (plugin_descs);
 	}
 	
 	return plugin_descs;
@@ -207,7 +235,7 @@
 	gtk_menu_append (menu, menuitem);
 	
 	/* Open with plugins menu items */
-	plugin_descs = get_available_plugins_for_mime (plugin, mime_type);
+	plugin_descs = get_available_plugins_for_mime (ANJUTA_PLUGIN (plugin), mime_type);
 	snode = plugin_descs;
 	while (snode)
 	{
@@ -304,7 +332,7 @@
 				{
 					GFile* file = g_file_new_for_uri (uri);
 					ianjuta_file_open (IANJUTA_FILE (loaded_plugin), file, NULL);
-					set_recent_file (plugin, uri, mime_type);
+					update_recent_file (plugin, uri, mime_type, TRUE);
 					g_object_unref (file);
 				}
 				else
@@ -330,10 +358,7 @@
 				launch_application_failure (plugin, uri, error->message);
 				g_error_free (error);
 			}
-			else
-			{
-				set_recent_file (plugin, uri, mime_type);
-			}
+			update_recent_file (plugin, uri, mime_type, error == NULL);
 			g_list_free (uris);
 		}
 	}
@@ -344,28 +369,6 @@
 	gtk_widget_destroy (dialog);
 }
 
-static gboolean
-launch_in_default_application (AnjutaFileLoaderPlugin *plugin,
-							   const gchar *mime_type, const gchar *uri)
-{
-	GAppInfo *appinfo;
-	GList *uris = NULL;
-
-	uris = g_list_prepend (uris, (gpointer)uri);
-
-	appinfo = g_app_info_get_default_for_type (mime_type, TRUE);
-	if (appinfo)
-	{
-		if (!g_app_info_launch_uris (appinfo, uris, NULL, NULL))
-		{
-			open_with_dialog (plugin, uri, mime_type);
-		}
-		g_object_unref (G_OBJECT (appinfo));
-	}
-	g_list_free (uris);
-	return TRUE;
-}
-
 static void
 open_file (AnjutaFileLoaderPlugin *plugin, const gchar *uri)
 {
@@ -380,12 +383,8 @@
 	g_free (path);
 	g_free (dirname);
 	
-	
-	/* FIXME: We have to manage the error to know if we have to remove the recent file
-	 */
 	ianjuta_file_loader_load (IANJUTA_FILE_LOADER (plugin),
 							  file, FALSE, NULL);
-	
 	g_object_unref (file);
 }
 
@@ -708,28 +707,25 @@
 }
 
 static void
-open_file_with (AnjutaFileLoaderPlugin *plugin, GtkMenuItem *menuitem,
+open_uri_with (AnjutaFileLoaderPlugin *plugin, GtkMenuItem *menuitem,
 				const gchar *uri)
 {
-	GList *mime_apps;
-	GAppInfo *mime_app;
-	gchar *mime_type;
-	gint idx;
+	GAppInfo *app;
 	AnjutaPluginDescription *desc;
-	AnjutaPluginManager *plugin_manager;
+	const gchar *mime_type;
 	
-	idx = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem), "index"));
+	/* Open with plugin */
 	desc = (AnjutaPluginDescription*) g_object_get_data (G_OBJECT (menuitem),
 														 "desc");
-	plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN (plugin)->shell,
-													  NULL);
-	mime_type = anjuta_util_get_uri_mime_type (uri);
-	mime_apps = g_app_info_get_all_for_type (mime_type);
-	
-	/* Open with plugin */
+	mime_type = (const gchar*) g_object_get_data (G_OBJECT (menuitem),
+														 "mime_type");
 	if (desc)
 	{
+		AnjutaPluginManager *plugin_manager;
 		gchar *location = NULL;
+
+		plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_PLUGIN (plugin)->shell,
+	 														  NULL);
 		
 		anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
 											  "Location", &location);
@@ -744,9 +740,12 @@
 			if (loaded_plugin)
 			{
 				GFile* file = g_file_new_for_uri (uri);
-				ianjuta_file_open (IANJUTA_FILE (loaded_plugin), file, NULL);
-				set_recent_file (plugin, uri, mime_type);
+				GError *error = NULL;
+				
+				ianjuta_file_open (IANJUTA_FILE (loaded_plugin), file, &error);
 				g_object_unref (file);
+				update_recent_file (plugin, uri, mime_type, error == NULL);
+				g_free (error);
 			}
 			else
 			{
@@ -759,23 +758,25 @@
 	}
 	else
 	{
-		GList *uris = NULL;
-		GError *error = NULL;
-		
-		mime_app = g_list_nth_data (mime_apps, idx);
-		uris = g_list_prepend (uris, (gpointer)uri);
-		g_app_info_launch_uris (mime_app, uris, NULL, &error);
-		if (error)
+		/* Open with application */
+		app = (GAppInfo *) g_object_get_data (G_OBJECT (menuitem),
+															 "app");
+		if (app)
 		{
-			launch_application_failure (plugin, uri, error->message);
-			g_error_free (error);
+			GList *uris = NULL;
+			GError *error = NULL;
+		
+			uris = g_list_prepend (uris, (gpointer)uri);
+			g_app_info_launch_uris (app, uris, NULL, &error);
+			g_list_free (uris);
+			if (error)
+			{
+				launch_application_failure (plugin, uri, error->message);
+				g_error_free (error);
+			}
+			update_recent_file (plugin, uri, mime_type, error == NULL);
 		}
-		else
-			set_recent_file (plugin, uri, mime_type);
-		g_list_free (uris);
 	}
-	g_list_free (mime_apps);
-	g_free (mime_type);
 }
 
 static void
@@ -789,7 +790,7 @@
 fm_open_with (GtkMenuItem *menuitem, AnjutaFileLoaderPlugin *plugin)
 {
 	if (plugin->fm_current_uri)
-		open_file_with (plugin, menuitem, plugin->fm_current_uri);
+		open_uri_with (plugin, menuitem, plugin->fm_current_uri);
 }
 
 static void
@@ -803,7 +804,7 @@
 pm_open_with (GtkMenuItem *menuitem, AnjutaFileLoaderPlugin *plugin)
 {
 	if (plugin->pm_current_uri)
-		open_file_with (plugin, menuitem, plugin->pm_current_uri);
+		open_uri_with (plugin, menuitem, plugin->pm_current_uri);
 }
 
 static GtkActionEntry actions_file[] = {
@@ -859,13 +860,12 @@
 						  const gchar *uri, GCallback callback,
 						  gpointer callback_data)
 {
-	GList *mime_apps, *node;
-	GAppInfo *mime_app;
-	GList *plugin_descs, *snode;
+	GList *mime_apps;
+	GList *plugin_descs;
+	GList *node;	
 	GtkWidget *menu, *menuitem;
 	gchar *mime_type;
-	gint idx;
-	gboolean ret;
+	GFile *file;
 	
 	g_return_val_if_fail (GTK_IS_MENU_ITEM (parentmenu), FALSE);
 	
@@ -873,21 +873,20 @@
 	gtk_widget_show (menu);
 	gtk_menu_item_set_submenu (GTK_MENU_ITEM (parentmenu), menu);
 	
-	mime_type = anjuta_util_get_uri_mime_type (uri);
+	file = g_file_new_for_uri (uri);
+	mime_type = anjuta_util_get_file_mime_type (file);
+	g_object_unref (file);
 	if (mime_type == NULL)
 		return FALSE;
 	
-	idx = 0;
-	
 	/* Open with plugins menu items */
-	plugin_descs = get_available_plugins_for_mime (plugin, mime_type);
-	snode = plugin_descs;
-	while (snode)
+	plugin_descs = get_available_plugins_for_mime (ANJUTA_PLUGIN (plugin), mime_type);
+	for (node = plugin_descs; node != NULL; node = g_list_next (node))
 	{
 		gchar *name;
 		AnjutaPluginDescription *desc;
 		
-		desc = (AnjutaPluginDescription *)(snode->data);
+		desc = (AnjutaPluginDescription *)(node->data);
 		name = NULL;
 		anjuta_plugin_description_get_locale_string (desc, "File Loader",
 													 "Title", &name);
@@ -902,54 +901,58 @@
 												  "Location", &name);
 		}
 		menuitem = gtk_menu_item_new_with_label (name);
-		g_object_set_data (G_OBJECT (menuitem), "index", GINT_TO_POINTER (idx));
 		g_object_set_data (G_OBJECT (menuitem), "desc", (gpointer)(desc));
+		g_object_set_data (G_OBJECT (menuitem), "mime_type", mime_type);			
 		g_signal_connect (G_OBJECT (menuitem), "activate",
 						  G_CALLBACK (callback), callback_data);
 		gtk_menu_append (menu, menuitem);
 		g_free (name);
-		snode = g_list_next (snode);
-		idx++;
 	}
+	g_list_free (plugin_descs);
 	
 	/* Open with applications */
 	mime_apps = g_app_info_get_all_for_type (mime_type);
-	if (idx > 0 && mime_apps)
+	if (plugin_descs && mime_apps)
 	{
 		menuitem = gtk_menu_item_new ();
 		gtk_menu_append (menu, menuitem);
-		idx++;
 	}
-	g_free (mime_type);
-	idx = 0;
-	node = mime_apps;
-	while (node)
+	
+	for (node = mime_apps; node != NULL; node = g_list_next (node))
 	{
+		GAppInfo *mime_app;
+		
 		mime_app = (GAppInfo *)(node->data);
 		if (g_app_info_should_show (mime_app))
 		{
 			menuitem = gtk_menu_item_new_with_label ( g_app_info_get_name (mime_app));
-			g_object_set_data (G_OBJECT (menuitem), "index", GINT_TO_POINTER (idx));
+			g_object_set_data_full (G_OBJECT (menuitem), "app", mime_app, g_object_unref);			
+			g_object_set_data (G_OBJECT (menuitem), "mime_type", mime_type);			
 			g_signal_connect (G_OBJECT (menuitem), "activate",
 							  G_CALLBACK (callback), callback_data);
 			gtk_menu_append (menu, menuitem);
 		}
-		node = g_list_next (node);
-		idx++;
+		else
+		{
+			g_object_unref (mime_app);
+		}
 	}
+	g_list_free (mime_apps);
+
 	gtk_widget_show_all (menu);
-	
-	if (mime_apps == NULL && plugin_descs == NULL)
-		ret = FALSE;
+
+	if ((mime_apps != NULL) || (plugin_descs != NULL))
+	{
+		g_object_set_data_full (G_OBJECT (menu), "mime_type", (gpointer)mime_type, g_free);
+		
+		return TRUE;
+	}
 	else
-		ret = TRUE;
-	
-	g_list_foreach (mime_apps, (GFunc) g_object_unref, NULL);
-	g_list_free (mime_apps);
-	if (plugin_descs)
-		g_list_free (plugin_descs);
-	
-	return ret;
+	{
+		g_free (mime_type);
+		
+		return FALSE;
+	}
 }
 						  
 static void
@@ -1084,11 +1087,7 @@
 				 AnjutaSession *session,
 				 AnjutaFileLoaderPlugin *plugin)
 {
-	AnjutaStatus *status;
-	const gchar *uri;
-	gchar *mime_type;
 	GList *files, *node;
-	gint i;
 				
 	/* We want to load the files first before other session loads */
 	if (phase != ANJUTA_SESSION_PHASE_FIRST)
@@ -1098,68 +1097,37 @@
 	if (!files)
 		return;
 		
-	/* Open project files first and then regular files */
-	for (i = 0; i < 2; i++)
+	/* Open all files except project files */
+	for (node = g_list_first (files); node != NULL; node = g_list_next (node))
 	{
-		node = files;
-		while (node)
+		gchar *uri = node->data;
+		
+		if (uri)
 		{
-			uri = node->data;
-			if (uri)
-			{
-				gchar *label, *filename;
-				
-				mime_type = anjuta_util_get_uri_mime_type (uri);
-				
-				filename = g_path_get_basename (uri);
-				if (strchr (filename, '#'))
-					*(strchr (filename, '#')) = '\0';
-				
-				label = g_strconcat (_("Loaded:"), " ", filename, NULL);
-				
-				if (i == 0 && mime_type &&
-					strcmp (mime_type, "application/x-anjuta") == 0)
-				{
-					/* Project files first */
-					/* FIXME: Ignore project files for now */
-					/*
-					ianjuta_file_loader_load (IANJUTA_FILE_LOADER (plugin),
-											  uri, FALSE, NULL);
-					*/
-				}
-				else if (i != 0 &&
-						 (!mime_type ||
-						  strcmp (mime_type, "application/x-anjuta") != 0))
-				{
-					/* Then rest of the files */
-					gchar *fragment = strchr (uri, '#');
+			gchar *fragment;
+			
+			fragment = strchr (uri, '#');
+			if (fragment)
+				*fragment = '\0';
 
-					if (fragment)
-						*fragment = '\0';
-					GFile* file = g_file_new_for_uri (uri);
-					GObject *loader = ianjuta_file_loader_load (IANJUTA_FILE_LOADER (plugin),
+			if (!anjuta_util_is_project_file (uri))
+			{
+				GFile* file = g_file_new_for_uri (uri);
+				GObject *loader = ianjuta_file_loader_load (IANJUTA_FILE_LOADER (plugin),
 											  file, FALSE, NULL);
-					if (fragment)
+				if (fragment)
+				{
+					if (IANJUTA_IS_DOCUMENT_MANAGER (loader))
 					{
-						if (IANJUTA_IS_DOCUMENT_MANAGER (loader))
-						{
-							ianjuta_document_manager_goto_file_line (IANJUTA_DOCUMENT_MANAGER (loader), file, atoi(fragment + 1), NULL);
-						}
+						ianjuta_document_manager_goto_file_line (IANJUTA_DOCUMENT_MANAGER (loader), file, atoi(fragment + 1), NULL);
 					}
-					g_object_unref (file);
 				}
-				g_free (filename);
-				g_free (label);
-				g_free (mime_type);
+				g_object_unref (file);
 			}
-			node = g_list_next (node);
 		}
+		g_free (uri);
 	}
-	if (files)
-	{
-		g_list_foreach (files, (GFunc)g_free, NULL);
-		g_list_free (files);
-	}
+	g_list_free (files);
 }
 
 static void
@@ -1263,7 +1231,7 @@
 	setup_recent_chooser_menu (GTK_RECENT_CHOOSER (toolbar_menu), loader_plugin);
 	gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (widget),
 								   toolbar_menu);
-	
+
 	/* Install drag n drop handler */
 	dnd_drop_init (GTK_WIDGET (plugin->shell), dnd_dropped, plugin,
 				   "text/plain", "text/html", "text/source", "application-x/anjuta",
@@ -1349,24 +1317,11 @@
 	klass->finalize = finalize;
 }
 
-static gchar*
-hide_fragment_identifier (const gchar *uri)
-{
-	gchar *new_uri;
-
-	new_uri = g_strdup (uri);
-	if (strchr (new_uri, '#'))
-		*(strchr (new_uri, '#')) = '\0';
-
-	return new_uri;
-}
-
 static GObject*
 iloader_load (IAnjutaFileLoader *loader, GFile* file,
 			  gboolean read_only, GError **err)
 {
 	gchar *mime_type;
-	gchar *new_uri;
 	AnjutaStatus *status;
 	AnjutaPluginManager *plugin_manager;
 	GList *plugin_descs = NULL;
@@ -1375,26 +1330,19 @@
 	
 	g_return_val_if_fail (uri != NULL, NULL);
 
-	new_uri = hide_fragment_identifier (uri);
-	GFile *file2 = g_file_new_for_uri (new_uri);
-	
-	if (!g_file_query_exists (file2, NULL))
-	{
-		launch_application_failure (ANJUTA_PLUGIN_FILE_LOADER (loader),
-									uri, _("File not found"));
-		g_object_unref (G_OBJECT (file2));
-		return NULL;
-	}
-	g_object_unref (G_OBJECT (file2));
-	
-	new_uri = hide_fragment_identifier (uri);
-	mime_type = anjuta_util_get_uri_mime_type (new_uri);
+	mime_type = anjuta_util_get_file_mime_type (file);
 	
 	if (mime_type == NULL)
 	{
-		launch_application_failure (ANJUTA_PLUGIN_FILE_LOADER (loader),
-									new_uri, _("File not found"));
-		g_free (new_uri);
+		g_object_unref (file);
+		update_recent_file (ANJUTA_PLUGIN_FILE_LOADER (loader), uri, NULL, FALSE);	
+		
+		if (err == NULL)
+			launch_application_failure (ANJUTA_PLUGIN_FILE_LOADER (loader), uri, _("File not found"));
+		
+		g_set_error (err, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, _("File not found"));
+		
+		g_free (uri);
 		return NULL;
 	}
 	
@@ -1405,13 +1353,7 @@
 	
 	DEBUG_PRINT ("Opening URI: %s", uri);
 	
-	plugin_descs = anjuta_plugin_manager_query (plugin_manager,
-												"Anjuta Plugin",
-												"Interfaces", "IAnjutaFile",
-												"File Loader",
-												"SupportedMimeTypes",
-												mime_type,
-												NULL);
+	plugin_descs = get_available_plugins_for_mime (ANJUTA_PLUGIN (loader), mime_type);
 	
 	if (g_list_length (plugin_descs) > 1)
 	{
@@ -1441,19 +1383,47 @@
 	}
 	else
 	{
-		launch_in_default_application (ANJUTA_PLUGIN_FILE_LOADER (loader), mime_type, uri);
+		GAppInfo *appinfo;
+		GList *uris = NULL;
+
+		uris = g_list_prepend (uris, (gpointer)uri);
+
+		appinfo = g_app_info_get_default_for_type (mime_type, TRUE);
+		if (appinfo)
+		{
+			GError *error = NULL;
+			if (!g_app_info_launch_uris (appinfo, uris, NULL, &error))
+			{
+				open_with_dialog (ANJUTA_PLUGIN_FILE_LOADER (loader), uri, mime_type);
+			}
+			else
+			{
+				update_recent_file (ANJUTA_PLUGIN_FILE_LOADER (loader), uri, mime_type, error == NULL);
+			}				
+			g_object_unref (G_OBJECT (appinfo));
+		}
+		g_list_free (uris);
 	}
+	
 	if (plugin)
 	{
-		ianjuta_file_open (IANJUTA_FILE(plugin), file, NULL);
+		GError *error = NULL;
+		
+		ianjuta_file_open (IANJUTA_FILE(plugin), file, &error);
+		if (error != NULL)
+		{
+			
+			if (err == NULL)
+				launch_application_failure (ANJUTA_PLUGIN_FILE_LOADER (loader), uri, error->message);
+			g_propagate_error (err, error);
+		}
+		update_recent_file (ANJUTA_PLUGIN_FILE_LOADER (loader), uri, mime_type, error == NULL);
 	}
 	
-	set_recent_file (ANJUTA_PLUGIN_FILE_LOADER (loader), new_uri, mime_type);
-	
 	if (plugin_descs)
 		g_list_free (plugin_descs);
+	
 	g_free (mime_type);
-	g_free (new_uri);
 	g_free (uri);
 	anjuta_status_busy_pop (status);
 		

Modified: trunk/src/anjuta.c
==============================================================================
--- trunk/src/anjuta.c	(original)
+++ trunk/src/anjuta.c	Fri Dec 19 20:27:15 2008
@@ -227,48 +227,34 @@
 extract_project_from_session (const gchar* session_dir)
 {
 	AnjutaSession *session;
-	GList *node, *files, *new_files = NULL;
+	GList *node, *files;
 	gchar *project_uri = NULL;
 	
 	session = anjuta_session_new (session_dir);
 	
 	files = anjuta_session_get_string_list (session, "File Loader", "Files");
-	if (!files)
-		return NULL;
+	g_object_unref (session);
 	
-	/* Open project files first and then regular files */
+	/* Find project file */
 	node = files;
-	while (node)
+	for (node = files; node != NULL; node = g_list_next (node))
 	{
 		gchar *uri = node->data;
 		if (uri)
 		{
-			gchar *mime_type;
-			mime_type = anjuta_util_get_uri_mime_type (uri);
-			if (mime_type && strcmp (mime_type, "application/x-anjuta") == 0)
+			if (anjuta_util_is_project_file (uri))
 			{
 				g_free (project_uri);
 				project_uri = uri;
 			}
 			else
 			{
-				new_files = g_list_prepend (new_files, uri);
+				g_free (uri);
 			}
-			g_free (mime_type);
 		}
-		node = g_list_next (node);
 	}
-	/* anjuta_session_set_string_list (session, "File Loader", "Files", new_files);
-	anjuta_session_sync (session); */
-	g_object_unref (session);
+	g_list_free (files);
 	
-	if (new_files)
-	{
-		g_list_foreach (new_files, (GFunc)g_free, NULL);
-		g_list_free (new_files);
-	}
-	if (files)
-		g_list_free (files);
 	return project_uri;
 }
 
@@ -400,27 +386,19 @@
 									   geometry);
 		
 		/* Identify non-project files and set them for loading in session */
-		node = prog_args;
-		while (node)
+		for (node = prog_args; node != NULL; node = g_list_next (node))
 		{
-			const gchar *ext;
-			const gchar *filename = node->data;
-			
-			ext = strrchr (filename, '.');
-			
-			if (!ext ||
-				(strcmp (ext, ".anjuta") != 0 &&
-				 strcmp (ext, ".prj") != 0))
-			{
-				files_load = g_list_prepend (files_load, node->data);
-			}
-			else
+			gchar *filename = node->data;
+			if (anjuta_util_is_project_file (filename))
 			{
 				/* Pick up the first project file for loading later */
 				g_free (project_file);
 				project_file = g_strdup (filename);
 			}
-			node = g_list_next (node);
+			else
+			{
+				files_load = g_list_prepend (files_load, filename);
+			}
 		}
 		if (files_load)
 		{



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