forked from enlightenment/enventor
enventor - refactoring code for future features comming.
introduce syntax_help and inline the syntax_color inside it. later, synax_helper share some resources (i.e string buffer) with syntax_color and indent
This commit is contained in:
parent
8591c6cda8
commit
aeed6f742d
|
@ -20,7 +20,8 @@ enventor_SOURCES = \
|
|||
panes.c \
|
||||
statusbar.c \
|
||||
syntax_color.c \
|
||||
ctxpopup.c
|
||||
ctxpopup.c \
|
||||
syntax_helper.c
|
||||
|
||||
# QuickLaunch
|
||||
enventorql_SOURCES = $(enventor_SOURCES)
|
||||
|
|
|
@ -12,7 +12,7 @@ struct editor_s
|
|||
Evas_Object *layout;
|
||||
Evas_Object *parent;
|
||||
|
||||
color_data *cd;
|
||||
syntax_helper *sh;
|
||||
stats_data *sd;
|
||||
option_data *od;
|
||||
parser_data *pd;
|
||||
|
@ -77,11 +77,13 @@ syntax_color_apply(edit_data *ed)
|
|||
|
||||
int pos = elm_entry_cursor_pos_get(ed->en_edit);
|
||||
|
||||
char *utf8 = (char *) color_cancel(ed->cd, text, strlen(text));
|
||||
char *utf8 = (char *) color_cancel(syntax_color_data_get(ed->sh), text,
|
||||
strlen(text));
|
||||
if (!utf8) return;
|
||||
|
||||
utf8 = strdup(utf8);
|
||||
const char *translated = color_apply(ed->cd, utf8, strlen(utf8), EINA_TRUE);
|
||||
const char *translated = color_apply(syntax_color_data_get(ed->sh), utf8,
|
||||
strlen(utf8), EINA_TRUE);
|
||||
|
||||
elm_entry_entry_set(ed->en_edit, NULL);
|
||||
elm_entry_entry_append(ed->en_edit, translated);
|
||||
|
@ -336,12 +338,12 @@ edit_data *
|
|||
edit_init(Evas_Object *parent, stats_data *sd, option_data *od)
|
||||
{
|
||||
parser_data *pd = parser_init();
|
||||
color_data *cd = color_init();
|
||||
syntax_helper *sh = syntax_init();
|
||||
|
||||
edit_data *ed = calloc(1, sizeof(edit_data));
|
||||
ed->sd = sd;
|
||||
ed->pd = pd;
|
||||
ed->cd = cd;
|
||||
ed->sh = sh;
|
||||
ed->od = od;
|
||||
|
||||
ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, key_down_cb, ed);
|
||||
|
@ -428,14 +430,14 @@ edit_term(edit_data *ed)
|
|||
{
|
||||
if (!ed) return;
|
||||
|
||||
color_data *cd = ed->cd;
|
||||
syntax_helper *sh = ed->sh;
|
||||
parser_data *pd = ed->pd;
|
||||
|
||||
if (ed->group_name) eina_stringshare_del(ed->group_name);
|
||||
if (ed->syntax_color_timer) ecore_timer_del(ed->syntax_color_timer);
|
||||
free(ed);
|
||||
|
||||
color_term(cd);
|
||||
syntax_term(sh);
|
||||
parser_term(pd);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,31 +17,13 @@ struct syntax_color_s
|
|||
Eina_Stringshare *col3;
|
||||
Eina_Stringshare *col4;
|
||||
Eina_Stringshare *col5;
|
||||
|
||||
Ecore_Timer *buf_flush_timer;
|
||||
|
||||
Eina_Bool enabled : 1;
|
||||
};
|
||||
|
||||
Eina_Bool
|
||||
buf_flush_timer_cb(void *data)
|
||||
{
|
||||
color_data *cd = data;
|
||||
/* At this moment, I have no idea the policy of the eina strbuf.
|
||||
If the string buffer wouldn't reduce the buffer size, it needs to prevent
|
||||
the buffer size not to be grown endlessly. */
|
||||
eina_strbuf_free(cd->strbuf);
|
||||
cd->strbuf = eina_strbuf_new();
|
||||
|
||||
return ECORE_CALLBACK_RENEW;
|
||||
}
|
||||
|
||||
color_data *
|
||||
color_init()
|
||||
color_init(Eina_Strbuf *strbuf)
|
||||
{
|
||||
color_data *cd = calloc(1, sizeof(color_data));
|
||||
cd->strbuf = eina_strbuf_new();
|
||||
cd->buf_flush_timer = ecore_timer_add(1800, buf_flush_timer_cb, cd);
|
||||
color_data *cd = malloc(sizeof(color_data));
|
||||
cd->strbuf = strbuf;
|
||||
cd->col1 = eina_stringshare_add("424242");
|
||||
cd->col2 = eina_stringshare_add("a000a0");
|
||||
cd->col3 = eina_stringshare_add("0000a0");
|
||||
|
@ -54,8 +36,6 @@ color_init()
|
|||
void
|
||||
color_term(color_data *cd)
|
||||
{
|
||||
if (cd->buf_flush_timer) ecore_timer_del(cd->buf_flush_timer);
|
||||
eina_strbuf_free(cd->strbuf);
|
||||
eina_stringshare_del(cd->col1);
|
||||
eina_stringshare_del(cd->col2);
|
||||
eina_stringshare_del(cd->col3);
|
||||
|
@ -260,7 +240,6 @@ const char *
|
|||
color_cancel(color_data *cd, const char *src, int length)
|
||||
{
|
||||
if (!src || length < 1) return NULL;
|
||||
|
||||
Eina_Strbuf *strbuf = cd->strbuf;
|
||||
eina_strbuf_reset(strbuf);
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
#include <Elementary.h>
|
||||
#include "common.h"
|
||||
|
||||
|
||||
struct syntax_helper_s
|
||||
{
|
||||
color_data *cd;
|
||||
Eina_Strbuf *strbuf;
|
||||
Ecore_Timer *buf_flush_timer;
|
||||
};
|
||||
|
||||
static Eina_Bool
|
||||
buf_flush_timer_cb(void *data)
|
||||
{
|
||||
syntax_helper *sh = data;
|
||||
/* At this moment, I have no idea the policy of the eina strbuf.
|
||||
If the string buffer wouldn't reduce the buffer size, it needs to prevent
|
||||
the buffer size not to be grown endlessly. */
|
||||
eina_strbuf_free(sh->strbuf);
|
||||
sh->strbuf = eina_strbuf_new();
|
||||
|
||||
return ECORE_CALLBACK_RENEW;
|
||||
}
|
||||
|
||||
syntax_helper *
|
||||
syntax_init()
|
||||
{
|
||||
syntax_helper *sh = malloc(sizeof(syntax_helper));
|
||||
sh->strbuf = eina_strbuf_new();
|
||||
sh->buf_flush_timer = ecore_timer_add(1800, buf_flush_timer_cb, sh);
|
||||
|
||||
sh->cd = color_init(sh->strbuf);
|
||||
|
||||
return sh;
|
||||
}
|
||||
|
||||
void
|
||||
syntax_term(syntax_helper *sh)
|
||||
{
|
||||
color_term(sh->cd);
|
||||
|
||||
if (sh->buf_flush_timer) ecore_timer_del(sh->buf_flush_timer);
|
||||
eina_strbuf_free(sh->strbuf);
|
||||
}
|
||||
|
||||
color_data *
|
||||
syntax_color_data_get(syntax_helper *sh)
|
||||
{
|
||||
return sh->cd;
|
||||
}
|
|
@ -34,11 +34,13 @@ typedef struct config_s option_data;
|
|||
typedef struct parser_s parser_data;
|
||||
typedef struct attr_value_s attr_value;
|
||||
typedef struct dummy_obj_s dummy_obj;
|
||||
typedef struct syntax_helper_s syntax_helper;
|
||||
|
||||
#include "edc_editor.h"
|
||||
#include "menu.h"
|
||||
#include "edj_viewer.h"
|
||||
#include "statusbar.h"
|
||||
#include "syntax_helper.h"
|
||||
#include "syntax_color.h"
|
||||
#include "config_data.h"
|
||||
#include "edc_parser.h"
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
syntax_helper *syntax_init();
|
||||
void syntax_term(syntax_helper *sh);
|
||||
color_data *syntax_color_data_get(syntax_helper *sh);
|
||||
|
Loading…
Reference in New Issue