hermet pushed a commit to branch master.

http://git.enlightenment.org/tools/enventor.git/commit/?id=3b038768f506f984565aa3c37308660d07df7214

commit 3b038768f506f984565aa3c37308660d07df7214
Author: Taehyub Kim <taehyub....@samsung.com>
Date:   Fri Apr 1 16:33:34 2016 +0900

    template: improve adding template of image resource do not duplicate
    
    Summary:
    when we insert image template or live view item,
    the template code of image resource will be duplicated.
    so, I added the code checking template image resource not to be duplicate
    
    Test Plan:
    1. launch enventor
    2. add image part twice using ctrl + t or live view item
    3. see the images block has an ENVENTOR_EMBEDDED_LOGO.png
    
    Reviewers: Hermet, Jaehyun_Cho, NikaWhite
    
    Differential Revision: https://phab.enlightenment.org/D3851
---
 src/lib/edc_parser.c       | 28 ++++++++++++++++++++++++++++
 src/lib/enventor_private.h |  1 +
 src/lib/template.c         | 11 +++++++++--
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/lib/edc_parser.c b/src/lib/edc_parser.c
index a8a4863..d46aed1 100644
--- a/src/lib/edc_parser.c
+++ b/src/lib/edc_parser.c
@@ -2186,6 +2186,34 @@ parser_styles_pos_get(const Evas_Object *entry, int *ret)
    return parser_collections_block_pos_get(entry, "styles", ret);
 }
 
+Eina_Bool
+parser_is_image_name(const Evas_Object *entry, const char *str)
+{
+   int start_pos, end_pos, i;
+   if (!parser_collections_block_pos_get(entry, "images", &start_pos))
+     return EINA_FALSE;
+
+   const char *text = elm_entry_entry_get(entry);
+   char *utf8 = elm_entry_markup_to_utf8(text);
+
+   for (i = start_pos ; i < strlen(utf8); i++)
+      if (utf8[i] == '}')
+        {
+           end_pos = i;
+           break;
+        }
+
+   char *candidate_str = alloca(end_pos - start_pos + 1);
+   const char *src_str = elm_entry_markup_to_utf8(str);
+   strncpy(candidate_str, utf8 + start_pos, end_pos - start_pos);
+   candidate_str[end_pos - start_pos] = '\0';
+
+   if (strstr(candidate_str, src_str))
+     return EINA_TRUE;
+   else
+     return EINA_FALSE;
+}
+
 void
 parser_macro_update(parser_data *pd, Eina_Bool macro_update)
 {
diff --git a/src/lib/enventor_private.h b/src/lib/enventor_private.h
index 7b3a37d..2054c50 100644
--- a/src/lib/enventor_private.h
+++ b/src/lib/enventor_private.h
@@ -138,6 +138,7 @@ int parser_line_cnt_get(parser_data *pd EINA_UNUSED, const 
char *src);
 Eina_List *parser_states_filtered_name_get(Eina_List *states);
 int 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, int *ret);
+Eina_Bool parser_is_image_name(const Evas_Object *entry, const char *str);
 Eina_Bool parser_styles_pos_get(const Evas_Object *entry, int *ret);
 const char *parser_colon_pos_get(parser_data *pd EINA_UNUSED, const char *cur);
 Eina_Bool parser_state_info_get(Evas_Object *entry, state_info *info);
diff --git a/src/lib/template.c b/src/lib/template.c
index 9480c8b..52ae193 100644
--- a/src/lib/template.c
+++ b/src/lib/template.c
@@ -49,8 +49,15 @@ image_description_add(edit_data *ed)
    int cursor_pos2;
    if (images_block)
      {
-        template_insert(ed, ENVENTOR_TEMPLATE_INSERT_LIVE_EDIT, NULL, 0);
-        cursor_pos2 = elm_entry_cursor_pos_get(edit_entry);
+        // the first line of TEMPLATE_IMG to check it is already exist
+        const char *template_image_str = TEMPLATE_IMG[0];
+        if (parser_is_image_name(edit_entry, template_image_str))
+          cursor_pos2 = cursor_pos1;
+        else
+          {
+             template_insert(ed, ENVENTOR_TEMPLATE_INSERT_LIVE_EDIT, NULL, 0);
+             cursor_pos2 = elm_entry_cursor_pos_get(edit_entry);
+          }
      }
    else
      {

-- 


Reply via email to