hermet pushed a commit to branch master. http://git.enlightenment.org/tools/enventor.git/commit/?id=71c3db0766940149b3898c69445d791c5197ab04
commit 71c3db0766940149b3898c69445d791c5197ab04 Author: Kateryna Fesyna <[email protected]> Date: Mon Aug 11 13:48:01 2014 +0900 Enventor: Prototipe of Drag-n-Drop feature. Patch 1. Summary: This commit contains the basic implementation of Live Edit mode. With this commit Live Edit toggling is added to Menu, Tools and Ctrl-M hot-key. Activating of Live Edit mode disables the EDC-Editor and allows user to add new parts by selecting corresponding part type in the menu that appears on right click on the EDJ-Viewer area. Reviewers: Hermet Projects: #enventor Differential Revision: https://phab.enlightenment.org/D1276 --- data/themes/default/images.edc | 40 ++++++ data/themes/default/images/disabler.png | Bin 0 -> 157 bytes .../default/images/live_edit_icons/icon-image.png | Bin 0 -> 299 bytes .../images/live_edit_icons/icon-live-edit.png | Bin 0 -> 323 bytes .../images/live_edit_icons/icon-rectangle.png | Bin 0 -> 160 bytes .../default/images/live_edit_icons/icon-spacer.png | Bin 0 -> 164 bytes .../images/live_edit_icons/icon-swallow.png | Bin 0 -> 208 bytes .../default/images/live_edit_icons/icon-text.png | Bin 0 -> 182 bytes .../images/live_edit_icons/icon-textblock.png | Bin 0 -> 286 bytes data/themes/default/layout_common.edc | 41 ++++++ src/bin/Makefile.am | 3 +- src/bin/config_data.c | 17 +++ src/bin/edc_editor.c | 12 ++ src/bin/edc_parser.c | 105 ++++++++++++++ src/bin/edj_viewer.c | 6 + src/bin/live_edit.c | 156 +++++++++++++++++++++ src/bin/main.c | 26 +++- src/bin/setting.c | 11 +- src/bin/template.c | 113 ++++++++++++--- src/bin/tools.c | 14 +- src/include/Makefile.am | 3 +- src/include/common.h | 2 + src/include/config_data.h | 2 + src/include/edc_editor.h | 3 +- src/include/edc_parser.h | 3 +- src/include/edj_viewer.h | 1 + src/include/live_edit.h | 3 + src/include/template.h | 2 +- src/include/template_code.h | 56 +++++--- src/include/tools.h | 2 +- 30 files changed, 570 insertions(+), 51 deletions(-) diff --git a/data/themes/default/images.edc b/data/themes/default/images.edc index 4b013d8..97586ea 100644 --- a/data/themes/default/images.edc +++ b/data/themes/default/images.edc @@ -10,6 +10,13 @@ images { image: "status.png" COMP; image: "swallow_s.png" COMP; image: "goto.png" COMP; + image: "live_edit_icons/icon-image.png" COMP; + image: "live_edit_icons/icon-rectangle.png" COMP; + image: "live_edit_icons/icon-swallow.png" COMP; + image: "live_edit_icons/icon-spacer.png" COMP; + image: "live_edit_icons/icon-text.png" COMP; + image: "live_edit_icons/icon-textblock.png" COMP; + image: "live_edit_icons/icon-live-edit.png" COMP; } group { name: "line"; @@ -131,3 +138,36 @@ group { name: "minus"; } } } + +group { name: "live-edit"; + parts { + part { name: "img"; + type: IMAGE; + description { state: "default" 0.0; + image.normal: "live_edit_icons/icon-live-edit.png"; + } + } + } +} + +#define ADD_LIVE_EDIT_ICON_GROUP(_group_name, _image_path) \ + group { name: _group_name; \ + parts { \ + part { name: "img"; \ + description { state: "default" 0.0; \ + image.normal: _image_path; \ + min: 10 10; \ + max: 10 10; \ + } \ + } \ + } \ + } + +ADD_LIVE_EDIT_ICON_GROUP("IMAGE", "live_edit_icons/icon-image.png") +ADD_LIVE_EDIT_ICON_GROUP("RECT", "live_edit_icons/icon-rectangle.png") +ADD_LIVE_EDIT_ICON_GROUP("SPACER", "live_edit_icons/icon-spacer.png") +ADD_LIVE_EDIT_ICON_GROUP("SWALLOW", "live_edit_icons/icon-swallow.png") +ADD_LIVE_EDIT_ICON_GROUP("TEXT", "live_edit_icons/icon-text.png") +ADD_LIVE_EDIT_ICON_GROUP("TEXTBLOCK", "live_edit_icons/icon-textblock.png") + +#undef ADD_LIVE_EDIT_ICON_GROUP diff --git a/data/themes/default/images/disabler.png b/data/themes/default/images/disabler.png new file mode 100644 index 0000000..81e80d7 Binary files /dev/null and b/data/themes/default/images/disabler.png differ diff --git a/data/themes/default/images/live_edit_icons/icon-image.png b/data/themes/default/images/live_edit_icons/icon-image.png new file mode 100644 index 0000000..97120c4 Binary files /dev/null and b/data/themes/default/images/live_edit_icons/icon-image.png differ diff --git a/data/themes/default/images/live_edit_icons/icon-live-edit.png b/data/themes/default/images/live_edit_icons/icon-live-edit.png new file mode 100644 index 0000000..0d0498b Binary files /dev/null and b/data/themes/default/images/live_edit_icons/icon-live-edit.png differ diff --git a/data/themes/default/images/live_edit_icons/icon-rectangle.png b/data/themes/default/images/live_edit_icons/icon-rectangle.png new file mode 100644 index 0000000..04f0af5 Binary files /dev/null and b/data/themes/default/images/live_edit_icons/icon-rectangle.png differ diff --git a/data/themes/default/images/live_edit_icons/icon-spacer.png b/data/themes/default/images/live_edit_icons/icon-spacer.png new file mode 100644 index 0000000..3c9813d Binary files /dev/null and b/data/themes/default/images/live_edit_icons/icon-spacer.png differ diff --git a/data/themes/default/images/live_edit_icons/icon-swallow.png b/data/themes/default/images/live_edit_icons/icon-swallow.png new file mode 100644 index 0000000..ef57cdb Binary files /dev/null and b/data/themes/default/images/live_edit_icons/icon-swallow.png differ diff --git a/data/themes/default/images/live_edit_icons/icon-text.png b/data/themes/default/images/live_edit_icons/icon-text.png new file mode 100644 index 0000000..8a16fea Binary files /dev/null and b/data/themes/default/images/live_edit_icons/icon-text.png differ diff --git a/data/themes/default/images/live_edit_icons/icon-textblock.png b/data/themes/default/images/live_edit_icons/icon-textblock.png new file mode 100644 index 0000000..1c8dcfc Binary files /dev/null and b/data/themes/default/images/live_edit_icons/icon-textblock.png differ diff --git a/data/themes/default/layout_common.edc b/data/themes/default/layout_common.edc index 23b4025..34fa19b 100644 --- a/data/themes/default/layout_common.edc +++ b/data/themes/default/layout_common.edc @@ -6,6 +6,7 @@ images { image: "logo.png" COMP; image: "shine.png" COMP; image: "bub_over_bot.png" COMP; + image: "disabler.png" COMP; } group { name: "about_layout"; @@ -2132,6 +2133,28 @@ group { name: "edit_layout"; fixed: 0 1; } } + part { name: "disabler_bg"; + type: RECT; + mouse_events: 0; + description { state: "default" 0.0; + color: 0 0 0 0; + } + description { state: "disabled" 0.0; + color: 0 0 0 160; + } + } + part { name: "disabler_decorations"; + mouse_events: 0; + description { state: "default" 0.0; + image.normal: "disabler.png"; + fill.type: TILE; + color: 155 155 155 0; + } + description { state: "disabled" 0.0; + inherit: "default" 0.0; + color: 55 55 77 200; + } + } } programs { program { name: "linenumber_show"; @@ -2147,4 +2170,22 @@ group { name: "edit_layout"; transition: DECELERATE 0.35; } } + programs { + program { name: "layout_disable"; + signal: "elm,state,disabled"; + source: "editor"; + action: STATE_SET "disabled" 0.0; + target: "disabler_bg"; + target: "disabler_decorations"; + transition: DECELERATE 0.35; + } + program { name: "layout_enable"; + signal: "elm,state,enabled"; + source: "editor"; + action: STATE_SET "default" 0.0; + target: "disabler_bg"; + target: "disabler_decorations"; + transition: DECELERATE 0.35; + } + } } diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 6f90d0f..2044e01 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -34,7 +34,8 @@ enventor_SOURCES = \ setting.c \ globals.c \ redoundo.c \ - template.c + template.c \ + live_edit.c enventor_LDADD = @ENVENTOR_LIBS@ enventor_LDFLAGS = $(LTLIBINTL) diff --git a/src/bin/config_data.c b/src/bin/config_data.c index 2233010..8663021 100644 --- a/src/bin/config_data.c +++ b/src/bin/config_data.c @@ -30,6 +30,7 @@ typedef struct config_s Eina_Bool tools; Eina_Bool auto_complete; Eina_Bool console; + Eina_Bool live_edit; } config_data; static config_data *g_cd = NULL; @@ -138,6 +139,7 @@ config_load(void) cd->tools = EINA_FALSE; cd->auto_complete = EINA_TRUE; cd->console = EINA_FALSE; + cd->live_edit = EINA_FALSE; } g_cd = cd; @@ -613,6 +615,21 @@ config_font_size_get(void) return cd->font_size; } +Eina_Bool +config_live_edit_get(void) +{ + config_data *cd = g_cd; + return cd->live_edit; +} + +void +config_live_edit_set(Eina_Bool enabled) +{ + config_data *cd = g_cd; + cd->live_edit = enabled; +} + + void config_auto_complete_set(Eina_Bool auto_complete) { diff --git a/src/bin/edc_editor.c b/src/bin/edc_editor.c index 91e466c..6d4d938 100644 --- a/src/bin/edc_editor.c +++ b/src/bin/edc_editor.c @@ -1187,3 +1187,15 @@ edit_redoundo_region_push(edit_data *ed, int cursor_pos1, int cursor_pos2) redoundo_entry_region_push(ed->rd, cursor_pos1, cursor_pos2); } +void +edit_disabled_set(edit_data *ed, Eina_Bool disable) +{ + elm_object_disabled_set(ed->layout, disable); + elm_object_focus_allow_set(ed->layout, disable); + evas_object_freeze_events_set (ed->layout, disable); + + if (disable) + elm_object_signal_emit(ed->layout, "elm,state,disabled", "editor"); + else + elm_object_signal_emit(ed->layout, "elm,state,enabled", "editor"); +} diff --git a/src/bin/edc_parser.c b/src/bin/edc_parser.c index 026b859..11518df 100644 --- a/src/bin/edc_parser.c +++ b/src/bin/edc_parser.c @@ -921,3 +921,108 @@ parser_term(parser_data *pd) free(pd); } + +static const char * +end_of_parts_block_find(const char *pos) +{ + //TODO: Process comments and quotes. + pos = strstr(pos, "parts"); + if (!pos) return NULL; + pos = strstr(pos, "{"); + if (!pos) return NULL; + pos++; + char level = 1; + + while (*pos) + { + if (*pos == '{') level++; + else if (*pos == '}') + { + level--; + } + if (!level) return --pos; + pos++; + } + return NULL; +} + +static const char * +group_beginning_pos_get(const char* source, const char *group_name) +{ + const char* group_block_name = "group"; + const int quot_len = QUOT_LEN; + const char *quot = QUOT; + + const char *pos = strstr(source, group_block_name); + //TODO: Process comments and quotes. + while (pos) + { + const char *name = strstr(pos, quot); + if (!name) return NULL; + pos = strstr(++name, quot); + if (!pos) return NULL; + if (!strncmp(name, group_name, strlen(group_name))) + return pos; + pos = strstr(++pos, group_block_name); + } + + return NULL; +} + +Evas_Coord +parser_end_of_parts_block_pos_get(const Evas_Object *entry, const char *group_name) +{ + if (!group_name) + return -1; + + const char *text = elm_entry_entry_get(entry); + if (!text) return -1; + + char *utf8 = elm_entry_markup_to_utf8(text); + if (!utf8) return -1; + + const char *pos = group_beginning_pos_get(utf8, group_name); + if (!pos) return -1; + pos = end_of_parts_block_find(++pos); + if (pos) return pos - utf8 + 1; + return -1; +} + +Eina_Bool +parser_images_pos_get(const Evas_Object *entry, Evas_Coord *res_position) +{ + if (!res_position) return EINA_FALSE; + + const char* group_block_name = "group"; + const char* images_block_name = "images"; + Evas_Coord images_block_name_len = 6; //strlen of "images" + + *res_position = -1; + const char *text = elm_entry_entry_get(entry); + if (!text) return EINA_FALSE; + + char *utf8 = elm_entry_markup_to_utf8(text); + if (!utf8) return EINA_FALSE; + + const char *pos = strstr(utf8, images_block_name); + if (pos) + { + // TODO: Remove this check and process lines of the form "images.image: "logo.png" COMP;" + if (*(pos + images_block_name_len + 1) == '.') + return EINA_FALSE; + + pos = strstr(pos, "{\n"); + if (!pos) return EINA_FALSE; + + *res_position = pos - utf8 + 2; + return EINA_TRUE; + } + pos = strstr(utf8, group_block_name); + if (pos) + { + *res_position = pos - utf8; + return EINA_FALSE; + } + return EINA_FALSE; +} + diff --git a/src/bin/edj_viewer.c b/src/bin/edj_viewer.c index 9c608f7..9f3e8f8 100644 --- a/src/bin/edj_viewer.c +++ b/src/bin/edj_viewer.c @@ -318,6 +318,12 @@ view_obj_get(view_data *vd) return vd->scroller; } +Evas_Object * +view_layout_get(view_data *vd) +{ + return vd->layout; +} + void view_program_run(view_data *vd, const char *program) { diff --git a/src/bin/live_edit.c b/src/bin/live_edit.c new file mode 100644 index 0000000..7917a80 --- /dev/null +++ b/src/bin/live_edit.c @@ -0,0 +1,156 @@ +#include <Elementary.h> +#include "common.h" + +struct live_editor_s +{ + Evas_Object *menu; + edit_data *ed; +}; + +#define LIVE_EDIT_ITEMS_NUM 6 +static const char *LIVE_EDIT_MENU_LABELS[LIVE_EDIT_ITEMS_NUM] = +{ + "RECT", + "IMAGE", + "SPACER", + "SWALLOW", + "TEXT", + "TEXTBLOCK" +}; + +static Eina_Bool +live_edit_part_insert(live_edit_data *led, unsigned int part_type, + Eina_Stringshare *group_name) +{ + Edje_Part_Type type; + switch (part_type) + { + case 0: + { + type = EDJE_PART_TYPE_RECTANGLE; + break; + } + case 1: + { + type = EDJE_PART_TYPE_IMAGE; + break; + } + case 2: + { + type = EDJE_PART_TYPE_SPACER; + break; + } + case 3: + { + type = EDJE_PART_TYPE_SWALLOW; + break; + } + case 4: + { + type = EDJE_PART_TYPE_TEXT; + break; + } + case 5: + { + type = EDJE_PART_TYPE_TEXTBLOCK; + break; + } + } + template_live_edit_part_insert(led->ed, type, group_name); + return EINA_TRUE; +} + +live_edit_data* +live_edit_init(edit_data *ed) +{ + live_edit_data *led = calloc(1, sizeof(live_edit_data)); + if (!led) + { + EINA_LOG_ERR("Failed to allocate Memory!"); + return NULL; + } + led->ed = ed; + + return led; +} + +static void +live_edit_menu_item_selected_cb(void *data, Evas_Object *obj, void *event_info) +{ + live_edit_data *led = data; + const Elm_Object_Item *it = event_info; + unsigned int part_type = elm_menu_item_index_get(it); + live_edit_part_insert(led, part_type, view_group_name_get(VIEW_DATA)); +} + +static Evas_Object * +live_edit_menu_create(Evas_Object *parent, live_edit_data *led) +{ + long int i; + Evas_Object* icon; + Elm_Object_Item *it; + + Evas_Object *menu = elm_menu_add(parent); + + for (i = 0; i < LIVE_EDIT_ITEMS_NUM; i++) + { + it = elm_menu_item_add(menu, NULL, NULL, + LIVE_EDIT_MENU_LABELS[i], + live_edit_menu_item_selected_cb, led); + icon = elm_image_add(menu); + elm_image_file_set(icon, EDJE_PATH, LIVE_EDIT_MENU_LABELS[i]); + elm_object_item_part_content_set(it, NULL, icon); + } + + return menu; +} + + +static void +live_edit_menu_show_cb(void *data, Evas *e EINA_UNUSED, + Evas_Object *obj EINA_UNUSED, void *event_info) +{ + Evas_Event_Mouse_Up *ev = event_info; + live_edit_data *led = data; + + // Check if the right button is pressed + if (ev->button != 3) return; + + if (!led->menu) + led->menu = live_edit_menu_create(obj, led); + + elm_menu_move(led->menu, ev->canvas.x, ev->canvas.y); + evas_object_show(led->menu); +} + +void +live_edit_toggle(live_edit_data* led, Eina_Bool is_on) +{ + if (VIEW_DATA) + { + Evas_Object *view_layout = view_layout_get(VIEW_DATA); + + if (is_on) + evas_object_event_callback_add(view_layout, EVAS_CALLBACK_MOUSE_UP, + live_edit_menu_show_cb, led); + else + evas_object_event_callback_del(view_layout, EVAS_CALLBACK_MOUSE_UP, + live_edit_menu_show_cb); + } + + edit_disabled_set(led->ed, is_on); + if (is_on) + stats_info_msg_update("Enabled Live View Edit Mode"); + else + stats_info_msg_update("Disabled Live View Edit Mode"); +} + +void +live_edit_term(live_edit_data* led) +{ + if (led->menu) + evas_object_del(led->menu); + free(led); +} + +#undef LIVE_EDIT_ITEMS_NUM diff --git a/src/bin/main.c b/src/bin/main.c index d44195c..485eb96 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -6,6 +6,7 @@ typedef struct app_s { edit_data *ed; + live_edit_data *led; Eio_Monitor *edc_monitor; @@ -189,6 +190,14 @@ ctrl_func(app_data *ad, const char *key) autocomp_toggle(); return ECORE_CALLBACK_DONE; } + //Live Edit + if (!strcmp(key, "m") || !strcmp(key, "M")) + { + Eina_Bool is_on = !config_live_edit_get(); + config_live_edit_set(is_on); + live_edit_toggle(ad->led, is_on); + return ECORE_CALLBACK_DONE; + } return ECORE_CALLBACK_PASS_ON; } @@ -384,6 +393,14 @@ edc_edit_set(app_data *ad) } static void +live_edit_set(app_data *ad) +{ + ad->led = live_edit_init(ad->ed); + Eina_Bool is_on = config_live_edit_get(); + live_edit_toggle(ad->led, is_on); +} + +static void statusbar_set() { Evas_Object *obj = stats_init(base_layout_get()); @@ -405,6 +422,7 @@ config_update_cb(void *data) base_statusbar_toggle(EINA_FALSE); edit_part_highlight_toggle(ad->ed, EINA_FALSE); view_dummy_toggle(VIEW_DATA, EINA_FALSE); + live_edit_toggle(ad->led, config_live_edit_get()); //previous build was failed, Need to rebuild then reload the edj. if (edj_mgr_reload_need_get()) @@ -527,9 +545,9 @@ edj_mgr_set() } static void -tools_set(edit_data *ed) +tools_set(edit_data *ed, live_edit_data *led) { - Evas_Object *tools = tools_create(base_layout_get(), ed); + Evas_Object *tools = tools_create(base_layout_get(), ed, led); base_tools_set(tools); } @@ -554,9 +572,10 @@ init(app_data *ad, int argc, char **argv) edj_mgr_set(); statusbar_set(); edc_edit_set(ad); + live_edit_set(ad); edc_view_set(stats_group_name_get()); menu_init(ad->ed); - tools_set(ad->ed); + tools_set(ad->ed, ad->led); base_gui_show(); @@ -574,6 +593,7 @@ term(app_data *ad) build_term(); menu_term(); edit_term(ad->ed); + live_edit_term(ad->led); edj_mgr_term(); stats_term(); base_gui_term(); diff --git a/src/bin/setting.c b/src/bin/setting.c index 915d0e6..e8a7364 100644 --- a/src/bin/setting.c +++ b/src/bin/setting.c @@ -19,6 +19,7 @@ struct setting_s Evas_Object *toggle_swallow; Evas_Object *toggle_indent; Evas_Object *toggle_autocomp; + Evas_Object *toggle_live_edit; }; typedef struct setting_s setting_data; @@ -115,6 +116,7 @@ setting_apply_btn_cb(void *data, Evas_Object *obj EINA_UNUSED, config_dummy_swallow_set(elm_check_state_get(sd->toggle_swallow)); config_auto_indent_set(elm_check_state_get(sd->toggle_indent)); config_auto_complete_set(elm_check_state_get(sd->toggle_autocomp)); + config_live_edit_set(elm_check_state_get(sd->toggle_live_edit)); config_apply(); @@ -154,6 +156,7 @@ setting_reset_btn_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, elm_check_state_set(sd->toggle_swallow, config_dummy_swallow_get()); elm_check_state_set(sd->toggle_indent, config_auto_indent_get()); elm_check_state_set(sd->toggle_autocomp, config_auto_complete_get()); + elm_check_state_set(sd->toggle_live_edit, config_live_edit_get()); } static Evas_Object * @@ -349,8 +352,13 @@ setting_open(void) //Toggle (Auto Complete) Evas_Object *toggle_autocomp = toggle_create(box, "Auto Completion", - config_auto_complete_get()); + config_auto_complete_get()); elm_box_pack_end(box, toggle_autocomp); + + //Toggle (Live Edit) + Evas_Object *toggle_live_edit = toggle_create(box, "Live Edit", + config_live_edit_get()); + elm_box_pack_end(box, toggle_live_edit); Evas_Object *btn; @@ -388,6 +396,7 @@ setting_open(void) sd->toggle_swallow = toggle_swallow; sd->toggle_indent = toggle_indent; sd->toggle_autocomp = toggle_autocomp; + sd->toggle_live_edit = toggle_live_edit; menu_activate_request(); } diff --git a/src/bin/template.c b/src/bin/template.c index 951ac07..ae549aa 100644 --- a/src/bin/template.c +++ b/src/bin/template.c @@ -2,6 +2,11 @@ #include "common.h" #include "template_code.h" +typedef enum { + TEMPLATE_PART_INSERT_DEFAULT, + TEMPLATE_PART_INSERT_LIVE_EDIT +} Template_Part_Insert_Type; + const char *NAME_SEED = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; const int NAME_SEED_LEN = 52; @@ -9,11 +14,12 @@ static const char * template_part_first_line_get(void) { static char buf[40]; - char name[8]; + char name[9]; int i; for (i = 0; i < 8; i++) name[i] = NAME_SEED[(rand() % NAME_SEED_LEN)]; + name[8] = '\0'; snprintf(buf, sizeof(buf), "part { name: \"%s\";<br/>", name); @@ -102,16 +108,73 @@ end: eina_stringshare_del(paragh); } -void -template_part_insert(edit_data *ed, Edje_Part_Type type) +static void +image_description_add(edit_data *ed) { - if (type == EDJE_PART_TYPE_NONE) return; + int cursor_pos; + Evas_Object * edit_entry = edit_entry_get(ed); - Evas_Object *entry = edit_entry_get(ed); + Evas_Coord cursor_pos_to_restore = elm_entry_cursor_pos_get(edit_entry_get(ed)); - int cursor_pos = elm_entry_cursor_pos_get(entry); - elm_entry_cursor_line_begin_set(entry); - int cursor_pos1 = elm_entry_cursor_pos_get(entry); + Eina_Bool images_block = parser_images_pos_get(edit_entry, &cursor_pos); + if (cursor_pos == -1) return; + if (images_block) + { + elm_entry_cursor_pos_set(edit_entry, cursor_pos); + template_insert(ed); + } + else + { + elm_entry_cursor_pos_set(edit_entry, cursor_pos); + elm_entry_cursor_line_begin_set(edit_entry); + int cursor_pos1 = elm_entry_cursor_pos_get(edit_entry); + elm_entry_entry_insert(edit_entry, TEMPLATE_IMG_BLOCK); + edit_line_increase(ed, TEMPLATE_IMG_BLOCK_LINE_CNT); + int cursor_pos2 = elm_entry_cursor_pos_get(edit_entry); + edit_redoundo_region_push(ed, cursor_pos1, cursor_pos2); + } + elm_entry_cursor_pos_set(edit_entry, cursor_pos_to_restore); +} + + +static int +template_part_insert_cursor_pos_set(edit_data *ed, + Template_Part_Insert_Type insert_type, + const Eina_Stringshare *group_name) +{ + int cursor_pos = -1; + Evas_Object *edit_entry = edit_entry_get(ed); + if (insert_type == TEMPLATE_PART_INSERT_LIVE_EDIT) + { + cursor_pos = parser_end_of_parts_block_pos_get(edit_entry, group_name); + if (cursor_pos != -1) + elm_entry_cursor_pos_set(edit_entry, cursor_pos); + } + else + { + cursor_pos = elm_entry_cursor_pos_get(edit_entry); + } + elm_entry_cursor_line_begin_set(edit_entry); + return cursor_pos; +} + + +static void +internal_template_part_insert(edit_data *ed, + Edje_Part_Type type, + Template_Part_Insert_Type insert_type, + const Eina_Stringshare *group_name) +{ + if (type == EDJE_PART_TYPE_NONE) return; + if ((type == EDJE_PART_TYPE_IMAGE) && + (insert_type == TEMPLATE_PART_INSERT_LIVE_EDIT)) + image_description_add(ed); + + Evas_Object *edit_entry = edit_entry_get(ed); + int cursor_pos = template_part_insert_cursor_pos_set(ed, insert_type, + group_name); + if (cursor_pos == -1) return; + int cursor_pos1 = elm_entry_cursor_pos_get(edit_entry); int space = edit_cur_indent_depth_get(ed); //Alloc Empty spaces @@ -166,30 +229,46 @@ template_part_insert(edit_data *ed, Edje_Part_Type type) break; } - elm_entry_entry_insert(entry, p); + elm_entry_entry_insert(edit_entry, p); const char *first_line = template_part_first_line_get(); - elm_entry_entry_insert(entry, first_line); + elm_entry_entry_insert(edit_entry, first_line); edit_line_increase(ed, 1); int i; for (i = 0; i < (line_cnt - 1); i++) { - elm_entry_entry_insert(entry, p); - elm_entry_entry_insert(entry, t[i]); + elm_entry_entry_insert(edit_entry, p); + elm_entry_entry_insert(edit_entry, t[i]); //Incease line by (line count - 1) edit_line_increase(ed, 1); } - elm_entry_entry_insert(entry, p); - elm_entry_entry_insert(entry, t[i]); + elm_entry_entry_insert(edit_entry, t[i]); - int cursor_pos2 = elm_entry_cursor_pos_get(entry); + int cursor_pos2 = elm_entry_cursor_pos_get(edit_entry); edit_redoundo_region_push(ed, cursor_pos1, cursor_pos2); - elm_entry_cursor_pos_set(entry, cursor_pos); + elm_entry_cursor_pos_set(edit_entry, cursor_pos); - edit_syntax_color_partial_apply(ed, 0); snprintf(buf, sizeof(buf), "Template code inserted. (%s Part)", part); stats_info_msg_update(buf); + edit_changed_set(ed, EINA_TRUE); + edit_save(ed); } +void +template_live_edit_part_insert(edit_data *ed, + Edje_Part_Type type, + const Eina_Stringshare *group_name) +{ + internal_template_part_insert(ed, type, TEMPLATE_PART_INSERT_LIVE_EDIT, + group_name); +} + +void +template_part_insert(edit_data *ed, + Edje_Part_Type type) +{ + internal_template_part_insert(ed, type, + TEMPLATE_PART_INSERT_DEFAULT, NULL); +} diff --git a/src/bin/tools.c b/src/bin/tools.c index ad17b85..8359621 100644 --- a/src/bin/tools.c +++ b/src/bin/tools.c @@ -100,8 +100,18 @@ console_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, item_unselect((Elm_Object_Item *)event_info); } +static void +live_edit_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info) +{ + live_edit_data *led = data; + Eina_Bool is_on = !config_live_edit_get(); + config_live_edit_set(is_on); + live_edit_toggle(led, is_on); + item_unselect((Elm_Object_Item *)event_info); +} + Evas_Object * -tools_create(Evas_Object *parent, edit_data *ed) +tools_create(Evas_Object *parent, edit_data *ed, live_edit_data *led) { Evas_Object *toolbar = elm_toolbar_add(parent); elm_object_style_set(toolbar, "item_horizontal"); @@ -136,6 +146,8 @@ tools_create(Evas_Object *parent, edit_data *ed) elm_toolbar_item_icon_file_set(it, EDJE_PATH, "status"); it = elm_toolbar_item_append(toolbar, NULL, "Console", console_cb, NULL); elm_toolbar_item_icon_file_set(it, EDJE_PATH, "console"); + it = elm_toolbar_item_append(toolbar, NULL, "LiveEdit", live_edit_cb, led); + elm_toolbar_item_icon_file_set(it, EDJE_PATH, "live-edit"); return toolbar; } diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 3d86423..14b6564 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -26,4 +26,5 @@ EXTRA_DIST = common.h \ setting.h \ search.h \ redoundo.h \ - template.h + template.h \ + live_edit.h diff --git a/src/include/common.h b/src/include/common.h index c88afd0..b4acc75 100644 --- a/src/include/common.h +++ b/src/include/common.h @@ -4,6 +4,7 @@ typedef struct viewer_s view_data; typedef struct statusbar_s stats_data; typedef struct editor_s edit_data; +typedef struct live_editor_s live_edit_data; typedef struct syntax_color_s color_data; typedef struct parser_s parser_data; typedef struct attr_value_s attr_value; @@ -34,5 +35,6 @@ typedef struct redoundo_s redoundo_data; #include "setting.h" #include "redoundo.h" #include "template.h" +#include "live_edit.h" #endif diff --git a/src/include/config_data.h b/src/include/config_data.h index a460eb6..7b99273 100644 --- a/src/include/config_data.h +++ b/src/include/config_data.h @@ -36,6 +36,8 @@ void config_auto_indent_set(Eina_Bool auto_indent); Eina_Bool config_auto_indent_get(void); void config_auto_complete_set(Eina_Bool auto_complete); Eina_Bool config_auto_complete_get(void); +Eina_Bool config_live_edit_get(void); +void config_live_edit_set(Eina_Bool live_edit); void config_font_size_set(float font_size); float config_font_size_get(void); void config_view_scale_set(double view_scale); diff --git a/src/include/edc_editor.h b/src/include/edc_editor.h index 89b1bad..a292920 100644 --- a/src/include/edc_editor.h +++ b/src/include/edc_editor.h @@ -12,8 +12,6 @@ void edit_new(edit_data* ed); void edit_view_sync_cb_set(edit_data *ed, void (*cb)(void *data, Eina_Stringshare *part_name, Eina_Stringshare *group_name), void *data); void edit_view_sync(edit_data *ed); void edit_font_size_update(edit_data *ed, Eina_Bool msg, Eina_Bool update); -void edit_template_insert(edit_data *ed); -void edit_template_part_insert(edit_data *ed, Edje_Part_Type type); void edit_part_highlight_toggle(edit_data *ed, Eina_Bool msg); void edit_line_delete(edit_data *ed); void edit_edc_reload(edit_data *ed, const char *edc_path); @@ -29,3 +27,4 @@ void edit_line_increase(edit_data *ed, int cnt); void edit_line_decrease(edit_data *ed, int cnt); int edit_cur_indent_depth_get(edit_data *ed); void edit_redoundo_region_push(edit_data *ed, int cursor_pos1, int cursor_pos2); +void edit_disabled_set(edit_data *ed, Eina_Bool disable); diff --git a/src/include/edc_parser.h b/src/include/edc_parser.h index 26edf40..0ee8684 100644 --- a/src/include/edc_parser.h +++ b/src/include/edc_parser.h @@ -19,4 +19,5 @@ char *parser_name_get(parser_data *pd, const char *cur); void parser_cancel(parser_data *pd); int parser_line_cnt_get(parser_data *pd EINA_UNUSED, const char *src); Eina_List *parser_states_filtered_name_get(Eina_List *states); - +Evas_Coord parser_end_of_parts_block_pos_get(const Evas_Object *entry, const char *group_name); +Eina_Bool parser_images_pos_get(const Evas_Object *entry, Evas_Coord *res_position); diff --git a/src/include/edj_viewer.h b/src/include/edj_viewer.h index 8c118e0..023b96b 100644 --- a/src/include/edj_viewer.h +++ b/src/include/edj_viewer.h @@ -2,6 +2,7 @@ view_data * view_init(Evas_Object *parent, const char *group, void (*del_cb)(void *data), void *data); void view_term(view_data *vd); Evas_Object *view_obj_get(view_data *vd); +Evas_Object *view_layout_get(view_data *vd); void view_new(view_data *vd, const char *group); void view_part_highlight_set(view_data *vd, const char *part_name); void view_dummy_toggle(view_data *vd, Eina_Bool msg); diff --git a/src/include/live_edit.h b/src/include/live_edit.h new file mode 100644 index 0000000..51b1037 --- /dev/null +++ b/src/include/live_edit.h @@ -0,0 +1,3 @@ +live_edit_data* live_edit_init(edit_data *ed); +void live_edit_toggle(live_edit_data* led, Eina_Bool is_on); +void live_edit_term(live_edit_data* led); diff --git a/src/include/template.h b/src/include/template.h index 0917da0..ddc3a10 100644 --- a/src/include/template.h +++ b/src/include/template.h @@ -1,3 +1,3 @@ void template_insert(edit_data *ed); void template_part_insert(edit_data *ed, Edje_Part_Type type); - +void template_live_edit_part_insert(edit_data *ed, Edje_Part_Type type, const Eina_Stringshare *group_name); diff --git a/src/include/template_code.h b/src/include/template_code.h index 6d04e1e..dd69adb 100644 --- a/src/include/template_code.h +++ b/src/include/template_code.h @@ -9,8 +9,8 @@ const char *TEMPLATE_GROUP[TEMPLATE_GROUP_LINE_CNT] = " scale: 1;<br/>", " mouse_events: 1;<br/>", " description { state: \"default\" 0.0;<br/>", - " rel1 { relative: 0.0 0.0; offset: 0 0; /*to: \"XXX\";*/ }<br/>", - " rel2 { relative: 1.0 1.0; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", + " rel1 { relative: 0.25 0.25; offset: 0 0; /*to: \"XXX\";*/ }<br/>", + " rel2 { relative: 0.75 0.75; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", " align: 0.5 0.5;<br/>", " fixed: 0 0;<br/>", " min: 0 0;<br/>", @@ -40,8 +40,8 @@ const char *TEMPLATE_PART_IMAGE[TEMPLATE_PART_IMAGE_LINE_CNT] = " scale: 1;<br/>", " mouse_events: 1;<br/>", " description { state: \"default\" 0.0;<br/>", - " rel1 { relative: 0.0 0.0; offset: 0 0; /*to: \"XXX\";*/ }<br/>", - " rel2 { relative: 1.0 1.0; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", + " rel1 { relative: 0.25 0.25; offset: 0 0; /*to: \"XXX\";*/ }<br/>", + " rel2 { relative: 0.75 0.75; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", " align: 0.5 0.5;<br/>", " fixed: 0 0;<br/>", " min: 0 0;<br/>", @@ -49,7 +49,8 @@ const char *TEMPLATE_PART_IMAGE[TEMPLATE_PART_IMAGE_LINE_CNT] = " image.normal: \"logo.png\";<br/>", " //aspect: 1 1;<br/>", " }<br/>", - "}" + "}<br/>", + "" }; #define TEMPLATE_PART_RECT_LINE_CNT 14 @@ -60,15 +61,16 @@ const char *TEMPLATE_PART_RECT[TEMPLATE_PART_RECT_LINE_CNT] = " scale: 1;<br/>", " mouse_events: 1;<br/>", " description { state: \"default\" 0.0;<br/>", - " rel1 { relative: 0.0 0.0; offset: 0 0; /*to: \"XXX\";*/ }<br/>", - " rel2 { relative: 1.0 1.0; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", + " rel1 { relative: 0.25 0.25; offset: 0 0; /*to: \"XXX\";*/ }<br/>", + " rel2 { relative: 0.75 0.75; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", " color: 255 255 255 255;<br/>", " align: 0.5 0.5;<br/>", " fixed: 0 0;<br/>", " min: 0 0;<br/>", " visible: 1;<br/>", " }<br/>", - "}" + "}<br/>", + "" }; #define TEMPLATE_PART_SWALLOW_LINE_CNT 13 @@ -79,14 +81,15 @@ const char *TEMPLATE_PART_SWALLOW[TEMPLATE_PART_SWALLOW_LINE_CNT] = " scale: 1;<br/>", " mouse_events: 1;<br/>", " description { state: \"default\" 0.0;<br/>", - " rel1 { relative: 0.0 0.0; offset: 0 0; /*to: \"XXXX\";*/ }<br/>", - " rel2 { relative: 1.0 1.0; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", + " rel1 { relative: 0.25 0.25; offset: 0 0; /*to: \"XXXX\";*/ }<br/>", + " rel2 { relative: 0.75 0.75; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", " align: 0.5 0.5;<br/>", " fixed: 0 0;<br/>", " min: 0 0;<br/>", " visible: 1;<br/>", " }<br/>", - "}" + "}<br/>", + "" }; #define TEMPLATE_PART_SPACER_LINE_CNT 11 @@ -96,13 +99,14 @@ const char *TEMPLATE_PART_SPACER[TEMPLATE_PART_SPACER_LINE_CNT] = " type: SPACER;<br/>", " scale: 1;<br/>", " description { state: \"default\" 0.0;<br/>", - " rel1 { relative: 0.0 0.0; offset: 0 0; /*to: \"XXX\";*/ }<br/>", - " rel2 { relative: 1.0 1.0; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", + " rel1 { relative: 0.25 0.25; offset: 0 0; /*to: \"XXX\";*/ }<br/>", + " rel2 { relative: 0.75 0.75; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", " align: 0.5 0.5;<br/>", " fixed: 0 0;<br/>", " min: 0 0;<br/>", " }<br/>", - "}" + "}<br/>", + "" }; #define TEMPLATE_PART_TEXT_LINE_CNT 24 @@ -114,8 +118,8 @@ const char *TEMPLATE_PART_TEXT[TEMPLATE_PART_TEXT_LINE_CNT] = " mouse_events: 1;<br/>", " //effect: SHADOW;<br/>", " description { state: \"default\" 0.0;<br/>", - " rel1 { relative: 0.0 0.0; offset: 0 0; /*to: \"XXX\";*/ }<br/>", - " rel2 { relative: 1.0 1.0; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", + " rel1 { relative: 0.25 0.25; offset: 0 0; /*to: \"XXX\";*/ }<br/>", + " rel2 { relative: 0.75 0.75; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", " align: 0.5 0.5;<br/>", " fixed: 0 0;<br/>", " min: 0 0;<br/>", @@ -131,17 +135,18 @@ const char *TEMPLATE_PART_TEXT[TEMPLATE_PART_TEXT_LINE_CNT] = " min: 0 0;<br/>", " }<br/>", " }<br/>", - "}" + "}<br/>", + "" }; -#define TEMPLATE_PART_TEXTBLOCK_LINE_CNT 18 +#define TEMPLATE_PART_TEXTBLOCK_LINE_CNT 17 const char *TEMPLATE_PART_TEXTBLOCK[TEMPLATE_PART_TEXTBLOCK_LINE_CNT] = { " type: TEXTBLOCK;<br/>", " description { state: \"default\" 0.0;<br/>", - " rel1 { relative: 0.0 0.0; offset: 0 0; /*to: \"XXX\";*/ }<br/>", - " rel2 { relative: 1.0 1.0; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", + " rel1 { relative: 0.25 0.25; offset: 0 0; /*to: \"XXX\";*/ }<br/>", + " rel2 { relative: 0.75 0.75; offset: -1 -1; /*to: \"XXX\";*/ }<br/>", " align: 0.5 0.5;<br/>", " fixed: 0 0;<br/>", " min: 0 0;<br/>", @@ -153,7 +158,8 @@ const char *TEMPLATE_PART_TEXTBLOCK[TEMPLATE_PART_TEXTBLOCK_LINE_CNT] = " min: 0 0;<br/>", " }<br/>", " }<br/>", - "}" + "}<br/>", + "" }; #define TEMPLATE_DESC_LINE_CNT 10 @@ -189,5 +195,11 @@ const char *TEMPLATE_PROG[TEMPLATE_PROG_LINE_CNT] = const char *TEMPLATE_IMG[TEMPLATE_IMG_LINE_CNT] = { - "image: \"logo.png\" COMP;" + "image: \"logo.png\" COMP;<br/>" }; + +#define TEMPLATE_IMG_BLOCK_LINE_CNT 3 + +const char *TEMPLATE_IMG_BLOCK = " images {<br/>" + " image: \"logo.png\" COMP;<br/>" + " }<br/>"; diff --git a/src/include/tools.h b/src/include/tools.h index 5dce118..9a146ee 100644 --- a/src/include/tools.h +++ b/src/include/tools.h @@ -1,2 +1,2 @@ -Evas_Object *tools_create(Evas_Object *parent, edit_data *ed); +Evas_Object *tools_create(Evas_Object *parent, edit_data *ed, live_edit_data *led); --
