diff --git a/elm_code/src/bin/elm_code_test_main.c b/elm_code/src/bin/elm_code_test_main.c index 7f9311b..e6235fc 100644 --- a/elm_code/src/bin/elm_code_test_main.c +++ b/elm_code/src/bin/elm_code_test_main.c @@ -31,12 +31,12 @@ static void _append_line(Elm_Code_File *file, const char *line) int length; length = strlen(line); - elm_code_file_line_append(file, line, length); + elm_code_file_line_append(file, line, length, NULL); } static Eina_Bool -_elm_code_test_line_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, - const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +_elm_code_test_line_clicked_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, + const Eo_Event_Description *desc EINA_UNUSED, void *event_info) { Elm_Code_Line *line; @@ -46,6 +46,22 @@ _elm_code_test_line_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, return EINA_TRUE; } +static Eina_Bool +_elm_code_test_line_done_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, + const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +{ + Elm_Code_Line *line; + + line = (Elm_Code_Line *)event_info; + + if (line->number == 1) + elm_code_line_token_add(line, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); + else if (line->number == 4) + line->status = ELM_CODE_STATUS_TYPE_ERROR; + + return EO_CALLBACK_STOP; +} + static Evas_Object * _elm_code_test_welcome_setup(Evas_Object *parent) { @@ -57,14 +73,13 @@ _elm_code_test_welcome_setup(Evas_Object *parent) eo_do(widget, elm_code_widget_code_set(code), elm_code_widget_font_size_set(12), - eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_cb, code)); + eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_test_line_done_cb, NULL); + eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code)); _append_line(code->file, "Hello World, Elm Code!"); - elm_code_file_line_token_add(code->file, 1, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); _append_line(code->file, ""); _append_line(code->file, "This is a demo of elm_code's capabilities."); _append_line(code->file, "*** Currently experimental ***"); - elm_code_file_line_status_set(code->file, 4, ELM_CODE_STATUS_TYPE_ERROR); evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL); diff --git a/elm_code/src/lib/Elm_Code.h b/elm_code/src/lib/Elm_Code.h index d60f2f4..9cfefa4 100644 --- a/elm_code/src/lib/Elm_Code.h +++ b/elm_code/src/lib/Elm_Code.h @@ -34,6 +34,7 @@ #endif /* ! _WIN32 */ #include "elm_code_common.h" +#include "elm_code_line.h" #include "elm_code_file.h" #include "elm_code_parse.h" #include "elm_code_widget.eo.h" diff --git a/elm_code/src/lib/Makefile.am b/elm_code/src/lib/Makefile.am index 3e8a4c8..274c845 100644 --- a/elm_code/src/lib/Makefile.am +++ b/elm_code/src/lib/Makefile.am @@ -19,6 +19,7 @@ lib_LTLIBRARIES = libelm_code.la includes_HEADERS = \ elm_code_common.h \ +elm_code_line.h \ elm_code_file.h \ elm_code_parse.h \ elm_code_widget.eo.h \ @@ -28,6 +29,7 @@ Elm_Code.h includesdir = $(includedir)/edi-@VMAJ@ libelm_code_la_SOURCES = \ +elm_code_line.c \ elm_code_file.c \ elm_code_parse.c \ elm_code_widget_text.c \ diff --git a/elm_code/src/lib/elm_code.c b/elm_code/src/lib/elm_code.c index 1f96512..105ab3b 100644 --- a/elm_code/src/lib/elm_code.c +++ b/elm_code/src/lib/elm_code.c @@ -12,8 +12,10 @@ static int _elm_code_init = 0; int _elm_code_lib_log_dom = -1; -EAPI const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE = - EO_EVENT_DESCRIPTION("line,set,done", ""); +EAPI const Eo_Event_Description ELM_CODE_EVENT_LINE_STYLE_SET = + EO_EVENT_DESCRIPTION("line,style,set", ""); +EAPI const Eo_Event_Description ELM_CODE_EVENT_LINE_LOAD_DONE = + EO_EVENT_DESCRIPTION("line,load,done", ""); EAPI const Eo_Event_Description ELM_CODE_EVENT_FILE_LOAD_DONE = EO_EVENT_DESCRIPTION("file,load,done", ""); diff --git a/elm_code/src/lib/elm_code_common.h b/elm_code/src/lib/elm_code_common.h index 12ab5be..35c8651 100644 --- a/elm_code/src/lib/elm_code_common.h +++ b/elm_code/src/lib/elm_code_common.h @@ -4,7 +4,11 @@ typedef struct _Elm_Code Elm_Code; typedef struct _Elm_Code_File Elm_Code_File; -EAPI extern const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE; +/** Event used to notify that a line's style callbacks have completed */ +EAPI extern const Eo_Event_Description ELM_CODE_EVENT_LINE_STYLE_SET; +/** Event marking that a single line has loaded and ready to be styled */ +EAPI extern const Eo_Event_Description ELM_CODE_EVENT_LINE_LOAD_DONE; +/** Event that marks a file load has been completed */ EAPI extern const Eo_Event_Description ELM_CODE_EVENT_FILE_LOAD_DONE; typedef enum { diff --git a/elm_code/src/lib/elm_code_diff_widget.c b/elm_code/src/lib/elm_code_diff_widget.c index 2315d0a..21790e9 100644 --- a/elm_code/src/lib/elm_code_diff_widget.c +++ b/elm_code/src/lib/elm_code_diff_widget.c @@ -6,78 +6,89 @@ #include "elm_code_private.h" -#define ELM_CODE_DIFF_WIDGET_LEFT "diffwidgetleft" -#define ELM_CODE_DIFF_WIDGET_RIGHT "diffwidgetright" +#define _ELM_CODE_DIFF_WIDGET_LEFT "diffwidgetleft" +#define _ELM_CODE_DIFF_WIDGET_RIGHT "diffwidgetright" -static void _elm_code_diff_widget_parse_diff_line(Elm_Code_Line *line, int number, Elm_Code_File *left, Elm_Code_File *right) +#define _ELM_CODE_DIFF_WIDGET_TYPE_ADDED "added" +#define _ELM_CODE_DIFF_WIDGET_TYPE_REMOVED "removed" +#define _ELM_CODE_DIFF_WIDGET_TYPE_CHANGED "changed" + +static void +_elm_code_diff_widget_parse_diff_line(Elm_Code_Line *line, Elm_Code_File *left, Elm_Code_File *right) { if (line->length < 1) { - elm_code_file_line_append(left, "", 0); - elm_code_file_line_append(right, "", 0); + elm_code_file_line_append(left, "", 0, NULL); + elm_code_file_line_append(right, "", 0, NULL); } if (line->content[0] == '+') { - elm_code_file_line_append(left, "", 0); - elm_code_file_line_append(right, line->content+1, line->length-1); - elm_code_file_line_status_set(right, number, ELM_CODE_STATUS_TYPE_ADDED); + elm_code_file_line_append(left, "", 0, NULL); + elm_code_file_line_append(right, line->content+1, line->length-1, _ELM_CODE_DIFF_WIDGET_TYPE_ADDED); } else if (line->content[0] == '-') { - elm_code_file_line_append(left, line->content+1, line->length-1); - elm_code_file_line_append(right, "", 0); - elm_code_file_line_status_set(left, number, ELM_CODE_STATUS_TYPE_REMOVED); + elm_code_file_line_append(left, line->content+1, line->length-1, _ELM_CODE_DIFF_WIDGET_TYPE_REMOVED); + elm_code_file_line_append(right, "", 0, NULL); } else { - elm_code_file_line_append(left, line->content+1, line->length-1); - elm_code_file_line_append(right, line->content+1, line->length-1); + elm_code_file_line_append(left, line->content+1, line->length-1, NULL); + elm_code_file_line_append(right, line->content+1, line->length-1, NULL); } } -static void _elm_code_diff_widget_parse_diff(Elm_Code_File *diff, Elm_Code_File *left, Elm_Code_File *right) +static void +_elm_code_diff_widget_parse_diff(Elm_Code_File *diff, Elm_Code_File *left, Elm_Code_File *right) { Eina_List *item; Elm_Code_Line *line; - int number, offset; + int offset; - number = 0; offset = 0; EINA_LIST_FOREACH(diff->lines, item, line) { - - if (line->length > 0) + if (line->length > 0 && (line->content[0] == 'd' || line->content[0] == 'i' || line->content[0] == 'n')) { - if (line->content[0] == 'd' || line->content[0] == 'i' || line->content[0] == 'n') - { - offset = 0; - continue; - } + offset = 0; + continue; } - number++; if (offset == 0) - { - elm_code_file_line_append(left, line->content+4, line->length-4); - elm_code_file_line_status_set(left, number, ELM_CODE_STATUS_TYPE_CHANGED); - } + elm_code_file_line_append(left, line->content+4, line->length-4, _ELM_CODE_DIFF_WIDGET_TYPE_CHANGED); else if (offset == 1) - { - number--; - elm_code_file_line_append(right, line->content+4, line->length-4); - elm_code_file_line_status_set(right, number, ELM_CODE_STATUS_TYPE_CHANGED); - } + elm_code_file_line_append(right, line->content+4, line->length-4, _ELM_CODE_DIFF_WIDGET_TYPE_CHANGED); else - { - _elm_code_diff_widget_parse_diff_line(line, number, left, right); - } + _elm_code_diff_widget_parse_diff_line(line, left, right); offset++; } } -EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) +static Eina_Bool +_elm_code_diff_widget_line_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, + const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +{ + Elm_Code_Line *line; + + line = (Elm_Code_Line *)event_info; + + if (!line->data) + return EO_CALLBACK_CONTINUE; + + if (!strcmp(_ELM_CODE_DIFF_WIDGET_TYPE_ADDED, (char *)line->data)) + line->status = ELM_CODE_STATUS_TYPE_ADDED; + else if (!strcmp(_ELM_CODE_DIFF_WIDGET_TYPE_REMOVED, (char *)line->data)) + line->status = ELM_CODE_STATUS_TYPE_REMOVED; + else if (!strcmp(_ELM_CODE_DIFF_WIDGET_TYPE_CHANGED, (char *)line->data)) + line->status = ELM_CODE_STATUS_TYPE_CHANGED; + + return EO_CALLBACK_CONTINUE; +} + +EAPI Evas_Object * +elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) { Elm_Code *wcode1, *wcode2; Elm_Code_Widget *widget_left, *widget_right; @@ -93,37 +104,40 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) wcode1 = elm_code_create(); widget_left = eo_add(ELM_CODE_WIDGET_CLASS, parent); eo_do(widget_left, - elm_code_widget_code_set(wcode1)); + elm_code_widget_code_set(wcode1), + eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_diff_widget_line_cb, NULL)); evas_object_size_hint_weight_set(widget_left, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(widget_left, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(widget_left); - evas_object_data_set(hbox, ELM_CODE_DIFF_WIDGET_LEFT, widget_left); + evas_object_data_set(hbox, _ELM_CODE_DIFF_WIDGET_LEFT, widget_left); elm_object_part_content_set(hbox, "left", widget_left); // right side of diff wcode2 = elm_code_create(); widget_right = eo_add(ELM_CODE_WIDGET_CLASS, parent); eo_do(widget_right, - elm_code_widget_code_set(wcode2)); + elm_code_widget_code_set(wcode2), + eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_diff_widget_line_cb, NULL)); evas_object_size_hint_weight_set(widget_right, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(widget_right, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(widget_right); - evas_object_data_set(hbox, ELM_CODE_DIFF_WIDGET_RIGHT, widget_right); + evas_object_data_set(hbox, _ELM_CODE_DIFF_WIDGET_RIGHT, widget_right); elm_object_part_content_set(hbox, "right", widget_right); _elm_code_diff_widget_parse_diff(code->file, wcode1->file, wcode2->file); return hbox; } -EAPI void elm_code_diff_widget_font_size_set(Evas_Object *widget, int size) +EAPI void +elm_code_diff_widget_font_size_set(Evas_Object *widget, int size) { Elm_Code_Widget *child; - child = (Elm_Code_Widget *) evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_LEFT); + child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_LEFT); eo_do(child, elm_code_widget_font_size_set(size)); - child = (Elm_Code_Widget *) evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_RIGHT); + child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_RIGHT); eo_do(child, elm_code_widget_font_size_set(size)); } diff --git a/elm_code/src/lib/elm_code_file.c b/elm_code/src/lib/elm_code_file.c index b4d7833..cc24dcd 100644 --- a/elm_code/src/lib/elm_code_file.c +++ b/elm_code/src/lib/elm_code_file.c @@ -6,7 +6,7 @@ #include "elm_code_private.h" -static Elm_Code_Line *_elm_code_blank_create(int line) +static Elm_Code_Line *_elm_code_blank_create(int line, void *data) { Elm_Code_Line *ecl; @@ -15,14 +15,16 @@ static Elm_Code_Line *_elm_code_blank_create(int line) ecl->number = line; ecl->status = ELM_CODE_STATUS_TYPE_DEFAULT; + ecl->data = data; + return ecl; } -static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *content, int length, int row, Eina_Bool mapped) +static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *content, int length, int row, Eina_Bool mapped, void *data) { Elm_Code_Line *line; - line = _elm_code_blank_create(row); + line = _elm_code_blank_create(row, data); if (!line) return; if (mapped) @@ -43,7 +45,10 @@ static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *con if (file->parent) { elm_code_parse_line(file->parent, line); - elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_SET_DONE, line); + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); + + // this is called so we can refresh after any styling changes from LOAD_DONE + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_STYLE_SET, line); } } @@ -83,13 +88,13 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) /* Working around the issue that eina_file_map_lines does not trigger an item for empty lines */ while (lastindex < line->index - 1) { - ecl = _elm_code_blank_create(++lastindex); + ecl = _elm_code_blank_create(++lastindex, NULL); if (!ecl) continue; ret->lines = eina_list_append(ret->lines, ecl); } - _elm_code_file_line_append_data(ret, line->start, line->length, lastindex = line->index, EINA_TRUE); + _elm_code_file_line_append_data(ret, line->start, line->length, lastindex = line->index, EINA_TRUE, NULL); } eina_iterator_free(it); @@ -159,12 +164,12 @@ EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file) } -EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length) +EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length, void *data) { int row; row = elm_code_file_lines_get(file); - _elm_code_file_line_append_data(file, line, length, row+1, EINA_FALSE); + return _elm_code_file_line_append_data(file, line, length, row+1, EINA_FALSE, data); } EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int number) @@ -172,53 +177,3 @@ EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int num return eina_list_nth(file->lines, number - 1); } -EAPI const char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int number, int *length) -{ - Elm_Code_Line *line; - - line = elm_code_file_line_get(file, number); - - if (!line) - return NULL; - - *length = line->length; - - if (line->modified) - return line->modified; - return line->content; -} - -EAPI void elm_code_file_line_status_set(Elm_Code_File *file, unsigned int number, Elm_Code_Status_Type status) -{ - Elm_Code_Line *line; - - line = elm_code_file_line_get(file, number); - - if (!line) - return; - - line->status = status; - - if (file->parent) - elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_SET_DONE, line); -} - -EAPI void elm_code_file_line_token_add(Elm_Code_File *file, unsigned int number, int start, int end, - Elm_Code_Token_Type type) -{ - Elm_Code_Line *line; - Elm_Code_Token *tok; - - line = elm_code_file_line_get(file, number); - tok = calloc(1, sizeof(Elm_Code_Token)); - - tok->start = start; - tok->end = end; - tok->type = type; - - line->tokens = eina_list_append(line->tokens, tok); - - if (file->parent) - elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_SET_DONE, line); -} - diff --git a/elm_code/src/lib/elm_code_file.h b/elm_code/src/lib/elm_code_file.h index b37de52..36f39a5 100644 --- a/elm_code/src/lib/elm_code_file.h +++ b/elm_code/src/lib/elm_code_file.h @@ -10,27 +10,6 @@ extern "C" { * @brief These routines are used for interacting with files using Elm Code. */ -typedef struct _Elm_Code_Token -{ - int start, end; - - Elm_Code_Token_Type type; - -} Elm_Code_Token; - -typedef struct _Elm_Code_Line -{ - const char *content; - int length; - unsigned int number; - char *modified; - - Elm_Code_Status_Type status; - Eina_List *tokens; - - -} Elm_Code_Line; - struct _Elm_Code_File { void *parent; @@ -79,17 +58,10 @@ EAPI void elm_code_file_clear(Elm_Code_File *file); EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file); -EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length); +EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length, void *data); EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int line); -EAPI const char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int line, int *length); - -EAPI void elm_code_file_line_status_set(Elm_Code_File *file, unsigned int line, Elm_Code_Status_Type status); - -EAPI void elm_code_file_line_token_add(Elm_Code_File *file, unsigned int number, int start, int end, - Elm_Code_Token_Type type); - /** * @} */ diff --git a/elm_code/src/lib/elm_code_line.c b/elm_code/src/lib/elm_code_line.c new file mode 100644 index 0000000..6a7af56 --- /dev/null +++ b/elm_code/src/lib/elm_code_line.c @@ -0,0 +1,44 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include "Elm_Code.h" + +#include "elm_code_private.h" + +EAPI const char *elm_code_line_content_get(Elm_Code_Line *line, int *length) +{ + if (!line) + return NULL; + + *length = line->length; + + if (line->modified) + return line->modified; + return line->content; +} + +EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status) +{ + if (!line) + return; + + line->status = status; +} + +EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, Elm_Code_Token_Type type) +{ + Elm_Code_Token *tok; + + if (!line) + return; + + tok = calloc(1, sizeof(Elm_Code_Token)); + + tok->start = start; + tok->end = end; + tok->type = type; + + line->tokens = eina_list_append(line->tokens, tok); +} + diff --git a/elm_code/src/lib/elm_code_line.h b/elm_code/src/lib/elm_code_line.h new file mode 100644 index 0000000..339c966 --- /dev/null +++ b/elm_code/src/lib/elm_code_line.h @@ -0,0 +1,58 @@ +#ifndef ELM_CODE_LINE_H_ +# define ELM_CODE_LINE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for interacting with lines of content using Elm Code. + */ + +typedef struct _Elm_Code_Token +{ + int start, end; + + Elm_Code_Token_Type type; + +} Elm_Code_Token; + +typedef struct _Elm_Code_Line +{ + const char *content; + int length; + unsigned int number; + char *modified; + + Elm_Code_Status_Type status; + Eina_List *tokens; + + void *data; +} Elm_Code_Line; + +/** + * @brief Line handling functions. + * @defgroup Line and content manipulation + * + * @{ + * + * Functions for handling content and styling of lines within elm code. + * + */ + +EAPI const char *elm_code_line_content_get(Elm_Code_Line *line, int *length); + +EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status); + +EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, Elm_Code_Token_Type type); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ELM_CODE_LINE_H_ */ diff --git a/elm_code/src/lib/elm_code_widget.c b/elm_code/src/lib/elm_code_widget.c index a12fac1..477f93f 100644 --- a/elm_code/src/lib/elm_code_widget.c +++ b/elm_code/src/lib/elm_code_widget.c @@ -243,7 +243,7 @@ _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); _elm_code_widget_fill_line(widget, cells, line); - return EINA_TRUE; + return EO_CALLBACK_CONTINUE; } @@ -256,7 +256,7 @@ _elm_code_widget_file_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descrip widget = (Elm_Code_Widget *)data; _elm_code_widget_fill(widget); - return EINA_TRUE; + return EO_CALLBACK_CONTINUE; } static void @@ -674,7 +674,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) evas_object_smart_callback_add(obj, "unfocused", _elm_code_widget_unfocused_event_cb, obj); eo_do(obj, - eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, obj); + eo_event_callback_add(&ELM_CODE_EVENT_LINE_STYLE_SET, _elm_code_widget_line_cb, obj); eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj)); _elm_code_widget_font_size_set(obj, pd, 10); diff --git a/elm_code/src/tests/Makefile.am b/elm_code/src/tests/Makefile.am index 168321d..7a829d3 100644 --- a/elm_code/src/tests/Makefile.am +++ b/elm_code/src/tests/Makefile.am @@ -17,6 +17,7 @@ elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/src/lib/ \ -DEFL_BETA_API_SUPPORT \ -DEFL_EO_API_SUPPORT \ -I$(top_srcdir)/elm_code/src/lib \ +-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ -DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/src/tests/\" \ -DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/src/tests/\" \ -DTESTS_DIR=\"$(abspath $(srcdir))/\" \ diff --git a/elm_code/src/tests/elm_code_file_test_memory.c b/elm_code/src/tests/elm_code_file_test_memory.c index cf4de29..e4b3e37 100644 --- a/elm_code/src/tests/elm_code_file_test_memory.c +++ b/elm_code/src/tests/elm_code_file_test_memory.c @@ -11,7 +11,7 @@ START_TEST (elm_code_file_memory_lines) code = elm_code_create(); ck_assert_uint_eq(0, elm_code_file_lines_get(code->file)); - elm_code_file_line_append(code->file, "a line", 6); + elm_code_file_line_append(code->file, "a line", 6, NULL); ck_assert_uint_eq(1, elm_code_file_lines_get(code->file)); elm_code_free(code); @@ -26,10 +26,10 @@ START_TEST (elm_code_file_memory_tokens) code = elm_code_create(); file = code->file; - elm_code_file_line_append(file, "a line", 6); - elm_code_file_line_token_add(file, 1, 2, 5, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_file_line_append(file, "a line", 6, NULL); line = elm_code_file_line_get(file, 1); + elm_code_line_token_add(line, 2, 5, ELM_CODE_TOKEN_TYPE_COMMENT); ck_assert_uint_eq(1, eina_list_count(line->tokens)); elm_code_free(code); } diff --git a/elm_code/src/tests/elm_code_test_parse.c b/elm_code/src/tests/elm_code_test_parse.c index d1d32cf..ebe8b34 100644 --- a/elm_code/src/tests/elm_code_test_parse.c +++ b/elm_code/src/tests/elm_code_test_parse.c @@ -29,7 +29,7 @@ START_TEST (elm_code_parse_hook_memory_test) file = elm_code_file_new(code); elm_code_parser_add(code, _parser_line_callback, _parser_file_callback); - elm_code_file_line_append(file, "some \"test content\" for parsing", 31); + elm_code_file_line_append(file, "some \"test content\" for parsing", 31, NULL); ck_assert_int_eq(1, line_calls); ck_assert_int_eq(0, file_calls); diff --git a/elm_code/src/tests/elm_code_test_widget.c b/elm_code/src/tests/elm_code_test_widget.c index 22ab5b5..2836bb4 100644 --- a/elm_code/src/tests/elm_code_test_widget.c +++ b/elm_code/src/tests/elm_code_test_widget.c @@ -22,12 +22,12 @@ START_TEST (elm_code_widget_token_render_simple_test) code = elm_code_create(); file = code->file; - elm_code_file_line_append(file, "some \"test content\", 45", 23); + elm_code_file_line_append(file, "some \"test content\", 45", 23, NULL); line = elm_code_file_line_get(file, 1); length = line->length; - elm_code_file_line_token_add(file, 1, 6+1, 17+1, ELM_CODE_TOKEN_TYPE_COMMENT); - elm_code_file_line_token_add(file, 1, 21+1, 22+1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 6+1, 17+1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 21+1, 22+1, ELM_CODE_TOKEN_TYPE_COMMENT); _elm_code_widget_fill_line_tokens(NULL, cells, length+1, line); _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT, 1); diff --git a/src/bin/edi_consolepanel.c b/src/bin/edi_consolepanel.c index f01b4ed..f9d2501 100644 --- a/src/bin/edi_consolepanel.c +++ b/src/bin/edi_consolepanel.c @@ -4,6 +4,10 @@ #define BUFFER_SIZE 1024 +#define _EDI_CONSOLE_ERROR "err" +#define _EDI_SUITE_FAILED "failed" +#define _EDI_SUITE_PASSED "passed" + #include #include #include @@ -92,7 +96,7 @@ _edi_consolepanel_clicked_cb(void *data, Eo *obj EINA_UNUSED, code = (Elm_Code *)data; line = (Elm_Code_Line *)event_info; - content = elm_code_file_line_content_get(code->file, line->number, &length); + content = elm_code_line_content_get(line, &length); terminated = malloc(sizeof(char) * (length + 1)); snprintf(terminated, length, "%s", content); @@ -115,14 +119,25 @@ _edi_consolepanel_clicked_cb(void *data, Eo *obj EINA_UNUSED, return EINA_TRUE; } +static Eina_Bool +_edi_consolepanel_line_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, + const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +{ + Elm_Code_Line *line; + + line = (Elm_Code_Line *)event_info; + + if (line->data) + line->status = ELM_CODE_STATUS_TYPE_ERROR; + + return EO_CALLBACK_CONTINUE; +} + static void _edi_consolepanel_append_line_type(const char *line, Eina_Bool err) { _edi_consolepanel_parse_directory(line); - elm_code_file_line_append(_edi_console_code->file, line, strlen(line)); - if (err) - elm_code_file_line_status_set(_edi_console_code->file, elm_code_file_lines_get(_edi_console_code->file), - ELM_CODE_STATUS_TYPE_ERROR); + elm_code_file_line_append(_edi_console_code->file, line, strlen(line), err ? _EDI_CONSOLE_ERROR : NULL); _edi_test_line_callback(line); } @@ -171,13 +186,6 @@ _exe_error(void *d EINA_UNUSED, int t EINA_UNUSED, void *event_info) return ECORE_CALLBACK_RENEW; } -static void -_edi_test_append(const char *content, int length, Elm_Code_Status_Type type) -{ - elm_code_file_line_append(_edi_test_code->file, content, length); - elm_code_file_line_status_set(_edi_test_code->file, elm_code_file_lines_get(_edi_test_code->file), type); -} - static void _edi_test_output_suite(int count, int pass, int fail) { @@ -193,7 +201,7 @@ _edi_test_output_suite(int count, int pass, int fail) percent = (int) ((pass / (double) count) * 100); snprintf(line, linemax, format, pass, percent, fail); - _edi_test_append(line, strlen(line), (fail > 0) ? ELM_CODE_STATUS_TYPE_FAILED : ELM_CODE_STATUS_TYPE_PASSED); + elm_code_file_line_append(_edi_test_code->file, line, strlen(line), (fail > 0) ? _EDI_SUITE_FAILED : _EDI_SUITE_PASSED); free(line); } @@ -248,12 +256,12 @@ _edi_test_line_parse_suite(const char *path) { _edi_test_count++; _edi_test_fail++; - _edi_test_append(line->start, line->length, ELM_CODE_STATUS_TYPE_FAILED); + elm_code_file_line_append(_edi_test_code->file, line->start, line->length, _EDI_SUITE_FAILED); } else if (_edi_test_line_contains(line->start, line->length, "Running")) { _edi_test_count = _edi_test_pass = _edi_test_fail = 0; - _edi_test_append(line->start, line->length, ELM_CODE_STATUS_TYPE_DEFAULT); + elm_code_file_line_append(_edi_test_code->file, line->start, line->length, NULL); } } eina_iterator_free(it); @@ -265,6 +273,25 @@ _edi_test_line_parse_suite(const char *path) } } +static Eina_Bool +_edi_testpanel_line_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, + const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +{ + Elm_Code_Line *line; + + line = (Elm_Code_Line *)event_info; + + if (!line->data) + return EO_CALLBACK_CONTINUE; + + if (!strcmp(_EDI_SUITE_PASSED, line->data)) + line->status = ELM_CODE_STATUS_TYPE_PASSED; + else if (!strcmp(_EDI_SUITE_FAILED, line->data)) + line->status = ELM_CODE_STATUS_TYPE_FAILED; + + return EO_CALLBACK_CONTINUE; +} + static void _edi_test_line_callback(const char *content) { if (!content) @@ -298,6 +325,7 @@ void edi_consolepanel_add(Evas_Object *parent) elm_code_widget_code_set(code), elm_code_widget_font_size_set(_edi_cfg->font.size), elm_code_widget_gravity_set(0.0, 1.0), + eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _edi_consolepanel_line_cb, NULL), eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _edi_consolepanel_clicked_cb, code)); evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -323,6 +351,7 @@ void edi_testpanel_add(Evas_Object *parent) elm_code_widget_code_set(code), elm_code_widget_font_size_set(_edi_cfg->font.size), elm_code_widget_gravity_set(0.0, 1.0), + eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _edi_testpanel_line_cb, NULL), eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _edi_consolepanel_clicked_cb, code)); evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); diff --git a/src/bin/edi_logpanel.c b/src/bin/edi_logpanel.c index cad3ba1..87cdcda 100644 --- a/src/bin/edi_logpanel.c +++ b/src/bin/edi_logpanel.c @@ -2,6 +2,7 @@ # include "config.h" #endif +#include #include #include @@ -10,32 +11,39 @@ #include "edi_private.h" +#define _EDI_LOG_ERROR "err" + static Evas_Object *_info_widget; static Elm_Code *_elm_code; -static void _print_cb(const Eina_Log_Domain *domain, - Eina_Log_Level level, - const char *file, - const char *fnc, - int line, - const char *fmt, - EINA_UNUSED void *data, - va_list args) +static void +_edi_logpanel_print_cb(const Eina_Log_Domain *domain, Eina_Log_Level level, + const char *file, const char *fnc, int line, const char *fmt, + void *data EINA_UNUSED, va_list args) { - unsigned int printed, line_count, buffer_len = 512; + unsigned int printed, buffer_len = 512; char buffer [buffer_len]; printed = snprintf(buffer, buffer_len, "%s:%s:%s (%d): ", domain->domain_str, file, fnc, line); vsnprintf(buffer + printed, buffer_len - printed, fmt, args); - elm_code_file_line_append(_elm_code->file, buffer, strlen(buffer)); - if (level <= EINA_LOG_LEVEL_ERR) - { - line_count = elm_code_file_lines_get(_elm_code->file); + elm_code_file_line_append(_elm_code->file, buffer, strlen(buffer), + (level <= EINA_LOG_LEVEL_ERR) ? _EDI_LOG_ERROR : NULL); +} - elm_code_file_line_status_set(_elm_code->file, line_count, ELM_CODE_STATUS_TYPE_ERROR); - } +static Eina_Bool +_edi_logpanel_line_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, + const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +{ + Elm_Code_Line *line; + + line = (Elm_Code_Line *)event_info; + + if (line->data) + line->status = ELM_CODE_STATUS_TYPE_ERROR; + + return EO_CALLBACK_CONTINUE; } void edi_logpanel_add(Evas_Object *parent) @@ -48,7 +56,8 @@ void edi_logpanel_add(Evas_Object *parent) eo_do(widget, elm_code_widget_code_set(code), elm_code_widget_font_size_set(_edi_cfg->font.size), - elm_code_widget_gravity_set(0.0, 1.0)); + elm_code_widget_gravity_set(0.0, 1.0), + eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _edi_logpanel_line_cb, NULL)); evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(widget); @@ -56,7 +65,7 @@ void edi_logpanel_add(Evas_Object *parent) _elm_code = code; _info_widget = widget; - eina_log_print_cb_set(_print_cb, NULL); + eina_log_print_cb_set(_edi_logpanel_print_cb, NULL); eina_log_color_disable_set(EINA_TRUE); elm_box_pack_end(parent, widget);