forked from enlightenment/enventor
updated
This commit is contained in:
parent
e453e08b7f
commit
d99d89ed1a
|
@ -127,7 +127,7 @@ Enventor_File_Format syntax_file_format_get(syntax_helper *sh);
|
|||
|
||||
|
||||
/* indent */
|
||||
indent_data *indent_init(Eina_Strbuf *strbuf);
|
||||
indent_data *indent_init(Eina_Strbuf *strbuf, Enventor_File_Format file_format);
|
||||
void indent_term(indent_data *id);
|
||||
int indent_space_get(indent_data *id, Evas_Object *entry);
|
||||
int indent_insert_apply(indent_data *id, Evas_Object *entry, const char *insert, int cur_line);
|
||||
|
|
298
src/lib/indent.c
298
src/lib/indent.c
|
@ -8,44 +8,14 @@
|
|||
struct indent_s
|
||||
{
|
||||
Eina_Strbuf *strbuf;
|
||||
Enventor_File_Format file_format;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Internal method implementation */
|
||||
/* Internal method implementation (EDC) */
|
||||
/*****************************************************************************/
|
||||
|
||||
static int
|
||||
indent_depth_get(indent_data *id EINA_UNUSED, char *src, int pos)
|
||||
{
|
||||
if (!src || (pos < 1)) return 0;
|
||||
|
||||
int depth = 0;
|
||||
const char *quot = "\"";
|
||||
int quot_len = 1; // strlen(""");
|
||||
char *cur = (char *) src;
|
||||
char *end = ((char *) src) + pos;
|
||||
|
||||
while (cur && (cur <= end))
|
||||
{
|
||||
//Skip "" range
|
||||
if (*cur == *quot)
|
||||
{
|
||||
cur += quot_len;
|
||||
cur = strstr(cur, quot);
|
||||
if (!cur) return depth;
|
||||
cur += quot_len;
|
||||
}
|
||||
|
||||
if (*cur == '{') depth++;
|
||||
else if (*cur == '}') depth--;
|
||||
cur++;
|
||||
}
|
||||
|
||||
return depth;
|
||||
}
|
||||
|
||||
static void
|
||||
indent_insert_br_case(indent_data *id, Evas_Object *entry)
|
||||
indent_edc_insert_br_case(indent_data *id, Evas_Object *entry)
|
||||
{
|
||||
Evas_Object *tb = elm_entry_textblock_get(entry);
|
||||
Evas_Textblock_Cursor *cur = evas_object_textblock_cursor_get(tb);
|
||||
|
@ -85,7 +55,7 @@ indent_insert_br_case(indent_data *id, Evas_Object *entry)
|
|||
}
|
||||
|
||||
static void
|
||||
indent_insert_bracket_case(indent_data *id, Evas_Object *entry, int cur_line)
|
||||
indent_edc_insert_bracket_case(indent_data *id, Evas_Object *entry, int cur_line)
|
||||
{
|
||||
Evas_Object *tb = elm_entry_textblock_get(entry);
|
||||
Evas_Textblock_Cursor *cur = evas_object_textblock_cursor_new(tb);
|
||||
|
@ -144,97 +114,9 @@ indent_insert_bracket_case(indent_data *id, Evas_Object *entry, int cur_line)
|
|||
free(utf8);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Externally accessible calls */
|
||||
/*****************************************************************************/
|
||||
|
||||
indent_data *
|
||||
indent_init(Eina_Strbuf *strbuf)
|
||||
{
|
||||
indent_data *id = malloc(sizeof(indent_data));
|
||||
if (!id)
|
||||
{
|
||||
EINA_LOG_ERR("Failed to allocate Memory!");
|
||||
return NULL;
|
||||
}
|
||||
id->strbuf = strbuf;
|
||||
return id;
|
||||
}
|
||||
|
||||
void
|
||||
indent_term(indent_data *id)
|
||||
{
|
||||
free(id);
|
||||
}
|
||||
|
||||
int
|
||||
indent_space_get(indent_data *id, Evas_Object *entry)
|
||||
{
|
||||
//Get the indentation depth
|
||||
int pos = elm_entry_cursor_pos_get(entry);
|
||||
char *src = elm_entry_markup_to_utf8(elm_entry_entry_get(entry));
|
||||
int space = indent_depth_get(id, src, pos);
|
||||
if (space < 0) space = 0;
|
||||
space *= TAB_SPACE;
|
||||
free(src);
|
||||
|
||||
return space;
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
indent_delete_apply(indent_data *id EINA_UNUSED, Evas_Object *entry,
|
||||
const char *del, int cur_line)
|
||||
{
|
||||
if (del[0] != ' ') return EINA_FALSE;
|
||||
|
||||
Evas_Object *tb = elm_entry_textblock_get(entry);
|
||||
Evas_Textblock_Cursor *cur = evas_object_textblock_cursor_new(tb);
|
||||
evas_textblock_cursor_line_set(cur, cur_line - 1);
|
||||
const char *text = evas_textblock_cursor_paragraph_text_get(cur);
|
||||
char *utf8 = elm_entry_markup_to_utf8(text);
|
||||
Eina_Strbuf* diff = eina_strbuf_new();
|
||||
int rd_cur_pos = evas_textblock_cursor_pos_get(cur);
|
||||
redoundo_data *rd = evas_object_data_get(entry, "redoundo");
|
||||
|
||||
int len = strlen(utf8);
|
||||
if (len < 0) return EINA_FALSE;
|
||||
|
||||
evas_textblock_cursor_paragraph_char_last(cur);
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
if ((utf8[(len - 1)] == ' '))
|
||||
{
|
||||
evas_textblock_cursor_char_prev(cur);
|
||||
eina_strbuf_append(diff, evas_textblock_cursor_content_get(cur));
|
||||
evas_textblock_cursor_char_delete(cur);
|
||||
}
|
||||
else break;
|
||||
len--;
|
||||
}
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
eina_strbuf_append(diff, evas_textblock_cursor_content_get(cur));
|
||||
evas_textblock_cursor_char_delete(cur);
|
||||
}
|
||||
redoundo_text_push(rd, eina_strbuf_string_get(diff), rd_cur_pos, 0,
|
||||
EINA_FALSE);
|
||||
elm_entry_calc_force(entry);
|
||||
evas_textblock_cursor_free(cur);
|
||||
free(utf8);
|
||||
eina_strbuf_free(diff);
|
||||
if (len == 0)
|
||||
{
|
||||
elm_entry_cursor_prev(entry);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
indent_text_auto_format(indent_data *id EINA_UNUSED,
|
||||
Evas_Object *entry, const char *insert)
|
||||
indent_edc_text_auto_format(indent_data *id EINA_UNUSED,
|
||||
Evas_Object *entry, const char *insert)
|
||||
{
|
||||
int line_cnt = 0;
|
||||
char *utf8 = evas_textblock_text_markup_to_utf8(NULL, insert);
|
||||
|
@ -342,28 +224,184 @@ indent_text_auto_format(indent_data *id EINA_UNUSED,
|
|||
eina_strbuf_free(buf);
|
||||
free(frmt_buf);
|
||||
evas_textblock_cursor_free(cur_start);
|
||||
|
||||
return line_cnt;
|
||||
}
|
||||
|
||||
int
|
||||
indent_insert_apply(indent_data *id, Evas_Object *entry, const char *insert,
|
||||
int cur_line)
|
||||
static int
|
||||
indent_edc_insert_apply(indent_data *id, Evas_Object *entry, const char *insert,
|
||||
int cur_line)
|
||||
{
|
||||
int len = strlen(insert);
|
||||
if (len == 1)
|
||||
{
|
||||
if (insert[0] == '}')
|
||||
indent_insert_bracket_case(id, entry, cur_line);
|
||||
indent_edc_insert_bracket_case(id, entry, cur_line);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!strcmp(insert, EOL))
|
||||
{
|
||||
indent_insert_br_case(id, entry);
|
||||
indent_edc_insert_br_case(id, entry);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return indent_text_auto_format(id, entry, insert);
|
||||
return indent_edc_text_auto_format(id, entry, insert);
|
||||
}
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
indent_edc_delete_apply(indent_data *id EINA_UNUSED, Evas_Object *entry,
|
||||
const char *del, int cur_line)
|
||||
{
|
||||
if (del[0] != ' ') return EINA_FALSE;
|
||||
|
||||
Evas_Object *tb = elm_entry_textblock_get(entry);
|
||||
Evas_Textblock_Cursor *cur = evas_object_textblock_cursor_new(tb);
|
||||
evas_textblock_cursor_line_set(cur, cur_line - 1);
|
||||
const char *text = evas_textblock_cursor_paragraph_text_get(cur);
|
||||
char *utf8 = elm_entry_markup_to_utf8(text);
|
||||
Eina_Strbuf* diff = eina_strbuf_new();
|
||||
int rd_cur_pos = evas_textblock_cursor_pos_get(cur);
|
||||
redoundo_data *rd = evas_object_data_get(entry, "redoundo");
|
||||
|
||||
int len = strlen(utf8);
|
||||
if (len < 0) return EINA_FALSE;
|
||||
|
||||
evas_textblock_cursor_paragraph_char_last(cur);
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
if ((utf8[(len - 1)] == ' '))
|
||||
{
|
||||
evas_textblock_cursor_char_prev(cur);
|
||||
eina_strbuf_append(diff, evas_textblock_cursor_content_get(cur));
|
||||
evas_textblock_cursor_char_delete(cur);
|
||||
}
|
||||
else break;
|
||||
len--;
|
||||
}
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
eina_strbuf_append(diff, evas_textblock_cursor_content_get(cur));
|
||||
evas_textblock_cursor_char_delete(cur);
|
||||
}
|
||||
redoundo_text_push(rd, eina_strbuf_string_get(diff), rd_cur_pos, 0,
|
||||
EINA_FALSE);
|
||||
elm_entry_calc_force(entry);
|
||||
evas_textblock_cursor_free(cur);
|
||||
free(utf8);
|
||||
eina_strbuf_free(diff);
|
||||
if (len == 0)
|
||||
{
|
||||
elm_entry_cursor_prev(entry);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
indent_edc_space_get(indent_data *id, Evas_Object *entry)
|
||||
{
|
||||
//Get the indentation depth
|
||||
int pos = elm_entry_cursor_pos_get(entry);
|
||||
if (pos == 0) return 0;
|
||||
|
||||
char *src = elm_entry_markup_to_utf8(elm_entry_entry_get(entry));
|
||||
if (!src) return 0;
|
||||
|
||||
int depth = 0;
|
||||
const char *quot = "\"";
|
||||
int quot_len = 1; // strlen(""");
|
||||
char *cur = (char *) src;
|
||||
char *end = ((char *) src) + pos;
|
||||
|
||||
while (cur && (cur <= end))
|
||||
{
|
||||
//Skip "" range
|
||||
if (*cur == *quot)
|
||||
{
|
||||
cur += quot_len;
|
||||
cur = strstr(cur, quot);
|
||||
if (!cur) return depth;
|
||||
cur += quot_len;
|
||||
}
|
||||
|
||||
if (*cur == '{') depth++;
|
||||
else if (*cur == '}') depth--;
|
||||
cur++;
|
||||
}
|
||||
|
||||
if (depth < 0) depth = 0;
|
||||
depth *= TAB_SPACE;
|
||||
free(src);
|
||||
|
||||
return depth;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Internal method implementation (XML) */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Externally accessible calls */
|
||||
/*****************************************************************************/
|
||||
|
||||
indent_data *
|
||||
indent_init(Eina_Strbuf *strbuf, Enventor_File_Format file_format)
|
||||
{
|
||||
indent_data *id = malloc(sizeof(indent_data));
|
||||
if (!id)
|
||||
{
|
||||
EINA_LOG_ERR("Failed to allocate Memory!");
|
||||
return NULL;
|
||||
}
|
||||
id->strbuf = strbuf;
|
||||
id->file_format = file_format;
|
||||
return id;
|
||||
}
|
||||
|
||||
void
|
||||
indent_term(indent_data *id)
|
||||
{
|
||||
free(id);
|
||||
}
|
||||
|
||||
int
|
||||
indent_space_get(indent_data *id, Evas_Object *entry)
|
||||
{
|
||||
switch (id->file_format)
|
||||
{
|
||||
default:
|
||||
return indent_edc_space_get(id, entry);
|
||||
}
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
indent_delete_apply(indent_data *id, Evas_Object *entry, const char *del,
|
||||
int cur_line)
|
||||
{
|
||||
switch (id->file_format)
|
||||
{
|
||||
default:
|
||||
return indent_edc_delete_apply(id, entry, del, cur_line);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
indent_insert_apply(indent_data *id, Evas_Object *entry, const char *insert,
|
||||
int cur_line)
|
||||
{
|
||||
switch (id->file_format)
|
||||
{
|
||||
default:
|
||||
return indent_edc_insert_apply(id, entry, insert, cur_line);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ syntax_init(Enventor_File_Format file_format)
|
|||
sh->file_format = file_format;
|
||||
|
||||
sh->cd = color_init(sh->strbuf, file_format);
|
||||
sh->id = indent_init(sh->strbuf);
|
||||
sh->id = indent_init(sh->strbuf, file_format);
|
||||
|
||||
return sh;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue