enventor - implementing template code inserting.

This commit is contained in:
ChunEon Park 2013-09-02 03:52:31 +09:00
parent 704a243d50
commit b6d324eba0
4 changed files with 119 additions and 15 deletions

View File

@ -259,11 +259,61 @@ 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)
{
//1. Find out Current paragraph
const char *paragh = parser_paragh_name_get(ed->pd, ed->en_edit);
if (!paragh) return;
if (!strcmp(paragh, "parts"))
{
edit_template_part_insert(ed, EDJE_PART_TYPE_IMAGE);
return;
}
int line_cnt;
char **t = NULL;
if (!strcmp(paragh, "part"))
{
line_cnt = TEMPLATE_DESC_LINE_CNT;
t = (char **) &TEMPLATE_DESC;
}
else if (!strcmp(paragh, "programs"))
{
line_cnt = TEMPLATE_PROG_LINE_CNT;
t = (char **) &TEMPLATE_PROG;
}
else if (!strcmp(paragh, "images"))
{
line_cnt = TEMPLATE_IMG_LINE_CNT;
t = (char **) &TEMPLATE_IMG;
}
if (!t) return;
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 i;
for (i = 0; i < line_cnt; i++)
{
elm_entry_entry_insert(ed->en_edit, p);
elm_entry_entry_insert(ed->en_edit, t[i]);
last_line_inc(ed);
}
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(SYNTAX_COLOR_TIME,
syntax_color_timer_cb, ed);
}
void

View File

@ -349,13 +349,33 @@ part_name_thread_cancel(void *data, Ecore_Thread *thread EINA_UNUSED)
free(td);
}
void
parser_current_paragh_name_get(parser_data *pd, Evas_Object *entry)
const char *
parser_paragh_name_get(parser_data *pd, Evas_Object *entry)
{
const char *PARTS = "parts";
const char *PART = "part";
const char *DESC = "description";
const char *PROGS = "programs";
//FIXME: list up groups
#define GROUP_CNT 13
typedef struct _group_info
{
char *str;
int len;
} group_info;
group_info group_list[GROUP_CNT] =
{
{ "collections", 11 },
{ "description", 11 },
{ "fill", 4 },
{ "group", 5 },
{ "images", 6 },
{ "map", 3 },
{ "origin", 6 },
{ "parts", 5 },
{ "part", 4 },
{ "programs", 8 },
{ "program", 7 },
{ "rel1", 4 },
{ "rel2", 4 }
};
Evas_Object *tb = elm_entry_textblock_get(entry);
char *text = (char *) evas_object_textblock_text_markup_get(tb);
@ -371,7 +391,10 @@ parser_current_paragh_name_get(parser_data *pd, Evas_Object *entry)
int quot_len = 1; // strlen("&quot;");
char *cur = utf8;
char *end = cur + cur_pos;
/*
char *stack[20];
int depth = 0;
//1. Figure out depth.
while (cur <= end)
{
//Skip "" range
@ -379,16 +402,39 @@ parser_current_paragh_name_get(parser_data *pd, Evas_Object *entry)
{
cur += quot_len;
cur = strstr(cur, quot);
if (!cur) return depth;
if (!cur) return NULL;
cur += quot_len;
}
if (*cur == '{') depth++;
else if (*cur == '}') depth--;
if (*cur == '{')
{
stack[depth] = cur;
depth++;
}
else if (*cur == '}')
{
if (depth > 0) depth--;
}
cur++;
}
*/
if (depth == 0) return NULL;
//2. Parse the paragraph Name
cur = stack[depth - 1];
int i;
while (cur > utf8)
{
cur--;
for (i = 0; i < GROUP_CNT; i++)
{
group_info *gi = &group_list[i];
if (!strncmp(cur, gi->str, gi->len))
return gi->str;
}
}
return NULL;
}
void

View File

@ -5,5 +5,6 @@ void parser_part_name_get(parser_data *pd, Evas_Object *entry, void (*cb)(void *
Eina_Bool parser_type_name_compare(parser_data *pd, const char *str);
const char *parser_markup_escape(parser_data *pd EINA_UNUSED, const char *str);
attr_value *parser_attribute_get(parser_data *pd, const char *text, const char *cur);
const char * parser_paragh_name_get(parser_data *pd, Evas_Object *entry);

View File

@ -142,7 +142,7 @@ const char *TEMPLATE_DESC[TEMPLATE_DESC_LINE_CNT] =
" visible: 1;<br/>",
" //image.normal: \"*.*\";<br/>",
" //aspect: 1 1;<br/>",
"}<br/>",
"}",
};
#define TEMPLATE_PROG_LINE_CNT 6
@ -156,3 +156,10 @@ const char *TEMPLATE_PROG[TEMPLATE_PROG_LINE_CNT] =
" target: \"template\";<br/>",
"}"
};
#define TEMPLATE_IMG_LINE_CNT 1
const char *TEMPLATE_IMG[TEMPLATE_IMG_LINE_CNT] =
{
"image: \"*.*\" COMP;"
};