hermet pushed a commit to branch master.

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

commit ae7f3e30b36470e8f2f561b21d24844d272fe19b
Author: Hermet Park <her...@hermet.pe.kr>
Date:   Sat May 7 04:14:47 2016 +0900

    redoundo: do coupling with edc_edit instance.
    
    one redoundo should work with it's owner editor.
    
    This is a refactoring for multiple edc editor.
---
 src/lib/auto_comp.c        |  2 +-
 src/lib/edc_editor.c       | 11 ++++++++---
 src/lib/enventor_private.h |  8 ++++----
 src/lib/enventor_smart.c   |  2 +-
 src/lib/redoundo.c         | 11 ++++++++---
 src/lib/syntax_helper.c    |  4 ++--
 src/lib/syntax_indent.c    | 26 ++++++++++++++------------
 7 files changed, 38 insertions(+), 26 deletions(-)

diff --git a/src/lib/auto_comp.c b/src/lib/auto_comp.c
index ff2b186..685c643 100644
--- a/src/lib/auto_comp.c
+++ b/src/lib/auto_comp.c
@@ -498,7 +498,7 @@ insert_completed_text(autocomp_data *ad)
      }
 
    int cursor_pos2 = elm_entry_cursor_pos_get(entry);
-   redoundo_data *rd = evas_object_data_get(entry, "redoundo");
+   redoundo_data *rd = edit_redoundo_get(ad->ed);
    redoundo_entry_region_push(rd, cursor_pos, cursor_pos2);
 
    entry_anchor_off(ad);
diff --git a/src/lib/edc_editor.c b/src/lib/edc_editor.c
index 4bd046d..1191891 100644
--- a/src/lib/edc_editor.c
+++ b/src/lib/edc_editor.c
@@ -1489,13 +1489,18 @@ edit_init(Evas_Object *enventor)
    ed->select_pos = -1;
    ed->font_scale = 1;
    ed->pd = parser_init();
-   ed->sh = syntax_init(en_edit);
-   ed->rd = redoundo_init(en_edit, ed);
-   evas_object_data_set(ed->en_edit, "redoundo", ed->rd);
+   ed->rd = redoundo_init(ed);
+   ed->sh = syntax_init(ed);
 
    return ed;
 }
 
+redoundo_data *
+edit_redoundo_get(edit_data *ed)
+{
+   return ed->rd;
+}
+
 Evas_Object *
 edit_obj_get(edit_data *ed)
 {
diff --git a/src/lib/enventor_private.h b/src/lib/enventor_private.h
index 05b9a87..18ad8ef 100644
--- a/src/lib/enventor_private.h
+++ b/src/lib/enventor_private.h
@@ -129,14 +129,14 @@ void parser_bracket_find(parser_data *pd, Evas_Object 
*entry, Bracket_Update_Cb
 void parser_bracket_cancel(parser_data *pd);
 
 /* syntax helper */
-syntax_helper *syntax_init(Evas_Object *entry);
+syntax_helper *syntax_init(edit_data *ed);
 void syntax_term(syntax_helper *sh);
 color_data *syntax_color_data_get(syntax_helper *sh);
 indent_data *syntax_indent_data_get(syntax_helper *sh);
 
 
 /* indent */
-indent_data *indent_init(Eina_Strbuf *strbuf, Evas_Object *entry);
+indent_data *indent_init(Eina_Strbuf *strbuf, edit_data *ed);
 void indent_term(indent_data *id);
 int indent_space_get(indent_data *id);
 int indent_insert_apply(indent_data *id, const char *insert, int cur_line);
@@ -179,7 +179,7 @@ void edj_mgr_all_views_reload(void);
 
 
 /* redoundo */
-redoundo_data *redoundo_init(Evas_Object *entry, edit_data *ed);
+redoundo_data *redoundo_init(edit_data *ed);
 void redoundo_term(redoundo_data *rd);
 void redoundo_clear(redoundo_data *rd);
 void redoundo_text_push(redoundo_data *rd, const char *text, int pos, int 
length, Eina_Bool insert);
@@ -278,5 +278,5 @@ void edit_disabled_set(edit_data *ed, Eina_Bool disabled);
 void edit_error_set(edit_data *ed, int line, const char *target);
 void edit_text_insert(edit_data *ed, const char *text);
 void edit_part_cursor_set(edit_data *ed, const char *group_name, const char 
*part_name);
-
+redoundo_data *edit_redoundo_get(edit_data *ed);
 #endif
diff --git a/src/lib/enventor_smart.c b/src/lib/enventor_smart.c
index 0bbd9a7..23d5a14 100644
--- a/src/lib/enventor_smart.c
+++ b/src/lib/enventor_smart.c
@@ -168,7 +168,7 @@ call_error:
    if (line_num || target)
      edit_syntax_color_full_apply(pd->ed, EINA_TRUE);
 
-   redoundo_data *rd = evas_object_data_get(edit_entry_get(pd->ed), 
"redoundo");
+   redoundo_data *rd = edit_redoundo_get(pd->ed);
 
    // When msg == NULL it mean, that needed to reset error state
    if (msg)
diff --git a/src/lib/redoundo.c b/src/lib/redoundo.c
index 362df45..a79494f 100644
--- a/src/lib/redoundo.c
+++ b/src/lib/redoundo.c
@@ -382,9 +382,14 @@ redoundo_text_push(redoundo_data *rd, const char *text, 
int pos, int length,
 }
 
 redoundo_data *
-redoundo_init(Evas_Object *entry, edit_data *ed)
+redoundo_init(edit_data *ed)
 {
-   if (!entry) return NULL;
+   Evas_Object *entry = edit_entry_get(ed);
+   if (!entry)
+     {
+        EINA_LOG_ERR("Should be initialized after edit entry is initialized!");
+        return NULL;
+     }
 
    redoundo_data *rd = calloc(1, sizeof(redoundo_data));
    if (!rd)
@@ -402,7 +407,7 @@ redoundo_init(Evas_Object *entry, edit_data *ed)
    rd->edit_data = ed;
 
    //FIXME: Why signal callback? not smart callback?
-   elm_object_signal_callback_add(entry, "entry,changed,user", "*",
+   elm_object_signal_callback_add(rd->entry, "entry,changed,user", "*",
                                   entry_changed_user_cb, rd);
    return rd;
 }
diff --git a/src/lib/syntax_helper.c b/src/lib/syntax_helper.c
index 057243c..e655a29 100644
--- a/src/lib/syntax_helper.c
+++ b/src/lib/syntax_helper.c
@@ -35,7 +35,7 @@ buf_flush_timer_cb(void *data)
 /*****************************************************************************/
 
 syntax_helper *
-syntax_init(Evas_Object *entry)
+syntax_init(edit_data *ed)
 {
    syntax_helper *sh = malloc(sizeof(syntax_helper));
    if (!sh)
@@ -47,7 +47,7 @@ syntax_init(Evas_Object *entry)
    sh->buf_flush_timer = ecore_timer_add(1800, buf_flush_timer_cb, sh);
 
    sh->cd = color_init(sh->strbuf);
-   sh->id = indent_init(sh->strbuf, entry);
+   sh->id = indent_init(sh->strbuf, ed);
 
    return sh;
 }
diff --git a/src/lib/syntax_indent.c b/src/lib/syntax_indent.c
index ccbab7d..5fde4b9 100644
--- a/src/lib/syntax_indent.c
+++ b/src/lib/syntax_indent.c
@@ -9,6 +9,7 @@ struct indent_s
 {
    Eina_Strbuf *strbuf;
    Evas_Object *entry;
+   redoundo_data *rd;
 };
 
 typedef struct indent_line_s
@@ -58,7 +59,6 @@ indent_insert_br_case(indent_data *id)
    Evas_Object *entry = id->entry;
    Evas_Object *tb = elm_entry_textblock_get(entry);
    Evas_Textblock_Cursor *cur = evas_object_textblock_cursor_get(tb);
-   redoundo_data *rd = evas_object_data_get(entry, "redoundo");
    const char *text = evas_textblock_cursor_paragraph_text_get(cur);
    char *utf8 = elm_entry_markup_to_utf8(text);
    Eina_Strbuf* diff = id->strbuf;
@@ -77,7 +77,7 @@ indent_insert_br_case(indent_data *id)
           }
      }
    free(utf8);
-   redoundo_text_push(rd, eina_strbuf_string_get(diff), rd_cur_pos, 0,
+   redoundo_text_push(id->rd, eina_strbuf_string_get(diff), rd_cur_pos, 0,
                       EINA_FALSE);
 
    int space = indent_space_get(id);
@@ -88,7 +88,7 @@ indent_insert_br_case(indent_data *id)
    memset(p, ' ', space);
    p[space] = '\0';
 
-   redoundo_text_push(rd, p, elm_entry_cursor_pos_get(entry), 0, EINA_TRUE);
+   redoundo_text_push(id->rd, p, elm_entry_cursor_pos_get(entry), 0, 
EINA_TRUE);
 
    elm_entry_entry_insert(entry, p);
 }
@@ -381,8 +381,6 @@ indent_text_auto_format(indent_data *id, const char *insert)
    Evas_Textblock_Cursor *cur_end = evas_object_textblock_cursor_get(tb);
    int tb_cur_pos = 0;
 
-   redoundo_data *rd = evas_object_data_get(id->entry, "redoundo");
-
    Eina_List *code_line_list = indent_code_line_list_create(id, utf8);
    indent_line *code_line = NULL;
    free(utf8);
@@ -458,7 +456,7 @@ indent_text_auto_format(indent_data *id, const char *insert)
    evas_textblock_cursor_range_delete(cur_start, cur_end);
 
    //Cancel last added diff, that was created when text pasted into entry.
-   redoundo_n_diff_cancel(rd, 1);
+   redoundo_n_diff_cancel(id->rd, 1);
 
    evas_textblock_cursor_line_char_first(cur_start);
 
@@ -484,7 +482,7 @@ indent_text_auto_format(indent_data *id, const char *insert)
                   tb_cur_pos = evas_textblock_cursor_pos_get(cur_end);
                   /* Add data about removal of prior spaces into the redoundo
                      queue. */
-                  redoundo_text_push(rd, prior_space, tb_cur_pos, 0,
+                  redoundo_text_push(id->rd, prior_space, tb_cur_pos, 0,
                                      EINA_FALSE);
                   free(prior_space);
                }
@@ -549,7 +547,7 @@ indent_text_auto_format(indent_data *id, const char *insert)
    evas_object_textblock_text_markup_prepend(cur_start, markup_buf);
 
    //Add data about formatted change into the redoundo queue.
-   redoundo_text_push(rd, markup_buf, tb_cur_pos, 0, EINA_TRUE);
+   redoundo_text_push(id->rd, markup_buf, tb_cur_pos, 0, EINA_TRUE);
    free(markup_buf);
 
    //Update cursor position to the end of the pasted string.
@@ -566,7 +564,7 @@ end:
 /*****************************************************************************/
 
 indent_data *
-indent_init(Eina_Strbuf *strbuf, Evas_Object *entry)
+indent_init(Eina_Strbuf *strbuf, edit_data *ed)
 {
    indent_data *id = malloc(sizeof(indent_data));
    if (!id)
@@ -575,7 +573,12 @@ indent_init(Eina_Strbuf *strbuf, Evas_Object *entry)
         return NULL;
      }
    id->strbuf = strbuf;
-   id->entry = entry;
+   id->entry = edit_entry_get(ed);
+   id->rd = edit_redoundo_get(ed);
+
+   if (!id->entry || !id->rd)
+     EINA_LOG_ERR("Should be called after edit entry and redoundo is 
initialized!");
+
    return id;
 }
 
@@ -614,7 +617,6 @@ indent_delete_apply(indent_data *id, const char *del, int 
cur_line)
    eina_strbuf_reset(diff);
 
    int rd_cur_pos = evas_textblock_cursor_pos_get(cur);
-   redoundo_data *rd = evas_object_data_get(id->entry, "redoundo");
 
    int len = strlen(utf8);
    if (len <= 0) goto end;
@@ -635,7 +637,7 @@ indent_delete_apply(indent_data *id, const char *del, int 
cur_line)
         else break;
         len--;
      }
-   redoundo_text_push(rd, eina_strbuf_string_get(diff), rd_cur_pos, 0,
+   redoundo_text_push(id->rd, eina_strbuf_string_get(diff), rd_cur_pos, 0,
                       EINA_FALSE);
    elm_entry_calc_force(id->entry);
 

-- 


Reply via email to