diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c index 3f531a1..e65e040 100644 --- a/src/bin/edi_main.c +++ b/src/bin/edi_main.c @@ -81,49 +81,56 @@ edi_content_setup(Evas_Object *win) } static void -_tb_sel_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +_tb_save_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - printf("Toolbar button pressed\n"); + edi_mainview_save(); +} + +static void +_tb_close_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + edi_mainview_close(); +} + +static void +_tb_cut_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + edi_mainview_cut(); +} + +static void +_tb_copy_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + edi_mainview_copy(); +} + +static void +_tb_paste_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED) +{ + edi_mainview_paste(); } static Evas_Object * edi_toolbar_setup(Evas_Object *win) { - Evas_Object *tb, *menu; - Elm_Object_Item *tb_it, *menu_it; + Evas_Object *tb; + Elm_Object_Item *tb_it; tb = elm_toolbar_add(win); - elm_toolbar_homogeneous_set(tb, EINA_FALSE); + elm_toolbar_homogeneous_set(tb, EINA_TRUE); elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_SCROLL); - evas_object_size_hint_weight_set(tb, 0.0, 0.0); + elm_toolbar_align_set(tb, 0.0); evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, 0.0); - tb_it = elm_toolbar_item_append(tb, "document-print", "Hello", _tb_sel_cb, NULL); - elm_object_item_disabled_set(tb_it, EINA_TRUE); - elm_toolbar_item_priority_set(tb_it, -100); + tb_it = elm_toolbar_item_append(tb, "save", "Save", _tb_save_cb, NULL); + tb_it = elm_toolbar_item_append(tb, "close", "Close", _tb_close_cb, NULL); - tb_it = elm_toolbar_item_append(tb, "folder-new", "World", _tb_sel_cb, NULL); - elm_toolbar_item_priority_set(tb_it, 100); + tb_it = elm_toolbar_item_append(tb, "separator", "", NULL, NULL); + elm_toolbar_item_separator_set(tb_it, EINA_TRUE); - tb_it = elm_toolbar_item_append(tb, "object-rotate-right", "H", _tb_sel_cb, NULL); - elm_toolbar_item_priority_set(tb_it, -150); - - tb_it = elm_toolbar_item_append(tb, "mail-send", "Comes", _tb_sel_cb, NULL); - elm_toolbar_item_priority_set(tb_it, -200); - - tb_it = elm_toolbar_item_append(tb, "clock", "Elementary", _tb_sel_cb, NULL); - elm_toolbar_item_priority_set(tb_it, 0); - - tb_it = elm_toolbar_item_append(tb, "refresh", "Menu", NULL, NULL); - elm_toolbar_item_menu_set(tb_it, EINA_TRUE); - elm_toolbar_item_priority_set(tb_it, -9999); - elm_toolbar_menu_parent_set(tb, win); - menu = elm_toolbar_item_menu_get(tb_it); - - elm_menu_item_add(menu, NULL, "edit-cut", "Shrink", _tb_sel_cb, NULL); - menu_it = elm_menu_item_add(menu, NULL, "edit-copy", "Mode", _tb_sel_cb, NULL); - elm_menu_item_add(menu, menu_it, "edit-paste", "is set to", _tb_sel_cb, NULL); - elm_menu_item_add(menu, NULL, "edit-delete", "Scroll", _tb_sel_cb, NULL); + tb_it = elm_toolbar_item_append(tb, "edit-cut", "Cut", _tb_cut_cb, NULL); + tb_it = elm_toolbar_item_append(tb, "edit-copy", "Copy", _tb_copy_cb, NULL); + tb_it = elm_toolbar_item_append(tb, "edit-paste", "Paste", _tb_paste_cb, NULL); evas_object_show(tb); return tb; diff --git a/src/bin/edi_mainview.c b/src/bin/edi_mainview.c index 960f702..a5b48e0 100644 --- a/src/bin/edi_mainview.c +++ b/src/bin/edi_mainview.c @@ -41,6 +41,7 @@ _get_item_for_path(const char *path) return NULL; } + static void _edi_mainview_open_file_text(const char *path) { @@ -56,8 +57,9 @@ _edi_mainview_open_file_text(const char *path) txt = elm_entry_add(nf); elm_entry_scrollable_set(txt, EINA_TRUE); + elm_entry_text_style_user_push(txt, "DEFAULT='font=Monospaced font_size=12'"); elm_entry_file_set(txt, path, ELM_TEXT_FORMAT_PLAIN_UTF8); - elm_entry_autosave_set(txt, EINA_TRUE); + 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); @@ -90,6 +92,64 @@ edi_mainview_open_path(const char *path) eina_stringshare_add(path)); } +EAPI void +edi_mainview_save() +{ + Evas_Object *txt; + Elm_Object_Item *it; + + it = elm_naviframe_top_item_get(nf); + txt = elm_object_item_content_get(it); + if (txt) + elm_entry_file_save(txt); +} + +EAPI void +edi_mainview_close() +{ + if (!elm_object_item_data_get(elm_naviframe_top_item_get(nf))) + return; + + elm_naviframe_item_pop(nf); + elm_object_item_del(elm_toolbar_selected_item_get(tb)); +} + +EAPI void +edi_mainview_cut() +{ + Evas_Object *txt; + Elm_Object_Item *it; + + it = elm_naviframe_top_item_get(nf); + txt = elm_object_item_content_get(it); + if (txt) + elm_entry_selection_cut(txt); +} + +EAPI void +edi_mainview_copy() +{ + Evas_Object *txt; + Elm_Object_Item *it; + + it = elm_naviframe_top_item_get(nf); + txt = elm_object_item_content_get(it); + if (txt) + elm_entry_selection_copy(txt); +} + +EAPI void +edi_mainview_paste() +{ + Evas_Object *txt; + Elm_Object_Item *it; + + it = elm_naviframe_top_item_get(nf); + txt = elm_object_item_content_get(it); + if (txt) + elm_entry_selection_paste(txt); +} + EAPI void edi_mainview_add(Evas_Object *parent) { diff --git a/src/bin/edi_mainview.h b/src/bin/edi_mainview.h index aaafcd4..6828d9d 100644 --- a/src/bin/edi_mainview.h +++ b/src/bin/edi_mainview.h @@ -25,7 +25,7 @@ extern "C" { /** * Initialize a new Edi main view and add it to the parent panel. * - * @param win The window into which the panel will be loaded. + * @param parent The parent into which the panel will be loaded. * * @ingroup UI */ @@ -44,9 +44,50 @@ EAPI void edi_mainview_add(Evas_Object *parent); * */ - +/** + * Open the file at path for editing. + * + * @param path The absolute path of the file to open. + * + * @ingroup Content + */ EAPI void edi_mainview_open_path(const char *path); +/** + * Save the current file. + * + * @ingroup Content + */ +EAPI void edi_mainview_save(); + +/** + * Close the current file. + * + * @ingroup Content + */ +EAPI void edi_mainview_close(); + +/** + * Cut the current selection into the clipboard. + * + * @ingroup Content + */ +EAPI void edi_mainview_cut(); + +/** + * Copy the current selection into the clipboard. + * + * @ingroup Content + */ +EAPI void edi_mainview_copy(); + +/** + * Paste the current clipboard contents at the current cursor position. + * + * @ingroup Content + */ +EAPI void edi_mainview_paste(); + /** * @} * diff --git a/src/bin/edi_private.h b/src/bin/edi_private.h index 4525c91..d6cda4e 100644 --- a/src/bin/edi_private.h +++ b/src/bin/edi_private.h @@ -1,6 +1,6 @@ #ifndef EDI_PRIVATE_H_ # define EDI_PRIVATE_H_ -// FIXME: put some private stuff related to your binary +#define EDI_CONTENT_AUTOSAVE EINA_TRUE #endif