Normalize directories paths; moo_folder_get_parent()
This commit is contained in:
parent
9cebfb590b
commit
ffe2e1e672
@ -227,7 +227,6 @@ MooFolder *moo_folder_new (MooFileSystem *fs,
|
||||
MooFileFlags wanted,
|
||||
GError **error)
|
||||
{
|
||||
char *norm_path;
|
||||
GDir *dir;
|
||||
MooFolder *folder;
|
||||
GError *file_error = NULL;
|
||||
@ -235,10 +234,8 @@ MooFolder *moo_folder_new (MooFileSystem *fs,
|
||||
g_return_val_if_fail (MOO_IS_FILE_SYSTEM (fs), NULL);
|
||||
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
norm_path = moo_normalize_path (path);
|
||||
g_return_val_if_fail (norm_path != NULL, NULL);
|
||||
|
||||
dir = g_dir_open (norm_path, 0, &file_error);
|
||||
dir = g_dir_open (path, 0, &file_error);
|
||||
|
||||
if (!dir)
|
||||
{
|
||||
@ -274,13 +271,12 @@ MooFolder *moo_folder_new (MooFileSystem *fs,
|
||||
}
|
||||
|
||||
g_error_free (file_error);
|
||||
g_free (norm_path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
folder = g_object_new (MOO_TYPE_FOLDER, NULL);
|
||||
folder->priv->fs = fs;
|
||||
folder->priv->path = norm_path;
|
||||
folder->priv->path = g_strdup (path);
|
||||
|
||||
folder->priv->dir = dir;
|
||||
|
||||
@ -678,6 +674,22 @@ MooFile *moo_folder_get_file (MooFolder *folder,
|
||||
}
|
||||
|
||||
|
||||
MooFolder *moo_folder_get_parent (MooFolder *folder,
|
||||
MooFileFlags wanted)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_FOLDER (folder), NULL);
|
||||
return moo_file_system_get_parent_folder (folder->priv->fs,
|
||||
folder, wanted);
|
||||
}
|
||||
|
||||
|
||||
MooFileSystem *moo_folder_get_file_system (MooFolder *folder)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_FOLDER (folder), NULL);
|
||||
return folder->priv->fs;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
/* MooFile
|
||||
*/
|
||||
@ -810,12 +822,6 @@ gboolean moo_file_test (const MooFile *file,
|
||||
}
|
||||
|
||||
|
||||
char *moo_normalize_path (const char *path)
|
||||
{
|
||||
return g_strdup (path);
|
||||
}
|
||||
|
||||
|
||||
const char *moo_file_get_display_basename (const MooFile *file)
|
||||
{
|
||||
g_return_val_if_fail (file != NULL, NULL);
|
||||
|
@ -117,8 +117,6 @@ GType moo_file_flags_get_type (void) G_GNUC_CONST;
|
||||
GType moo_file_info_get_type (void) G_GNUC_CONST;
|
||||
GType moo_folder_get_type (void) G_GNUC_CONST;
|
||||
|
||||
char *moo_normalize_path (const char *path);
|
||||
|
||||
MooFile *moo_file_ref (MooFile *file);
|
||||
void moo_file_unref (MooFile *file);
|
||||
|
||||
@ -138,11 +136,15 @@ GdkPixbuf *moo_file_get_icon (const MooFile *file,
|
||||
GtkIconSize size);
|
||||
|
||||
|
||||
const char *moo_folder_get_path (MooFolder *folder);
|
||||
const char *moo_folder_get_path (MooFolder *folder);
|
||||
/* list should be freed and elements unref'ed */
|
||||
GSList *moo_folder_list_files (MooFolder *folder);
|
||||
MooFile *moo_folder_get_file (MooFolder *folder,
|
||||
const char *basename);
|
||||
GSList *moo_folder_list_files (MooFolder *folder);
|
||||
MooFile *moo_folder_get_file (MooFolder *folder,
|
||||
const char *basename);
|
||||
/* result should be unref'ed */
|
||||
MooFolder *moo_folder_get_parent (MooFolder *folder,
|
||||
MooFileFlags wanted);
|
||||
char *moo_folder_get_parent_path (MooFolder *folder);
|
||||
|
||||
|
||||
#ifdef MOO_FILE_SYSTEM_COMPILATION
|
||||
|
@ -28,23 +28,31 @@ static MooFileSystem *fs_instance = NULL;
|
||||
|
||||
static void moo_file_system_finalize (GObject *object);
|
||||
|
||||
static MooFolder*get_folder_default (MooFileSystem *fs,
|
||||
const char *path,
|
||||
MooFileFlags wanted,
|
||||
GError **error);
|
||||
static gboolean create_folder_default (MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error);
|
||||
static gboolean delete_file_default (MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error);
|
||||
static char *get_parent_default (MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error);
|
||||
static char *make_path_default (MooFileSystem *fs,
|
||||
const char *base_path,
|
||||
const char *display_name,
|
||||
GError **error);
|
||||
static MooFolder *get_folder_default (MooFileSystem *fs,
|
||||
const char *path,
|
||||
MooFileFlags wanted,
|
||||
GError **error);
|
||||
static MooFolder *get_parent_folder_default (MooFileSystem *fs,
|
||||
MooFolder *folder,
|
||||
MooFileFlags flags);
|
||||
|
||||
// static gboolean create_folder_default (MooFileSystem *fs,
|
||||
// const char *path,
|
||||
// GError **error);
|
||||
// static gboolean delete_file_default (MooFileSystem *fs,
|
||||
// const char *path,
|
||||
// GError **error);
|
||||
// static char *get_parent_default (MooFileSystem *fs,
|
||||
// const char *path,
|
||||
// GError **error);
|
||||
// static char *make_path_default (MooFileSystem *fs,
|
||||
// const char *base_path,
|
||||
// const char *display_name,
|
||||
// GError **error);
|
||||
|
||||
static char *normalize_folder_path (const char *path);
|
||||
static char *normalize_path (const char *path);
|
||||
static char *normalize_path_unix (const char *path);
|
||||
|
||||
|
||||
/* MOO_TYPE_FILE_SYSTEM */
|
||||
@ -67,10 +75,11 @@ static void moo_file_system_class_init (MooFileSystemClass *klass)
|
||||
gobject_class->finalize = moo_file_system_finalize;
|
||||
|
||||
klass->get_folder = get_folder_default;
|
||||
klass->create_folder = create_folder_default;
|
||||
klass->delete_file = delete_file_default;
|
||||
klass->get_parent = get_parent_default;
|
||||
klass->make_path = make_path_default;
|
||||
klass->get_parent_folder = get_parent_folder_default;
|
||||
// klass->create_folder = create_folder_default;
|
||||
// klass->delete_file = delete_file_default;
|
||||
// klass->get_parent = get_parent_default;
|
||||
// klass->make_path = make_path_default;
|
||||
}
|
||||
|
||||
|
||||
@ -116,41 +125,52 @@ MooFolder *moo_file_system_get_folder (MooFileSystem *fs,
|
||||
MooFileFlags wanted,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_FILE_SYSTEM (fs), NULL);
|
||||
return MOO_FILE_SYSTEM_GET_CLASS(fs)->get_folder (fs, path, wanted, error);
|
||||
}
|
||||
|
||||
|
||||
gboolean moo_file_system_create_folder (MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error)
|
||||
MooFolder *moo_file_system_get_parent_folder (MooFileSystem *fs,
|
||||
MooFolder *folder,
|
||||
MooFileFlags wanted)
|
||||
{
|
||||
return MOO_FILE_SYSTEM_GET_CLASS(fs)->create_folder (fs, path, error);
|
||||
g_return_val_if_fail (MOO_IS_FILE_SYSTEM (fs), NULL);
|
||||
g_return_val_if_fail (MOO_IS_FOLDER (folder), NULL);
|
||||
return MOO_FILE_SYSTEM_GET_CLASS(fs)->get_parent_folder (fs, folder, wanted);
|
||||
}
|
||||
|
||||
|
||||
gboolean moo_file_system_delete_file(MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error)
|
||||
{
|
||||
return MOO_FILE_SYSTEM_GET_CLASS(fs)->delete_file (fs, path, error);
|
||||
}
|
||||
// gboolean moo_file_system_create_folder (MooFileSystem *fs,
|
||||
// const char *path,
|
||||
// GError **error)
|
||||
// {
|
||||
// return MOO_FILE_SYSTEM_GET_CLASS(fs)->create_folder (fs, path, error);
|
||||
// }
|
||||
|
||||
|
||||
char *moo_file_system_get_parent (MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error)
|
||||
{
|
||||
return MOO_FILE_SYSTEM_GET_CLASS(fs)->get_parent (fs, path, error);
|
||||
}
|
||||
// gboolean moo_file_system_delete_file(MooFileSystem *fs,
|
||||
// const char *path,
|
||||
// GError **error)
|
||||
// {
|
||||
// return MOO_FILE_SYSTEM_GET_CLASS(fs)->delete_file (fs, path, error);
|
||||
// }
|
||||
|
||||
|
||||
char *moo_file_system_make_path (MooFileSystem *fs,
|
||||
const char *base_path,
|
||||
const char *display_name,
|
||||
GError **error)
|
||||
{
|
||||
return MOO_FILE_SYSTEM_GET_CLASS(fs)->make_path (fs, base_path, display_name, error);
|
||||
}
|
||||
// char *moo_file_system_get_parent (MooFileSystem *fs,
|
||||
// const char *path,
|
||||
// GError **error)
|
||||
// {
|
||||
// return MOO_FILE_SYSTEM_GET_CLASS(fs)->get_parent (fs, path, error);
|
||||
// }
|
||||
|
||||
|
||||
// char *moo_file_system_make_path (MooFileSystem *fs,
|
||||
// const char *base_path,
|
||||
// const char *display_name,
|
||||
// GError **error)
|
||||
// {
|
||||
// return MOO_FILE_SYSTEM_GET_CLASS(fs)->make_path (fs, base_path, display_name, error);
|
||||
// }
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
@ -163,11 +183,18 @@ MooFolder *get_folder_default (MooFileSystem *fs,
|
||||
GError **error)
|
||||
{
|
||||
MooFolder *folder;
|
||||
char *norm_path;
|
||||
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
|
||||
/* TODO: this is not gonna work on windows, where '' is the 'root',
|
||||
containing drives */
|
||||
g_return_val_if_fail (g_path_is_absolute (path), NULL);
|
||||
|
||||
folder = g_hash_table_lookup (fs->priv->folders, path);
|
||||
norm_path = normalize_folder_path (path);
|
||||
g_return_val_if_fail (norm_path != NULL, NULL);
|
||||
|
||||
folder = g_hash_table_lookup (fs->priv->folders, norm_path);
|
||||
|
||||
if (folder)
|
||||
{
|
||||
@ -176,79 +203,103 @@ MooFolder *get_folder_default (MooFileSystem *fs,
|
||||
return folder;
|
||||
}
|
||||
|
||||
if (!g_file_test (path, G_FILE_TEST_IS_DIR))
|
||||
if (!g_file_test (norm_path, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
g_set_error (error, MOO_FILE_ERROR,
|
||||
MOO_FILE_ERROR_NOT_FOLDER,
|
||||
"'%s' is not a folder", path);
|
||||
"'%s' is not a folder", norm_path);
|
||||
g_free (norm_path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
folder = moo_folder_new (fs, path, wanted, error);
|
||||
folder = moo_folder_new (fs, norm_path, wanted, error);
|
||||
|
||||
if (folder)
|
||||
g_hash_table_insert (fs->priv->folders,
|
||||
g_strdup (path),
|
||||
g_strdup (norm_path),
|
||||
g_object_ref (folder));
|
||||
|
||||
g_free (norm_path);
|
||||
return folder;
|
||||
}
|
||||
|
||||
|
||||
static gboolean create_folder_default (G_GNUC_UNUSED MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error)
|
||||
static MooFolder *get_parent_folder_default (MooFileSystem *fs,
|
||||
MooFolder *folder,
|
||||
MooFileFlags wanted)
|
||||
{
|
||||
g_return_val_if_fail (path != NULL, FALSE);
|
||||
g_return_val_if_fail (g_path_is_absolute (path), FALSE);
|
||||
g_set_error (error, MOO_FILE_ERROR,
|
||||
MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
||||
"don't know how to create folder '%s'", path);
|
||||
return FALSE;
|
||||
char *parent_path;
|
||||
MooFolder *parent;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_FILE_SYSTEM (fs), NULL);
|
||||
g_return_val_if_fail (MOO_IS_FOLDER (folder), NULL);
|
||||
g_return_val_if_fail (moo_folder_get_file_system (folder) == fs, NULL);
|
||||
|
||||
parent_path = g_strdup_printf ("%s/..", moo_folder_get_path (folder));
|
||||
|
||||
parent = moo_file_system_get_folder (fs, parent_path, wanted, NULL);
|
||||
g_assert (parent != NULL);
|
||||
|
||||
g_free (parent_path);
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
||||
static gboolean delete_file_default (G_GNUC_UNUSED MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (path != NULL, FALSE);
|
||||
g_return_val_if_fail (g_path_is_absolute (path), FALSE);
|
||||
g_set_error (error, MOO_FILE_ERROR,
|
||||
MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
||||
"don't know how to delete file '%s'", path);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static char *get_parent_default (G_GNUC_UNUSED MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
g_return_val_if_fail (g_path_is_absolute (path), NULL);
|
||||
g_set_error (error, MOO_FILE_ERROR,
|
||||
MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
||||
"don't know how to delete file '%s'", path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static char *make_path_default (G_GNUC_UNUSED MooFileSystem *fs,
|
||||
const char *base_path,
|
||||
const char *display_name,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (base_path != NULL, NULL);
|
||||
g_return_val_if_fail (display_name != NULL, NULL);
|
||||
g_return_val_if_fail (g_path_is_absolute (base_path), NULL);
|
||||
|
||||
g_set_error (error, MOO_FILE_ERROR,
|
||||
MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
||||
"don't know how to make path of '%s' and '%s'",
|
||||
base_path, display_name);
|
||||
return NULL;
|
||||
}
|
||||
// static gboolean create_folder_default (G_GNUC_UNUSED MooFileSystem *fs,
|
||||
// const char *path,
|
||||
// GError **error)
|
||||
// {
|
||||
// g_return_val_if_fail (path != NULL, FALSE);
|
||||
// g_return_val_if_fail (g_path_is_absolute (path), FALSE);
|
||||
// g_set_error (error, MOO_FILE_ERROR,
|
||||
// MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
||||
// "don't know how to create folder '%s'", path);
|
||||
// return FALSE;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// static gboolean delete_file_default (G_GNUC_UNUSED MooFileSystem *fs,
|
||||
// const char *path,
|
||||
// GError **error)
|
||||
// {
|
||||
// g_return_val_if_fail (path != NULL, FALSE);
|
||||
// g_return_val_if_fail (g_path_is_absolute (path), FALSE);
|
||||
// g_set_error (error, MOO_FILE_ERROR,
|
||||
// MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
||||
// "don't know how to delete file '%s'", path);
|
||||
// return FALSE;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// static char *get_parent_default (G_GNUC_UNUSED MooFileSystem *fs,
|
||||
// const char *path,
|
||||
// GError **error)
|
||||
// {
|
||||
// g_return_val_if_fail (path != NULL, NULL);
|
||||
// g_return_val_if_fail (g_path_is_absolute (path), NULL);
|
||||
// g_set_error (error, MOO_FILE_ERROR,
|
||||
// MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
||||
// "don't know how to delete file '%s'", path);
|
||||
// return NULL;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// static char *make_path_default (G_GNUC_UNUSED MooFileSystem *fs,
|
||||
// const char *base_path,
|
||||
// const char *display_name,
|
||||
// GError **error)
|
||||
// {
|
||||
// g_return_val_if_fail (base_path != NULL, NULL);
|
||||
// g_return_val_if_fail (display_name != NULL, NULL);
|
||||
// g_return_val_if_fail (g_path_is_absolute (base_path), NULL);
|
||||
//
|
||||
// g_set_error (error, MOO_FILE_ERROR,
|
||||
// MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
||||
// "don't know how to make path of '%s' and '%s'",
|
||||
// base_path, display_name);
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
|
||||
GQuark moo_file_error_quark (void)
|
||||
@ -258,3 +309,119 @@ GQuark moo_file_error_quark (void)
|
||||
quark = g_quark_from_static_string ("moo-file-error-quark");
|
||||
return quark;
|
||||
}
|
||||
|
||||
|
||||
static char *normalize_path_unix (const char *path)
|
||||
{
|
||||
GPtrArray *comps;
|
||||
gboolean first_slash;
|
||||
char **pieces, **p;
|
||||
char *normpath;
|
||||
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
|
||||
first_slash = (path[0] == '/');
|
||||
|
||||
pieces = g_strsplit (path, "/", 0);
|
||||
g_return_val_if_fail (pieces != NULL, NULL);
|
||||
|
||||
comps = g_ptr_array_new ();
|
||||
|
||||
for (p = pieces; *p != NULL; ++p)
|
||||
{
|
||||
char *s = *p;
|
||||
gboolean push = TRUE;
|
||||
gboolean pop = FALSE;
|
||||
|
||||
if (!strcmp (s, "") || !strcmp (s, "."))
|
||||
{
|
||||
push = FALSE;
|
||||
}
|
||||
else if (!strcmp (s, ".."))
|
||||
{
|
||||
if (!comps->len && first_slash)
|
||||
{
|
||||
push = FALSE;
|
||||
}
|
||||
else if (comps->len)
|
||||
{
|
||||
push = FALSE;
|
||||
pop = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (pop)
|
||||
{
|
||||
g_free (comps->pdata[comps->len - 1]);
|
||||
g_ptr_array_remove_index (comps, comps->len - 1);
|
||||
}
|
||||
|
||||
if (push)
|
||||
g_ptr_array_add (comps, g_strdup (s));
|
||||
}
|
||||
|
||||
g_ptr_array_add (comps, NULL);
|
||||
|
||||
if (comps->len == 1)
|
||||
{
|
||||
if (first_slash)
|
||||
normpath = g_strdup ("/");
|
||||
else
|
||||
normpath = g_strdup ("");
|
||||
}
|
||||
else
|
||||
{
|
||||
char *tmp = g_strjoinv ("/", (char**) comps->pdata);
|
||||
|
||||
if (first_slash)
|
||||
{
|
||||
normpath = g_strdup_printf ("/%s", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
normpath = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev (pieces);
|
||||
g_strfreev ((char**) comps->pdata);
|
||||
g_ptr_array_free (comps, FALSE);
|
||||
|
||||
return normpath;
|
||||
}
|
||||
|
||||
|
||||
static char *normalize_path (const char *path)
|
||||
{
|
||||
return normalize_path_unix (path);
|
||||
}
|
||||
|
||||
|
||||
static char *normalize_folder_path (const char *path)
|
||||
{
|
||||
guint len;
|
||||
char *normpath, *tmp;
|
||||
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
|
||||
tmp = normalize_path (path);
|
||||
len = strlen (tmp);
|
||||
g_return_val_if_fail (len > 0, tmp);
|
||||
|
||||
if (tmp[len-1] != '/')
|
||||
{
|
||||
normpath = g_strdup_printf ("%s/", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert (len == 1);
|
||||
normpath = tmp;
|
||||
}
|
||||
|
||||
g_print ("path: '%s'\nnormpath: '%s'\n",
|
||||
path, normpath);
|
||||
|
||||
return normpath;
|
||||
}
|
||||
|
@ -50,47 +50,40 @@ struct _MooFileSystemClass
|
||||
const char *path,
|
||||
MooFileFlags flags,
|
||||
GError **error);
|
||||
|
||||
gboolean (*create_folder) (MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error);
|
||||
gboolean (*delete_file) (MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error);
|
||||
|
||||
char* (*get_parent) (MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error);
|
||||
char* (*make_path) (MooFileSystem *fs,
|
||||
const char *base_path,
|
||||
const char *display_name,
|
||||
GError **error);
|
||||
MooFolder* (*get_parent_folder)(MooFileSystem *fs,
|
||||
MooFolder *folder,
|
||||
MooFileFlags flags);
|
||||
};
|
||||
|
||||
|
||||
GType moo_file_system_get_type (void) G_GNUC_CONST;
|
||||
GType moo_file_system_get_type (void) G_GNUC_CONST;
|
||||
|
||||
MooFileSystem *moo_file_system_create (void);
|
||||
MooFileSystem *moo_file_system_create (void);
|
||||
|
||||
MooFolder *moo_file_system_get_folder (MooFileSystem *fs,
|
||||
const char *path,
|
||||
MooFileFlags wanted,
|
||||
GError **error);
|
||||
MooFolder *moo_file_system_get_folder (MooFileSystem *fs,
|
||||
const char *path,
|
||||
MooFileFlags wanted,
|
||||
GError **error);
|
||||
MooFolder *moo_file_system_get_parent_folder (MooFileSystem *fs,
|
||||
MooFolder *folder,
|
||||
MooFileFlags wanted);
|
||||
|
||||
gboolean moo_file_system_create_folder (MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error);
|
||||
gboolean moo_file_system_delete_file(MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error);
|
||||
MooFileSystem *moo_folder_get_file_system (MooFolder *folder);
|
||||
|
||||
char *moo_file_system_get_parent (MooFileSystem *fs,
|
||||
const char *path,
|
||||
GError **error);
|
||||
char *moo_file_system_make_path (MooFileSystem *fs,
|
||||
const char *base_path,
|
||||
const char *display_name,
|
||||
GError **error);
|
||||
// gboolean moo_file_system_create_folder (MooFileSystem *fs,
|
||||
// const char *path,
|
||||
// GError **error);
|
||||
// gboolean moo_file_system_delete_file (MooFileSystem *fs,
|
||||
// const char *path,
|
||||
// GError **error);
|
||||
//
|
||||
// char *moo_file_system_get_parent (MooFileSystem *fs,
|
||||
// const char *path,
|
||||
// GError **error);
|
||||
// char *moo_file_system_make_path (MooFileSystem *fs,
|
||||
// const char *base_path,
|
||||
// const char *display_name,
|
||||
// GError **error);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -78,6 +78,7 @@ struct _MooFileViewPrivate {
|
||||
gboolean show_hidden_files;
|
||||
gboolean show_two_dots;
|
||||
History *history;
|
||||
gboolean select_first;
|
||||
char *name_to_select;
|
||||
char *temp_visible; /* tempporary visible name, for interactive search */
|
||||
GtkTreeRowReference *temp_visible_row; /* row containing temp_visible (in the store) */
|
||||
@ -112,9 +113,12 @@ static gboolean moo_file_view_key_press (GtkWidget *widget,
|
||||
static void moo_file_view_set_file_mgr (MooFileView *fileview,
|
||||
MooEditFileMgr *mgr);
|
||||
|
||||
static gboolean moo_file_view_chdir_real(MooFileView *fileview,
|
||||
const char *dir,
|
||||
GError **error);
|
||||
static void moo_file_view_set_current_dir (MooFileView *fileview,
|
||||
MooFolder *folder);
|
||||
static gboolean moo_file_view_chdir_real (MooFileView *fileview,
|
||||
const char *dir,
|
||||
GError **error);
|
||||
|
||||
static void moo_file_view_go_up (MooFileView *fileview);
|
||||
static void moo_file_view_go_home (MooFileView *fileview);
|
||||
static void moo_file_view_go_back (MooFileView *fileview);
|
||||
@ -582,17 +586,18 @@ static gboolean clear_list_in_idle (MooFileView *fileview)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean moo_file_view_chdir_real(MooFileView *fileview,
|
||||
const char *new_dir,
|
||||
GError **error)
|
||||
static void moo_file_view_set_current_dir (MooFileView *fileview,
|
||||
MooFolder *folder)
|
||||
{
|
||||
char *real_new_dir;
|
||||
MooFolder *folder;
|
||||
GSList *files;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_FILE_VIEW (fileview), FALSE);
|
||||
g_return_if_fail (MOO_IS_FILE_VIEW (fileview));
|
||||
g_return_if_fail (!folder || MOO_IS_FOLDER (folder));
|
||||
|
||||
if (!new_dir)
|
||||
if (folder == fileview->priv->current_dir)
|
||||
return;
|
||||
|
||||
if (!folder)
|
||||
{
|
||||
if (fileview->priv->current_dir)
|
||||
{
|
||||
@ -603,12 +608,54 @@ static gboolean moo_file_view_chdir_real(MooFileView *fileview,
|
||||
gtk_list_store_clear (fileview->priv->store);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (fileview->priv->current_dir &&
|
||||
!strcmp (moo_folder_get_path (fileview->priv->current_dir), new_dir))
|
||||
return TRUE;
|
||||
disconnect_folder (fileview);
|
||||
if (fileview->priv->current_dir)
|
||||
g_object_unref (fileview->priv->current_dir);
|
||||
|
||||
fileview->priv->current_dir = g_object_ref (folder);
|
||||
|
||||
history_goto (fileview, moo_folder_get_path (folder));
|
||||
|
||||
fileview->priv->need_to_clear = TRUE;
|
||||
g_idle_add_full (G_PRIORITY_LOW,
|
||||
(GSourceFunc) clear_list_in_idle,
|
||||
fileview, NULL);
|
||||
fileview->priv->process_changes_now = TRUE;
|
||||
|
||||
if (fileview->priv->files)
|
||||
g_hash_table_destroy (fileview->priv->files);
|
||||
fileview->priv->files =
|
||||
g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
||||
(GDestroyNotify) moo_file_unref,
|
||||
(GDestroyNotify) gtk_tree_row_reference_free);
|
||||
|
||||
connect_folder (fileview);
|
||||
|
||||
fileview->priv->select_first = TRUE;
|
||||
files = moo_folder_list_files (folder);
|
||||
fileview_add_files (fileview, files);
|
||||
g_slist_foreach (files, (GFunc) moo_file_unref, NULL);
|
||||
g_slist_free (files);
|
||||
}
|
||||
|
||||
|
||||
static gboolean moo_file_view_chdir_real(MooFileView *fileview,
|
||||
const char *new_dir,
|
||||
GError **error)
|
||||
{
|
||||
char *real_new_dir;
|
||||
MooFolder *folder;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_FILE_VIEW (fileview), FALSE);
|
||||
|
||||
if (!new_dir)
|
||||
{
|
||||
moo_file_view_set_current_dir (fileview, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_path_is_absolute (new_dir) || !fileview->priv->current_dir)
|
||||
{
|
||||
@ -629,34 +676,8 @@ static gboolean moo_file_view_chdir_real(MooFileView *fileview,
|
||||
if (!folder)
|
||||
return FALSE;
|
||||
|
||||
disconnect_folder (fileview);
|
||||
if (fileview->priv->current_dir)
|
||||
g_object_unref (fileview->priv->current_dir);
|
||||
|
||||
fileview->priv->current_dir = folder;
|
||||
|
||||
history_goto (fileview, moo_folder_get_path (folder));
|
||||
|
||||
fileview->priv->need_to_clear = TRUE;
|
||||
g_idle_add_full (G_PRIORITY_LOW,
|
||||
(GSourceFunc) clear_list_in_idle,
|
||||
fileview, NULL);
|
||||
fileview->priv->process_changes_now = TRUE;
|
||||
|
||||
if (fileview->priv->files)
|
||||
g_hash_table_destroy (fileview->priv->files);
|
||||
fileview->priv->files =
|
||||
g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
||||
(GDestroyNotify) moo_file_unref,
|
||||
(GDestroyNotify) gtk_tree_row_reference_free);
|
||||
|
||||
connect_folder (fileview);
|
||||
|
||||
files = moo_folder_list_files (folder);
|
||||
fileview_add_files (fileview, files);
|
||||
g_slist_foreach (files, (GFunc) moo_file_unref, NULL);
|
||||
g_slist_free (files);
|
||||
|
||||
moo_file_view_set_current_dir (fileview, folder);
|
||||
g_object_unref (folder);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -796,12 +817,20 @@ static void add_one_file (MooFileView *fileview,
|
||||
COLUMN_SIZE, NULL,
|
||||
COLUMN_DATE, NULL, -1);
|
||||
|
||||
if (fileview->priv->name_to_select &&
|
||||
!strcmp (fileview->priv->name_to_select,
|
||||
moo_file_get_display_basename (file)))
|
||||
if (fileview->priv->name_to_select)
|
||||
{
|
||||
g_free (fileview->priv->name_to_select);
|
||||
fileview->priv->name_to_select = NULL;
|
||||
if (!strcmp (fileview->priv->name_to_select,
|
||||
moo_file_get_display_basename (file)))
|
||||
{
|
||||
g_free (fileview->priv->name_to_select);
|
||||
fileview->priv->name_to_select = NULL;
|
||||
moo_file_view_select_file (fileview,
|
||||
moo_file_get_display_basename (file));
|
||||
}
|
||||
}
|
||||
else if (fileview->priv->select_first)
|
||||
{
|
||||
fileview->priv->select_first = FALSE;
|
||||
moo_file_view_select_file (fileview,
|
||||
moo_file_get_display_basename (file));
|
||||
}
|
||||
@ -811,8 +840,10 @@ static void add_one_file (MooFileView *fileview,
|
||||
static gboolean fileview_add_files_in_idle (MooFileView *fileview)
|
||||
{
|
||||
if (fileview->priv->need_to_clear)
|
||||
{
|
||||
gtk_list_store_clear (fileview->priv->store);
|
||||
fileview->priv->need_to_clear = FALSE;
|
||||
fileview->priv->need_to_clear = FALSE;
|
||||
}
|
||||
|
||||
if (fileview->priv->remove_files_idle)
|
||||
remove_a_bit (fileview);
|
||||
@ -1581,36 +1612,28 @@ gboolean moo_file_view_chdir (MooFileView *fileview,
|
||||
|
||||
static void moo_file_view_go_up (MooFileView *fileview)
|
||||
{
|
||||
char *dirname, *basename;
|
||||
GError *error = NULL;
|
||||
MooFolder *parent;
|
||||
char *name;
|
||||
|
||||
g_return_if_fail (fileview->priv->current_dir != NULL);
|
||||
|
||||
basename = g_path_get_basename (moo_folder_get_path (fileview->priv->current_dir));
|
||||
dirname = g_path_get_dirname (moo_folder_get_path (fileview->priv->current_dir));
|
||||
parent = moo_folder_get_parent (fileview->priv->current_dir,
|
||||
MOO_FILE_HAS_ICON);
|
||||
|
||||
/* TODO TODO do something about top-level directories */
|
||||
if (!strcmp (basename, dirname))
|
||||
goto out;
|
||||
g_print ("current dir: '%s'\nparent dir: '%s'\n",
|
||||
moo_folder_get_path (fileview->priv->current_dir),
|
||||
moo_folder_get_path (parent));
|
||||
|
||||
if (!moo_file_view_chdir (fileview, dirname, &error))
|
||||
if (parent != fileview->priv->current_dir)
|
||||
{
|
||||
g_warning ("%s: could not go up", G_STRLOC);
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_warning ("%s: %s", G_STRLOC, error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
goto out;
|
||||
name = g_filename_display_basename (
|
||||
moo_folder_get_path (fileview->priv->current_dir));
|
||||
moo_file_view_set_current_dir (fileview, parent);
|
||||
moo_file_view_select_file (fileview, name);
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
moo_file_view_select_file (fileview, basename);
|
||||
|
||||
out:
|
||||
g_free (dirname);
|
||||
g_free (basename);
|
||||
g_object_unref (parent);
|
||||
}
|
||||
|
||||
|
||||
@ -2719,12 +2742,24 @@ static gboolean search_entry_key_press (G_GNUC_UNUSED GtkWidget *entry,
|
||||
GdkEventKey *event,
|
||||
MooFileView *fileview)
|
||||
{
|
||||
GtkWidget *filewidget;
|
||||
switch (event->keyval)
|
||||
{
|
||||
case GDK_Escape:
|
||||
stop_interactive_search (fileview, TRUE);
|
||||
return TRUE;
|
||||
|
||||
case GDK_Up:
|
||||
case GDK_KP_Up:
|
||||
case GDK_Down:
|
||||
case GDK_KP_Down:
|
||||
stop_interactive_search (fileview, TRUE);
|
||||
filewidget = get_file_view_widget (fileview);
|
||||
gtk_widget_grab_focus (filewidget);
|
||||
GTK_WIDGET_CLASS(G_OBJECT_GET_CLASS (filewidget))->
|
||||
key_press_event (filewidget, event);
|
||||
return TRUE;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
@ -2896,7 +2931,11 @@ void moo_file_view_select_file (MooFileView *fileview,
|
||||
if (!filter_path)
|
||||
{
|
||||
gtk_tree_path_free (path);
|
||||
file_widget_move_selection (fileview, NULL);
|
||||
if (gtk_tree_model_get_iter_first (fileview->priv->filter_model,
|
||||
&filter_iter))
|
||||
file_widget_move_selection (fileview, &filter_iter);
|
||||
else
|
||||
fileview->priv->select_first = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user