2016-06-02 17:19:08 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "elementary_config.h"
|
2015-03-17 15:42:03 -07:00
|
|
|
#endif
|
|
|
|
|
2016-06-02 17:19:08 -07:00
|
|
|
#include "Elementary.h"
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2015-04-04 10:17:01 -07:00
|
|
|
#include "elm_code_widget_private.h"
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2017-01-10 04:53:21 -08:00
|
|
|
static char _breaking_chars[] = " \t,.?!;:*&()[]{}'\"";
|
2016-02-15 15:51:51 -08:00
|
|
|
|
2015-03-17 15:42:03 -07:00
|
|
|
static Elm_Code_Widget_Selection_Data *
|
|
|
|
_elm_code_widget_selection_new()
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Selection_Data *data;
|
|
|
|
|
|
|
|
data = calloc(1, sizeof(Elm_Code_Widget_Selection_Data));
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2015-03-18 15:24:56 -07:00
|
|
|
static void
|
|
|
|
_elm_code_widget_selection_limit(Evas_Object *widget EINA_UNUSED, Elm_Code_Widget_Data *pd,
|
|
|
|
unsigned int *row, unsigned int *col)
|
|
|
|
{
|
|
|
|
Elm_Code_Line *line;
|
|
|
|
Elm_Code_File *file;
|
2015-03-29 12:12:28 -07:00
|
|
|
unsigned int width;
|
2015-03-18 15:24:56 -07:00
|
|
|
|
|
|
|
file = pd->code->file;
|
|
|
|
|
|
|
|
if (*row > elm_code_file_lines_get(file))
|
|
|
|
*row = elm_code_file_lines_get(file);
|
|
|
|
|
|
|
|
line = elm_code_file_line_get(file, *row);
|
2015-06-03 13:29:31 -07:00
|
|
|
width = elm_code_widget_line_text_column_width_get(widget, line);
|
2015-03-18 15:24:56 -07:00
|
|
|
|
2015-03-29 12:12:28 -07:00
|
|
|
if (*col > width + 1)
|
|
|
|
*col = width + 1;
|
2015-03-18 15:24:56 -07:00
|
|
|
}
|
|
|
|
|
2015-03-17 15:42:03 -07:00
|
|
|
EAPI void
|
|
|
|
elm_code_widget_selection_start(Evas_Object *widget,
|
|
|
|
unsigned int line, unsigned int col)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Elm_Code_Widget_Selection_Data *selection;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2015-03-18 15:24:56 -07:00
|
|
|
_elm_code_widget_selection_limit(widget, pd, &line, &col);
|
2015-03-17 15:42:03 -07:00
|
|
|
if (!pd->selection)
|
|
|
|
{
|
|
|
|
selection = _elm_code_widget_selection_new();
|
|
|
|
|
|
|
|
selection->end_line = line;
|
|
|
|
selection->end_col = col;
|
|
|
|
|
|
|
|
pd->selection = selection;
|
|
|
|
}
|
|
|
|
|
|
|
|
pd->selection->start_line = line;
|
|
|
|
pd->selection->start_col = col;
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget);
|
2015-03-17 15:42:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_code_widget_selection_end(Evas_Object *widget,
|
|
|
|
unsigned int line, unsigned int col)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Elm_Code_Widget_Selection_Data *selection;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2015-03-18 15:24:56 -07:00
|
|
|
_elm_code_widget_selection_limit(widget, pd, &line, &col);
|
2015-03-17 15:42:03 -07:00
|
|
|
if (!pd->selection)
|
|
|
|
{
|
|
|
|
selection = _elm_code_widget_selection_new();
|
|
|
|
|
|
|
|
selection->start_line = line;
|
|
|
|
selection->start_col = col;
|
|
|
|
|
|
|
|
pd->selection = selection;
|
|
|
|
}
|
|
|
|
|
|
|
|
pd->selection->end_line = line;
|
|
|
|
pd->selection->end_col = col;
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget);
|
2015-03-17 15:42:03 -07:00
|
|
|
}
|
|
|
|
|
2015-09-16 04:32:25 -07:00
|
|
|
EAPI Elm_Code_Widget_Selection_Data *
|
|
|
|
elm_code_widget_selection_normalized_get(Evas_Object *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Elm_Code_Widget_Selection_Data *selection;
|
|
|
|
Eina_Bool reverse;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-09-16 04:32:25 -07:00
|
|
|
selection = _elm_code_widget_selection_new();
|
|
|
|
|
|
|
|
if (!pd->selection)
|
|
|
|
{
|
|
|
|
selection->start_line = selection->end_line = 1;
|
|
|
|
selection->start_col = selection->end_col = 1;
|
|
|
|
|
|
|
|
return selection;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pd->selection->start_line == pd->selection->end_line)
|
|
|
|
reverse = pd->selection->start_col > pd->selection->end_col;
|
|
|
|
else
|
|
|
|
reverse = pd->selection->start_line > pd->selection->end_line;
|
|
|
|
|
|
|
|
if (reverse)
|
|
|
|
{
|
|
|
|
selection->start_line = pd->selection->end_line;
|
|
|
|
selection->start_col = pd->selection->end_col;
|
|
|
|
selection->end_line = pd->selection->start_line;
|
|
|
|
selection->end_col = pd->selection->start_col;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selection->start_line = pd->selection->start_line;
|
|
|
|
selection->start_col = pd->selection->start_col;
|
|
|
|
selection->end_line = pd->selection->end_line;
|
|
|
|
selection->end_col = pd->selection->end_col;
|
|
|
|
}
|
|
|
|
|
|
|
|
return selection;
|
|
|
|
}
|
|
|
|
|
2015-03-17 15:42:03 -07:00
|
|
|
EAPI void
|
|
|
|
elm_code_widget_selection_clear(Evas_Object *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2016-02-25 07:50:34 -08:00
|
|
|
if (!pd->selection)
|
|
|
|
return;
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2016-02-25 07:50:34 -08:00
|
|
|
free(pd->selection);
|
2015-03-17 15:42:03 -07:00
|
|
|
pd->selection = NULL;
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget);
|
2015-03-17 15:42:03 -07:00
|
|
|
}
|
|
|
|
|
2015-03-28 08:17:08 -07:00
|
|
|
static void
|
2015-06-03 13:29:31 -07:00
|
|
|
_elm_code_widget_selection_delete_single(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd)
|
2015-03-28 08:17:08 -07:00
|
|
|
{
|
|
|
|
Elm_Code_Line *line;
|
|
|
|
const char *old;
|
2015-05-30 12:46:34 -07:00
|
|
|
unsigned int old_length, start, end, length;
|
2015-03-28 08:17:08 -07:00
|
|
|
char *content;
|
2015-09-16 04:32:25 -07:00
|
|
|
Elm_Code_Widget_Selection_Data *selection;
|
2015-03-28 08:17:08 -07:00
|
|
|
|
2015-09-16 04:32:25 -07:00
|
|
|
selection = elm_code_widget_selection_normalized_get(widget);
|
|
|
|
line = elm_code_file_line_get(pd->code->file, selection->start_line);
|
2015-03-28 08:17:08 -07:00
|
|
|
old = elm_code_line_text_get(line, &old_length);
|
2015-09-16 04:32:25 -07:00
|
|
|
start = elm_code_widget_line_text_position_for_column_get(widget, line, selection->start_col);
|
|
|
|
end = elm_code_widget_line_text_position_for_column_get(widget, line, selection->end_col);
|
2015-05-30 12:46:34 -07:00
|
|
|
length = line->length - (end - start + 1);
|
2015-05-18 07:49:24 -07:00
|
|
|
|
2016-02-21 10:48:07 -08:00
|
|
|
if (end == line->length)
|
|
|
|
{
|
|
|
|
length = line->length - (end - start);
|
|
|
|
|
|
|
|
content = malloc(sizeof(char) * length);
|
|
|
|
strncpy(content, old, start);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
length = line->length - (end - start + 1);
|
|
|
|
|
|
|
|
content = malloc(sizeof(char) * length);
|
|
|
|
strncpy(content, old, start);
|
|
|
|
strncpy(content + start, old + end + 1,
|
|
|
|
old_length - (end + 1));
|
|
|
|
}
|
2015-03-28 08:17:08 -07:00
|
|
|
elm_code_line_text_set(line, content, length);
|
|
|
|
free(content);
|
2015-09-16 04:32:25 -07:00
|
|
|
free(selection);
|
2015-03-28 08:17:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-06-03 13:29:31 -07:00
|
|
|
_elm_code_widget_selection_delete_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd)
|
2015-03-28 08:17:08 -07:00
|
|
|
{
|
|
|
|
Elm_Code_Line *line;
|
|
|
|
const char *first, *last;
|
2015-05-30 12:46:34 -07:00
|
|
|
unsigned int last_length, start, end, length, i;
|
2015-03-28 08:17:08 -07:00
|
|
|
char *content;
|
2015-09-16 04:32:25 -07:00
|
|
|
Elm_Code_Widget_Selection_Data *selection;
|
2015-03-28 08:17:08 -07:00
|
|
|
|
2015-09-16 04:32:25 -07:00
|
|
|
if (pd->selection->end_line == pd->selection->start_line)
|
2015-03-28 08:17:08 -07:00
|
|
|
return;
|
|
|
|
|
2015-09-16 04:32:25 -07:00
|
|
|
selection = elm_code_widget_selection_normalized_get(widget);
|
|
|
|
line = elm_code_file_line_get(pd->code->file, selection->start_line);
|
2015-03-28 08:17:08 -07:00
|
|
|
first = elm_code_line_text_get(line, NULL);
|
2015-09-16 04:32:25 -07:00
|
|
|
start = elm_code_widget_line_text_position_for_column_get(widget, line, selection->start_col);
|
2015-05-30 12:46:34 -07:00
|
|
|
|
2015-09-16 04:32:25 -07:00
|
|
|
line = elm_code_file_line_get(pd->code->file, selection->end_line);
|
2015-03-28 08:17:08 -07:00
|
|
|
last = elm_code_line_text_get(line, &last_length);
|
2015-09-16 04:32:25 -07:00
|
|
|
end = elm_code_widget_line_text_position_for_column_get(widget, line, selection->end_col);
|
2015-05-30 12:46:34 -07:00
|
|
|
|
2016-02-21 10:03:29 -08:00
|
|
|
if (last_length == end)
|
|
|
|
{
|
|
|
|
length = start + last_length - end;
|
|
|
|
content = malloc(sizeof(char) * length);
|
|
|
|
strncpy(content, first, start);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
length = start + last_length - (end + 1);
|
|
|
|
content = malloc(sizeof(char) * length);
|
|
|
|
strncpy(content, first, start);
|
|
|
|
|
|
|
|
strncpy(content + start, last + end + 1, last_length - (end + 1));
|
|
|
|
}
|
2015-03-28 08:17:08 -07:00
|
|
|
|
2015-09-16 04:32:25 -07:00
|
|
|
for (i = line->number; i > selection->start_line; i--)
|
2015-03-28 08:17:08 -07:00
|
|
|
elm_code_file_line_remove(pd->code->file, i);
|
|
|
|
|
2015-09-16 04:32:25 -07:00
|
|
|
line = elm_code_file_line_get(pd->code->file, selection->start_line);
|
2015-03-28 08:17:08 -07:00
|
|
|
elm_code_line_text_set(line, content, length);
|
|
|
|
free(content);
|
2015-09-16 04:32:25 -07:00
|
|
|
free(selection);
|
2015-03-28 08:17:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_code_widget_selection_delete(Evas_Object *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
2016-09-01 13:41:57 -07:00
|
|
|
Elm_Code_Widget_Selection_Data *selection;
|
2015-03-28 08:17:08 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-28 08:17:08 -07:00
|
|
|
|
|
|
|
if (!pd->selection)
|
|
|
|
return;
|
|
|
|
|
2016-09-01 13:41:57 -07:00
|
|
|
selection = elm_code_widget_selection_normalized_get(widget);
|
|
|
|
if (selection->start_line == selection->end_line)
|
2015-06-03 13:29:31 -07:00
|
|
|
_elm_code_widget_selection_delete_single(widget, pd);
|
2015-03-28 08:17:08 -07:00
|
|
|
else
|
2015-06-03 13:29:31 -07:00
|
|
|
_elm_code_widget_selection_delete_multi(widget, pd);
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_code_widget_cursor_position_set(widget, selection->start_line, selection->start_col);
|
2015-03-28 08:17:08 -07:00
|
|
|
|
|
|
|
free(pd->selection);
|
|
|
|
pd->selection = NULL;
|
2016-09-01 13:41:57 -07:00
|
|
|
free(selection);
|
|
|
|
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget);
|
2015-03-28 08:17:08 -07:00
|
|
|
}
|
|
|
|
|
2016-02-15 14:54:12 -08:00
|
|
|
EAPI void
|
|
|
|
elm_code_widget_selection_select_line(Evas_Object *widget, unsigned int line)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Elm_Code_Line *lineobj;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2016-02-15 14:54:12 -08:00
|
|
|
lineobj = elm_code_file_line_get(pd->code->file, line);
|
|
|
|
|
|
|
|
if (!lineobj)
|
|
|
|
return;
|
|
|
|
|
|
|
|
elm_code_widget_selection_start(widget, line, 1);
|
|
|
|
elm_code_widget_selection_end(widget, line, lineobj->length);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_elm_code_widget_selection_char_breaks(char chr)
|
|
|
|
{
|
2016-02-15 15:51:51 -08:00
|
|
|
unsigned int i;
|
|
|
|
|
2016-02-15 14:54:12 -08:00
|
|
|
if (chr == 0)
|
|
|
|
return EINA_TRUE;
|
2016-02-15 15:51:51 -08:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(_breaking_chars); i++)
|
|
|
|
if (chr == _breaking_chars[i])
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
2016-02-15 14:54:12 -08:00
|
|
|
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_code_widget_selection_select_word(Evas_Object *widget, unsigned int line, unsigned int col)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Elm_Code_Line *lineobj;
|
|
|
|
unsigned int colpos, length, pos;
|
|
|
|
const char *content;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2016-02-15 14:54:12 -08:00
|
|
|
lineobj = elm_code_file_line_get(pd->code->file, line);
|
|
|
|
content = elm_code_line_text_get(lineobj, &length);
|
|
|
|
|
|
|
|
_elm_code_widget_selection_limit(widget, pd, &line, &col);
|
|
|
|
colpos = elm_code_widget_line_text_position_for_column_get(widget, lineobj, col);
|
|
|
|
|
|
|
|
pos = colpos;
|
|
|
|
while (pos > 0)
|
|
|
|
{
|
|
|
|
if (_elm_code_widget_selection_char_breaks(content[pos - 1]))
|
|
|
|
break;
|
|
|
|
pos--;
|
|
|
|
}
|
|
|
|
elm_code_widget_selection_start(widget, line,
|
|
|
|
elm_code_widget_line_text_column_width_to_position(widget, lineobj, pos));
|
|
|
|
|
|
|
|
pos = colpos;
|
|
|
|
while (pos < length - 1)
|
|
|
|
{
|
|
|
|
if (_elm_code_widget_selection_char_breaks(content[pos + 1]))
|
|
|
|
break;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
elm_code_widget_selection_end(widget, line,
|
|
|
|
elm_code_widget_line_text_column_width_to_position(widget, lineobj, pos));
|
|
|
|
}
|
|
|
|
|
2015-03-25 14:55:00 -07:00
|
|
|
EAPI char *
|
2015-03-17 15:42:03 -07:00
|
|
|
elm_code_widget_selection_text_get(Evas_Object *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
2016-02-21 15:46:10 -08:00
|
|
|
Elm_Code_Widget_Selection_Data *selection;
|
|
|
|
char *text;
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
2015-03-17 15:42:03 -07:00
|
|
|
|
2015-09-16 04:32:25 -07:00
|
|
|
if (!pd->selection)
|
2015-03-25 14:55:00 -07:00
|
|
|
return strdup("");
|
|
|
|
|
2016-02-21 15:46:10 -08:00
|
|
|
selection = elm_code_widget_selection_normalized_get(widget);
|
|
|
|
|
|
|
|
text = elm_code_widget_text_between_positions_get(widget,
|
2016-12-27 14:17:01 -08:00
|
|
|
selection->start_line, selection->start_col,
|
|
|
|
selection->end_line, selection->end_col);
|
2016-02-21 15:46:10 -08:00
|
|
|
|
|
|
|
free(selection);
|
|
|
|
return text;
|
2015-03-17 15:42:03 -07:00
|
|
|
}
|
2015-03-28 10:57:47 -07:00
|
|
|
|
|
|
|
static void
|
2016-06-07 10:37:53 -07:00
|
|
|
_selection_loss_cb(void *data EINA_UNUSED, Elm_Sel_Type selection EINA_UNUSED)
|
2015-03-28 10:57:47 -07:00
|
|
|
{
|
2016-06-07 10:37:53 -07:00
|
|
|
/* Elm_Code_Widget *widget; */
|
2015-03-28 10:57:47 -07:00
|
|
|
|
2016-06-07 10:37:53 -07:00
|
|
|
/* widget = (Elm_Code_Widget *)data; */
|
2015-03-28 10:57:47 -07:00
|
|
|
// TODO we need to know whih selection we are clearing!
|
|
|
|
// elm_code_widget_selection_clear(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_code_widget_selection_cut(Evas_Object *widget)
|
|
|
|
{
|
|
|
|
char *text;
|
|
|
|
|
2017-02-01 01:08:14 -08:00
|
|
|
if (elm_code_widget_selection_is_empty(widget))
|
|
|
|
return;
|
|
|
|
|
2015-03-28 10:57:47 -07:00
|
|
|
text = elm_code_widget_selection_text_get(widget);
|
|
|
|
elm_cnp_selection_set(widget, ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT, text, strlen(text));
|
|
|
|
elm_cnp_selection_loss_callback_set(widget, ELM_SEL_TYPE_CLIPBOARD, _selection_loss_cb, widget);
|
|
|
|
free(text);
|
|
|
|
|
2017-02-01 01:08:14 -08:00
|
|
|
_elm_code_widget_change_selection_add(widget);
|
2015-03-28 10:57:47 -07:00
|
|
|
elm_code_widget_selection_delete(widget);
|
2016-12-17 05:03:31 -08:00
|
|
|
|
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL);
|
2015-03-28 10:57:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_code_widget_selection_copy(Evas_Object *widget)
|
|
|
|
{
|
|
|
|
char *text;
|
|
|
|
|
2017-02-01 01:08:14 -08:00
|
|
|
if (elm_code_widget_selection_is_empty(widget))
|
|
|
|
return;
|
|
|
|
|
2015-03-28 10:57:47 -07:00
|
|
|
text = elm_code_widget_selection_text_get(widget);
|
|
|
|
elm_cnp_selection_set(widget, ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT, text, strlen(text));
|
|
|
|
elm_cnp_selection_loss_callback_set(widget, ELM_SEL_TYPE_CLIPBOARD, _selection_loss_cb, widget);
|
|
|
|
free(text);
|
|
|
|
}
|
|
|
|
|
2015-04-19 07:00:10 -07:00
|
|
|
static void
|
2015-06-03 13:29:31 -07:00
|
|
|
_selection_paste_single(Elm_Code_Widget *widget, Elm_Code *code,
|
2015-04-19 07:00:10 -07:00
|
|
|
unsigned int col, unsigned int row, const char *text, unsigned int len)
|
|
|
|
{
|
|
|
|
Elm_Code_Line *line;
|
|
|
|
unsigned int position, newcol;
|
|
|
|
|
|
|
|
line = elm_code_file_line_get(code->file, row);
|
2015-06-03 13:29:31 -07:00
|
|
|
position = elm_code_widget_line_text_position_for_column_get(widget, line, col);
|
|
|
|
elm_code_line_text_insert(line, position, text, len);
|
2015-04-19 07:00:10 -07:00
|
|
|
|
2015-06-03 13:29:31 -07:00
|
|
|
newcol = elm_code_widget_line_text_column_width_to_position(widget, line, position + len);
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_set(widget, row, newcol);
|
2015-04-19 07:00:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-06-03 13:29:31 -07:00
|
|
|
_selection_paste_multi(Elm_Code_Widget *widget, Elm_Code *code,
|
2015-04-19 07:00:10 -07:00
|
|
|
unsigned int col, unsigned int row, const char *text, unsigned int len)
|
|
|
|
{
|
|
|
|
Elm_Code_Line *line;
|
2015-05-05 13:40:22 -07:00
|
|
|
unsigned int position, newrow, remain;
|
2015-04-19 07:00:10 -07:00
|
|
|
int nlpos;
|
2015-05-05 13:41:29 -07:00
|
|
|
short nllen;
|
2015-04-19 07:00:10 -07:00
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
line = elm_code_file_line_get(code->file, row);
|
2015-06-03 13:29:31 -07:00
|
|
|
position = elm_code_widget_line_text_position_for_column_get(widget, line, col);
|
2015-04-19 07:00:10 -07:00
|
|
|
elm_code_line_split_at(line, position);
|
|
|
|
|
|
|
|
newrow = row;
|
|
|
|
ptr = (char *)text;
|
2015-05-05 13:40:22 -07:00
|
|
|
remain = len;
|
2015-05-05 13:41:29 -07:00
|
|
|
while ((nlpos = elm_code_text_newlinenpos(ptr, remain, &nllen)) != ELM_CODE_TEXT_NOT_FOUND)
|
2015-04-19 07:00:10 -07:00
|
|
|
{
|
|
|
|
if (newrow == row)
|
2015-06-03 13:29:31 -07:00
|
|
|
_selection_paste_single(widget, code, col, row, text, nlpos);
|
2015-04-19 07:00:10 -07:00
|
|
|
else
|
|
|
|
elm_code_file_line_insert(code->file, newrow, ptr, nlpos, NULL);
|
|
|
|
|
2015-05-05 13:41:29 -07:00
|
|
|
remain -= nlpos + nllen;
|
|
|
|
ptr += nlpos + nllen;
|
2015-04-19 07:00:10 -07:00
|
|
|
newrow++;
|
|
|
|
}
|
|
|
|
|
2015-06-03 13:29:31 -07:00
|
|
|
_selection_paste_single(widget, code, 1, newrow, ptr, len - (ptr - text));
|
2015-04-19 07:00:10 -07:00
|
|
|
}
|
|
|
|
|
2015-03-28 10:57:47 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data *ev)
|
|
|
|
{
|
|
|
|
Elm_Code *code;
|
2017-02-01 01:08:14 -08:00
|
|
|
Elm_Code_Line *line;
|
2015-03-28 10:57:47 -07:00
|
|
|
Elm_Code_Widget *widget;
|
2017-02-01 01:08:14 -08:00
|
|
|
Elm_Code_Widget_Change_Info *change;
|
|
|
|
unsigned int row, col, end_row, end_col, position;
|
2015-03-28 10:57:47 -07:00
|
|
|
|
|
|
|
widget = (Elm_Code_Widget *)data;
|
2015-03-30 12:07:45 -07:00
|
|
|
|
2015-03-28 10:57:47 -07:00
|
|
|
if (ev->format != ELM_SEL_FORMAT_TEXT)
|
|
|
|
return EINA_TRUE;
|
|
|
|
if (ev->len <= 0)
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
2016-03-09 16:06:50 -08:00
|
|
|
code = elm_obj_code_widget_code_get(widget);
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_obj_code_widget_cursor_position_get(widget, &row, &col);
|
2015-03-28 10:57:47 -07:00
|
|
|
|
2015-05-05 13:41:29 -07:00
|
|
|
if (elm_code_text_newlinenpos(ev->data, ev->len, NULL) == ELM_CODE_TEXT_NOT_FOUND)
|
2015-06-03 13:29:31 -07:00
|
|
|
_selection_paste_single(widget, code, col, row, ev->data, ev->len - 1);
|
2015-04-19 07:00:10 -07:00
|
|
|
else
|
2015-06-03 13:29:31 -07:00
|
|
|
_selection_paste_multi(widget, code, col, row, ev->data, ev->len - 1);
|
2015-03-28 10:57:47 -07:00
|
|
|
|
2017-02-01 01:08:14 -08:00
|
|
|
elm_obj_code_widget_cursor_position_get(widget, &end_row, &end_col);
|
|
|
|
|
|
|
|
line = elm_code_file_line_get(code->file, end_row);
|
|
|
|
position = elm_code_widget_line_text_position_for_column_get(widget, line, end_col);
|
|
|
|
|
|
|
|
change = calloc(1, sizeof(Elm_Code_Widget_Change_Info));
|
|
|
|
change->insert = EINA_TRUE;
|
|
|
|
change->start_col = col;
|
|
|
|
change->start_line = row;
|
|
|
|
change->end_col = position;
|
|
|
|
change->end_line = end_row;
|
|
|
|
change->content = strndup(ev->data, ev->len);
|
|
|
|
change->length = ev->len;
|
|
|
|
|
|
|
|
_elm_code_widget_undo_change_add(widget, change);
|
|
|
|
free((char *)change->content);
|
|
|
|
free(change);
|
|
|
|
|
2016-12-17 05:03:31 -08:00
|
|
|
efl_event_callback_legacy_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL);
|
2015-03-28 10:57:47 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_code_widget_selection_paste(Evas_Object *widget)
|
|
|
|
{
|
2017-02-01 01:08:14 -08:00
|
|
|
_elm_code_widget_change_selection_add(widget);
|
2015-03-28 10:57:47 -07:00
|
|
|
elm_code_widget_selection_delete(widget);
|
|
|
|
|
|
|
|
elm_cnp_selection_get(widget, ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT, _selection_paste_cb, widget);
|
|
|
|
}
|
2017-01-31 11:04:33 -08:00
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_code_widget_selection_is_empty(Evas_Object *widget)
|
|
|
|
{
|
|
|
|
Elm_Code_Widget_Data *pd;
|
|
|
|
Elm_Code_Widget_Selection_Data *selection;
|
|
|
|
Eina_Bool ret = EINA_FALSE;
|
|
|
|
|
|
|
|
pd = efl_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
|
|
|
|
|
|
|
|
if (!pd->selection)
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
selection = elm_code_widget_selection_normalized_get(widget);
|
|
|
|
|
|
|
|
if (selection->start_col == selection->end_col &&
|
|
|
|
selection->start_line == selection->end_line)
|
|
|
|
ret = EINA_TRUE;
|
|
|
|
|
|
|
|
free(selection);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|