ajwillia-ms pushed a commit to branch master. http://git.enlightenment.org/tools/edi.git/commit/?id=c233fcad819e0f7f3669c04587b754273d8b2579
commit c233fcad819e0f7f3669c04587b754273d8b2579 Author: Andy Williams <[email protected]> Date: Fri Feb 6 14:16:26 2015 +0000 Split code editor type from text, don't try to highlight text. Update our internal registry to know the difference between text and code. Add some tests that verify we're getting the right type of editor. --- src/bin/edi_content_provider.c | 5 +++-- src/bin/edi_filepanel.c | 8 ++++++++ src/bin/editor/edi_editor.c | 8 +++++++- src/bin/editor/edi_editor.h | 1 + src/bin/mainview/edi_mainview.c | 3 +++ src/tests/edi_test_content_provider.c | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/bin/edi_content_provider.c b/src/bin/edi_content_provider.c index d31f57a..0472d5b 100644 --- a/src/bin/edi_content_provider.c +++ b/src/bin/edi_content_provider.c @@ -48,6 +48,7 @@ _edi_content_provider_diff_add(Evas_Object *parent, Edi_Mainview_Item *item) static Edi_Content_Provider _edi_content_provider_registry[] = { {"text", EINA_TRUE, EINA_TRUE, _edi_editor_add}, + {"code", EINA_TRUE, EINA_TRUE, _edi_editor_add}, {"image", EINA_FALSE, EINA_FALSE, _edi_content_provider_image_add}, {"diff", EINA_TRUE, EINA_FALSE, _edi_content_provider_diff_add}, @@ -65,9 +66,9 @@ Edi_Content_Provider *edi_content_provider_for_mime_get(const char *mime) id = "text"; else if (!strcasecmp(mime, "text/x-chdr") || !strcasecmp(mime, "text/x-csrc") || !strcasecmp(mime, "text/x-modelica")) - id = "text"; // TODO make a code view + id = "code"; else if (!strcasecmp(mime, "text/x-c++src") || !strcasecmp(mime, "text/x-c++hdr")) - id = "text"; + id = "code"; else if (!strncasecmp(mime, "image/", 6)) id = "image"; else if (!strcasecmp(mime, "text/x-diff") || !strcasecmp(mime, "text/x-patch")) diff --git a/src/bin/edi_filepanel.c b/src/bin/edi_filepanel.c index 435fdbb..9e069da 100644 --- a/src/bin/edi_filepanel.c +++ b/src/bin/edi_filepanel.c @@ -66,6 +66,13 @@ _item_menu_open_as_text_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, } static void +_item_menu_open_as_code_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + _open_cb(_menu_cb_path, "code", EINA_FALSE); +} + +static void _item_menu_open_as_image_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { @@ -95,6 +102,7 @@ _item_menu_create(Evas_Object *win) _item_menu_xdgopen_cb, NULL); menu_it = elm_menu_item_add(menu, NULL, NULL, "open as", NULL, NULL); elm_menu_item_add(menu, menu_it, "txt", "text", _item_menu_open_as_text_cb, NULL); + elm_menu_item_add(menu, menu_it, "text-x-csrc", "code", _item_menu_open_as_code_cb, NULL); elm_menu_item_add(menu, menu_it, "image", "image", _item_menu_open_as_image_cb, NULL); } diff --git a/src/bin/editor/edi_editor.c b/src/bin/editor/edi_editor.c index 8c3a12f..947c740 100644 --- a/src/bin/editor/edi_editor.c +++ b/src/bin/editor/edi_editor.c @@ -669,6 +669,9 @@ _update_highlight_window(Edi_Editor *editor) static void _reset_highlight(Edi_Editor *editor) { + if (!editor->show_highlight) + return; + _update_highlight_window(editor); #if HAVE_LIBCLANG @@ -685,6 +688,9 @@ _reset_highlight(Edi_Editor *editor) static void _update_highlight(Edi_Editor *editor) { + if (!editor->show_highlight) + return; + _update_highlight_window(editor); #if HAVE_LIBCLANG @@ -756,6 +762,7 @@ Evas_Object *_edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item) editor = calloc(1, sizeof(*editor)); editor->entry = txt; editor->lines = lines; + editor->show_highlight = !strcmp(item->editortype, "code"); evas_object_event_callback_add(txt, EVAS_CALLBACK_KEY_DOWN, _smart_cb_key_down, editor); evas_object_smart_callback_add(txt, "changed,user", _changed_cb, editor); @@ -772,7 +779,6 @@ Evas_Object *_edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item) evas_object_show(txt); elm_box_pack_end(box, txt); - _edi_editor_search_add(searchbar, editor); _edi_editor_statusbar_add(statusbar, editor, item); diff --git a/src/bin/editor/edi_editor.h b/src/bin/editor/edi_editor.h index 3219aa7..93562e9 100644 --- a/src/bin/editor/edi_editor.h +++ b/src/bin/editor/edi_editor.h @@ -56,6 +56,7 @@ struct _Edi_Editor Ecore_Timer *delay_highlight; int format_start, format_end, format_line; + Eina_Bool show_highlight; }; /** diff --git a/src/bin/mainview/edi_mainview.c b/src/bin/mainview/edi_mainview.c index 92ef262..53fd087 100644 --- a/src/bin/mainview/edi_mainview.c +++ b/src/bin/mainview/edi_mainview.c @@ -284,6 +284,9 @@ _edi_mainview_choose_type(Evas_Object *parent EINA_UNUSED, Edi_Path_Options *opt elm_icon_standard_set(icon, "txt"); elm_popup_item_append(popup, "text", icon, cb, "text"); icon = elm_icon_add(popup); + elm_icon_standard_set(icon, "text-x-csrc"); + elm_popup_item_append(popup, "code", icon, cb, "code"); + icon = elm_icon_add(popup); elm_icon_standard_set(icon, "image"); elm_popup_item_append(popup, "image", icon, cb, "image"); diff --git a/src/tests/edi_test_content_provider.c b/src/tests/edi_test_content_provider.c index 3f0a82b..4206ec5 100644 --- a/src/tests/edi_test_content_provider.c +++ b/src/tests/edi_test_content_provider.c @@ -34,9 +34,44 @@ START_TEST (edi_test_content_provider_mime_lookup) } END_TEST +static void +_edi_test_content_provider_type_assert(const char *mime, const char *type) +{ + Edi_Content_Provider *provider; + + provider = edi_content_provider_for_mime_get(mime); + + ck_assert(provider); + ck_assert_str_eq(provider->id, type); +} + +START_TEST (edi_test_content_provider_text_files) +{ + _edi_test_content_provider_type_assert("text/plain", "text"); + _edi_test_content_provider_type_assert("application/x-shellscript", "text"); +} +END_TEST + +START_TEST (edi_test_content_provider_c_files) +{ + _edi_test_content_provider_type_assert("text/x-csrc", "code"); + _edi_test_content_provider_type_assert("text/x-chdr", "code"); +} +END_TEST + +START_TEST (edi_test_content_provider_cpp_files) +{ + _edi_test_content_provider_type_assert("text/x-c++src", "code"); + _edi_test_content_provider_type_assert("text/x-c++hdr", "code"); +} +END_TEST + void edi_test_content_provider(TCase *tc) { tcase_add_test(tc, edi_test_content_provider_id_lookup); tcase_add_test(tc, edi_test_content_provider_mime_lookup); + tcase_add_test(tc, edi_test_content_provider_text_files); + tcase_add_test(tc, edi_test_content_provider_c_files); + tcase_add_test(tc, edi_test_content_provider_cpp_files); } --
