hermet pushed a commit to branch master.

http://git.enlightenment.org/tools/enventor.git/commit/?id=165c955bee34b3bb0bccbe8e98636523c6696d48

commit 165c955bee34b3bb0bccbe8e98636523c6696d48
Author: ChunEon Park <her...@hermet.pe.kr>
Date:   Fri May 22 22:24:34 2015 +0900

     Update part state in dependence of the cursor position.
    
    Summary:
    Added ability to switch part state on live view, when cursor located inside 
the "description" subblock of part.
    In case when cursor move out from "description" block, default state of 
part will be displayed.
    
    Reviewers: Hermet, Jaehyun_Cho
    
    Projects: #enventor
    
    Differential Revision: https://phab.enlightenment.org/D2499
---
 src/lib/edc_editor.c       | 28 ++++++++++++++++
 src/lib/edc_parser.c       | 81 ++++++++++++++++++++++++++++++++++++++++++++++
 src/lib/edj_viewer.c       |  7 ++++
 src/lib/enventor_private.h | 10 ++++++
 4 files changed, 126 insertions(+)

diff --git a/src/lib/edc_editor.c b/src/lib/edc_editor.c
index 5969d28..1db2c67 100644
--- a/src/lib/edc_editor.c
+++ b/src/lib/edc_editor.c
@@ -101,6 +101,33 @@ visible_text_region_get(edit_data *ed, int *from_line, int 
*to_line)
 }
 
 static void
+part_state_update(edit_data *ed)
+{
+   static Eina_Stringshare *part_name = NULL;
+   
+   state_info info = {0, NULL, NULL};
+   if (!parser_state_info_get(ed->en_edit, &info))
+     {
+        view_part_state_set(VIEW_DATA, part_name, "default", 0.0);
+        eina_stringshare_del(part_name);
+        part_name = NULL;
+        return;
+     }
+      
+   if ((part_name) && (part_name != info.part))
+     {
+       view_part_state_set(VIEW_DATA, part_name, "default", 0.0);
+       eina_stringshare_del(part_name);
+       part_name = NULL;
+     }
+
+   view_part_state_set(VIEW_DATA, info.part, info.state, info.value);
+   part_name = info.part;
+
+   eina_stringshare_del(info.state);
+}
+
+static void
 entry_recover(edit_data *ed, int cursor_pos)
 {
    elm_entry_calc_force(ed->en_edit);
@@ -624,6 +651,7 @@ edit_cursor_changed_cb(void *data, Evas_Object *obj 
EINA_UNUSED,
 {
    edit_data *ed = data;
    cur_line_pos_set(ed, EINA_FALSE);
+   part_state_update(ed);
 }
 
 static void
diff --git a/src/lib/edc_parser.c b/src/lib/edc_parser.c
index 7903338..2452321 100644
--- a/src/lib/edc_parser.c
+++ b/src/lib/edc_parser.c
@@ -1295,6 +1295,87 @@ parser_first_group_name_get(parser_data *pd EINA_UNUSED, 
Evas_Object *entry)
    return NULL;
 }
 
+Eina_Bool
+parser_state_info_get(Evas_Object *entry, state_info *info)
+{
+   if (!info) return EINA_FALSE;
+
+   info->part = parser_cur_name_fast_get(entry, "part");
+   if (!info->part) return EINA_FALSE;
+
+   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;
+
+   int cur_pos = elm_entry_cursor_pos_get(entry);
+
+   char *p = utf8;
+   char *end = utf8 + cur_pos;
+
+   const char *name = NULL;
+   int name_len = 0;
+
+   const char *value = NULL;
+   int value_len = 0;
+   char *value_buf = NULL;;    
+
+   while (p <= end)
+     {
+        //Skip "" range
+        if (!strncmp(p, QUOT_UTF8, QUOT_UTF8_LEN))
+          {
+             p += QUOT_UTF8_LEN;
+             p = strstr(p, QUOT_UTF8);
+             if (!p) goto end;
+             p += QUOT_UTF8_LEN;
+          }
+
+        //11 - length of "description" keyword
+        if (!strncmp(p, "description", 11))
+          {
+             p += 11;
+             char *name_begin = strstr(p, QUOT_UTF8);
+             if (!name_begin) goto end;
+             name_begin += QUOT_UTF8_LEN;
+             p = name_begin;
+             char *name_end = strstr(p, QUOT_UTF8);
+             if (!name_end) goto end;
+             name = name_begin;
+             name_len = name_end - name_begin;
+             p = name_end + QUOT_UTF8_LEN;
+             value = p;
+             continue;
+          }
+
+        p++;
+     }
+
+   if (!value) goto end;
+   char *value_end = strchr(value, ';');
+   while (value < value_end)
+     {
+        if (isdigit(*value) || *value == '.')
+          {
+             value_len = value_end - value;
+             value_buf = (char *)calloc(1, value_len);
+             memcpy(value_buf, value, value_len);
+             break;
+          }
+        value++;
+     }
+
+   info->state = eina_stringshare_add_length(name, name_len);
+   info->value = atof(value_buf);
+   free(value_buf);
+
+end:
+   free(utf8);
+   if (!info->state) return EINA_FALSE;
+   return EINA_TRUE;
+}
+
 Eina_List *
 parser_states_filtered_name_get(Eina_List *states)
 {
diff --git a/src/lib/edj_viewer.c b/src/lib/edj_viewer.c
index 9f15689..c9c8ad7 100644
--- a/src/lib/edj_viewer.c
+++ b/src/lib/edj_viewer.c
@@ -558,3 +558,10 @@ view_string_list_free(Eina_List *list)
 {
    edje_edit_string_list_free(list);
 }
+
+void
+view_part_state_set(view_data *vd, const char *part, const char *description, 
const double state)
+{
+   if (!vd) return;
+   edje_edit_part_selected_state_set(vd->layout, part, description, state);
+}
diff --git a/src/lib/enventor_private.h b/src/lib/enventor_private.h
index 07291fb..e194f16 100644
--- a/src/lib/enventor_private.h
+++ b/src/lib/enventor_private.h
@@ -39,6 +39,7 @@ typedef struct syntax_helper_s syntax_helper;
 typedef struct indent_s indent_data;
 typedef struct redoundo_s redoundo_data;
 typedef struct editor_s edit_data;
+typedef struct state_info_s state_info;
 
 typedef enum attr_value_type
 {
@@ -65,6 +66,13 @@ struct attr_value_s
    Eina_Bool program : 1;
 };
 
+struct state_info_s
+{
+   double value;
+   const char *part;
+   const char *state;
+};
+
 /* auto_comp */
 void autocomp_init(void);
 void autocomp_term(void);
@@ -103,6 +111,7 @@ int parser_end_of_parts_block_pos_get(const Evas_Object 
*entry, const char *grou
 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);
+Eina_Bool parser_state_info_get(Evas_Object *entry, state_info *info);
 
 
 /* syntax helper */
@@ -182,6 +191,7 @@ Eina_List *view_programs_list_get(view_data *vd);
 Eina_List *view_part_states_list_get(view_data *vd, const char *part);
 Eina_List *view_program_targets_get(view_data *vd, const char *prog);
 void view_string_list_free(Eina_List *list);
+void view_part_state_set(view_data *vd, const char *part, const char 
*description, const double state);
 
 
 /* template */

-- 


Reply via email to