elm_code: add a TODO/FIXME standard parser
Corret some callback code and re-parse each time the file is saved. Use this to clean up save/parse code in EDI too
This commit is contained in:
parent
4e7cae76dc
commit
d2f14a82b7
|
@ -24,6 +24,8 @@ typedef enum {
|
|||
ELM_CODE_STATUS_TYPE_PASSED,
|
||||
ELM_CODE_STATUS_TYPE_FAILED,
|
||||
|
||||
ELM_CODE_STATUS_TYPE_TODO,
|
||||
|
||||
ELM_CODE_STATUS_TYPE_COUNT
|
||||
} Elm_Code_Status_Type;
|
||||
|
||||
|
|
|
@ -186,6 +186,13 @@ EAPI void elm_code_file_save(Elm_Code_File *file)
|
|||
|
||||
ecore_file_mv(tmp, path);
|
||||
free(tmp);
|
||||
|
||||
if (file->parent)
|
||||
{
|
||||
_elm_code_parse_reset_file(file->parent, file);
|
||||
_elm_code_parse_file(file->parent, file);
|
||||
elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_FILE_LOAD_DONE, file);
|
||||
}
|
||||
}
|
||||
|
||||
EAPI void elm_code_file_free(Elm_Code_File *file)
|
||||
|
|
|
@ -45,6 +45,18 @@ _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
_elm_code_parse_reset_file(Elm_Code *code, Elm_Code_File *file)
|
||||
{
|
||||
Elm_Code_Line *line;
|
||||
Eina_List *item;
|
||||
|
||||
EINA_LIST_FOREACH(file->lines, item, line)
|
||||
{
|
||||
_elm_code_parse_line(code, line);
|
||||
}
|
||||
}
|
||||
|
||||
static Elm_Code_Parser *
|
||||
_elm_code_parser_new(void (*parse_line)(Elm_Code_Line *, void *),
|
||||
void (*parse_file)(Elm_Code_File *, void *))
|
||||
|
@ -164,9 +176,19 @@ _elm_code_parser_diff_parse_file(Elm_Code_File *file, void *data EINA_UNUSED)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_elm_code_parser_todo_parse_line(Elm_Code_Line *line, void *data EINA_UNUSED)
|
||||
{
|
||||
if (elm_code_line_text_strpos(line, "TODO", 0) != ELM_CODE_TEXT_NOT_FOUND)
|
||||
elm_code_line_status_set(line, ELM_CODE_STATUS_TYPE_TODO);
|
||||
else if (elm_code_line_text_strpos(line, "FIXME", 0) != ELM_CODE_TEXT_NOT_FOUND)
|
||||
elm_code_line_status_set(line, ELM_CODE_STATUS_TYPE_TODO);
|
||||
}
|
||||
|
||||
void
|
||||
_elm_code_parse_setup()
|
||||
{
|
||||
ELM_CODE_PARSER_STANDARD_DIFF = _elm_code_parser_new(_elm_code_parser_diff_parse_line,
|
||||
_elm_code_parser_diff_parse_file);
|
||||
ELM_CODE_PARSER_STANDARD_TODO = _elm_code_parser_new(_elm_code_parser_todo_parse_line, NULL);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ extern "C" {
|
|||
typedef struct _Elm_Code_Parser Elm_Code_Parser;
|
||||
|
||||
EAPI Elm_Code_Parser *ELM_CODE_PARSER_STANDARD_DIFF; /**< A provided parser that will mark up diff text */
|
||||
EAPI Elm_Code_Parser *ELM_CODE_PARSER_STANDARD_TODO; /**< A provided parser that will highlight TODO and FIXME lines */
|
||||
|
||||
/**
|
||||
* @brief Parser helper functions.
|
||||
|
|
|
@ -32,5 +32,7 @@ void _elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line);
|
|||
|
||||
void _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file);
|
||||
|
||||
void _elm_code_parse_reset_file(Elm_Code *code, Elm_Code_File *file);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -38,8 +38,12 @@ elm_code_line_text_set(Elm_Code_Line *line, const char *chars, unsigned int leng
|
|||
line->length = length;
|
||||
|
||||
file = line->file;
|
||||
if (file->parent)
|
||||
{
|
||||
_elm_code_parse_line(file->parent, line);
|
||||
elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line);
|
||||
}
|
||||
}
|
||||
|
||||
EAPI int
|
||||
elm_code_text_strnpos(const char *content, unsigned int length, const char *search, int offset)
|
||||
|
|
|
@ -1299,6 +1299,9 @@ _elm_code_widget_setup_palette(Evas_Object *o)
|
|||
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FAILED,
|
||||
96, 54, 54, 255);
|
||||
|
||||
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_TODO,
|
||||
54, 54, 96, 255);
|
||||
|
||||
// setup token colors
|
||||
evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT,
|
||||
205, 205, 205, 255);
|
||||
|
|
|
@ -60,9 +60,35 @@ START_TEST (elm_code_parse_hook_file_test)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (elm_code_parse_todo_test)
|
||||
{
|
||||
Elm_Code *code;
|
||||
Elm_Code_File *file;
|
||||
Elm_Code_Line *line;
|
||||
|
||||
elm_code_init();
|
||||
|
||||
code = elm_code_create();
|
||||
elm_code_parser_standard_add(code, ELM_CODE_PARSER_STANDARD_TODO);
|
||||
file = elm_code_file_new(code);
|
||||
|
||||
elm_code_file_line_append(file, "xxx TODO line", 13, NULL);
|
||||
line = elm_code_file_line_get(file, 1);
|
||||
ck_assert_int_eq(ELM_CODE_STATUS_TYPE_TODO, line->status);
|
||||
|
||||
elm_code_line_text_set(line, "FIXME too", 9);
|
||||
ck_assert_int_eq(ELM_CODE_STATUS_TYPE_TODO, line->status);
|
||||
|
||||
elm_code_line_text_set(line, "TOFIX", 5);
|
||||
ck_assert_int_eq(ELM_CODE_STATUS_TYPE_DEFAULT, line->status);
|
||||
elm_code_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void elm_code_test_parse(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, elm_code_parse_hook_memory_test);
|
||||
tcase_add_test(tc, elm_code_parse_hook_file_test);
|
||||
tcase_add_test(tc, elm_code_parse_todo_test);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue