diff --git a/src/bin/edi_filepanel.c b/src/bin/edi_filepanel.c index ef76b14..9600f47 100644 --- a/src/bin/edi_filepanel.c +++ b/src/bin/edi_filepanel.c @@ -4,65 +4,18 @@ #include -#include +#include #include "edi_filepanel.h" #include "edi_private.h" -static void stat_done(void *data, Eio_File *handler EINA_UNUSED, const Eina_Stat *st); - // TODO take this from the command line! -static char *PROJECT_ROOT = "/home/andy/Code/edi"; +static char *PROJECT_ROOT = "/home/andy/Code/E/edi"; static Elm_Genlist_Item_Class itc, itc2; static Evas_Object *list; -static void -dummy() -{} - -static void -ls_done(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *path) -{ - eio_file_direct_stat(path, stat_done, dummy, eina_stringshare_add(path)); -} - -static Eina_Bool -ls_filter(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *file) -{ - struct stat st; - if (stat(file, &st)) return EINA_FALSE; - - return !(eina_str_has_prefix(basename(file), ".")); -} - -static void -stat_done(void *data, Eio_File *handler EINA_UNUSED, const Eina_Stat *st) -{ - if (S_ISREG(st->mode)) - { - elm_genlist_item_append(list, &itc, data, - NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); - } - else if (S_ISDIR(st->mode)) - { - if (strcmp(data, PROJECT_ROOT)) - { - elm_genlist_item_append(list, &itc2, data, - NULL, ELM_GENLIST_ITEM_TREE, NULL, NULL); - // TODO remove this and recurse - return; - } - - eio_file_ls(data, ls_filter, ls_done, dummy, dummy, data); - } - else - printf("WAT %s\n", data); - - eina_stringshare_del(data); -} - static char * _text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *source EINA_UNUSED) { @@ -88,6 +41,7 @@ _content_get(void *data, Evas_Object *obj, const char *source) static void _item_del(void *data, Evas_Object *obj EINA_UNUSED) { + eina_stringshare_del(data); } static Evas_Object * @@ -106,6 +60,43 @@ _content_dir_get(void *data, Evas_Object *obj, const char *source) return NULL; } +static Eina_Bool +ignore_file(const char *file) +{ + return eina_str_has_prefix(file, "."); +} + +static void +load_tree(char *path, Elm_Object_Item *parent) +{ + Eina_Iterator *iter; + Eina_File_Direct_Info *info; + Elm_Object_Item *newParent; + char *name; + + iter = eina_file_stat_ls(path); + if (iter) + { + EINA_ITERATOR_FOREACH(iter, info) + { + name = info->path + info->name_start; + if (ignore_file(name)) continue; + + if (info->type == EINA_FILE_DIR) + { + newParent = elm_genlist_item_append(list, &itc2, eina_stringshare_add(name), + parent, ELM_GENLIST_ITEM_NONE, NULL, NULL); + load_tree(info->path, newParent); + } + else if (info->type == EINA_FILE_REG) + { + elm_genlist_item_append(list, &itc, eina_stringshare_add(name), + parent, ELM_GENLIST_ITEM_NONE, NULL, NULL); + } + } + } +} + void edi_filepanel_add(Evas_Object *parent) { @@ -118,14 +109,15 @@ edi_filepanel_add(Evas_Object *parent) itc.item_style = "default"; itc.func.text_get = _text_get; itc.func.content_get = _content_get; -// itc.func.state_get = _state_get; itc.func.del = _item_del; itc2.item_style = "default"; itc2.func.text_get = _text_get; itc2.func.content_get = _content_dir_get; +// itc2.func.state_get = _state_get; itc2.func.del = _item_del; - eio_file_direct_stat(PROJECT_ROOT, stat_done, dummy, eina_stringshare_add(PROJECT_ROOT)); + load_tree(PROJECT_ROOT, NULL); + elm_box_pack_end(parent, list); }