forked from enlightenment/enventor
enventor - implementing template code inserting feature.
This commit is contained in:
parent
45d88c2f5b
commit
2c51d81a3a
|
@ -22,8 +22,8 @@ enventor_SOURCES = \
|
|||
syntax_color.c \
|
||||
ctxpopup.c \
|
||||
syntax_helper.c \
|
||||
indent.c \
|
||||
template_code.c
|
||||
indent.c
|
||||
# template_code.c
|
||||
|
||||
# QuickLaunch
|
||||
enventorql_SOURCES = $(enventor_SOURCES)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <Elementary.h>
|
||||
#include "common.h"
|
||||
#include "template_code.h"
|
||||
|
||||
//FIXME: Make flexible
|
||||
const int MAX_LINE_DIGIT_CNT = 10;
|
||||
|
@ -32,6 +33,21 @@ struct editor_s
|
|||
Eina_Bool ctrl_pressed : 1;
|
||||
};
|
||||
|
||||
static int
|
||||
indent_space_get(edit_data *ed)
|
||||
{
|
||||
const int TAB_SPACE = 3;
|
||||
|
||||
//Get the indentation depth
|
||||
int pos = elm_entry_cursor_pos_get(ed->en_edit);
|
||||
char *src = elm_entry_markup_to_utf8(elm_entry_entry_get(ed->en_edit));
|
||||
int space = indent_depth_get(syntax_indent_data_get(ed->sh), src, pos);
|
||||
space *= TAB_SPACE;
|
||||
free(src);
|
||||
|
||||
return space;
|
||||
}
|
||||
|
||||
static void
|
||||
last_line_inc(edit_data *ed)
|
||||
{
|
||||
|
@ -117,14 +133,7 @@ syntax_color_animator_cb(void *data)
|
|||
static void
|
||||
indent_apply(edit_data *ed)
|
||||
{
|
||||
const int TAB_SPACE = 3;
|
||||
|
||||
//Get the indentation depth
|
||||
int pos = elm_entry_cursor_pos_get(ed->en_edit);
|
||||
char *src = elm_entry_markup_to_utf8(elm_entry_entry_get(ed->en_edit));
|
||||
int space = indent_depth_get(syntax_indent_data_get(ed->sh), src, pos);
|
||||
space *= TAB_SPACE;
|
||||
free(src);
|
||||
int space = indent_space_get(ed);
|
||||
|
||||
//Alloc Empty spaces
|
||||
char *p = alloca(space) + 1;
|
||||
|
@ -250,12 +259,37 @@ edit_attr_candidate_show(edit_data *ed, attr_value *attr, int x, int y, const ch
|
|||
elm_object_disabled_set(ed->layout, EINA_TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
edit_template_insert(edit_data *ed)
|
||||
{
|
||||
int cursor_pos = elm_entry_cursor_pos_get(ed->en_edit);
|
||||
elm_entry_cursor_line_begin_set(ed->en_edit);
|
||||
int space = indent_space_get(ed);
|
||||
|
||||
//Alloc Empty spaces
|
||||
char *p = alloca(space) + 1;
|
||||
memset(p, ' ', space);
|
||||
p[space] = '\0';
|
||||
|
||||
int line_cnt = TEMPLATE_PART_LINE_CNT;
|
||||
int i;
|
||||
for (i = 0; i < line_cnt; i++)
|
||||
{
|
||||
elm_entry_entry_insert(ed->en_edit, p);
|
||||
elm_entry_entry_insert(ed->en_edit, TEMPLATE_PART[i]);
|
||||
}
|
||||
|
||||
elm_entry_cursor_pos_set(ed->en_edit, cursor_pos);
|
||||
|
||||
if (ed->syntax_color_timer) ecore_timer_del(ed->syntax_color_timer);
|
||||
ed->syntax_color_timer = ecore_timer_add(0.25, syntax_color_timer_cb, ed);
|
||||
}
|
||||
|
||||
static void
|
||||
edit_mouse_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
|
||||
Evas_Object *obj, void *event_info EINA_UNUSED)
|
||||
{
|
||||
Evas_Event_Mouse_Down *ev = event_info;
|
||||
|
||||
if (ev->button == 1)
|
||||
{
|
||||
elm_entry_select_none(obj);
|
||||
|
|
|
@ -213,6 +213,12 @@ ctrl_func(app_data *ad, const char *keyname)
|
|||
//Select All
|
||||
if (!strcmp(keyname, "a") || !strcmp(keyname, "A"))
|
||||
return ECORE_CALLBACK_PASS_ON;
|
||||
//Select All
|
||||
if (!strcmp(keyname, "t") || !strcmp(keyname, "T"))
|
||||
{
|
||||
edit_template_insert(ad->ed);
|
||||
return ECORE_CALLBACK_DONE;
|
||||
}
|
||||
//Part Highlight
|
||||
if (!strcmp(keyname, "h") || !strcmp(keyname, "H"))
|
||||
{
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#ifndef __TEMPLATE_CODE_H__
|
||||
#define __TEMPLATE_CODE_H__
|
||||
|
||||
#define TEMPLATE_PART_LINE_CNT 11
|
||||
|
||||
const char *TEMPLATE_PART[TEMPLATE_PART_LINE_CNT] =
|
||||
|
@ -36,3 +39,5 @@ const char *TEMPLATE_PROG[TEMPLATE_PROG_LINE_CNT] =
|
|||
" target: \"template\";\n",
|
||||
"}\n"
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,4 +14,4 @@ void edit_new(edit_data* ed);
|
|||
void edit_part_changed_cb_set(edit_data *ed, void (*cb)(void *data, const char *part_name), void *data);
|
||||
void edit_cur_part_update(edit_data *ed);
|
||||
void edit_font_size_update(edit_data *ed, Eina_Bool msg);
|
||||
|
||||
void edit_template_insert(edit_data *ed);
|
||||
|
|
Loading…
Reference in New Issue