From d2117bac253e25440f1b6ac14a8318db6baa01af Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 15 May 2014 22:40:19 +0100 Subject: [PATCH] Begin factoring out the text editor from the mainview code --- src/bin/Makefile.am | 1 + src/bin/edi_mainview.c | 74 +++------------------------------- src/bin/editor/edi_editor.c | 80 +++++++++++++++++++++++++++++++++++++ src/bin/editor/edi_editor.h | 21 ++++++++++ 4 files changed, 107 insertions(+), 69 deletions(-) create mode 100644 src/bin/editor/edi_editor.c diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index a597a00..caa3a9c 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -11,6 +11,7 @@ AM_CPPFLAGS = -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ edi_SOURCES = \ editor/edi_editor_search.c \ +editor/edi_editor.c \ edi_filepanel.c \ edi_logpanel.c \ edi_consolepanel.c \ diff --git a/src/bin/edi_mainview.c b/src/bin/edi_mainview.c index f715e62..4104215 100644 --- a/src/bin/edi_mainview.c +++ b/src/bin/edi_mainview.c @@ -9,6 +9,8 @@ #include "edi_mainview.h" +#include "editor/edi_editor.h" + #include "edi_private.h" static Evas_Object *nf, *tb, *_main_win; @@ -22,7 +24,7 @@ dummy() {} EAPI void -_edi_mainview_item_prev() +edi_mainview_item_prev() { Eina_List *item; Elm_Object_Item *current; @@ -43,7 +45,7 @@ _edi_mainview_item_prev() } EAPI void -_edi_mainview_item_next() +edi_mainview_item_next() { Eina_List *item; Elm_Object_Item *current; @@ -116,72 +118,6 @@ _edi_mainview_item_add(const char *path, Elm_Object_Item *tab, Evas_Object *view return item; } -static void -_smart_cb_key_down(void *data, Evas *e EINA_UNUSED, - Evas_Object *obj EINA_UNUSED, void *event) -{ - Eina_Bool ctrl, alt, shift; - Evas_Event_Key_Down *ev = event; - - ctrl = evas_key_modifier_is_set(ev->modifiers, "Control"); - alt = evas_key_modifier_is_set(ev->modifiers, "Alt"); - shift = evas_key_modifier_is_set(ev->modifiers, "Shift"); - - if ((!alt) && (ctrl) && (!shift)) - { - if (!strcmp(ev->key, "Prior")) - { - _edi_mainview_item_prev(); - } - else if (!strcmp(ev->key, "Next")) - { - _edi_mainview_item_next(); - } - else if (!strcmp(ev->key, "s")) - { - edi_mainview_save(); - } - else if (!strcmp(ev->key, "f")) - { - edi_mainview_search(); - } - } -} - -static Evas_Object * -_edi_mainview_content_text_create(const char *path, Evas_Object *parent) -{ - Evas_Object *txt; - Evas_Modifier_Mask ctrl, shift, alt; - Evas *e; - - txt = elm_entry_add(parent); - elm_entry_editable_set(txt, EINA_TRUE); - elm_entry_scrollable_set(txt, EINA_TRUE); - elm_entry_line_wrap_set(txt, EINA_FALSE); - elm_entry_text_style_user_push(txt, "DEFAULT='font=Monospace font_size=12'"); - elm_entry_file_set(txt, path, ELM_TEXT_FORMAT_PLAIN_UTF8); - elm_entry_autosave_set(txt, EDI_CONTENT_AUTOSAVE); - 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); - - evas_object_event_callback_add(txt, EVAS_CALLBACK_KEY_DOWN, - _smart_cb_key_down, txt); - - e = evas_object_evas_get(txt); - ctrl = evas_key_modifier_mask_get(e, "Control"); - alt = evas_key_modifier_mask_get(e, "Alt"); - shift = evas_key_modifier_mask_get(e, "Shift"); - - evas_object_key_grab(txt, "Prior", ctrl, shift | alt, 1); - evas_object_key_grab(txt, "Next", ctrl, shift | alt, 1); - evas_object_key_grab(txt, "s", ctrl, shift | alt, 1); - evas_object_key_grab(txt, "f", ctrl, shift | alt, 1); - - return txt; -} - static Evas_Object * _edi_mainview_content_image_create(const char *path, Evas_Object *parent) { @@ -205,7 +141,7 @@ _edi_mainview_content_create(const char *path, const char *type, Evas_Object *pa { if (!strcmp(type, "text")) { - return _edi_mainview_content_text_create(path, parent); + return edi_editor_add(parent, path); } else if (!strcmp(type, "image")) { diff --git a/src/bin/editor/edi_editor.c b/src/bin/editor/edi_editor.c new file mode 100644 index 0000000..02eea6c --- /dev/null +++ b/src/bin/editor/edi_editor.c @@ -0,0 +1,80 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include +#include + +#include "edi_editor.h" + +#include "edi_mainview.h" + +#include "edi_private.h" + + +static void +_smart_cb_key_down(void *data, Evas *e EINA_UNUSED, + Evas_Object *obj EINA_UNUSED, void *event) +{ + Eina_Bool ctrl, alt, shift; + Evas_Event_Key_Down *ev = event; + + ctrl = evas_key_modifier_is_set(ev->modifiers, "Control"); + alt = evas_key_modifier_is_set(ev->modifiers, "Alt"); + shift = evas_key_modifier_is_set(ev->modifiers, "Shift"); + + if ((!alt) && (ctrl) && (!shift)) + { + if (!strcmp(ev->key, "Prior")) + { + edi_mainview_item_prev(); + } + else if (!strcmp(ev->key, "Next")) + { + edi_mainview_item_next(); + } + else if (!strcmp(ev->key, "s")) + { + edi_mainview_save(); + } + else if (!strcmp(ev->key, "f")) + { + edi_mainview_search(); + } + } +} + +EAPI Evas_Object *edi_editor_add(Evas_Object *parent, const char *path) +{ + Evas_Object *txt; + Evas_Modifier_Mask ctrl, shift, alt; + Evas *e; + + txt = elm_entry_add(parent); + elm_entry_editable_set(txt, EINA_TRUE); + elm_entry_scrollable_set(txt, EINA_TRUE); + elm_entry_line_wrap_set(txt, EINA_FALSE); + elm_entry_text_style_user_push(txt, "DEFAULT='font=Monospace font_size=12'"); + elm_entry_file_set(txt, path, ELM_TEXT_FORMAT_PLAIN_UTF8); + elm_entry_autosave_set(txt, EDI_CONTENT_AUTOSAVE); + 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); + + evas_object_event_callback_add(txt, EVAS_CALLBACK_KEY_DOWN, + _smart_cb_key_down, txt); + + e = evas_object_evas_get(txt); + ctrl = evas_key_modifier_mask_get(e, "Control"); + alt = evas_key_modifier_mask_get(e, "Alt"); + shift = evas_key_modifier_mask_get(e, "Shift"); + + evas_object_key_grab(txt, "Prior", ctrl, shift | alt, 1); + evas_object_key_grab(txt, "Next", ctrl, shift | alt, 1); + evas_object_key_grab(txt, "s", ctrl, shift | alt, 1); + evas_object_key_grab(txt, "f", ctrl, shift | alt, 1); + + return txt; +} diff --git a/src/bin/editor/edi_editor.h b/src/bin/editor/edi_editor.h index 85fb032..313f2b8 100644 --- a/src/bin/editor/edi_editor.h +++ b/src/bin/editor/edi_editor.h @@ -13,6 +13,27 @@ extern "C" { */ /** + * @brief Editor. + * @defgroup Editor The main text editor functions + * + * @{ + * + */ + +/** + * Initialize a new Edi editor and add it to the parent panel. + * + * @param parent The panel into which the panel will be loaded. + * @param path The file path to be loaded in the editor. + * @return the created evas object that contains the editor. + * + * @ingroup Editor + */ +EAPI Evas_Object *edi_editor_add(Evas_Object *parent, const char *path); + +/** + * @} + * * @brief Dialogs. * @defgroup Dialogs Functions that open other dialogs *