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.
This commit is contained in:
parent
0b5fa028bb
commit
c233fcad81
|
@ -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"))
|
||||
|
|
|
@ -65,6 +65,13 @@ _item_menu_open_as_text_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
|
|||
_open_cb(_menu_cb_path, "text", EINA_FALSE);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ struct _Edi_Editor
|
|||
|
||||
Ecore_Timer *delay_highlight;
|
||||
int format_start, format_end, format_line;
|
||||
Eina_Bool show_highlight;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue