hermet pushed a commit to branch master.

http://git.enlightenment.org/tools/enventor.git/commit/?id=7c23ae8be461709ac1c69235c01ca68009efbb19

commit 7c23ae8be461709ac1c69235c01ca68009efbb19
Author: ChunEon Park <[email protected]>
Date:   Sat Aug 30 18:20:38 2014 +0900

    template: insert the textblock styles when template code inserted.
    
    Signed-Off-By: Kateryna Fesyna <[email protected]>
---
 data/themes/default/live_edit.edc |  8 +++++
 src/bin/edc_parser.c              | 27 +++++++++-----
 src/bin/template.c                | 75 +++++++++++++++++++++++++++++++--------
 src/include/edc_parser.h          |  3 +-
 src/include/template_code.h       | 21 +++++++----
 5 files changed, 103 insertions(+), 31 deletions(-)

diff --git a/data/themes/default/live_edit.edc 
b/data/themes/default/live_edit.edc
index 3818f42..ab98d8e 100644
--- a/data/themes/default/live_edit.edc
+++ b/data/themes/default/live_edit.edc
@@ -1,6 +1,13 @@
 images {
    image: "live_spacer.png" COMP;
 }
+
+styles {
+   style { name: "default_style";
+      base: "font="Sans" font_size=30 text_class=entry color=#0088AA 
style=shadow,bottom shadow_color=#00000080 valign=0.5 ellipsis=1.0 wrap=none 
align=center";
+   }
+}
+
 group { name: "IMAGE_bg";
    parts {
       part { name: "logo";
@@ -42,6 +49,7 @@ group { name: "TEXTBLOCK_bg";
          description { state: "default" 0.0;
             color: 255 255 255 255;
             text {
+               style: "default_style";
                size: 10;
                font: FN;
                text: "TEXTBLOCK";
diff --git a/src/bin/edc_parser.c b/src/bin/edc_parser.c
index 6b363de..6cd51b1 100644
--- a/src/bin/edc_parser.c
+++ b/src/bin/edc_parser.c
@@ -1010,15 +1010,12 @@ parser_end_of_parts_block_pos_get(const Evas_Object 
*entry,
    return ret;
 }
 
-Eina_Bool
-parser_images_pos_get(const Evas_Object *entry, int *ret)
+static Eina_Bool
+parser_collections_block_pos_get(const Evas_Object *entry,
+                                 const char *block_name, int *ret)
 {
    const char* GROUP_SYNTAX_NAME = "group";
-   const char* IMAGES_BLOCK_NAME = "images";
-   const int IMAGES_BLOCK_NAME_LEN = 6; //strlen of "images"
-
-   if (!ret) return EINA_FALSE;
-
+   const int BLOCK_NAME_LEN = strlen(block_name);
    *ret = -1;
 
    const char *text = elm_entry_entry_get(entry);
@@ -1027,12 +1024,12 @@ parser_images_pos_get(const Evas_Object *entry, int 
*ret)
    char *utf8 = elm_entry_markup_to_utf8(text);
    if (!utf8) return EINA_FALSE;
 
-   const char *pos = strstr(utf8, IMAGES_BLOCK_NAME);
+   const char *pos = strstr(utf8, 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) == '.')
+        if (*(pos + BLOCK_NAME_LEN + 1) == '.')
           return EINA_FALSE;
 
         pos = strstr(pos, "{\n");
@@ -1050,3 +1047,15 @@ parser_images_pos_get(const Evas_Object *entry, int *ret)
    return EINA_FALSE;
 }
 
+Eina_Bool
+parser_images_pos_get(const Evas_Object *entry, int *ret)
+{
+   return parser_collections_block_pos_get(entry, "images", ret);
+}
+
+Eina_Bool
+parser_styles_pos_get(const Evas_Object *entry, int *ret)
+{
+   return parser_collections_block_pos_get(entry, "styles", ret);
+}
+
diff --git a/src/bin/template.c b/src/bin/template.c
index a3ecb03..411d30d 100644
--- a/src/bin/template.c
+++ b/src/bin/template.c
@@ -6,16 +6,12 @@ const char *NAME_SEED = 
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 const int NAME_SEED_LEN = 52;
 
 static void
-template_part_first_line_get(char *buf, int size)
+template_random_string_create(char *buf, int size)
 {
-   char name[9];
    int i;
-
-   for (i = 0; i < 8; i++)
-     name[i] = NAME_SEED[(rand() % NAME_SEED_LEN)];
-   name[i]='\0';
-
-   snprintf(buf, size, "part { name: \"%s\";<br/>", name);
+   for (i = 0; i < (size - 1); i++)
+     buf[i] = NAME_SEED[(rand() % NAME_SEED_LEN)];
+   buf[i]='\0';
 }
 
 static void
@@ -46,6 +42,41 @@ image_description_add(edit_data *ed)
    elm_entry_cursor_pos_set(edit_entry, cursor_pos_to_restore);
 }
 
+static void
+textblock_style_add(edit_data *ed, const char *style_name)
+{
+   int cursor_pos;
+   Evas_Object * edit_entry = edit_entry_get(ed);
+   Eina_Bool styles_block = parser_styles_pos_get(edit_entry, &cursor_pos);
+   if (cursor_pos == -1) return;
+   int cursor_pos_to_restore = elm_entry_cursor_pos_get(edit_entry_get(ed));
+
+   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);
+
+   if (!styles_block)
+     elm_entry_entry_insert(edit_entry, TEMPLATE_TEXTBLOCK_STYLE_BLOCK[0]);
+
+   int buf_len = strlen(TEMPLATE_TEXTBLOCK_STYLE_BLOCK[1]) + 
strlen(style_name);
+   char *buf = malloc(buf_len);
+   snprintf(buf, buf_len, TEMPLATE_TEXTBLOCK_STYLE_BLOCK[1], style_name);
+   elm_entry_entry_insert(edit_entry, buf);
+   free(buf);
+
+   if (!styles_block)
+     elm_entry_entry_insert(edit_entry, TEMPLATE_TEXTBLOCK_STYLE_BLOCK[2]);
+
+   int line_inc = TEMPLATE_TEXTBLOCK_STYLE_LINE_CNT;
+   if (!styles_block) line_inc += 2;
+   edit_line_increase(ed, line_inc);
+
+   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_Insert_Type insert_type,
@@ -73,10 +104,6 @@ template_part_insert(edit_data *ed, Edje_Part_Type 
part_type,
                      float rel1_y, float rel2_x, float rel2_y,
                      const Eina_Stringshare *group_name)
 {
-   if ((part_type == EDJE_PART_TYPE_IMAGE) &&
-       (insert_type == TEMPLATE_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);
@@ -138,8 +165,11 @@ template_part_insert(edit_data *ed, Edje_Part_Type 
part_type,
 
    //Insert first line of the part block with generated name.
    char first_line[40];
+   char random_name[9];
+   template_random_string_create(random_name, 9);
+
    elm_entry_entry_insert(edit_entry, p);
-   template_part_first_line_get(first_line, 40);
+   snprintf(first_line, 40, "part { name: \"%s\";<br/>", random_name);
    elm_entry_entry_insert(edit_entry, first_line);
 
    //Insert part body
@@ -150,6 +180,14 @@ template_part_insert(edit_data *ed, Edje_Part_Type 
part_type,
         elm_entry_entry_insert(edit_entry, t[i]);
      }
 
+   if (part_type == EDJE_PART_TYPE_TEXTBLOCK)
+     {
+        elm_entry_entry_insert(edit_entry, p);
+        snprintf(buf, sizeof(buf), "      text.style: \"%s\";<br/>",
+                 random_name);
+        elm_entry_entry_insert(edit_entry, buf);
+     }
+
    //Insert relatives
    elm_entry_entry_insert(edit_entry, p);
    snprintf(buf, sizeof(buf), "      rel1.relative: %.2f %.2f;<br/>", rel1_x,
@@ -184,6 +222,14 @@ template_part_insert(edit_data *ed, Edje_Part_Type 
part_type,
 
    elm_entry_cursor_pos_set(edit_entry, cursor_pos);
 
+   if (insert_type == TEMPLATE_INSERT_LIVE_EDIT)
+     {
+        if (part_type == EDJE_PART_TYPE_IMAGE)
+          image_description_add(ed);
+        else if (part_type == EDJE_PART_TYPE_TEXTBLOCK)
+          textblock_style_add(ed, random_name);
+     }
+
    snprintf(buf, sizeof(buf), "Template code inserted. (%s Part)", part);
    stats_info_msg_update(buf);
    edit_syntax_color_partial_apply(ed, 0);
@@ -194,7 +240,8 @@ template_part_insert(edit_data *ed, Edje_Part_Type 
part_type,
 void
 template_insert(edit_data *ed, Template_Insert_Type insert_type)
 {
-   const char *EXCEPT_MSG = "Can't insert template code here. Move the cursor" 
                             " inside the \"Collections,Images,Parts,Part,"
+   const char *EXCEPT_MSG = "Can't insert template code here. Move the cursor"
+                            "inside the \"Collections,Images,Parts,Part,"
                             "Programs\" scope.";
 
    Evas_Object *entry = edit_entry_get(ed);
diff --git a/src/include/edc_parser.h b/src/include/edc_parser.h
index 634a2c1..bf53ab7 100644
--- a/src/include/edc_parser.h
+++ b/src/include/edc_parser.h
@@ -20,6 +20,7 @@ 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);
 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 *pos);
+Eina_Bool parser_images_pos_get(const Evas_Object *entry, int *ret);
+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);
 
diff --git a/src/include/template_code.h b/src/include/template_code.h
index e2ea895..9017342 100644
--- a/src/include/template_code.h
+++ b/src/include/template_code.h
@@ -122,7 +122,7 @@ const char *TEMPLATE_PART_TEXT[TEMPLATE_PART_TEXT_LINE_CNT] 
=
    "      }<br/>"
 };
 
-#define TEMPLATE_PART_TEXTBLOCK_LINE_CNT 12
+#define TEMPLATE_PART_TEXTBLOCK_LINE_CNT 7
 
 const char *TEMPLATE_PART_TEXTBLOCK[TEMPLATE_PART_TEXTBLOCK_LINE_CNT] =
 {
@@ -132,12 +132,7 @@ const char 
*TEMPLATE_PART_TEXTBLOCK[TEMPLATE_PART_TEXTBLOCK_LINE_CNT] =
    "      fixed: 0 0;<br/>",
    "      min: 0 0;<br/>",
    "      visible: 1;<br/>",
-   "      text {<br/>",
-   "         style: \"XXX\";<br/>",
-   "         text: \"TEXTBLOCK\";<br/>",
-   "         align: 0.5 0.5;<br/>",
-   "         min: 0 0;<br/>",
-   "      }<br/>"
+   "      text.text: \"TEXTBLOCK\";<br/>"
 };
 
 #define TEMPLATE_DESC_LINE_CNT 10
@@ -181,3 +176,15 @@ const char *TEMPLATE_IMG[TEMPLATE_IMG_LINE_CNT] =
 const char *TEMPLATE_IMG_BLOCK = "   images {<br/>"
                                  "      image: \"logo.png\" COMP;<br/>"
                                  "   }<br/>";
+
+#define TEMPLATE_TEXTBLOCK_STYLE_LINE_CNT 3
+
+const char *TEMPLATE_TEXTBLOCK_STYLE_BLOCK[TEMPLATE_TEXTBLOCK_STYLE_LINE_CNT] =
+{
+   "   styles {<br/>",
+   "      style { name: \"%s\";<br/>"
+   "         base: \"font=\"Sans\" font_size=30 text_class=entry color=#0088AA 
style=shadow,bottom shadow_color=#00000080 valign=0.5 ellipsis=1.0 wrap=none 
align=center\";<br/>"
+   "      }<br/>",
+   "   }<br/>"
+};
+

-- 


Reply via email to