From 6e27500f6867411184c981885f49e9cee8263604 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 15 Feb 2014 23:17:40 +0000 Subject: [PATCH] Adding (blind) loading of files as text for editing. Use a naviframe for holding the content and a callback from filepanel through main to open new files --- src/bin/Makefile.am | 1 + src/bin/edi_filepanel.c | 18 +++++++--- src/bin/edi_filepanel.h | 11 +++--- src/bin/edi_main.c | 23 ++++++++----- src/bin/edi_mainview.c | 75 +++++++++++++++++++++++++++++++++++++++++ src/bin/edi_mainview.h | 59 ++++++++++++++++++++++++++++++++ 6 files changed, 171 insertions(+), 16 deletions(-) create mode 100644 src/bin/edi_mainview.c create mode 100644 src/bin/edi_mainview.h diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index cc29988..71069a8 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -11,6 +11,7 @@ AM_CPPFLAGS = -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ edi_SOURCES = \ edi_filepanel.c \ +edi_mainview.c \ edi_main.c edi_LDADD = @EFL_LIBS@ $(top_builddir)/src/lib/libedi.la diff --git a/src/bin/edi_filepanel.c b/src/bin/edi_filepanel.c index 494dab9..cf365bc 100644 --- a/src/bin/edi_filepanel.c +++ b/src/bin/edi_filepanel.c @@ -15,6 +15,7 @@ static char *PROJECT_ROOT = "/home/andy/Code/E/edi"; static Elm_Genlist_Item_Class itc, itc2; static Evas_Object *list; +static edi_filepanel_item_clicked_cb _open_cb; static char * _text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *source EINA_UNUSED) @@ -39,9 +40,16 @@ _content_get(void *data, Evas_Object *obj, const char *source) } static void -_item_del(void *data, Evas_Object *obj EINA_UNUSED) +_item_del(void *data, Evas_Object *obj) { eina_stringshare_del(data); + eina_stringshare_del(elm_object_item_data_get(obj)); +} + +static void +_item_sel(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + _open_cb((const char*)data); } static Evas_Object * @@ -96,20 +104,21 @@ load_tree(char *path, Elm_Object_Item *parent) if (info->type == EINA_FILE_DIR) { newParent = elm_genlist_item_sorted_insert(list, &itc2, eina_stringshare_add(name), - parent, ELM_GENLIST_ITEM_NONE, _item_sort, NULL, NULL); + parent, ELM_GENLIST_ITEM_NONE, _item_sort, _item_sel, eina_stringshare_add(info->path)); load_tree(info->path, newParent); } else if (info->type == EINA_FILE_REG) { elm_genlist_item_sorted_insert(list, &itc, eina_stringshare_add(name), - parent, ELM_GENLIST_ITEM_NONE, _item_sort, NULL, NULL); + parent, ELM_GENLIST_ITEM_NONE, _item_sort, _item_sel, eina_stringshare_add(info->path)); } } } } void -edi_filepanel_add(Evas_Object *parent) +edi_filepanel_add(Evas_Object *parent, + edi_filepanel_item_clicked_cb cb) { list = elm_genlist_add(parent); evas_object_size_hint_min_set(list, 100, -1); @@ -128,6 +137,7 @@ edi_filepanel_add(Evas_Object *parent) // itc2.func.state_get = _state_get; itc2.func.del = _item_del; + _open_cb = cb; load_tree(PROJECT_ROOT, NULL); elm_box_pack_end(parent, list); diff --git a/src/bin/edi_filepanel.h b/src/bin/edi_filepanel.h index ba7afa3..b17b5b9 100644 --- a/src/bin/edi_filepanel.h +++ b/src/bin/edi_filepanel.h @@ -1,5 +1,5 @@ -#ifndef EDI_H_ -# define EDI_H_ +#ifndef EDI_FILEPANEL_H_ +# define EDI_FILEPANEL_H_ #include @@ -12,6 +12,8 @@ extern "C" { * @brief These routines are used for managing the Edi file panel. */ + typedef void (*edi_filepanel_item_clicked_cb)(const char *path); + /** * @brief UI management functions. * @defgroup UI @@ -29,7 +31,8 @@ extern "C" { * * @ingroup UI */ -void edi_filepanel_add(Evas_Object *parent); +void edi_filepanel_add(Evas_Object *parent, + edi_filepanel_item_clicked_cb cb); /** * @} @@ -41,4 +44,4 @@ void edi_filepanel_add(Evas_Object *parent); } #endif -#endif /* EDI_H_ */ +#endif /* EDI_FILEPANEL_H_ */ diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c index ec03100..0d608a4 100644 --- a/src/bin/edi_main.c +++ b/src/bin/edi_main.c @@ -14,6 +14,7 @@ #include "Edi.h" #include "edi_filepanel.h" +#include "edi_mainview.h" #include "edi_private.h" @@ -25,6 +26,12 @@ _edi_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_i elm_exit(); } +static void +_edi_file_open_cb(const char *path) +{ + edi_mainview_open(path); +} + static Evas_Object * edi_content_setup(Evas_Object *win) { @@ -38,7 +45,7 @@ edi_content_setup(Evas_Object *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); + edi_filepanel_add(panel, _edi_file_open_cb); elm_object_part_content_set(panes, "left", panel); elm_panes_content_left_size_set(panes, 0.2); @@ -53,13 +60,13 @@ edi_content_setup(Evas_Object *win) elm_object_part_content_set(panes, "right", panes_h); // add main content - txt = elm_entry_add(win); - elm_entry_scrollable_set(txt, EINA_TRUE); - elm_object_text_set(txt, "Main"); - evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(txt); - elm_object_part_content_set(panes_h, "top", txt); + 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_mainview_add(panel); + + elm_object_part_content_set(panes_h, "top", panel); // add lower panel txt = elm_label_add(win); diff --git a/src/bin/edi_mainview.c b/src/bin/edi_mainview.c new file mode 100644 index 0000000..0486a99 --- /dev/null +++ b/src/bin/edi_mainview.c @@ -0,0 +1,75 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include + +#include "edi_mainview.h" + +#include "edi_private.h" + +static Evas_Object *nf, *tb; + +static void +_promote(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + elm_naviframe_item_promote(data); +} + +EAPI void +edi_mainview_open(const char *path) +{ + Evas_Object *txt; + Elm_Object_Item *it, *tab; + + txt = elm_entry_add(nf); + elm_entry_scrollable_set(txt, EINA_TRUE); + elm_entry_file_set(txt, path, ELM_TEXT_FORMAT_PLAIN_UTF8); + elm_entry_autosave_set(txt, EINA_TRUE); + evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(txt); + + it = elm_naviframe_item_simple_push(nf, txt); + tab = elm_toolbar_item_append(tb, NULL, basename(path), _promote, it); + elm_toolbar_item_selected_set(tab, EINA_TRUE); +} + +EAPI void +edi_mainview_add(Evas_Object *parent) +{ + Evas_Object *box, *txt; + Elm_Object_Item *it; + + box = elm_box_add(parent); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(box); + elm_box_pack_end(parent, box); + + tb = elm_toolbar_add(parent); + evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_toolbar_homogeneous_set(tb, EINA_FALSE); + elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_SCROLL); + elm_toolbar_select_mode_set(tb, ELM_OBJECT_SELECT_MODE_ALWAYS); + elm_box_pack_end(box, tb); + evas_object_show(tb); + + nf = elm_naviframe_add(parent); + evas_object_size_hint_weight_set(nf, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(nf, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(box, nf); + evas_object_show(nf); + + txt = elm_label_add(parent); + elm_object_text_set(txt, "Welcome - tap a file to edit"); + evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(txt); + + it = elm_naviframe_item_simple_push(nf, txt); + elm_toolbar_item_append(tb, NULL, "Welcome", _promote, it); +} diff --git a/src/bin/edi_mainview.h b/src/bin/edi_mainview.h new file mode 100644 index 0000000..b663325 --- /dev/null +++ b/src/bin/edi_mainview.h @@ -0,0 +1,59 @@ +#ifndef EDI_MAINVIEW_H_ +# define EDI_MAINVIEW_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for managing the main area of the Edi interface. + */ + +/** + * @brief UI management functions. + * @defgroup UI + * + * @{ + * + * Initialisation and management of the main view UI + * + */ + +/** + * Initialize a new Edi main view and add it to the parent panel. + * + * @param win The window into which the panel will be loaded. + * + * @ingroup UI + */ +EAPI void edi_mainview_add(Evas_Object *parent); + +/** + * @} + * + * + * @brief Content management functions. + * @defgroup Content + * + * @{ + * + * Opening and managing content within the view. + * + */ + + +EAPI void edi_mainview_open(const char *path); + +/** + * @} + * + */ + +#ifdef __cplusplus +} +#endif + +#endif /* EDI_MAINVIEW_H_ */