forked from enlightenment/edi
Adding line numbers to the text editor.
Not the prettiest approach right now, but we've got a scrolling list of lines that stays aligned with the text scroll
This commit is contained in:
parent
db613fe6ea
commit
d90d0e3c94
|
@ -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)
|
2014-05-15 ajwillia.ms (Andy Williams)
|
||||||
|
|
||||||
* Add basic undo support
|
* Add basic undo support
|
||||||
|
|
||||||
2014-04-27 ajwillia.ms (Andy Williams)
|
2014-04-27 ajwillia.ms (Andy Williams)
|
||||||
|
|
||||||
|
|
1
NEWS
1
NEWS
|
@ -4,6 +4,7 @@ Changes since Edi project started:
|
||||||
pre-1.0 phase 2 "Code aware editor"
|
pre-1.0 phase 2 "Code aware editor"
|
||||||
- Simple build functions
|
- Simple build functions
|
||||||
- Added a command line builder application
|
- Added a command line builder application
|
||||||
|
- Added line numbers and line goto to the text editor
|
||||||
|
|
||||||
|
|
||||||
pre-1.0 phase 1 "Basic text editing"
|
pre-1.0 phase 1 "Basic text editing"
|
||||||
|
|
1
TODO
1
TODO
|
@ -5,7 +5,6 @@ This project is in heavy development, we are currenty working towards the
|
||||||
* Redo changes that have been undone
|
* Redo changes that have been undone
|
||||||
* Add a menu for easier access to some features
|
* Add a menu for easier access to some features
|
||||||
* Search / replace in project / directory
|
* Search / replace in project / directory
|
||||||
* Line numbers & go to line
|
|
||||||
* Creation of new projects from name input and skeleton project files
|
* Creation of new projects from name input and skeleton project files
|
||||||
* Automatic code indenting / formatting
|
* Automatic code indenting / formatting
|
||||||
* Syntax highlighting - from elm_code project (cedric and TAsn)
|
* Syntax highlighting - from elm_code project (cedric and TAsn)
|
||||||
|
|
|
@ -423,13 +423,16 @@ edi_mainview_open_window(Edi_Path_Options *options)
|
||||||
EAPI void
|
EAPI void
|
||||||
edi_mainview_save()
|
edi_mainview_save()
|
||||||
{
|
{
|
||||||
Evas_Object *txt;
|
Evas_Object *content;
|
||||||
Elm_Object_Item *it;
|
Elm_Object_Item *it;
|
||||||
|
Edi_Editor *editor;
|
||||||
|
|
||||||
it = elm_naviframe_top_item_get(nf);
|
it = elm_naviframe_top_item_get(nf);
|
||||||
txt = elm_object_item_content_get(it);
|
content = elm_object_item_content_get(it);
|
||||||
if (txt)
|
editor = (Edi_Editor *)evas_object_data_get(content, "editor");
|
||||||
elm_entry_file_save(txt);
|
|
||||||
|
if (editor)
|
||||||
|
elm_entry_file_save(editor->entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
|
@ -463,74 +466,88 @@ edi_mainview_close()
|
||||||
EAPI void
|
EAPI void
|
||||||
edi_mainview_cut()
|
edi_mainview_cut()
|
||||||
{
|
{
|
||||||
Evas_Object *txt;
|
Evas_Object *content;
|
||||||
Elm_Object_Item *it;
|
Elm_Object_Item *it;
|
||||||
|
Edi_Editor *editor;
|
||||||
|
|
||||||
it = elm_naviframe_top_item_get(nf);
|
it = elm_naviframe_top_item_get(nf);
|
||||||
txt = elm_object_item_content_get(it);
|
content = elm_object_item_content_get(it);
|
||||||
if (txt)
|
editor = (Edi_Editor *)evas_object_data_get(content, "editor");
|
||||||
elm_entry_selection_cut(txt);
|
|
||||||
|
if (editor)
|
||||||
|
elm_entry_selection_cut(editor->entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
edi_mainview_copy()
|
edi_mainview_copy()
|
||||||
{
|
{
|
||||||
Evas_Object *txt;
|
Evas_Object *content;
|
||||||
Elm_Object_Item *it;
|
Elm_Object_Item *it;
|
||||||
|
Edi_Editor *editor;
|
||||||
|
|
||||||
it = elm_naviframe_top_item_get(nf);
|
it = elm_naviframe_top_item_get(nf);
|
||||||
txt = elm_object_item_content_get(it);
|
content = elm_object_item_content_get(it);
|
||||||
if (txt)
|
editor = (Edi_Editor *)evas_object_data_get(content, "editor");
|
||||||
elm_entry_selection_copy(txt);
|
|
||||||
|
if (editor)
|
||||||
|
elm_entry_selection_copy(editor->entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
edi_mainview_paste()
|
edi_mainview_paste()
|
||||||
{
|
{
|
||||||
Evas_Object *txt;
|
Evas_Object *content;
|
||||||
Elm_Object_Item *it;
|
Elm_Object_Item *it;
|
||||||
|
Edi_Editor *editor;
|
||||||
|
|
||||||
it = elm_naviframe_top_item_get(nf);
|
it = elm_naviframe_top_item_get(nf);
|
||||||
txt = elm_object_item_content_get(it);
|
content = elm_object_item_content_get(it);
|
||||||
if (txt)
|
editor = (Edi_Editor *)evas_object_data_get(content, "editor");
|
||||||
elm_entry_selection_paste(txt);
|
|
||||||
|
if (editor)
|
||||||
|
elm_entry_selection_paste(editor->entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
edi_mainview_search()
|
edi_mainview_search()
|
||||||
{
|
{
|
||||||
Evas_Object *txt;
|
Evas_Object *content;
|
||||||
Elm_Object_Item *it;
|
Elm_Object_Item *it;
|
||||||
|
Edi_Editor *editor;
|
||||||
|
|
||||||
it = elm_naviframe_top_item_get(nf);
|
it = elm_naviframe_top_item_get(nf);
|
||||||
txt = elm_object_item_content_get(it);
|
content = elm_object_item_content_get(it);
|
||||||
if (txt)
|
editor = (Edi_Editor *)evas_object_data_get(content, "editor");
|
||||||
edi_editor_search(txt);
|
|
||||||
|
if (editor)
|
||||||
|
edi_editor_search(editor->entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
edi_mainview_goto(int line)
|
edi_mainview_goto(int line)
|
||||||
{
|
{
|
||||||
Evas_Object *txt;
|
Evas_Object *content;
|
||||||
Elm_Object_Item *it;
|
Elm_Object_Item *it;
|
||||||
|
Edi_Editor *editor;
|
||||||
Evas_Object *tb;
|
Evas_Object *tb;
|
||||||
Evas_Textblock_Cursor *mcur;
|
Evas_Textblock_Cursor *mcur;
|
||||||
Evas_Coord x, y, w, h;
|
Evas_Coord x, y, w, h;
|
||||||
|
|
||||||
it = elm_naviframe_top_item_get(nf);
|
it = elm_naviframe_top_item_get(nf);
|
||||||
txt = elm_object_item_content_get(it);
|
content = elm_object_item_content_get(it);
|
||||||
if (!txt || line <= 0)
|
editor = (Edi_Editor *)evas_object_data_get(content, "editor");
|
||||||
|
if (!content || line <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tb = elm_entry_textblock_get(txt);
|
tb = elm_entry_textblock_get(editor->entry);
|
||||||
mcur = evas_object_textblock_cursor_get(tb);
|
mcur = evas_object_textblock_cursor_get(tb);
|
||||||
|
|
||||||
evas_textblock_cursor_line_set(mcur, line-1);
|
evas_textblock_cursor_line_set(mcur, line-1);
|
||||||
evas_object_textblock_line_number_geometry_get(tb, line, &x, &y, &w, &h);
|
elm_entry_cursor_geometry_get(editor->entry, &x, &y, &w, &h);
|
||||||
elm_scroller_region_show(txt, x, y, w, h);
|
elm_scroller_region_show(editor->entry, x, y, w, h);
|
||||||
elm_entry_calc_force(txt);
|
elm_entry_calc_force(editor->entry);
|
||||||
|
|
||||||
elm_object_focus_set(txt, EINA_TRUE);
|
elm_object_focus_set(editor->entry, EINA_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#include "edi_private.h"
|
#include "edi_private.h"
|
||||||
|
|
||||||
|
#define EDITOR_FONT "DEFAULT='font=Monospace font_size=12'"
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_undo_do(Edi_Editor *editor, Elm_Entry_Change_Info *inf)
|
_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, "<align=right>");
|
||||||
|
for (i = line; i < line + count; i++)
|
||||||
|
{
|
||||||
|
eina_strbuf_append_printf(content, "%d<br>", i);
|
||||||
|
}
|
||||||
|
eina_strbuf_append(content, "</align>");
|
||||||
|
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)
|
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_Modifier_Mask ctrl, shift, alt;
|
||||||
Evas *e;
|
Evas *e;
|
||||||
Edi_Editor *editor;
|
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_editable_set(txt, EINA_TRUE);
|
||||||
elm_entry_scrollable_set(txt, EINA_TRUE);
|
elm_entry_scrollable_set(txt, EINA_TRUE);
|
||||||
elm_entry_line_wrap_set(txt, EINA_FALSE);
|
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_file_set(txt, path, ELM_TEXT_FORMAT_PLAIN_UTF8);
|
||||||
elm_entry_autosave_set(txt, EDI_CONTENT_AUTOSAVE);
|
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_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||||
evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||||
evas_object_show(txt);
|
evas_object_show(txt);
|
||||||
|
elm_box_pack_end(box, txt);
|
||||||
|
|
||||||
editor = calloc(1, sizeof(*editor));
|
editor = calloc(1, sizeof(*editor));
|
||||||
editor->entry = txt;
|
editor->entry = txt;
|
||||||
|
editor->lines = lines;
|
||||||
evas_object_event_callback_add(txt, EVAS_CALLBACK_KEY_DOWN,
|
evas_object_event_callback_add(txt, EVAS_CALLBACK_KEY_DOWN,
|
||||||
_smart_cb_key_down, editor);
|
_smart_cb_key_down, editor);
|
||||||
evas_object_smart_callback_add(txt, "changed,user", _changed_cb, 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);
|
evas_object_smart_callback_add(txt, "undo,request", _undo_cb, editor);
|
||||||
|
|
||||||
e = evas_object_evas_get(txt);
|
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, "f", ctrl, shift | alt, 1);
|
||||||
(void)!evas_object_key_grab(txt, "z", 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ typedef struct _Edi_Editor Edi_Editor;
|
||||||
struct _Edi_Editor
|
struct _Edi_Editor
|
||||||
{
|
{
|
||||||
Evas_Object *entry; /**< The main text entry widget for the 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 */
|
Eina_List *undo_stack; /**< The list of operations that can be undone */
|
||||||
|
|
||||||
/* Private */
|
/* Private */
|
||||||
|
|
Loading…
Reference in New Issue