Commit 1ef81e0e authored by Paolo Borelli's avatar Paolo Borelli Committed by Paolo Borelli

Improve how the dirname in the titlebar is shown for remote files which

2009-02-28  Paolo Borelli  <pborelli@katamail.com>

	* gedit/gedit-utils.[ch]:
	* gedit/gedit-window.c:
	* gedit/gedit-tab.c:
	Improve how the dirname in the titlebar is shown for remote files
	which have a mount name. Bug #573286, based on a patch by Ignacio
	Casal Quinteiro.


svn path=/trunk/; revision=6926
parent c519dcd5
2009-02-28 Paolo Borelli <pborelli@katamail.com>
* gedit/gedit-utils.[ch]:
* gedit/gedit-window.c:
* gedit/gedit-tab.c:
Improve how the dirname in the titlebar is shown for remote files
which have a mount name. Bug #573286, based on a patch by Ignacio
Casal Quinteiro.
2009-02-25 Paolo Borelli <pborelli@katamail.com>
* gedit/gedit-plugin.c:
......
......@@ -631,15 +631,16 @@ show_loading_message_area (GeditTab *tab)
}
else
{
gchar *uri;
gchar *str;
uri = gedit_document_get_uri_for_display (doc);
str = gedit_utils_uri_get_dirname (uri);
g_free (uri);
GFile *file;
if (str != NULL)
file = gedit_document_get_location (doc);
if (file != NULL)
{
gchar *str;
str = gedit_utils_location_get_dirname_for_display (file);
g_object_unref (file);
/* use the remaining space for the dir, but use a min of 20 chars
* so that we do not end up with a dirname like "(a...b)".
* This means that in the worst case when the filename is long 99
......
......@@ -661,7 +661,9 @@ gedit_utils_uri_get_dirname (const gchar *uri)
gchar *res;
gchar *str;
// CHECK: does it work with uri chaining? - Paolo
g_return_val_if_fail (uri != NULL, NULL);
/* CHECK: does it work with uri chaining? - Paolo */
str = g_path_get_dirname (uri);
g_return_val_if_fail (str != NULL, ".");
......@@ -679,6 +681,71 @@ gedit_utils_uri_get_dirname (const gchar *uri)
return res;
}
/**
* gedit_utils_location_get_dirname_for_display
* @file: the location
*
* Returns a string suitable to be displayed in the UI indicating
* the name of the directory where the file is located.
* For remote files it may also contain the hostname etc.
* For local files it tries to replace the home dir with ~.
*
* Returns: a string to display the dirname
*/
gchar *
gedit_utils_location_get_dirname_for_display (GFile *location)
{
gchar *uri;
gchar *res;
GMount *mount;
g_return_val_if_fail (location != NULL, NULL);
/* we use the parse name, that is either the local path
* or an uri but which is utf8 safe */
uri = g_file_get_parse_name (location);
/* FIXME: this is sync... is it a problem? */
mount = g_file_find_enclosing_mount (location, NULL, NULL);
if (mount != NULL)
{
gchar *mount_name;
gchar *path;
mount_name = g_mount_get_name (mount);
g_object_unref (mount);
/* obtain the "path" patrt of the uri */
if (gedit_utils_decode_uri (uri,
NULL, NULL,
NULL, NULL,
&path))
{
gchar *dirname;
dirname = gedit_utils_uri_get_dirname (path);
res = g_strdup_printf ("%s %s", mount_name, dirname);
g_free (path);
g_free (dirname);
g_free (mount_name);
}
else
{
res = mount_name;
}
}
else
{
/* fallback for local files or uris without mounts */
res = gedit_utils_uri_get_dirname (uri);
}
g_free (uri);
return res;
}
gchar *
gedit_utils_replace_home_dir_with_tilde (const gchar *uri)
{
......
......@@ -111,6 +111,9 @@ gchar *gedit_utils_make_valid_utf8 (const char *name);
/* Note that this function replace home dir with ~ */
gchar *gedit_utils_uri_get_dirname (const char *uri);
gchar *gedit_utils_location_get_dirname_for_display
(GFile *location);
gchar *gedit_utils_replace_home_dir_with_tilde (const gchar *uri);
guint gedit_utils_get_current_workspace (GdkScreen *screen);
......
......@@ -2125,15 +2125,16 @@ set_title (GeditWindow *window)
}
else
{
gchar *uri;
gchar *str;
uri = gedit_document_get_uri_for_display (doc);
str = gedit_utils_uri_get_dirname (uri);
g_free (uri);
GFile *file;
if (str != NULL)
file = gedit_document_get_location (doc);
if (file != NULL)
{
gchar *str;
str = gedit_utils_location_get_dirname_for_display (file);
g_object_unref (file);
/* use the remaining space for the dir, but use a min of 20 chars
* so that we do not end up with a dirname like "(a...b)".
* This means that in the worst case when the filename is long 99
......
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