hermet pushed a commit to branch master.

http://git.enlightenment.org/tools/enventor.git/commit/?id=9c66f6fcf00258cd347b0ce17f5e74da3da9564a

commit 9c66f6fcf00258cd347b0ce17f5e74da3da9564a
Author: Mykyta Biliavskyi <m.biliavs...@samsung.com>
Date:   Tue Aug 11 13:18:07 2015 +0900

    Build: marks line, that contain error in edc_editor.
    
    Summary:
    parse error messages from edje_cc, and marked
    by underline the mistaken line.  In cases for messages
    that does not contain line numbers, trying to parse
    name of wrong parameter. Trying to searching the parsed name
    in edc code, and highlight the first entity.
    
    Reviewers: Hermet
    
    Differential Revision: https://phab.enlightenment.org/D2791
---
 data/themes/default/theme_ext.edc |  2 ++
 src/lib/edc_editor.c              | 51 +++++++++++++++++++++++++++++++++++++--
 src/lib/enventor_private.h        |  1 +
 src/lib/enventor_smart.c          | 41 ++++++++++++++++++++++++++++---
 4 files changed, 89 insertions(+), 6 deletions(-)

diff --git a/data/themes/default/theme_ext.edc 
b/data/themes/default/theme_ext.edc
index 78be780..5173170 100644
--- a/data/themes/default/theme_ext.edc
+++ b/data/themes/default/theme_ext.edc
@@ -14,6 +14,7 @@
 #define ENABLED_TEXTBLOCK_TAGS                                             \
    tag: "em" "+ font_style=Oblique";                                       \
    tag: "hilight" "+ font_weight=Bold style=glow glow_color=#3399ff80";    \
+   tag: "error" "+ underline=single underline_color=#ff0000 
underline2_color=#ff0000";  \
    tag: "link" "+ color=#3399ff underline=on underline_color=#3399ff";     \
    tag: "preedit" "+ underline=on underline_color=#3399ff";                \
    tag: "preedit_sel" "+ backing=on backing_color=#000000 color=#ffffff";  \
@@ -47,6 +48,7 @@
 #define DISABLED_TEXTBLOCK_TAGS                                            \
    tag: "em" "+ font_style=Oblique";                                       \
    tag: "hilight" "+ font_weight=Bold style=glow glow_color=#3399ff20";    \
+   tag: "error" "+ underline=double underline_color=#ff0000 
underline2_color=#ff0000";  \
    tag: "link" "+ color=#101820 shadow_color=#66aaff28 underline=on 
underline_color=#101820"; \
    tag: "preedit" "+ underline=on underline_color=#3399ff88";              \
    tag: "preedit_sel" "+ backing=on backing_color=#000000 color=#888888";  \
diff --git a/src/lib/edc_editor.c b/src/lib/edc_editor.c
index ea5367d..e2db0e6 100644
--- a/src/lib/edc_editor.c
+++ b/src/lib/edc_editor.c
@@ -36,6 +36,7 @@ struct editor_s
 
    int cur_line;
    int line_max;
+   int error_line;
    int syntax_color_lock;
    Evas_Coord scroller_h;
 
@@ -49,6 +50,7 @@ struct editor_s
    double font_scale;
    const char *font_name;
    const char *font_style;
+   const char *error_target;
 
    Eina_Bool edit_changed : 1;
    Eina_Bool linenumber : 1;
@@ -137,6 +139,39 @@ edit_font_apply(edit_data *ed, const char *font_name, 
const char *font_style)
 }
 
 static void
+error_highlight(edit_data *ed, Evas_Object *tb)
+{
+   Evas_Textblock_Cursor *cur1 = evas_object_textblock_cursor_new(tb);
+   if (ed->error_line)
+     {
+        evas_textblock_cursor_line_set(cur1, ed->error_line);
+        evas_textblock_cursor_line_char_first(cur1);
+        while(evas_textblock_cursor_content_get(cur1)[0] == ' ')
+           evas_textblock_cursor_char_next(cur1);
+        evas_object_textblock_text_markup_prepend(cur1, "<error>");
+        evas_textblock_cursor_line_char_last(cur1);
+        evas_object_textblock_text_markup_prepend(cur1, "</error>");
+     }
+   else if (ed->error_target)
+     {
+        const char *ptr = NULL;
+        const char *par = NULL;
+        while (evas_textblock_cursor_paragraph_next(cur1))
+          {
+             par = evas_textblock_cursor_paragraph_text_get(cur1);
+             if (par && (ptr = strstr(par, ed->error_target)))
+                break;
+          }
+        evas_textblock_cursor_paragraph_char_first(cur1);
+        while(evas_textblock_cursor_content_get(cur1)[0] == ' ')
+           evas_textblock_cursor_char_next(cur1);
+        evas_object_textblock_text_markup_prepend(cur1, "<error>");
+        evas_textblock_cursor_paragraph_char_last(cur1);
+        evas_object_textblock_text_markup_prepend(cur1, "</error>");
+     }
+   evas_textblock_cursor_free(cur1);
+}
+static void
 syntax_color_apply(edit_data *ed, Eina_Bool partial)
 {
    Evas_Object *tb = elm_entry_textblock_get(ed->en_edit);
@@ -162,7 +197,7 @@ syntax_color_apply(edit_data *ed, Eina_Bool partial)
       But it can avoid entry_object_text_escaped_set() in Edje.
       Logically that's unnecessary in this case. */
    evas_object_textblock_text_markup_set(tb, translated);
-
+   error_highlight(ed, tb);
    entry_recover(ed, pos);
 }
 
@@ -213,7 +248,7 @@ syntax_color_thread_end_cb(void *data, Ecore_Thread *thread 
EINA_UNUSED)
       But it can avoid entry_object_text_escaped_set() in Edje.
       Logically that's unnecessary in this case. */
    evas_object_textblock_text_markup_set(tb, td->translated);
-
+   error_highlight(td->ed, tb);
    entry_recover(td->ed, pos);
 
    td->ed->syntax_color_thread = NULL;
@@ -224,6 +259,8 @@ static void
 syntax_color_thread_cancel_cb(void *data, Ecore_Thread *thread EINA_UNUSED)
 {
    syntax_color_td *td = data;
+   Evas_Object *tb = elm_entry_textblock_get(td->ed->en_edit);
+   error_highlight(td->ed, tb);
    td->ed->syntax_color_thread = NULL;
    free(td);
 }
@@ -236,6 +273,9 @@ edit_changed_cb(void *data, Evas_Object *obj EINA_UNUSED, 
void *event_info)
    edit_changed_set(ed, EINA_TRUE);
 
    Eina_Bool syntax_color = EINA_TRUE;
+   ed->error_line = 0;
+   eina_stringshare_del(ed->error_target);
+   ed->error_target = NULL;
 
    if (info->insert)
      {
@@ -1360,6 +1400,13 @@ edit_auto_indent_get(edit_data *ed)
    return ed->auto_indent;
 }
 
+void
+edit_error_set(edit_data *ed, int line, const char *target)
+{
+   ed->error_line = line;
+   ed->error_target = target;
+}
+
 Eina_Bool
 edit_ctxpopup_enabled_get(edit_data *ed)
 {
diff --git a/src/lib/enventor_private.h b/src/lib/enventor_private.h
index 7e86206..1b37811 100644
--- a/src/lib/enventor_private.h
+++ b/src/lib/enventor_private.h
@@ -257,5 +257,6 @@ Eina_Bool edit_load(edit_data *ed, const char *edc_path);
 void edit_selection_clear(edit_data *ed);
 Eina_Bool edit_redoundo(edit_data *ed, Eina_Bool undo);
 void edit_disabled_set(edit_data *ed, Eina_Bool disabled);
+void edit_error_set(edit_data *ed, int line, const char *target);
 
 #endif
diff --git a/src/lib/enventor_smart.c b/src/lib/enventor_smart.c
index 7e9de95..702603e 100644
--- a/src/lib/enventor_smart.c
+++ b/src/lib/enventor_smart.c
@@ -134,7 +134,7 @@ edit_view_sync_cb(void *data, Eina_Stringshare *state_name, 
double state_value,
         prev_part_name = NULL;
         return;
      }
-      
+
    if ((part_name) && (part_name != prev_part_name))
      {
        view_part_state_set(VIEW_DATA, prev_part_name, "default", 0.0);
@@ -149,8 +149,41 @@ edit_view_sync_cb(void *data, Eina_Stringshare 
*state_name, double state_value,
 static void
 build_err_noti_cb(void *data, const char *msg)
 {
-   Evas_Object *enventor = data;
-   evas_object_smart_callback_call(enventor, SIG_COMPILE_ERROR, (char *)msg);
+   Enventor_Object_Data *pd = data;
+
+   int line_num = 1;
+   Eina_Stringshare *target = NULL;
+   char *ptr = NULL;
+   char *utf8 = evas_textblock_text_markup_to_utf8(NULL, msg);
+
+   if (!utf8) goto call_error;
+
+   if ((ptr = strstr(utf8, ".edc")))
+     {
+        ptr += strlen(".edc");
+        if (!ptr || (ptr[0] != ':')) goto call_error;
+        if (!(ptr++)) goto call_error;
+        line_num = atoi(ptr);
+     }
+   else if ((ptr = strstr(utf8, "image")) ||
+            (ptr = strstr(utf8, "group")) ||
+            (ptr = strstr(utf8, "part")))
+      {
+        ptr = strchr(ptr, '\"');
+        if (!ptr || !(ptr++)) goto call_error;
+        char *ptr2 = strchr(ptr, '\"');
+        if (!ptr2) goto call_error;
+        int length = ptr2 - ptr;
+        target = eina_stringshare_add_length(ptr, length);
+     }
+
+call_error:
+   free(utf8);
+   edit_error_set(pd->ed, line_num - 1, target);
+   if (line_num || target)
+     edit_syntax_color_full_apply(pd->ed, EINA_TRUE);
+   evas_object_smart_callback_call(pd->obj, SIG_COMPILE_ERROR, (char *)msg);
+
 }
 
 /*****************************************************************************/
@@ -176,7 +209,7 @@ _enventor_object_evas_object_smart_add(Eo *obj, 
Enventor_Object_Data *pd)
    edj_mgr_init(obj);
    pd->ed = edit_init(obj);
    edit_view_sync_cb_set(pd->ed, edit_view_sync_cb, pd);
-   build_err_noti_cb_set(build_err_noti_cb, obj);
+   build_err_noti_cb_set(build_err_noti_cb, pd);
 
    evas_object_smart_member_add(edit_obj_get(pd->ed), obj);
    elm_widget_can_focus_set(obj, EINA_FALSE);

-- 


Reply via email to