diff --git a/ChangeLog b/ChangeLog index aefc025..41f34d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ +2014-06-07 ajwillia.ms (Andy Williams) + + * Add line numbers to the text editpr + 2014-05-15 ajwillia.ms (Andy Williams) - * Add basic undo support + * Add basic undo support 2014-04-27 ajwillia.ms (Andy Williams) diff --git a/NEWS b/NEWS index a3260f0..4286401 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ Changes since Edi project started: pre-1.0 phase 2 "Code aware editor" - Simple build functions - Added a command line builder application + - Added line numbers and line goto to the text editor pre-1.0 phase 1 "Basic text editing" diff --git a/TODO b/TODO index 8b722e6..bcdced9 100644 --- a/TODO +++ b/TODO @@ -5,7 +5,6 @@ This project is in heavy development, we are currenty working towards the * Redo changes that have been undone * Add a menu for easier access to some features * Search / replace in project / directory -* Line numbers & go to line * Creation of new projects from name input and skeleton project files * Automatic code indenting / formatting * Syntax highlighting - from elm_code project (cedric and TAsn) diff --git a/src/bin/edi_mainview.c b/src/bin/edi_mainview.c index bb1c6c4..e45b7da 100644 --- a/src/bin/edi_mainview.c +++ b/src/bin/edi_mainview.c @@ -423,13 +423,16 @@ edi_mainview_open_window(Edi_Path_Options *options) EAPI void edi_mainview_save() { - Evas_Object *txt; + Evas_Object *content; Elm_Object_Item *it; + Edi_Editor *editor; it = elm_naviframe_top_item_get(nf); - txt = elm_object_item_content_get(it); - if (txt) - elm_entry_file_save(txt); + content = elm_object_item_content_get(it); + editor = (Edi_Editor *)evas_object_data_get(content, "editor"); + + if (editor) + elm_entry_file_save(editor->entry); } EAPI void @@ -463,74 +466,88 @@ edi_mainview_close() EAPI void edi_mainview_cut() { - Evas_Object *txt; + Evas_Object *content; Elm_Object_Item *it; + Edi_Editor *editor; it = elm_naviframe_top_item_get(nf); - txt = elm_object_item_content_get(it); - if (txt) - elm_entry_selection_cut(txt); + content = elm_object_item_content_get(it); + editor = (Edi_Editor *)evas_object_data_get(content, "editor"); + + if (editor) + elm_entry_selection_cut(editor->entry); } EAPI void edi_mainview_copy() { - Evas_Object *txt; + Evas_Object *content; Elm_Object_Item *it; + Edi_Editor *editor; it = elm_naviframe_top_item_get(nf); - txt = elm_object_item_content_get(it); - if (txt) - elm_entry_selection_copy(txt); + content = elm_object_item_content_get(it); + editor = (Edi_Editor *)evas_object_data_get(content, "editor"); + + if (editor) + elm_entry_selection_copy(editor->entry); } EAPI void edi_mainview_paste() { - Evas_Object *txt; + Evas_Object *content; Elm_Object_Item *it; + Edi_Editor *editor; it = elm_naviframe_top_item_get(nf); - txt = elm_object_item_content_get(it); - if (txt) - elm_entry_selection_paste(txt); + content = elm_object_item_content_get(it); + editor = (Edi_Editor *)evas_object_data_get(content, "editor"); + + if (editor) + elm_entry_selection_paste(editor->entry); } EAPI void edi_mainview_search() { - Evas_Object *txt; + Evas_Object *content; Elm_Object_Item *it; + Edi_Editor *editor; it = elm_naviframe_top_item_get(nf); - txt = elm_object_item_content_get(it); - if (txt) - edi_editor_search(txt); + content = elm_object_item_content_get(it); + editor = (Edi_Editor *)evas_object_data_get(content, "editor"); + + if (editor) + edi_editor_search(editor->entry); } EAPI void edi_mainview_goto(int line) { - Evas_Object *txt; + Evas_Object *content; Elm_Object_Item *it; + Edi_Editor *editor; Evas_Object *tb; Evas_Textblock_Cursor *mcur; Evas_Coord x, y, w, h; it = elm_naviframe_top_item_get(nf); - txt = elm_object_item_content_get(it); - if (!txt || line <= 0) + content = elm_object_item_content_get(it); + editor = (Edi_Editor *)evas_object_data_get(content, "editor"); + if (!content || line <= 0) return; - tb = elm_entry_textblock_get(txt); + tb = elm_entry_textblock_get(editor->entry); mcur = evas_object_textblock_cursor_get(tb); evas_textblock_cursor_line_set(mcur, line-1); - evas_object_textblock_line_number_geometry_get(tb, line, &x, &y, &w, &h); - elm_scroller_region_show(txt, x, y, w, h); - elm_entry_calc_force(txt); + elm_entry_cursor_geometry_get(editor->entry, &x, &y, &w, &h); + elm_scroller_region_show(editor->entry, x, y, w, h); + elm_entry_calc_force(editor->entry); - elm_object_focus_set(txt, EINA_TRUE); + elm_object_focus_set(editor->entry, EINA_TRUE); } EAPI void diff --git a/src/bin/editor/edi_editor.c b/src/bin/editor/edi_editor.c index a887270..0249179 100644 --- a/src/bin/editor/edi_editor.c +++ b/src/bin/editor/edi_editor.c @@ -13,6 +13,8 @@ #include "edi_private.h" +#define EDITOR_FONT "DEFAULT='font=Monospace font_size=12'" + static void _undo_do(Edi_Editor *editor, Elm_Entry_Change_Info *inf) @@ -130,29 +132,88 @@ _smart_cb_key_down(void *data, Evas *e EINA_UNUSED, } } +static void _set_offset(Evas_Object *lines, int offset, int height) +{ + elm_scroller_region_show(lines, 0, offset, 10, height); +} + +static void _set_line(Evas_Object *lines, int line, int count) +{ + Eina_Strbuf *content; + int i; + + content = eina_strbuf_new(); + eina_strbuf_append(content, ""); + for (i = line; i < line + count; i++) + { + eina_strbuf_append_printf(content, "%d
", i); + } + eina_strbuf_append(content, ""); + elm_object_text_set(lines, eina_strbuf_string_get(content)); + eina_strbuf_free(content); +} + +static void +_scroll_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Edi_Editor *editor = data; + Evas_Coord y, h; + int line, lines, offset, line_height; + + line_height = 14; + elm_scroller_region_get(editor->entry, NULL, &y, NULL, &h); + offset = y % line_height; + line = (y - offset) / line_height + 1; + lines = h / line_height + 2; + + _set_offset(editor->lines, offset, h); + _set_line(editor->lines, line, lines); +} + EAPI Evas_Object *edi_editor_add(Evas_Object *parent, const char *path) { - Evas_Object *txt; + Evas_Object *txt, *lines, *box; Evas_Modifier_Mask ctrl, shift, alt; Evas *e; Edi_Editor *editor; - txt = elm_entry_add(parent); + box = elm_box_add(parent); + elm_box_horizontal_set(box, EINA_TRUE); + evas_object_show(box); + + lines = elm_entry_add(box); + elm_entry_scrollable_set(lines, EINA_TRUE); + elm_scroller_policy_set(lines, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); + elm_entry_editable_set(lines, EINA_FALSE); + + elm_entry_text_style_user_push(lines, EDITOR_FONT); + evas_object_color_set(lines, 127, 127, 127, 255); + _set_line(lines, 1, 200); + + evas_object_size_hint_weight_set(lines, 0.052, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(lines, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(box, lines); + evas_object_show(lines); + + txt = elm_entry_add(box); elm_entry_editable_set(txt, EINA_TRUE); elm_entry_scrollable_set(txt, EINA_TRUE); elm_entry_line_wrap_set(txt, EINA_FALSE); - elm_entry_text_style_user_push(txt, "DEFAULT='font=Monospace font_size=12'"); + elm_entry_text_style_user_push(txt, EDITOR_FONT); elm_entry_file_set(txt, path, ELM_TEXT_FORMAT_PLAIN_UTF8); elm_entry_autosave_set(txt, EDI_CONTENT_AUTOSAVE); evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(txt); + elm_box_pack_end(box, txt); editor = calloc(1, sizeof(*editor)); editor->entry = txt; + editor->lines = lines; 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); + evas_object_smart_callback_add(txt, "scroll", _scroll_cb, editor); evas_object_smart_callback_add(txt, "undo,request", _undo_cb, editor); e = evas_object_evas_get(txt); @@ -166,5 +227,6 @@ EAPI Evas_Object *edi_editor_add(Evas_Object *parent, const char *path) (void)!evas_object_key_grab(txt, "f", ctrl, shift | alt, 1); (void)!evas_object_key_grab(txt, "z", ctrl, shift | alt, 1); - return txt; + evas_object_data_set(box, "editor", editor); + return box; } diff --git a/src/bin/editor/edi_editor.h b/src/bin/editor/edi_editor.h index 04897b8..1cdcad0 100644 --- a/src/bin/editor/edi_editor.h +++ b/src/bin/editor/edi_editor.h @@ -25,6 +25,7 @@ typedef struct _Edi_Editor Edi_Editor; struct _Edi_Editor { Evas_Object *entry; /**< The main text entry widget for the editor */ + Evas_Object *lines; Eina_List *undo_stack; /**< The list of operations that can be undone */ /* Private */