hermet pushed a commit to branch master.

http://git.enlightenment.org/tools/enventor.git/commit/?id=14daddac74269ea99de752a0ac7f394a8590b564

commit 14daddac74269ea99de752a0ac7f394a8590b564
Author: Hermet Park <her...@hermet.pe.kr>
Date:   Wed Jan 27 14:27:49 2016 +0900

    code refactoring.
    
    revise bracket logics which was newly introduced.
---
 data/themes/default/theme_ext.edc |   2 +-
 src/lib/edc_editor.c              |  74 ++++---
 src/lib/edc_parser.c              | 407 ++++++++++++++------------------------
 src/lib/enventor_private.h        |  14 +-
 4 files changed, 201 insertions(+), 296 deletions(-)

diff --git a/data/themes/default/theme_ext.edc 
b/data/themes/default/theme_ext.edc
index f8593f5..7979a00 100644
--- a/data/themes/default/theme_ext.edc
+++ b/data/themes/default/theme_ext.edc
@@ -12,7 +12,7 @@
 #define PANEWID 32
 
 #define ENABLED_TEXTBLOCK_TAGS                            \
-   tag: "hilight" "+ style=glow glow_color=#3399ff80";    \
+   tag: "hilight" "+ style=glow glow_color=#3388ddaa";    \
 
 #define DISABLED_TEXTBLOCK_TAGS                           \
    tag: "hilight" "+ style=glow glow_color=#3399ff20";    \
diff --git a/src/lib/edc_editor.c b/src/lib/edc_editor.c
index 1f3b9af..5ecb5ba 100644
--- a/src/lib/edc_editor.c
+++ b/src/lib/edc_editor.c
@@ -40,6 +40,13 @@ struct editor_s
    int syntax_color_lock;
    Evas_Coord scroller_h;
 
+   struct {
+      int prev_left;
+      int prev_right;
+      int left;
+      int right;
+   } bracket;
+
    Ecore_Timer *syntax_color_timer;
    Ecore_Thread *syntax_color_thread;
 
@@ -181,18 +188,15 @@ bracket_highlight(edit_data *ed, Evas_Object *tb)
 {
    Evas_Textblock_Cursor *cur1 = evas_object_textblock_cursor_new(tb);
 
-   int left_bracket = parser_left_bracket_pos_get(ed->pd);
-   int right_bracket = parser_right_bracket_pos_get(ed->pd);
-
-   evas_textblock_cursor_pos_set(cur1, left_bracket);
-   evas_object_textblock_text_markup_prepend(cur1, 
"<hilight><color=#B1B1B1FF>");
-   evas_textblock_cursor_pos_set(cur1, left_bracket+1);
-   evas_object_textblock_text_markup_prepend(cur1, "</color></hilight>");
+   evas_textblock_cursor_pos_set(cur1, ed->bracket.left);
+   evas_object_textblock_text_markup_prepend(cur1, "<hilight>");
+   evas_textblock_cursor_pos_set(cur1, ed->bracket.left + 1);
+   evas_object_textblock_text_markup_prepend(cur1, "</hilight>");
 
-   evas_textblock_cursor_pos_set(cur1, right_bracket);
-   evas_object_textblock_text_markup_prepend(cur1, 
"<hilight><color=#B1B1B1FF>");
-   evas_textblock_cursor_pos_set(cur1, right_bracket+1);
-   evas_object_textblock_text_markup_prepend(cur1, "</color></hilight>");
+   evas_textblock_cursor_pos_set(cur1, ed->bracket.right);
+   evas_object_textblock_text_markup_prepend(cur1, "<hilight>");
+   evas_textblock_cursor_pos_set(cur1, ed->bracket.right + 1);
+   evas_object_textblock_text_markup_prepend(cur1, "</hilight>");
 
    evas_textblock_cursor_free(cur1);
 }
@@ -293,10 +297,31 @@ syntax_color_thread_cancel_cb(void *data, Ecore_Thread 
*thread EINA_UNUSED)
 }
 
 void
-bracket_changed_cb(void *data)
+bracket_changed_cb(void *data, int left, int right)
 {
    edit_data *ed = data;
-   syntax_color_partial_update(ed, SYNTAX_COLOR_SHORT_TIME);
+
+   ed->bracket.left = left;
+   ed->bracket.right = right;
+
+   if ((left != -1) && (right != -1))
+     {
+        if ((ed->bracket.prev_left != left) &&
+            (ed->bracket.prev_right != right))
+          {
+             syntax_color_partial_update(ed, SYNTAX_COLOR_SHORT_TIME);
+
+             ed->bracket.prev_left = left;
+             ed->bracket.prev_right = right;
+          }
+     }
+   else if((ed->bracket.prev_left != -1) && (ed->bracket.prev_right != -1))
+     {
+        syntax_color_partial_update(ed, SYNTAX_COLOR_SHORT_TIME);
+
+        ed->bracket.prev_left = -1;
+        ed->bracket.prev_right = -1;
+     }
 }
 
 static void
@@ -320,20 +345,19 @@ bracket_update(edit_data *ed)
 
    if (ch1 != '{' && ch1 != '}' && ch2 != '{' && ch2 != '}')
      {
-        int prev_left_bracket = parser_prev_left_bracket_pos_get(ed->pd);
-        int prev_right_bracket = parser_prev_right_bracket_pos_get(ed->pd);
-        if (prev_left_bracket != -1 && prev_right_bracket != -1)
+        if (ed->bracket.prev_left != -1 && ed->bracket.prev_right != -1)
           {
-             parser_left_bracket_pos_set(ed->pd, -1);
-             parser_right_bracket_pos_set(ed->pd, -1);
-             parser_prev_left_bracket_pos_set(ed->pd, -1);
-             parser_prev_right_bracket_pos_set(ed->pd, -1);
+             //initialize bracket
+             ed->bracket.left = -1;
+             ed->bracket.right = -1;
+             ed->bracket.prev_left = -1;
+             ed->bracket.prev_right = -1;
+
              syntax_color_partial_update(ed, SYNTAX_COLOR_SHORT_TIME);
           }
         return;
      }
-
-   parser_bracket_pair_find(ed->pd, ed->en_edit, bracket_changed_cb, ed);
+   parser_bracket_find(ed->pd, ed->en_edit, bracket_changed_cb, ed);
 }
 
 static void
@@ -395,7 +419,7 @@ edit_changed_cb(void *data, Evas_Object *obj EINA_UNUSED, 
void *event_info)
    if (!syntax_color) return;
    syntax_color_partial_update(ed, SYNTAX_COLOR_DEFAULT_TIME);
 
-   parser_bracket_pair_cancel(ed->pd);
+   parser_bracket_cancel(ed->pd);
 }
 
 static void
@@ -1250,6 +1274,10 @@ edit_init(Evas_Object *enventor)
    ed->pd = pd;
    ed->sh = sh;
    ed->error_line = -1;
+   ed->bracket.prev_left = -1;
+   ed->bracket.prev_right = -1;
+   ed->bracket.left = -1;
+   ed->bracket.right = -1;
 
    ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, key_down_cb, ed);
    ecore_event_handler_add(ECORE_EVENT_KEY_UP, key_up_cb, ed);
diff --git a/src/lib/edc_parser.c b/src/lib/edc_parser.c
index 6820e30..23b517c 100644
--- a/src/lib/edc_parser.c
+++ b/src/lib/edc_parser.c
@@ -52,38 +52,29 @@ typedef struct type_init_thread_data_s
    parser_data *pd;
 } type_init_td;
 
-typedef struct bracket_data_s
-{
-   int left;
-   int right;
-   int prev_left;
-   int prev_right;
-} bracket;
-
 typedef struct bracket_thread_data_s
 {
    int pos;
    const char *text;
    Bracket_Update_Cb update_cb;
    void *data;
-} bracket_data_td;
+   Ecore_Thread *thread;
+   parser_data *pd;
+
+} bracket_td;
 
 struct parser_s
 {
    Eina_Inarray *attrs;
    cur_name_td *cntd;
    type_init_td *titd;
+   bracket_td *btd;
    Eina_List *macro_list;
 
-   bracket_data_td *bracket_td;
-   Ecore_Thread *bracket_thread;
-   bracket bracket_pos;
-
-   Eina_Bool is_bracket_thread_req: 1;
-
    Eina_Bool macro_update : 1;
 };
 
+
 /*****************************************************************************/
 /* Internal method implementation                                            */
 /*****************************************************************************/
@@ -1329,6 +1320,125 @@ parser_collections_block_pos_get(const Evas_Object 
*entry,
    return EINA_FALSE;
 }
 
+static void
+bracket_thread_blocking(void *data, Ecore_Thread *thread EINA_UNUSED)
+{
+   bracket_td *btd = data;
+   int left_bracket = -1;
+   int right_bracket = -1;
+   int cur_pos = btd->pos;
+   int depth = 0;
+   const char *utf8 = btd->text;
+
+   if (cur_pos == 0) return;
+
+   int length = strlen(utf8);
+
+   // left,  {
+   if (utf8[cur_pos] == '{')
+     {
+        left_bracket = cur_pos;
+        cur_pos++;
+        while (cur_pos < length)
+          {
+             if (utf8[cur_pos] == '{') depth++;
+             else if (utf8[cur_pos] == '}')
+               {
+                  if (depth) depth--;
+                  else
+                    {
+                       right_bracket = cur_pos;
+                       break;
+                    }
+               }
+             cur_pos++;
+          }
+     }
+   // left,  }
+   else if(utf8[cur_pos] == '}')
+     {
+        right_bracket = cur_pos;
+        cur_pos--;
+        while (cur_pos)
+          {
+             if (utf8[cur_pos] == '}') depth++;
+             else if(utf8[cur_pos] == '{')
+               {
+                  if(depth) depth--;
+                  else
+                    {
+                       left_bracket = cur_pos;
+                       break;
+                    }
+               }
+             cur_pos--;
+          }
+     }
+   // right, {
+   else if(utf8[cur_pos - 1] == '{')
+     {
+        left_bracket = cur_pos - 1;
+        while (cur_pos < length)
+          {
+             if (utf8[cur_pos] == '{') depth++;
+             else if (utf8[cur_pos] == '}')
+               {
+                  if (depth) depth--;
+                  else
+                    {
+                       right_bracket = cur_pos;
+                       break;
+                    }
+               }
+             cur_pos++;
+          }
+     }
+   // right, }
+   else if(utf8[cur_pos - 1] == '}')
+     {
+        right_bracket = cur_pos - 1;
+        cur_pos -= 2;
+        while (cur_pos)
+          {
+             if (utf8[cur_pos] == '}') depth++;
+             else if (utf8[cur_pos] == '{')
+               {
+                  if(depth) depth--;
+                  else
+                    {
+                       left_bracket = cur_pos;
+                       break;
+                    }
+               }
+             cur_pos--;
+          }
+     }
+
+   if (left_bracket == -1 || right_bracket == -1)
+     {
+        left_bracket = -1;
+        right_bracket = -1;
+     }
+
+   btd->update_cb(btd->data, left_bracket, right_bracket);
+}
+
+static void
+bracket_thread_end(void *data, Ecore_Thread *thread EINA_UNUSED)
+{
+   bracket_td *btd = data;
+   if (btd->pd->btd == btd) btd->pd->btd = NULL;
+   free(btd);
+}
+
+static void
+bracket_thread_cancel(void *data, Ecore_Thread *thread EINA_UNUSED)
+{
+   bracket_td *btd = data;
+   if (btd->pd->btd == btd) btd->pd->btd = NULL;
+   free(btd);
+}
+
 /*****************************************************************************/
 /* Externally accessible calls                                               */
 /*****************************************************************************/
@@ -1878,8 +1988,6 @@ parser_init(void)
 
    td->pd = pd;
    pd->titd = td;
-   pd->bracket_pos.left = -1;
-   pd->bracket_pos.right = -1;
    td->thread = ecore_thread_run(type_init_thread_blocking,
                                  type_init_thread_end,
                                  type_init_thread_cancel, td);
@@ -1899,6 +2007,7 @@ parser_term(parser_data *pd)
         pd->titd->pd = NULL;
         ecore_thread_cancel(pd->titd->thread);
      }
+   if (pd->btd) ecore_thread_cancel(pd->btd->thread);
 
    parser_attr *attr;
 
@@ -1973,259 +2082,35 @@ parser_macro_update(parser_data *pd, Eina_Bool 
macro_update)
    pd->macro_update = macro_update;
 }
 
-static Eina_Bool
-bracket_pair_parse(int pos, const char *text, int *left, int *right)
-{
-   int left_bracket = -1;
-   int right_bracket = -1;
-
-   int cur_pos = pos;
-   int depth = 0;
-
-   if (cur_pos == 0)
-     return EINA_FALSE;
-
-   const char *utf8 = text;
-   int length = strlen(utf8);
-
-   // left,  {
-   if (utf8[cur_pos] == '{')
-     {
-        left_bracket = cur_pos;
-        cur_pos++;
-        while (cur_pos < length)
-          {
-             if (utf8[cur_pos] == '{') depth++;
-             else if (utf8[cur_pos] == '}')
-               {
-                  if (depth) depth--;
-                  else
-                    {
-                       right_bracket = cur_pos;
-                       break;
-                    }
-               }
-             cur_pos++;
-          }
-     }
-   // left,  }
-   else if(utf8[cur_pos] == '}')
-     {
-        right_bracket = cur_pos;
-        cur_pos--;
-        while (cur_pos)
-          {
-             if (utf8[cur_pos] == '}') depth++;
-             else if(utf8[cur_pos] == '{')
-               {
-                  if(depth) depth--;
-                  else
-                    {
-                       left_bracket = cur_pos;
-                       break;
-                    }
-               }
-             cur_pos--;
-          }
-     }
-   // right, {
-   else if(utf8[cur_pos - 1] == '{')
-     {
-        left_bracket = cur_pos - 1;
-        while (cur_pos < length)
-          {
-             if (utf8[cur_pos] == '{') depth++;
-             else if (utf8[cur_pos] == '}')
-               {
-                  if (depth) depth--;
-                  else
-                    {
-                       right_bracket = cur_pos;
-                       break;
-                    }
-               }
-             cur_pos++;
-          }
-     }
-   // right, }
-   else if(utf8[cur_pos - 1] == '}')
-     {
-        right_bracket = cur_pos - 1;
-        cur_pos -= 2;
-        while (cur_pos)
-          {
-             if (utf8[cur_pos] == '}') depth++;
-             else if (utf8[cur_pos] == '{')
-               {
-                  if(depth) depth--;
-                  else
-                    {
-                       left_bracket = cur_pos;
-                       break;
-                    }
-               }
-             cur_pos--;
-          }
-     }
-
-   if (left_bracket == -1 || right_bracket == -1)
-     {
-        left_bracket = -1;
-           right_bracket = -1;
-        }
-
-   *left = left_bracket;
-   *right = right_bracket;
-
-  return EINA_TRUE;
-}
-
-static void bracket_thread_cb(void *data, Ecore_Thread *thread EINA_UNUSED);
-static void bracket_thread_end_cb(void *data, Ecore_Thread *thread 
EINA_UNUSED);
-static void bracket_thread_cancel_cb(void *data, Ecore_Thread *thread 
EINA_UNUSED);
-
-static void
-bracket_thread_cb(void *data, Ecore_Thread *thread EINA_UNUSED)
-{
-   parser_data *pd = data;
-
-   if (bracket_pair_parse(pd->bracket_td->pos, pd->bracket_td->text,
-                          &(pd->bracket_pos.left),
-                          &(pd->bracket_pos.right)) == EINA_FALSE)
-     return;
-
-   if (pd->bracket_pos.left != -1 && pd->bracket_pos.right != -1)
-     {
-        if (pd->bracket_pos.prev_left != pd->bracket_pos.left
-            && pd->bracket_pos.prev_right != pd->bracket_pos.right)
-          {
-             pd->bracket_td->update_cb(pd->bracket_td->data);
-             pd->bracket_pos.prev_left = pd->bracket_pos.left;
-             pd->bracket_pos.prev_right = pd->bracket_pos.right;
-          }
-     }
-   else if(pd->bracket_pos.prev_left != -1 && pd->bracket_pos.prev_right != -1)
-     {
-        pd->bracket_td->update_cb(pd->bracket_td->data);
-        pd->bracket_pos.prev_left = -1;
-        pd->bracket_pos.prev_right = -1;
-     }
-}
-
-static void
-bracket_thread_end_cb(void *data, Ecore_Thread *thread EINA_UNUSED)
+void
+parser_bracket_cancel(parser_data *pd)
 {
-   parser_data *pd = data;
-
-   if (pd->is_bracket_thread_req == EINA_TRUE)
-     {
-        pd->is_bracket_thread_req = EINA_FALSE;
-        pd->bracket_thread = ecore_thread_run(bracket_thread_cb,
-                                              bracket_thread_end_cb,
-                                              bracket_thread_cancel_cb,
-                                              pd);
-     }
-   else
-    {
-        free(pd->bracket_td);
-        pd->bracket_td = NULL;
-        pd->bracket_thread = NULL;
-    }
+   if (pd->btd) ecore_thread_cancel(pd->btd->thread);
 }
 
-static void
-bracket_thread_cancel_cb(void *data, Ecore_Thread *thread EINA_UNUSED)
+void
+parser_bracket_find(parser_data *pd, Evas_Object *entry,
+                    Bracket_Update_Cb func, void *data)
 {
-   parser_data *pd = data;
-
-   if (pd->is_bracket_thread_req == EINA_TRUE)
-     {
-        pd->is_bracket_thread_req = EINA_FALSE;
-        pd->bracket_thread = ecore_thread_run(bracket_thread_cb,
-                                              bracket_thread_end_cb,
-                                              bracket_thread_cancel_cb,
-                                              pd);
-     }
-   else
+   if (pd->btd)
      {
-        free(pd->bracket_td);
-        pd->bracket_td = NULL;
-        pd->bracket_thread = NULL;
+        ecore_thread_cancel(pd->btd->thread);
      }
-}
-
-void
-parser_bracket_pair_find(parser_data *pd, Evas_Object *entry,
-                         Bracket_Update_Cb func, void *data)
-{
-
-   ecore_thread_cancel(pd->bracket_thread);
-
-   if (pd->bracket_td == NULL)
-     pd->bracket_td = calloc(1, sizeof(bracket_data_td));
 
    const char *text = elm_entry_entry_get(entry);
    char *utf8 = elm_entry_markup_to_utf8(text);
    int pos = elm_entry_cursor_pos_get(entry);
 
-   pd->bracket_td->pos = pos;
-   pd->bracket_td->text = utf8;
-   pd->bracket_td->update_cb = func;
-   pd->bracket_td->data = data;
-
-   if (pd->bracket_thread == NULL)
-     {
-        pd->is_bracket_thread_req = EINA_FALSE;
-        pd->bracket_thread = ecore_thread_run(bracket_thread_cb,
-                                              bracket_thread_end_cb,
-                                              bracket_thread_cancel_cb,
-                                              pd);
-     }
-   else
-     pd->is_bracket_thread_req = EINA_TRUE;
-}
-
-void parser_bracket_pair_cancel(parser_data *pd)
-{
-   ecore_thread_cancel(pd->bracket_thread);
-}
-
-void parser_left_bracket_pos_set(parser_data *pd, int pos)
-{
-   pd->bracket_pos.left = pos;
-}
-
-void parser_right_bracket_pos_set(parser_data *pd, int pos)
-{
-   pd->bracket_pos.right = pos;
-}
-
-void parser_prev_left_bracket_pos_set(parser_data *pd, int pos)
-{
-   pd->bracket_pos.prev_left = pos;
-}
-
-void parser_prev_right_bracket_pos_set(parser_data *pd, int pos)
-{
-   pd->bracket_pos.prev_right = pos;
-}
-
-int parser_left_bracket_pos_get(parser_data *pd)
-{
-   return pd->bracket_pos.left;
-}
-
-int parser_right_bracket_pos_get(parser_data *pd)
-{
-   return pd->bracket_pos.right;
-}
-
-int parser_prev_left_bracket_pos_get(parser_data *pd)
-{
-   return pd->bracket_pos.prev_left;
-}
-
-int parser_prev_right_bracket_pos_get(parser_data *pd)
-{
-   return pd->bracket_pos.prev_right;
+   bracket_td *btd = malloc(sizeof(bracket_td));
+   pd->btd = btd;
+
+   btd->pos = pos;
+   btd->text = utf8;
+   btd->update_cb = func;
+   btd->data = data;
+   btd->pd = pd;
+   btd->thread = ecore_thread_run(bracket_thread_blocking,
+                                  bracket_thread_end,
+                                  bracket_thread_cancel,
+                                  btd);
 }
diff --git a/src/lib/enventor_private.h b/src/lib/enventor_private.h
index b7e835b..0202109 100644
--- a/src/lib/enventor_private.h
+++ b/src/lib/enventor_private.h
@@ -139,17 +139,9 @@ Eina_Bool parser_state_info_get(Evas_Object *entry, 
state_info *info);
 void parser_macro_list_set(parser_data *pd, const char *text);
 Eina_List *parser_macro_list_get(parser_data *pd);
 void parser_macro_update(parser_data *pd, Eina_Bool macro_update);
-typedef void (*Bracket_Update_Cb)(void *data);
-void parser_bracket_pair_find(parser_data *pd, Evas_Object *entry, 
Bracket_Update_Cb func, void *data);
-void parser_bracket_pair_cancel(parser_data *pd);
-void parser_left_bracket_pos_set(parser_data *pd, int pos);
-void parser_right_bracket_pos_set(parser_data *pd, int pos);
-void parser_prev_left_bracket_pos_set(parser_data *pd, int pos);
-void parser_prev_right_bracket_pos_set(parser_data *pd, int pos);
-int parser_left_bracket_pos_get(parser_data *pd);
-int parser_right_bracket_pos_get(parser_data *pd);
-int parser_prev_left_bracket_pos_get(parser_data *pd);
-int parser_prev_right_bracket_pos_get(parser_data *pd);
+typedef void (*Bracket_Update_Cb)(void *data, int left, int right);
+void parser_bracket_find(parser_data *pd, Evas_Object *entry, 
Bracket_Update_Cb func, void *data);
+void parser_bracket_cancel(parser_data *pd);
 
 /* syntax helper */
 syntax_helper *syntax_init(void);

-- 


Reply via email to