From 5d8981d09db513aa6347a1814257ec158e29a6aa Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 14 Feb 2014 23:50:25 +0000 Subject: [PATCH] Loading the panel from the filesystem. organise out a little and commit where i've got to --- configure.ac | 1 + src/bin/Makefile.am | 5 +- src/bin/edi_filepanel.c | 131 ++++++++++++++++++++++++++++++++++++++++ src/bin/edi_filepanel.h | 44 ++++++++++++++ src/bin/edi_main.c | 66 +++----------------- 5 files changed, 190 insertions(+), 57 deletions(-) create mode 100644 src/bin/edi_filepanel.c create mode 100644 src/bin/edi_filepanel.h diff --git a/configure.ac b/configure.ac index 24dfeac..3c01a39 100644 --- a/configure.ac +++ b/configure.ac @@ -35,6 +35,7 @@ PKG_CHECK_MODULES([EFL], ecore >= 1.8.0 edje >= 1.8.0 elementary >= 1.8.0 + eio >= 1.8.0 ]) # Check for tests and coverage diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 87bf281..cc29988 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -9,7 +9,10 @@ AM_CPPFLAGS = -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ -I$(top_srcdir)/src/lib/ \ @EFL_CFLAGS@ -edi_SOURCES = edi_main.c +edi_SOURCES = \ +edi_filepanel.c \ +edi_main.c + edi_LDADD = @EFL_LIBS@ $(top_builddir)/src/lib/libedi.la localedir = $(datadir)/locale diff --git a/src/bin/edi_filepanel.c b/src/bin/edi_filepanel.c new file mode 100644 index 0000000..ef76b14 --- /dev/null +++ b/src/bin/edi_filepanel.c @@ -0,0 +1,131 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#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 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) +{ + return strdup(basename(data)); +} + +static Evas_Object * +_content_get(void *data, Evas_Object *obj, const char *source) +{ + if (!strcmp(source, "elm.swallow.icon")) + { + Evas_Object *ic; + + ic = elm_icon_add(obj); + elm_icon_standard_set(ic, "file"); + evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); + evas_object_show(ic); + return ic; + } + return NULL; +} + +static void +_item_del(void *data, Evas_Object *obj EINA_UNUSED) +{ +} + +static Evas_Object * +_content_dir_get(void *data, Evas_Object *obj, const char *source) +{ + if (!strcmp(source, "elm.swallow.icon")) + { + Evas_Object *ic; + + ic = elm_icon_add(obj); + elm_icon_standard_set(ic, "folder"); + evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); + evas_object_show(ic); + return ic; + } + return NULL; +} + +void +edi_filepanel_add(Evas_Object *parent) +{ + list = elm_genlist_add(parent); + evas_object_size_hint_min_set(list, 100, -1); + evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(list); + + 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.del = _item_del; + + eio_file_direct_stat(PROJECT_ROOT, stat_done, dummy, eina_stringshare_add(PROJECT_ROOT)); + elm_box_pack_end(parent, list); +} diff --git a/src/bin/edi_filepanel.h b/src/bin/edi_filepanel.h new file mode 100644 index 0000000..ba7afa3 --- /dev/null +++ b/src/bin/edi_filepanel.h @@ -0,0 +1,44 @@ +#ifndef EDI_H_ +# define EDI_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for managing the Edi file panel. + */ + +/** + * @brief UI management functions. + * @defgroup UI + * + * @{ + * + * Initialisation and management of the file panel UI + * + */ + +/** + * Initialize a new Edi filepanel and add it to the parent panel. + * + * @param win The window into which the panel will be loaded. + * + * @ingroup UI + */ +void edi_filepanel_add(Evas_Object *parent); + +/** + * @} + */ + + + +#ifdef __cplusplus +} +#endif + +#endif /* EDI_H_ */ diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c index 53bc305..ec03100 100644 --- a/src/bin/edi_main.c +++ b/src/bin/edi_main.c @@ -8,85 +8,39 @@ #include #include +#include #include "gettext.h" #include "Edi.h" +#include "edi_filepanel.h" #include "edi_private.h" #define COPYRIGHT "Copyright © 2014 Andy Williams and various contributors (see AUTHORS)." -static Elm_Genlist_Item_Class itc; - static void _edi_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { elm_exit(); } -static char * -_text_get(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *source EINA_UNUSED) -{ - return strdup(data); -} - -static Evas_Object * -_content_get(void *data, Evas_Object *obj, const char *source) -{ - if (!strcmp(source, "elm.swallow.icon")) - { - Evas_Object *ic; - - ic = elm_icon_add(obj); - if (!strcmp(data, "Dir")) - elm_icon_standard_set(ic, "folder"); - else - elm_icon_standard_set(ic, "file"); - evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); - evas_object_show(ic); - return ic; - } - return NULL; -} - -static Evas_Object * -edi_filetree_setup(Evas_Object *win) -{ - Evas_Object *list; - - list = elm_genlist_add(win); - evas_object_size_hint_min_set(list, 100, -1); - evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(list); - - 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; - - elm_genlist_item_append(list, &itc, "File 1", - NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); - elm_genlist_item_append(list, &itc, "File 2", - NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); - elm_genlist_item_append(list, &itc, "Dir", - NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); - - return list; -} - static Evas_Object * edi_content_setup(Evas_Object *win) { - Evas_Object *panes, *panes_h, *txt; + Evas_Object *panes, *panes_h, *panel, *txt; panes = elm_panes_add(win); evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); // add file list - elm_object_part_content_set(panes, "left", edi_filetree_setup(win)); + panel = elm_box_add(win); + evas_object_size_hint_weight_set(panel, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(panel, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(panel); + edi_filepanel_add(panel); + + elm_object_part_content_set(panes, "left", panel); elm_panes_content_left_size_set(panes, 0.2); // add panes