Use g_file_get_parse_name()

This commit is contained in:
Yevgen Muntyan 2008-09-16 20:13:30 -05:00
parent de263422ab
commit 68df063249
2 changed files with 17 additions and 29 deletions

View File

@ -1171,49 +1171,36 @@ _moo_edit_get_default_encoding (void)
char * char *
_moo_file_get_display_name (GFile *file) _moo_file_get_display_name (GFile *file)
{
g_return_val_if_fail (G_IS_FILE (file), NULL);
return g_file_get_parse_name (file);
}
char *
_moo_file_get_display_basename (GFile *file)
{ {
char *name; char *name;
char *filename; const char *slash;
g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (G_IS_FILE (file), NULL);
if ((filename = g_file_get_path (file))) name = _moo_file_get_display_name (file);
{ g_return_val_if_fail (name != NULL, NULL);
name = g_filename_display_name (filename);
g_free (filename);
}
else
{
name = g_file_get_uri (file);
}
if (!name) slash = strrchr (name, '/');
{
g_critical ("%s: oops", G_STRFUNC);
name = g_strdup ("<UNKNOWN>");
}
return name;
}
static char *
get_basename (const char *filename)
{
const char *slash;
slash = strrchr (filename, '/');
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
{ {
const char *backslash = strrchr (filename, '\\'); const char *backslash = strrchr (name, '\\');
if (backslash && (!slash || backslash > slash)) if (backslash && (!slash || backslash > slash))
slash = backslash; slash = backslash;
} }
#endif #endif
if (slash) if (slash)
return g_strdup (slash + 1); memmove (name, slash + 1, strlen (slash + 1) + 1);
else
return g_strdup (filename); return name;
} }
@ -1253,7 +1240,7 @@ _moo_edit_set_file (MooEdit *edit,
edit->priv->file = g_file_dup (file); edit->priv->file = g_file_dup (file);
edit->priv->filename = g_file_get_path (file); edit->priv->filename = g_file_get_path (file);
edit->priv->display_filename = _moo_file_get_display_name (file); edit->priv->display_filename = _moo_file_get_display_name (file);
edit->priv->display_basename = get_basename (edit->priv->display_filename); edit->priv->display_basename = _moo_file_get_display_basename (file);
} }
if (!encoding) if (!encoding)

View File

@ -60,6 +60,7 @@ gboolean _moo_edit_save_file_copy (MooEdit *edit,
GError **error); GError **error);
char *_moo_file_get_display_name (GFile *file); char *_moo_file_get_display_name (GFile *file);
char *_moo_file_get_display_basename (GFile *file);
G_END_DECLS G_END_DECLS