Commit 579595ba authored by Sebastien Granjoux's avatar Sebastien Granjoux

Partial fix for #511589 - Anjuta uses GNOME-VFS

	* 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

svn path=/trunk/; revision=4456
parent cb96886c
2008-12-19 Sébastien Granjoux <seb.sfo@free.fr>
* 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
2008-12-19 Massimo Cora' <mcora@svn.gnome.org>
* plugins/symbol-db/symbol-db-engine-iterator.c
......@@ -1118,63 +1118,89 @@ gboolean anjuta_util_diff(const gchar* uri, const gchar* text)
}
}
/**
* 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)
{
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
if (info != NULL)
{
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 @@ anjuta_util_help_display (GtkWidget *parent,
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"));
......
......@@ -110,7 +110,6 @@ pid_t anjuta_util_execute_shell (const gchar *dir, const gchar *command);
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_shell_expand (const gchar *string);
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,
......
......@@ -1252,25 +1252,11 @@ anjuta_docman_goto_file_line_mark (AnjutaDocman *docman, GFile* file,
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 @@ anjuta_docman_goto_file_line_mark (AnjutaDocman *docman, GFile* file,
ianjuta_document_grab_focus (IANJUTA_DOCUMENT (doc), NULL);
}
g_object_unref (real_file);
return te;
}
......
......@@ -19,7 +19,8 @@ loader_plugin_DATA = $(plugin_in_files:.plugin.in=.plugin)
AM_CPPFLAGS = \
$(WARN_CFLAGS) \
$(DEPRECATED_FLAGS) \
$(LIBANJUTA_CFLAGS)
$(LIBANJUTA_CFLAGS) \
-DG_LOG_DOMAIN=\"libanjuta-loader\"
# Where to install the plugin
plugindir = $(anjuta_plugin_dir)
......
This diff is collapsed.
......@@ -227,48 +227,34 @@ static gchar*
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 @@ anjuta_new (gchar *prog_name, GList *prog_args, gboolean no_splash,
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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment