forked from enlightenment/efl
elm_code: support line insertion
in our widget call a line insertion on enter pressed
This commit is contained in:
parent
a7adf4f1f6
commit
c4f97f2f3e
|
@ -21,9 +21,10 @@ static Elm_Code_Line *_elm_code_file_line_blank_create(Elm_Code_File *file, int
|
||||||
return ecl;
|
return ecl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *content, int length, int row, Eina_Bool mapped, void *data)
|
static void _elm_code_file_line_insert_data(Elm_Code_File *file, const char *content, int length,
|
||||||
|
unsigned int row, Eina_Bool mapped, void *data)
|
||||||
{
|
{
|
||||||
Elm_Code_Line *line;
|
Elm_Code_Line *line, *after;
|
||||||
|
|
||||||
line = _elm_code_file_line_blank_create(file, row, data);
|
line = _elm_code_file_line_blank_create(file, row, data);
|
||||||
if (!line) return;
|
if (!line) return;
|
||||||
|
@ -41,7 +42,15 @@ static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *con
|
||||||
line->length = length;
|
line->length = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (row == 1)
|
||||||
|
file->lines = eina_list_prepend(file->lines, line);
|
||||||
|
else if (row == eina_list_count(file->lines) + 1)
|
||||||
file->lines = eina_list_append(file->lines, line);
|
file->lines = eina_list_append(file->lines, line);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
after = eina_list_nth(file->lines, row - 2);
|
||||||
|
file->lines = eina_list_append_relative(file->lines, line, after);
|
||||||
|
}
|
||||||
|
|
||||||
if (file->parent)
|
if (file->parent)
|
||||||
{
|
{
|
||||||
|
@ -92,7 +101,7 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path)
|
||||||
ret->lines = eina_list_append(ret->lines, ecl);
|
ret->lines = eina_list_append(ret->lines, ecl);
|
||||||
}
|
}
|
||||||
|
|
||||||
_elm_code_file_line_append_data(ret, line->start, line->length, lastindex = line->index, EINA_TRUE, NULL);
|
_elm_code_file_line_insert_data(ret, line->start, line->length, lastindex = line->index, EINA_TRUE, NULL);
|
||||||
}
|
}
|
||||||
eina_iterator_free(it);
|
eina_iterator_free(it);
|
||||||
|
|
||||||
|
@ -166,8 +175,29 @@ EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int l
|
||||||
{
|
{
|
||||||
int row;
|
int row;
|
||||||
|
|
||||||
row = elm_code_file_lines_get(file);
|
row = elm_code_file_lines_get(file) + 1;
|
||||||
return _elm_code_file_line_append_data(file, line, length, row+1, EINA_FALSE, data);
|
_elm_code_file_line_insert_data(file, line, length, row, EINA_FALSE, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
EAPI void elm_code_file_line_insert(Elm_Code_File *file, unsigned int row, const char *line, int length, void *data)
|
||||||
|
{
|
||||||
|
Eina_List *item;
|
||||||
|
Elm_Code_Line *line_item;
|
||||||
|
unsigned int r;
|
||||||
|
|
||||||
|
_elm_code_file_line_insert_data(file, line, length, row, EINA_FALSE, data);
|
||||||
|
|
||||||
|
r = row;
|
||||||
|
EINA_LIST_FOREACH(file->lines, item, line_item)
|
||||||
|
{
|
||||||
|
if (line_item->number < row)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
line_item->number = r++;
|
||||||
|
|
||||||
|
if (file->parent)
|
||||||
|
elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line_item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int number)
|
EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int number)
|
||||||
|
|
|
@ -60,6 +60,8 @@ EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file);
|
||||||
|
|
||||||
EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length, void *data);
|
EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length, void *data);
|
||||||
|
|
||||||
|
EAPI void elm_code_file_line_insert(Elm_Code_File *file, unsigned int row, const char *line, int length, void *data);
|
||||||
|
|
||||||
EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int line);
|
EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int line);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -580,6 +580,24 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text
|
||||||
elm_code_widget_cursor_position_set(col + length, row));
|
elm_code_widget_cursor_position_set(col + length, row));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_elm_code_widget_newline(Elm_Code_Widget *widget)
|
||||||
|
{
|
||||||
|
Elm_Code *code;
|
||||||
|
Elm_Code_Line *line;
|
||||||
|
unsigned int row, col;
|
||||||
|
|
||||||
|
eo_do(widget,
|
||||||
|
code = elm_code_widget_code_get(),
|
||||||
|
elm_code_widget_cursor_position_get(&col, &row));
|
||||||
|
line = elm_code_file_line_get(code->file, row);
|
||||||
|
|
||||||
|
elm_code_file_line_insert(code->file, line->number + 1, "", 0, NULL);
|
||||||
|
|
||||||
|
eo_do(widget,
|
||||||
|
elm_code_widget_cursor_position_set(1, row + 1));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
|
_elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
|
||||||
Evas_Object *obj EINA_UNUSED, void *event_info)
|
Evas_Object *obj EINA_UNUSED, void *event_info)
|
||||||
|
@ -605,6 +623,10 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
|
||||||
_elm_code_widget_cursor_move_left(widget);
|
_elm_code_widget_cursor_move_left(widget);
|
||||||
else if (!strcmp(ev->key, "Right"))
|
else if (!strcmp(ev->key, "Right"))
|
||||||
_elm_code_widget_cursor_move_right(widget);
|
_elm_code_widget_cursor_move_right(widget);
|
||||||
|
|
||||||
|
else if (!strcmp(ev->key, "KP_Enter") || !strcmp(ev->key, "Return"))
|
||||||
|
_elm_code_widget_newline(widget);
|
||||||
|
|
||||||
else if (ev->string && strlen(ev->string) == 1)
|
else if (ev->string && strlen(ev->string) == 1)
|
||||||
_elm_code_widget_text_at_cursor_insert(widget, ev->string, 1);
|
_elm_code_widget_text_at_cursor_insert(widget, ev->string, 1);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue