elm_code: Cut, copy and paste working

Current limitations that paste is into a single line
This commit is contained in:
Andy Williams 2015-03-28 17:57:47 +00:00
parent eee6e3c411
commit 08daaed1f5
3 changed files with 93 additions and 0 deletions

View File

@ -942,6 +942,20 @@ _elm_code_widget_delete(Elm_Code_Widget *widget)
eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL));
}
static void
_elm_code_widget_control_key_down_cb(Elm_Code_Widget *widget, const char *key)
{
if (!key)
return;
if (!strcmp("c", key))
elm_code_widget_selection_copy(widget);
else if (!strcmp("v", key))
elm_code_widget_selection_paste(widget);
else if (!strcmp("x", key))
elm_code_widget_selection_cut(widget);
}
static void
_elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
Evas_Object *obj EINA_UNUSED, void *event_info)
@ -959,6 +973,12 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED,
_elm_code_widget_update_focus_directions((Elm_Code_Widget *)obj);
if (evas_key_modifier_is_set(ev->modifiers, "Control"))
{
_elm_code_widget_control_key_down_cb(widget, ev->key);
return;
}
if (!strcmp(ev->key, "Up"))
_elm_code_widget_cursor_move_up(widget);
else if (!strcmp(ev->key, "Down"))

View File

@ -250,3 +250,72 @@ elm_code_widget_selection_text_get(Evas_Object *widget)
else
return _elm_code_widget_selection_text_multi_get(pd);
}
static void
_selection_loss_cb(void *data, Elm_Sel_Type selection EINA_UNUSED)
{
Elm_Code_Widget *widget;
widget = (Elm_Code_Widget *)data;
// 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;
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);
elm_code_widget_selection_delete(widget);
}
EAPI void
elm_code_widget_selection_copy(Evas_Object *widget)
{
char *text;
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);
}
static Eina_Bool
_selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data *ev)
{
Elm_Code *code;
Elm_Code_Widget *widget;
Elm_Code_Line *line;
unsigned int row, col;
widget = (Elm_Code_Widget *)data;
if (ev->format != ELM_SEL_FORMAT_TEXT)
return EINA_TRUE;
if (ev->len <= 0)
return EINA_TRUE;
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_line_text_insert(line, col, ev->data, ev->len - 1);
eo_do(widget,
elm_code_widget_cursor_position_set(col + ev->len - 1, row));
return EINA_TRUE;
}
EAPI void
elm_code_widget_selection_paste(Evas_Object *widget)
{
elm_code_widget_selection_delete(widget);
elm_cnp_selection_get(widget, ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT, _selection_paste_cb, widget);
}

View File

@ -25,6 +25,10 @@ EAPI void elm_code_widget_selection_delete(Evas_Object *widget);
EAPI char *elm_code_widget_selection_text_get(Evas_Object *widget);
EAPI void elm_code_widget_selection_cut(Evas_Object *widget);
EAPI void elm_code_widget_selection_copy(Evas_Object *widget);
EAPI void elm_code_widget_selection_paste(Evas_Object *widget);
/**
* @}
*/