From db5f77693983897af7c17fb08975b834ee98a2ab Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 15 Feb 2014 14:44:55 +0000 Subject: [PATCH] Order files by name in the tree --- src/bin/edi_filepanel.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/bin/edi_filepanel.c b/src/bin/edi_filepanel.c index 9600f47..494dab9 100644 --- a/src/bin/edi_filepanel.c +++ b/src/bin/edi_filepanel.c @@ -66,6 +66,17 @@ ignore_file(const char *file) return eina_str_has_prefix(file, "."); } +static int +_item_sort(const void *data1, const void *data2) +{ + const Elm_Object_Item *item1 = data1; + const Elm_Object_Item *item2 = data2; + + const char *name1 = elm_object_item_data_get(item1); + const char *name2 = elm_object_item_data_get(item2); + return strcasecmp(name1, name2); +} + static void load_tree(char *path, Elm_Object_Item *parent) { @@ -84,14 +95,14 @@ load_tree(char *path, Elm_Object_Item *parent) if (info->type == EINA_FILE_DIR) { - newParent = elm_genlist_item_append(list, &itc2, eina_stringshare_add(name), - parent, ELM_GENLIST_ITEM_NONE, NULL, NULL); + newParent = elm_genlist_item_sorted_insert(list, &itc2, eina_stringshare_add(name), + parent, ELM_GENLIST_ITEM_NONE, _item_sort, 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); + elm_genlist_item_sorted_insert(list, &itc, eina_stringshare_add(name), + parent, ELM_GENLIST_ITEM_NONE, _item_sort, NULL, NULL); } } }