forked from enlightenment/edi
parent
9f112d07ae
commit
2262d7bf1c
65 changed files with 13 additions and 7268 deletions
@ -1,4 +0,0 @@ |
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
SUBDIRS = src data
|
||||
|
@ -1,4 +0,0 @@ |
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
SUBDIRS = themes
|
||||
|
@ -1,4 +0,0 @@ |
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
SUBDIRS = default
|
||||
|
@ -1,20 +0,0 @@ |
||||
AUTOMAKE_OPTIONS = subdir-objects
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
EXTRA_DIST = \
|
||||
default.edc |
||||
|
||||
include ../../../../Makefile_Edje_Helper.am |
||||
|
||||
filesdir = $(datadir)/$(PACKAGE)/themes
|
||||
files_DATA = elm_code.edj
|
||||
|
||||
elm_code.edj: Makefile $(EXTRA_DIST) |
||||
$(AM_V_EDJ)$(EDJE_CC) $(EDJE_CC_FLAGS) \
|
||||
-id ${top_srcdir}/elm_code/data/themes/default/images \
|
||||
-sd ${top_srcdir}/elm_code/data/themes/default/sounds \
|
||||
$(top_srcdir)/elm_code/data/themes/default/default.edc \
|
||||
$(top_builddir)/elm_code/data/themes/default/elm_code.edj
|
||||
|
||||
clean-local: |
||||
rm -f *.edj
|
@ -1,19 +0,0 @@ |
||||
collections { |
||||
/* simple layout to pack our scrolling content into an elm_layout */ |
||||
group { name: "elm_code/layout/default"; |
||||
parts { |
||||
part { name: "elm.swallow.content"; type: SWALLOW; |
||||
description { state: "default" 0.0; |
||||
align: 0.5 0.0; |
||||
fixed: 0 1; |
||||
|
||||
rel2 { |
||||
relative: 1.0 1.0; |
||||
offset: 0 0; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,4 +0,0 @@ |
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
SUBDIRS = lib bin tests
|
||||
|
@ -1,20 +0,0 @@ |
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
bin_PROGRAMS = elm_code_test
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-DPACKAGE_BIN_DIR=\"$(bindir)\" \
|
||||
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
|
||||
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
|
||||
-I$(top_srcdir)/elm_code/src/lib/ \ |
||||
-I$(top_builddir)/elm_code/src/lib/ \ |
||||
-DLOCALEDIR=\"$(datadir)/locale\" \
|
||||
-DDATA_DIR=\"$(abspath $(srcdir))/../tests/\" \
|
||||
-DEFL_BETA_API_SUPPORT \ |
||||
@EFL_CFLAGS@ |
||||
|
||||
elm_code_test_SOURCES = \
|
||||
elm_code_test_main.c \ |
||||
elm_code_test_private.h |
||||
|
||||
elm_code_test_LDADD = @EFL_LIBS@ $(top_builddir)/elm_code/src/lib/libelm_code.la
|
@ -1,441 +0,0 @@ |
||||
#ifdef HAVE_CONFIG_H |
||||
# include "config.h" |
||||
#endif |
||||
|
||||
/* NOTE: Respecting header order is important for portability.
|
||||
* Always put system first, then EFL, then your public header, |
||||
* and finally your private one. */ |
||||
|
||||
#if ENABLE_NLS |
||||
# include <libintl.h> |
||||
#endif |
||||
|
||||
#include <Ecore_Getopt.h> |
||||
#include <Elementary.h> |
||||
|
||||
#include <Elm_Code.h> |
||||
|
||||
#include "elm_code_test_private.h" |
||||
|
||||
#define COPYRIGHT "Copyright ยฉ 2014 andy <andy@andywilliams.me> and various contributors (see AUTHORS)." |
||||
|
||||
static void |
||||
_elm_code_test_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) |
||||
{ |
||||
elm_exit(); |
||||
} |
||||
|
||||
static void _append_line(Elm_Code_File *file, const char *line) |
||||
{ |
||||
int length; |
||||
|
||||
length = strlen(line); |
||||
elm_code_file_line_append(file, line, length, NULL); |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_elm_code_test_line_clicked_cb(void *data EINA_UNUSED, const Eo_Event *event) |
||||
{ |
||||
Elm_Code_Line *line; |
||||
|
||||
line = (Elm_Code_Line *)event->info; |
||||
|
||||
printf("CLICKED line %d\n", line->number); |
||||
return EO_CALLBACK_CONTINUE; |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_elm_code_test_line_done_cb(void *data EINA_UNUSED, const Eo_Event *event) |
||||
{ |
||||
Elm_Code_Line *line; |
||||
|
||||
line = (Elm_Code_Line *)event->info; |
||||
|
||||
if (line->number == 1) |
||||
elm_code_line_token_add(line, 17, 24, 1, ELM_CODE_TOKEN_TYPE_COMMENT); |
||||
else if (line->number == 4) |
||||
line->status = ELM_CODE_STATUS_TYPE_ERROR; |
||||
|
||||
return EO_CALLBACK_STOP; |
||||
} |
||||
|
||||
static Evas_Object * |
||||
_elm_code_test_welcome_setup(Evas_Object *parent) |
||||
{ |
||||
Elm_Code *code; |
||||
Elm_Code_Widget *widget; |
||||
|
||||
code = elm_code_create(); |
||||
widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code)); |
||||
elm_obj_code_widget_font_set(widget, NULL, 12); |
||||
eo_event_callback_add(widget, &ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_test_line_done_cb, NULL); |
||||
eo_event_callback_add(widget, ELM_OBJ_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code); |
||||
|
||||
_append_line(code->file, "โค Hello World, Elm Code! โค"); |
||||
_append_line(code->file, ""); |
||||
_append_line(code->file, "This is a demo of elm_code's capabilities."); |
||||
_append_line(code->file, "โ *** Currently experimental ***"); |
||||
|
||||
evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL); |
||||
evas_object_show(widget); |
||||
|
||||
elm_code_widget_selection_start(widget, 1, 3); |
||||
elm_code_widget_selection_end(widget, 1, 13); |
||||
|
||||
return widget; |
||||
} |
||||
|
||||
static Evas_Object * |
||||
_elm_code_test_editor_setup(Evas_Object *parent, Eina_Bool log) |
||||
{ |
||||
Elm_Code *code; |
||||
Elm_Code_Line *line; |
||||
Elm_Code_Widget *widget; |
||||
|
||||
code = elm_code_create(); |
||||
widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code)); |
||||
elm_obj_code_widget_font_set(widget, NULL, 14); |
||||
elm_obj_code_widget_editable_set(widget, EINA_TRUE); |
||||
elm_obj_code_widget_show_whitespace_set(widget, EINA_TRUE); |
||||
elm_obj_code_widget_line_numbers_set(widget, EINA_TRUE); |
||||
|
||||
if (!log) |
||||
{ |
||||
_append_line(code->file, "Edit me :)"); |
||||
_append_line(code->file, ""); |
||||
_append_line(code->file, ""); |
||||
_append_line(code->file, "...Please?"); |
||||
|
||||
line = elm_code_file_line_get(code->file, 1); |
||||
elm_code_line_token_add(line, 5, 6, 1, ELM_CODE_TOKEN_TYPE_COMMENT); |
||||
elm_code_callback_fire(code, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); |
||||
} |
||||
|
||||
evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL); |
||||
evas_object_show(widget); |
||||
|
||||
return widget; |
||||
} |
||||
|
||||
static Evas_Object * |
||||
_elm_code_test_mirror_setup(Elm_Code *code, char *font_name, Evas_Object *parent) |
||||
{ |
||||
Elm_Code_Widget *widget; |
||||
|
||||
widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code)); |
||||
elm_obj_code_widget_font_set(widget, font_name, 11); |
||||
elm_obj_code_widget_line_numbers_set(widget, EINA_TRUE); |
||||
|
||||
evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL); |
||||
evas_object_show(widget); |
||||
|
||||
return widget; |
||||
} |
||||
|
||||
static Evas_Object * |
||||
_elm_code_test_diff_inline_setup(Evas_Object *parent) |
||||
{ |
||||
Evas_Object *diff; |
||||
Elm_Code *code; |
||||
|
||||
code = elm_code_create(); |
||||
diff = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code)); |
||||
|
||||
evas_object_size_hint_weight_set(diff, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
evas_object_size_hint_align_set(diff, EVAS_HINT_FILL, EVAS_HINT_FILL); |
||||
evas_object_show(diff); |
||||
|
||||
elm_code_parser_standard_add(code, ELM_CODE_PARSER_STANDARD_DIFF); |
||||
elm_code_file_open(code, DATA_DIR "testdiff.diff"); |
||||
|
||||
return diff; |
||||
} |
||||
|
||||
static Evas_Object * |
||||
_elm_code_test_diff_setup(Evas_Object *parent) |
||||
{ |
||||
Evas_Object *diff; |
||||
Elm_Code *code; |
||||
|
||||
code = elm_code_create(); |
||||
elm_code_file_open(code, DATA_DIR "testdiff.diff"); |
||||
|
||||
diff = elm_code_diff_widget_add(parent, code); |
||||
return diff; |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_elm_code_test_log_timer(void *data) |
||||
{ |
||||
Elm_Code *code = data; |
||||
static int line = 0; |
||||
char buf[250]; |
||||
|
||||
sprintf(buf, "line %d", ++line); |
||||
_append_line(code->file, buf); |
||||
|
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
static void |
||||
_elm_code_test_log_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) |
||||
{ |
||||
static Ecore_Timer *t = NULL; |
||||
|
||||
if (t) |
||||
{ |
||||
elm_object_text_set(obj, "Start"); |
||||
ecore_timer_del(t); |
||||
t = NULL; |
||||
return; |
||||
} |
||||
|
||||
t = ecore_timer_add(0.05, _elm_code_test_log_timer, data); |
||||
elm_object_text_set(obj, "Stop"); |
||||
} |
||||
|
||||
static void |
||||
_elm_code_test_welcome_editor_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) |
||||
{ |
||||
Evas_Object *naviframe, *screen; |
||||
|
||||
naviframe = (Evas_Object *)data; |
||||
screen = elm_box_add(naviframe); |
||||
evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
elm_box_pack_end(screen, _elm_code_test_editor_setup(screen, EINA_FALSE)); |
||||
evas_object_show(screen); |
||||
|
||||
elm_naviframe_item_push(naviframe, "Editor", |
||||
NULL, NULL, screen, NULL); |
||||
} |
||||
|
||||
static void |
||||
_elm_code_test_welcome_log_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) |
||||
{ |
||||
Evas_Object *naviframe, *screen, *o, *code; |
||||
|
||||
naviframe = (Evas_Object *)data; |
||||
screen = elm_box_add(naviframe); |
||||
evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
|
||||
code = _elm_code_test_editor_setup(screen, EINA_TRUE); |
||||
elm_box_pack_end(screen, code); |
||||
|
||||
o = elm_button_add(screen); |
||||
elm_object_text_set(o, "log"); |
||||
evas_object_smart_callback_add(o, "clicked", _elm_code_test_log_clicked, elm_obj_code_widget_code_get(code)); |
||||
elm_box_pack_end(screen, o); |
||||
evas_object_show(o); |
||||
|
||||
evas_object_show(screen); |
||||
|
||||
elm_naviframe_item_push(naviframe, "Editor", |
||||
NULL, NULL, screen, NULL); |
||||
} |
||||
|
||||
static void |
||||
_elm_code_test_welcome_mirror_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) |
||||
{ |
||||
Elm_Code *code; |
||||
Evas_Object *naviframe, *screen, *widget; |
||||
|
||||
naviframe = (Evas_Object *)data; |
||||
screen = elm_box_add(naviframe); |
||||
elm_box_homogeneous_set(screen, EINA_TRUE); |
||||
evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
|
||||
widget = _elm_code_test_editor_setup(screen, EINA_FALSE); |
||||
code = elm_obj_code_widget_code_get(widget); |
||||
elm_box_pack_end(screen, widget); |
||||
|
||||
elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, "Mono:style=Oblique", screen)); |
||||
elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, "Nimbus Mono", screen)); |
||||
|
||||
evas_object_show(screen); |
||||
elm_naviframe_item_push(naviframe, "Mirrored editor", |
||||
NULL, NULL, screen, NULL); |
||||
} |
||||
|
||||
static void |
||||
_elm_code_test_welcome_diff_inline_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) |
||||
{ |
||||
Evas_Object *naviframe, *screen; |
||||
|
||||
naviframe = (Evas_Object *)data; |
||||
screen = elm_box_add(naviframe); |
||||
evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
elm_box_pack_end(screen, _elm_code_test_diff_inline_setup(screen)); |
||||
evas_object_show(screen); |
||||
|
||||
elm_naviframe_item_push(naviframe, "Diff widget (inline)", |
||||
NULL, NULL, screen, NULL); |
||||
} |
||||
|
||||
static void |
||||
_elm_code_test_welcome_diff_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) |
||||
{ |
||||
Evas_Object *naviframe, *screen; |
||||
|
||||
naviframe = (Evas_Object *)data; |
||||
screen = elm_box_add(naviframe); |
||||
evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
elm_box_pack_end(screen, _elm_code_test_diff_setup(screen)); |
||||
evas_object_show(screen); |
||||
|
||||
elm_naviframe_item_push(naviframe, "Diff widget (comparison)", |
||||
NULL, NULL, screen, NULL); |
||||
} |
||||
|
||||
static Evas_Object * |
||||
elm_code_test_win_setup(void) |
||||
{ |
||||
Evas_Object *win, *vbox, *text, *button, *naviframe; |
||||
Elm_Object_Item *item; |
||||
|
||||
win = elm_win_util_standard_add("main", "Elm_Code Demo"); |
||||
if (!win) return NULL; |
||||
|
||||
naviframe = elm_naviframe_add(win); |
||||
evas_object_size_hint_weight_set(naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
elm_win_resize_object_add(win, naviframe); |
||||
evas_object_show(naviframe); |
||||
|
||||
vbox = elm_box_add(win); |
||||
evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, EVAS_HINT_FILL); |
||||
evas_object_show(vbox); |
||||
|
||||
text = _elm_code_test_welcome_setup(vbox); |
||||
evas_object_size_hint_weight_set(text, EVAS_HINT_EXPAND, 0.5); |
||||
elm_box_pack_end(vbox, text); |
||||
|
||||
button = elm_button_add(vbox); |
||||
elm_object_text_set(button, "Editor"); |
||||
evas_object_size_hint_weight_set(button, 0.5, 0.25); |
||||
evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 1.0); |
||||
evas_object_smart_callback_add(button, "clicked", |
||||
_elm_code_test_welcome_editor_cb, naviframe); |
||||
elm_box_pack_end(vbox, button); |
||||
evas_object_show(button); |
||||
|
||||
button = elm_button_add(vbox); |
||||
elm_object_text_set(button, "Log viewer"); |
||||
evas_object_size_hint_weight_set(button, 0.5, 0.0); |
||||
evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 1.0); |
||||
evas_object_smart_callback_add(button, "clicked", |
||||
_elm_code_test_welcome_log_cb, naviframe); |
||||
elm_box_pack_end(vbox, button); |
||||
evas_object_show(button); |
||||
|
||||
button = elm_button_add(vbox); |
||||
elm_object_text_set(button, "Mirrored editor"); |
||||
evas_object_size_hint_weight_set(button, 0.5, 0.0); |
||||
evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 0.5); |
||||
evas_object_smart_callback_add(button, "clicked", |
||||
_elm_code_test_welcome_mirror_cb, naviframe); |
||||
elm_box_pack_end(vbox, button); |
||||
evas_object_show(button); |
||||
|
||||
button = elm_button_add(vbox); |
||||
elm_object_text_set(button, "Diff (inline)"); |
||||
evas_object_size_hint_weight_set(button, 0.5, 0.0); |
||||
evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 0.5); |
||||
evas_object_smart_callback_add(button, "clicked", |
||||
_elm_code_test_welcome_diff_inline_cb, naviframe); |
||||
elm_box_pack_end(vbox, button); |
||||
evas_object_show(button); |
||||
|
||||
button = elm_button_add(vbox); |
||||
elm_object_text_set(button, "Diff (comparison)"); |
||||
evas_object_size_hint_weight_set(button, 0.5, 0.25); |
||||
evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 0.0); |
||||
evas_object_smart_callback_add(button, "clicked", |
||||
_elm_code_test_welcome_diff_cb, naviframe); |
||||
elm_box_pack_end(vbox, button); |
||||
evas_object_show(button); |
||||
|
||||
item = elm_naviframe_item_push(naviframe, "Choose Demo", |
||||
NULL, NULL,vbox, NULL); |
||||
elm_naviframe_item_title_enabled_set(item, EINA_FALSE, EINA_FALSE); |
||||
elm_win_resize_object_add(win, naviframe); |
||||
|
||||
evas_object_smart_callback_add(win, "delete,request", _elm_code_test_win_del, NULL); |
||||
evas_object_resize(win, 400 * elm_config_scale_get(), 320 * elm_config_scale_get()); |
||||
evas_object_show(win); |
||||
|
||||
return win; |
||||
} |
||||
|
||||
static const Ecore_Getopt optdesc = { |
||||
"elm_code_test", |
||||
"%prog [options]", |
||||
PACKAGE_VERSION, |
||||
COPYRIGHT, |
||||
"BSD with advertisement clause", |
||||
"An EFL elm_code_test program", |
||||
0, |
||||
{ |
||||
ECORE_GETOPT_LICENSE('L', "license"), |
||||
ECORE_GETOPT_COPYRIGHT('C', "copyright"), |
||||
ECORE_GETOPT_VERSION('V', "version"), |
||||
ECORE_GETOPT_HELP('h', "help"), |
||||
ECORE_GETOPT_SENTINEL |
||||
} |
||||
}; |
||||
|
||||
EAPI_MAIN int |
||||
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) |
||||
{ |
||||
Evas_Object *win; |
||||
int args; |
||||
Eina_Bool quit_option = EINA_FALSE; |
||||
|
||||
Ecore_Getopt_Value values[] = { |
||||
ECORE_GETOPT_VALUE_BOOL(quit_option), |
||||
ECORE_GETOPT_VALUE_BOOL(quit_option), |
||||
ECORE_GETOPT_VALUE_BOOL(quit_option), |
||||
ECORE_GETOPT_VALUE_BOOL(quit_option), |
||||
ECORE_GETOPT_VALUE_NONE |
||||
}; |
||||
|
||||
#if ENABLE_NLS |
||||
setlocale(LC_ALL, ""); |
||||
bindtextdomain(PACKAGE, LOCALEDIR); |
||||
bind_textdomain_codeset(PACKAGE, "UTF-8"); |
||||
textdomain(PACKAGE); |
||||
#endif |
||||
|
||||
elm_code_init(); |
||||
|
||||
args = ecore_getopt_parse(&optdesc, values, argc, argv); |
||||
if (args < 0) |
||||
{ |
||||
EINA_LOG_CRIT("Could not parse arguments."); |
||||
goto end; |
||||
} |
||||
else if (quit_option) |
||||
{ |
||||
goto end; |
||||
} |
||||
|
||||
/* tell elm about our app so it can figure out where to get files */ |
||||
elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR); |
||||
elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR); |
||||
elm_app_compile_data_dir_set(PACKAGE_DATA_DIR); |
||||
elm_app_info_set(elm_main, "elm_code_test", "images/elm_code.png"); |
||||
|
||||
if (!(win = elm_code_test_win_setup())) |
||||
goto end; |
||||
|
||||
elm_run(); |
||||
|
||||
end: |
||||
elm_code_shutdown(); |
||||
elm_shutdown(); |
||||
|
||||
return 0; |
||||
} |
||||
ELM_MAIN() |
@ -1,6 +0,0 @@ |
||||
#ifndef ELM_CODE_TEST_PRIVATE_H_ |
||||
# define ELM_CODE_TEST_PRIVATE_H_ |
||||
|
||||
// FIXME: put some private stuff related to your binary
|
||||
|
||||
#endif |
@ -1,143 +0,0 @@ |
||||
#ifndef ELM_CODE_H_ |
||||
# define ELM_CODE_H_ |
||||
|
||||
#include <Eina.h> |
||||
#include <Eo.h> |
||||
#include <Elementary.h> |
||||
#define ELM_INTERNAL_API_ARGESFSDFEFC |
||||
#include <elm_widget.h> |
||||
|
||||
#ifdef EAPI |
||||
# undef EAPI |
||||
#endif |
||||
|
||||
#ifdef _WIN32 |
||||
# ifdef EFL_ELM_CODE_BUILD |
||||
# ifdef DLL_EXPORT |
||||
# define EAPI __declspec(dllexport) |
||||
# else |
||||
# define EAPI |
||||
# endif /* ! DLL_EXPORT */ |
||||
# else |
||||
# define EAPI __declspec(dllimport) |
||||
# endif /* ! EFL_ELM_CODE_BUILD */ |
||||
#else |
||||
# ifdef __GNUC__ |
||||
# if __GNUC__ >= 4 |
||||
# define EAPI __attribute__ ((visibility("default"))) |
||||
# else |
||||
# define EAPI |
||||
# endif |
||||
# else |
||||
# define EAPI |
||||
# endif |
||||
#endif /* ! _WIN32 */ |
||||
|
||||
#include "elm_code_common.h" |
||||
#include "elm_code_line.h" |
||||
#include "elm_code_text.h" |
||||
#include "elm_code_file.h" |
||||
#include "elm_code_parse.h" |
||||
#include "widget/elm_code_widget.eo.h" |
||||
#include "widget/elm_code_widget_legacy.h" |
||||
#include "widget/elm_code_widget_selection.h" |
||||
#include "elm_code_diff_widget.h" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/**
|
||||
* @file |
||||
* @brief These routines are used for loading Elm Code widgets. |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief Init / shutdown functions. |
||||
* @defgroup Init Init / Shutdown |
||||
* |
||||
* @{ |
||||
* |
||||
* Functions of obligatory usage, handling proper initialization |
||||
* and shutdown routines. |
||||
* |
||||
* Before the usage of any other function, Elm Code should be properly |
||||
* initialized with @ref elm_code_init() and the last call to Elm Code's |
||||
* functions should be @ref elm_code_shutdown(), so everything will |
||||
* be correctly freed. |
||||
* |
||||
* Elm Code logs everything with Eina Log, using the "elm_code" log domain. |
||||
* |
||||
*/ |
||||
|
||||
/**
|
||||
* Initialize Elm Code. |
||||
* |
||||
* Initializes Elm Code, its dependencies and modules. Should be the first |
||||
* function of Elm Code to be called. |
||||
* |
||||
* @return The init counter value. |
||||
* |
||||
* @see elm_code_shutdown(). |
||||
* |
||||
* @ingroup Init |
||||
*/ |
||||
EAPI int elm_code_init(void); |
||||
|
||||
/**
|
||||
* Shutdown Elm Code |
||||
* |
||||
* Shutdown Elm Code. If init count reaches 0, all the internal structures will |
||||
* be freed. Any Elm Code library call after this point will leads to an error. |
||||
* |
||||
* @return Elm Code's init counter value. |
||||
* |
||||
* @see elm_code_init() |
||||
* |
||||
* @ingroup Init |
||||
*/ |
||||
EAPI int elm_code_shutdown(void); |
||||
|
||||
/**
|
||||
* Create a new Elm Code instance |
||||
* |
||||
* This method creates a new Elm Code instance using an in-memory file for backing changes. |
||||
* A regular file can be set after creation if required. |
||||
* Once an Elm Code has been created you can create widgets that render the content. |
||||
* |
||||
* @return an allocated Elm_Code that references the given file |
||||
* @see elm_code_file_open() |
||||
*/ |
||||
EAPI Elm_Code *elm_code_create(); |
||||
|
||||
/**
|
||||
* Free an Elm Code instance |
||||
* |
||||
* Releases the resources retained by the code instance and any files it references. |
||||
*/ |
||||
EAPI void elm_code_free(Elm_Code *code); |
||||
|
||||
/**
|
||||
* @} |
||||
* |
||||
* @brief Callbacks and message passing. |
||||
* @defgroup Callbacks Managing the information flow between Elm_Code objects and Evas_Object widgets |
||||
* |
||||
* @{ |
||||
* |
||||
* Managing the callbacks and other behaviours that cross the backend - frontend divide. |
||||
*/ |
||||
|
||||
|
||||
EAPI void elm_code_callback_fire(Elm_Code *code, const Eo_Event_Description *signal, void *data); |
||||
|
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* ELM_CODE_H_ */ |
@ -1,73 +0,0 @@ |
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
SUBDIRS = widget
|
||||
|
||||
CLEANFILES=
|
||||
|
||||
EOLIAN_FLAGS = @DEPS_EOLIAN_FLAGS@ \
|
||||
-I$(top_srcdir)/elm_code/src/lib
|
||||
|
||||
include $(top_srcdir)/Makefile_Eolian_Helper.am |
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir)/elm_code/src/lib \ |
||||
-I$(top_builddir)/elm_code/src/lib \ |
||||
-I$(top_srcdir)/elm_code/src/lib/widget \ |
||||
-I$(top_builddir)/elm_code/src/lib/widget \ |
||||
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
|
||||
-DEFL_BETA_API_SUPPORT \ |
||||
-DEFL_EO_API_SUPPORT \ |
||||
@EFL_CFLAGS@ \ |
||||
-DEFL_ELM_CODE_BUILD |
||||
|
||||
lib_LTLIBRARIES = libelm_code.la
|
||||
|
||||
includes_HEADERS = \
|
||||
elm_code_common.h \ |
||||
elm_code_line.h \ |
||||
elm_code_text.h \ |
||||
elm_code_file.h \ |
||||
elm_code_parse.h \ |
||||
widget/elm_code_widget.eo.h \ |
||||
widget/elm_code_widget.eo.legacy.h \ |
||||
widget/elm_code_widget_legacy.h \ |
||||
widget/elm_code_widget_selection.h \ |
||||
elm_code_diff_widget.h \ |
||||
Elm_Code.h |
||||
includesdir = $(includedir)/edi-@VMAJ@
|
||||
|
||||
libelm_code_la_SOURCES = \
|
||||
elm_code_line.c \ |
||||
elm_code_text.c \ |
||||
elm_code_file.c \ |
||||
elm_code_parse.c \ |
||||
widget/elm_code_widget_selection.c \ |
||||
widget/elm_code_widget.c \ |
||||
elm_code_diff_widget.c \ |
||||
elm_code.c \ |
||||
elm_code_private.h \ |
||||
widget/elm_code_widget_private.h |
||||
|
||||
libelm_code_la_LIBADD = @EFL_LIBS@ -lm
|
||||
libelm_code_la_LDFLAGS = -no-undefined @EFL_LTLIBRARY_FLAGS@
|
||||
|
||||
elm_code_eolian_files = \
|
||||
widget/elm_code_widget.eo |
||||
|
||||
elm_code_eolian_c = $(elm_code_eolian_files:%.eo=%.eo.c)
|
||||
elm_code_eolian_h = $(elm_code_eolian_files:%.eo=%.eo.h)
|
||||
elm_code_eolian_legacy_h = $(elm_code_eolian_files:%.eo=%.eo.legacy.h)
|
||||
|
||||
BUILT_SOURCES = \
|
||||
$(elm_code_eolian_c) \
|
||||
$(elm_code_eolian_h) \
|
||||
$(elm_code_eolian_legacy_h)
|
||||
|
||||
elmcodeeolianfilesdir = $(datadir)/eolian/include/elm_code-@VMAJ@
|
||||
elmcodeeolianfiles_DATA = $(elm_code_eolian_files)
|
||||
EXTRA_DIST = ${elmcodeeolianfiles_DATA} \
|
||||
widget/elm_code_widget_text.c \
|
||||
widget/elm_code_widget_undo.c
|
||||
|
||||
CLEANFILES += $(elm_code_eolian_h) $(elm_code_eolian_legacy_h)
|
||||
|
@ -1,115 +0,0 @@ |
||||
#ifdef HAVE_CONFIG |
||||
# include "config.h" |
||||
#endif |
||||
|
||||
#include <Eo.h> |
||||
#include <Evas.h> |
||||
|
||||
#include "Elm_Code.h" |
||||
|
||||
#include "elm_code_private.h" |
||||
|
||||
static int _elm_code_init = 0; |
||||
int _elm_code_lib_log_dom = -1; |
||||
|
||||
EAPI const Eo_Event_Description ELM_CODE_EVENT_LINE_LOAD_DONE = |
||||
EO_EVENT_DESCRIPTION("line,load,done"); |
||||
EAPI const Eo_Event_Description ELM_CODE_EVENT_FILE_LOAD_DONE = |
||||
EO_EVENT_DESCRIPTION("file,load,done"); |
||||
|
||||
|
||||
EAPI int |
||||
elm_code_init(void) |
||||
{ |
||||
_elm_code_init++; |
||||
if (_elm_code_init > 1) return _elm_code_init; |
||||
|
||||
eina_init(); |
||||
|
||||
_elm_code_lib_log_dom = eina_log_domain_register("elm_code", EINA_COLOR_CYAN); |
||||
if (_elm_code_lib_log_dom < 0) |
||||
{ |
||||
EINA_LOG_ERR("Elm Code can not create its log domain."); |
||||
goto shutdown_eina; |
||||
} |
||||
|
||||
_elm_code_parse_setup(); |
||||
|
||||
eina_log_timing(_elm_code_lib_log_dom, EINA_LOG_STATE_STOP, EINA_LOG_STATE_INIT); |
||||
|
||||
return _elm_code_init; |
||||
|
||||
shutdown_eina: |
||||
eina_shutdown(); |
||||
_elm_code_init--; |
||||
|
||||
return _elm_code_init; |
||||
} |
||||
|
||||
EAPI int |
||||
elm_code_shutdown(void) |
||||
{ |
||||
_elm_code_init--; |
||||
if (_elm_code_init != 0) return _elm_code_init; |
||||
|
||||
eina_log_timing(_elm_code_lib_log_dom, |
||||
EINA_LOG_STATE_START, |
||||
EINA_LOG_STATE_SHUTDOWN); |
||||
|
||||
// Put here your shutdown logic
|
||||
|
||||
eina_log_domain_unregister(_elm_code_lib_log_dom); |
||||
_elm_code_lib_log_dom = -1; |
||||
|
||||
eina_shutdown(); |
||||
|
||||
return _elm_code_init; |
||||
} |
||||
|
||||
EAPI Elm_Code * |
||||
elm_code_create() |
||||
{ |
||||
Elm_Code *ret; |
||||
|
||||
ret = calloc(1, sizeof(Elm_Code)); |
||||
|
||||
// create an in-memory backing for this elm_code by default
|
||||
elm_code_file_new(ret); |
||||
return ret; |
||||
} |
||||
|
||||
EAPI void |
||||
elm_code_free(Elm_Code *code) |
||||
{ |
||||
Evas_Object *widget; |
||||
Elm_Code_Parser *parser; |
||||
|
||||
if (code->file) |
||||
elm_code_file_free(code->file); |
||||
|
||||
EINA_LIST_FREE(code->widgets, widget) |
||||
{ |
||||
evas_object_hide(widget); |
||||
evas_object_del(widget); |
||||
} |
||||
|
||||
EINA_LIST_FREE(code->parsers, parser) |
||||
{ |
||||
_elm_code_parser_free(parser); |
||||
} |
||||
|
||||
free(code); |
||||
} |
||||
|
||||
EAPI void |
||||
elm_code_callback_fire(Elm_Code *code, const Eo_Event_Description *signal, void *data) |
||||
{ |
||||
Eina_List *item; |
||||
Eo *widget; |
||||
|
||||
EINA_LIST_FOREACH(code->widgets, item, widget) |
||||
{ |
||||
eo_event_callback_call(widget, signal, data); |
||||
} |
||||
} |
||||
|
@ -1,87 +0,0 @@ |
||||
#ifndef ELM_CODE_COMMON_H_ |
||||
# define ELM_CODE_COMMON_H_ |
||||
|
||||
typedef struct _Elm_Code Elm_Code; |
||||
typedef struct _Elm_Code_File Elm_Code_File; |
||||
|
||||
/** Event marking that a single line has loaded or changed */ |
||||
EAPI extern const Eo_Event_Description ELM_CODE_EVENT_LINE_LOAD_DONE; |
||||
/** Event that marks a file load has been completed */ |
||||
EAPI extern const Eo_Event_Description ELM_CODE_EVENT_FILE_LOAD_DONE; |
||||
|
||||
typedef enum { |
||||
ELM_CODE_STATUS_TYPE_DEFAULT = 0, |
||||
ELM_CODE_STATUS_TYPE_CURRENT, |
||||
ELM_CODE_STATUS_TYPE_IGNORED, |
||||
ELM_CODE_STATUS_TYPE_NOTE, |
||||
ELM_CODE_STATUS_TYPE_WARNING, |
||||
ELM_CODE_STATUS_TYPE_ERROR, |
||||
ELM_CODE_STATUS_TYPE_FATAL, |
||||
|
||||
ELM_CODE_STATUS_TYPE_ADDED, |
||||
ELM_CODE_STATUS_TYPE_REMOVED, |
||||
ELM_CODE_STATUS_TYPE_CHANGED, |
||||
|
||||
ELM_CODE_STATUS_TYPE_PASSED, |
||||
ELM_CODE_STATUS_TYPE_FAILED, |
||||
|
||||
ELM_CODE_STATUS_TYPE_TODO, |
||||
|
||||
ELM_CODE_STATUS_TYPE_COUNT |
||||
} Elm_Code_Status_Type; |
||||
|
||||
|
||||
typedef enum { |
||||
ELM_CODE_TOKEN_TYPE_DEFAULT = ELM_CODE_STATUS_TYPE_COUNT, |
||||
ELM_CODE_TOKEN_TYPE_COMMENT, |
||||
ELM_CODE_TOKEN_TYPE_STRING, |
||||
ELM_CODE_TOKEN_TYPE_NUMBER, |
||||
ELM_CODE_TOKEN_TYPE_BRACE, |
||||
ELM_CODE_TOKEN_TYPE_TYPE, |
||||
ELM_CODE_TOKEN_TYPE_CLASS, |
||||
ELM_CODE_TOKEN_TYPE_FUNCTION, |
||||
ELM_CODE_TOKEN_TYPE_PARAM, |
||||
ELM_CODE_TOKEN_TYPE_KEYWORD, |
||||
ELM_CODE_TOKEN_TYPE_PREPROCESSOR, |
||||
|
||||
ELM_CODE_TOKEN_TYPE_ADDED, |
||||
ELM_CODE_TOKEN_TYPE_REMOVED, |
||||
ELM_CODE_TOKEN_TYPE_CHANGED, |
||||
|
||||
ELM_CODE_TOKEN_TYPE_COUNT |
||||
} Elm_Code_Token_Type; |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
|
||||
/**
|
||||
* @file |
||||
* @brief Common data structures and constants. |
||||
*/ |
||||
|
||||
struct _Elm_Code_Config |
||||
{ |
||||
Eina_Bool trim_whitespace; |
||||
}; |
||||
|
||||
struct _Elm_Code |
||||
{ |
||||
Elm_Code_File *file; |
||||
Eina_List *widgets; |
||||
Eina_List *parsers; |
||||
|
||||
struct _Elm_Code_Config config; |
||||
}; |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* ELM_CODE_COMMON_H_ */ |
@ -1,131 +0,0 @@ |
||||
#ifdef HAVE_CONFIG |
||||
# include "config.h" |
||||
#endif |
||||
|
||||
#include "Elm_Code.h" |
||||
|
||||
#include "elm_code_private.h" |
||||
|
||||
#define _ELM_CODE_DIFF_WIDGET_LEFT "diffwidgetleft" |
||||
#define _ELM_CODE_DIFF_WIDGET_RIGHT "diffwidgetright" |
||||
|
||||
#define _ELM_CODE_DIFF_WIDGET_TYPE_ADDED "added" |
||||
#define _ELM_CODE_DIFF_WIDGET_TYPE_REMOVED "removed" |
||||
#define _ELM_CODE_DIFF_WIDGET_TYPE_CHANGED "changed" |
||||
|
||||
static void |
||||
_elm_code_diff_widget_parse_diff_line(Elm_Code_Line *line, Elm_Code_File *left, Elm_Code_File *right) |
||||
{ |
||||
const char *content; |
||||
unsigned int length; |
||||
|
||||
if (line->length < 1) |
||||
{ |
||||
elm_code_file_line_append(left, "", 0, NULL); |
||||
elm_code_file_line_append(right, "", 0, NULL); |
||||
} |
||||
|
||||
content = elm_code_line_text_get(line, &length); |
||||
if (content[0] == '+') |
||||
{ |
||||
elm_code_file_line_append(left, "", 0, NULL); |
||||
elm_code_file_line_append(right, content, length, NULL); |
||||
} |
||||
else if (content[0] == '-') |
||||
{ |
||||
elm_code_file_line_append(left, content, length, NULL); |
||||
elm_code_file_line_append(right, "", 0, NULL); |
||||
} |
||||
else |
||||
{ |
||||
elm_code_file_line_append(left, content, length, NULL); |
||||
elm_code_file_line_append(right, content, length, NULL); |
||||
} |
||||
} |
||||
|
||||
static void |
||||
_elm_code_diff_widget_parse_diff(Elm_Code_File *diff, Elm_Code_File *left, Elm_Code_File *right) |
||||
{ |
||||
Eina_List *item; |
||||
Elm_Code_Line *line; |
||||
const char *content; |
||||
unsigned int offset, length; |
||||
|
||||
offset = 0; |
||||
EINA_LIST_FOREACH(diff->lines, item, line) |
||||
{ |
||||
content = elm_code_line_text_get(line, &length); |
||||
|
||||
if (length > 0 && (content[0] == 'd' || content[0] == 'i' || content[0] == 'n')) |
||||
{ |
||||
offset = 0; |
||||
elm_code_file_line_append(left, content, length, NULL); |
||||
elm_code_file_line_append(right, content, length, NULL); |
||||
|
||||
continue; |
||||
} |
||||
|
||||
if (offset == 0) |
||||
elm_code_file_line_append(left, content, length, NULL); |
||||
else if (offset == 1) |
||||
elm_code_file_line_append(right, content, length, NULL); |
||||
else |
||||
_elm_code_diff_widget_parse_diff_line(line, left, right); |
||||
|
||||
offset++; |
||||
} |
||||
|
||||
_elm_code_parse_file(left->parent, left); |
||||
_elm_code_parse_file(right->parent, right); |
||||
} |
||||
|
||||
EAPI Evas_Object * |
||||
elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) |
||||
{ |
||||
Elm_Code *wcode1, *wcode2; |
||||
Elm_Code_Widget *widget_left, *widget_right; |
||||
Evas_Object *hbox; |
||||
|
||||
hbox = elm_panes_add(parent); |
||||
evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL); |
||||
elm_panes_horizontal_set(hbox, EINA_FALSE); |
||||
evas_object_show(hbox); |
||||
|
||||
// left side of diff
|
||||
wcode1 = elm_code_create(); |
||||
elm_code_parser_standard_add(wcode1, ELM_CODE_PARSER_STANDARD_DIFF); |
||||
widget_left = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, wcode1)); |
||||
|
||||
evas_object_size_hint_weight_set(widget_left, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
evas_object_size_hint_align_set(widget_left, EVAS_HINT_FILL, EVAS_HINT_FILL); |
||||
evas_object_show(widget_left); |
||||
evas_object_data_set(hbox, _ELM_CODE_DIFF_WIDGET_LEFT, widget_left); |
||||
elm_object_part_content_set(hbox, "left", widget_left); |
||||
|
||||
// right side of diff
|
||||
wcode2 = elm_code_create(); |
||||
elm_code_parser_standard_add(wcode2, ELM_CODE_PARSER_STANDARD_DIFF); |
||||
widget_right = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, wcode2)); |
||||
|
||||
evas_object_size_hint_weight_set(widget_right, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); |
||||
evas_object_size_hint_align_set(widget_right, EVAS_HINT_FILL, EVAS_HINT_FILL); |
||||
evas_object_show(widget_right); |
||||
evas_object_data_set(hbox, _ELM_CODE_DIFF_WIDGET_RIGHT, widget_right); |
||||
elm_object_part_content_set(hbox, "right", widget_right); |
||||
|
||||
_elm_code_diff_widget_parse_diff(code->file, wcode1->file, wcode2->file); |
||||
return hbox; |
||||
} |
||||
|
||||
EAPI void |
||||
elm_code_diff_widget_font_set(Evas_Object *widget, const char *name, int size) |
||||
{ |
||||
Elm_Code_Widget *child; |
||||
|
||||
child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_LEFT); |
||||
elm_obj_code_widget_font_set(child, name, size); |
||||
child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_RIGHT); |
||||
elm_obj_code_widget_font_set(child, name, size); |
||||
} |
||||
|
@ -1,37 +0,0 @@ |
||||
#ifndef ELM_CODE_DIFF_WIDGET_H_ |
||||
# define ELM_CODE_DIFF_WIDGET_H_ |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/**
|
||||
* @file |
||||
* @brief These routines are used for rendering diff instances of Elm Code. |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief UI Loading functions. |
||||
* @defgroup Init Creating a diff widget to render an Elm Code backend |
||||
* when it's referencing a diff file |
||||
* |
||||
* @{ |
||||
* |
||||
* Functions for Diff UI loading. |
||||
* |
||||
*/ |
||||
|
||||
EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code); |
||||
|
||||
EAPI void elm_code_diff_widget_font_set(Evas_Object *widget, const char *name, |
||||
int size); |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* ELM_CODE_DIFF_WIDGET_H_ */ |
@ -1,322 +0,0 @@ |
||||
#ifdef HAVE_CONFIG |
||||
# include "config.h" |
||||
#endif |
||||
|
||||
#include "Elm_Code.h" |
||||
|
||||
#include "elm_code_private.h" |
||||
|
||||
static Elm_Code_Line *_elm_code_file_line_blank_create(Elm_Code_File *file, int line, void *data) |
||||
{ |
||||
Elm_Code_Line *ecl; |
||||
|
||||
ecl = calloc(1, sizeof(Elm_Code_Line)); |
||||
if (!ecl) return NULL; |
||||
|
||||
ecl->file = file; |
||||
ecl->number = line; |
||||
ecl->status = ELM_CODE_STATUS_TYPE_DEFAULT; |
||||
ecl->data = data; |
||||
|
||||
return ecl; |
||||
} |
||||
|
||||
static Elm_Code_File_Line_Ending _elm_code_line_ending_get(const char *ending) |
||||
{ |
||||
switch (*ending) |
||||
{ |
||||
case '\r': |
||||
return ELM_CODE_FILE_LINE_ENDING_WINDOWS; |
||||
default: |
||||
return ELM_CODE_FILE_LINE_ENDING_UNIX; |
||||
} |
||||
} |
||||
|
||||
static void _elm_code_file_line_insert_data(Elm_Code_File *file, const char *content, unsigned int length, |
||||
unsigned int row, Eina_Bool mapped, void *data) |
||||
{ |
||||
Elm_Code_Line *line, *after; |
||||
|
||||
line = _elm_code_file_line_blank_create(file, row, data); |
||||
if (!line) return; |
||||
|
||||
if (mapped) |
||||
{ |
||||
line->content = content; |
||||
line->length = length; |
||||
} |
||||
else |
||||
{ |
||||
line->modified = malloc(sizeof(char)*(length+1)); |
||||
strncpy(line->modified, content, length); |
||||
line->modified[length] = 0; |
||||
line->length = length; |
||||
} |
||||
|
||||
if (row == 1) |
||||
file->lines = eina_list_prepend(file->lines, line); |
||||
else if (row == eina_list_count(file->lines) + 1) |
||||
file->lines = eina_list_append(file->lines, line); |
||||
else |
||||
{ |
||||
after = eina_list_nth(file->lines, row - 2); |
||||
file->lines = eina_list_append_relative(file->lines, line, after); |
||||
} |
||||
|
||||
if (file->parent) |
||||
{ |
||||
_elm_code_parse_line(file->parent, line); |
||||
elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); |
||||
} |
||||
} |
||||
|
||||
EAPI const char *elm_code_file_filename_get(Elm_Code_File *file) |
||||
{ |
||||
return basename((char *)eina_file_filename_get(file->file)); |
||||
} |
||||
|
||||
EAPI const char *elm_code_file_path_get(Elm_Code_File *file) |
||||
{ |
||||
return eina_file_filename_get(file->file); |
||||
} |
||||
|
||||
EAPI char *_elm_code_file_tmp_path_get(Elm_Code_File *file) |
||||
{ |
||||
const char *name, *path; |
||||
char *tmp; |
||||
size_t dirlen; |
||||
|
||||
path = elm_code_file_path_get(file); |
||||
name = elm_code_file_filename_get(file); |
||||
dirlen = strlen(path) - strlen(name); |
||||
|
||||
tmp = malloc(sizeof(char) * (strlen(path) + 6)); |
||||
snprintf(tmp, dirlen + 1, "%s", path); |
||||
snprintf(tmp + dirlen, strlen(name) + 6, ".%s.tmp", name); |
||||
|
||||
return tmp; |
||||
} |
||||
|
||||
EAPI Elm_Code_File *elm_code_file_new(Elm_Code *code) |
||||
{ |
||||
Elm_Code_File *ret; |
||||
|
||||
if (code->file) |
||||
elm_code_file_free(code->file); |
||||
|
||||
ret = calloc(1, sizeof(Elm_Code_File)); |
||||
code->file = ret; |
||||
ret->parent = code; |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) |
||||
{ |
||||
Elm_Code_File *ret; |
||||
Eina_File *file; |
||||
Eina_File_Line *line; |
||||
Eina_Iterator *it; |
||||
unsigned int lastindex; |
||||
|
||||
ret = elm_code_file_new(code); |
||||
file = eina_file_open(path, EINA_FALSE); |
||||
ret->file = file; |
||||
lastindex = 1; |
||||
|
||||
ret->map = eina_file_map_all(file, EINA_FILE_POPULATE); |
||||
it = eina_file_map_lines(file); |
||||
EINA_ITERATOR_FOREACH(it, line) |
||||
{ |
||||
Elm_Code_Line *ecl; |
||||
|
||||
if (lastindex == 1) |
||||
ret->line_ending = _elm_code_line_ending_get(line->start + line->length); |
||||
|
||||
/* Working around the issue that eina_file_map_lines does not trigger an item for empty lines */ |
||||
/* This was fixed in 1.13.99 so once we depend on 1.14 minimum this can go */ |
||||
while (lastindex < line->index - 1) |
||||
{ |
||||
ecl = _elm_code_file_line_blank_create(ret, ++lastindex, NULL); |
||||
if (!ecl) continue; |
||||
|
||||
ret->lines = eina_list_append(ret->lines, ecl); |
||||
} |
||||
|
||||
_elm_code_file_line_insert_data(ret, line->start, line->length, lastindex = line->index, EINA_TRUE, NULL); |
||||
} |
||||
eina_iterator_free(it); |
||||
|
||||
if (ret->parent) |
||||
{ |
||||
_elm_code_parse_file(ret->parent, ret); |
||||
elm_code_callback_fire(ret->parent, &ELM_CODE_EVENT_FILE_LOAD_DONE, ret); |
||||
} |
||||
return ret; |
||||
} |
||||
|
||||
EAPI void elm_code_file_save(Elm_Code_File *file) |
||||
{ |
||||
Eina_List *item; |
||||
Elm_Code *code; |
||||
Elm_Code_Line *line_item; |
||||
const char *path, *content, *crchars; |
||||
char *tmp; |
||||
unsigned int length; |
||||
short crlength; |
||||
FILE *out; |
||||
|
||||
code = file->parent; |