From 997b338270221b276483e3afa4c6bfb9c2f59fff Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 17 Oct 2014 21:36:03 +0100 Subject: [PATCH 001/254] Base addition of elm_code area within the edi codebase, including an empty test to verify it's working --- legacy/elm_code/Makefile.am | 4 + legacy/elm_code/lib/Elm_Code.h | 95 ++++++++++++++++ legacy/elm_code/lib/Makefile.am | 19 ++++ legacy/elm_code/lib/elm_code.c | 58 ++++++++++ legacy/elm_code/lib/elm_code_private.h | 27 +++++ legacy/elm_code/tests/Makefile.am | 21 ++++ legacy/elm_code/tests/elm_code_suite.c | 122 +++++++++++++++++++++ legacy/elm_code/tests/elm_code_suite.h | 10 ++ legacy/elm_code/tests/elm_code_test_load.c | 17 +++ 9 files changed, 373 insertions(+) create mode 100644 legacy/elm_code/Makefile.am create mode 100644 legacy/elm_code/lib/Elm_Code.h create mode 100644 legacy/elm_code/lib/Makefile.am create mode 100644 legacy/elm_code/lib/elm_code.c create mode 100644 legacy/elm_code/lib/elm_code_private.h create mode 100644 legacy/elm_code/tests/Makefile.am create mode 100644 legacy/elm_code/tests/elm_code_suite.c create mode 100644 legacy/elm_code/tests/elm_code_suite.h create mode 100644 legacy/elm_code/tests/elm_code_test_load.c diff --git a/legacy/elm_code/Makefile.am b/legacy/elm_code/Makefile.am new file mode 100644 index 0000000000..d01d7e3fde --- /dev/null +++ b/legacy/elm_code/Makefile.am @@ -0,0 +1,4 @@ +MAINTAINERCLEANFILES = Makefile.in + +SUBDIRS = lib tests + diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h new file mode 100644 index 0000000000..13f6369ab9 --- /dev/null +++ b/legacy/elm_code/lib/Elm_Code.h @@ -0,0 +1,95 @@ +#ifndef ELM_CODE_H_ +# define ELM_CODE_H_ + +#include + +#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 */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for interacting with files using Elm Code. + */ + +/** + * @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); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ELM_CODE_H_ */ diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am new file mode 100644 index 0000000000..468b75abf4 --- /dev/null +++ b/legacy/elm_code/lib/Makefile.am @@ -0,0 +1,19 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CPPFLAGS = \ +-I$(top_srcdir)/elm_code/lib \ +-I$(top_builddir)/elm_code/lib \ +-DPACKAGE_LIB_DIR=\"$(libdir)\" \ +-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ +@EFL_CFLAGS@ \ +-DEFL_EFL_BUILD + +lib_LTLIBRARIES = libelm_code.la + +includes_HEADERS = Elm_Code.h +includesdir = $(includedir)/edi-@VMAJ@ + +libelm_code_la_SOURCES = \ +elm_code.c +libelm_code_la_LIBADD = @EFL_LIBS@ -lm +libelm_code_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c new file mode 100644 index 0000000000..0532ce6eac --- /dev/null +++ b/legacy/elm_code/lib/elm_code.c @@ -0,0 +1,58 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include "Elm_Code.h" + +#include "elm_code_private.h" + +static int _elm_code_init = 0; +int _elm_code_lib_log_dom = -1; + +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; + } + + // Put here your initialization logic of your library + + 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; +} diff --git a/legacy/elm_code/lib/elm_code_private.h b/legacy/elm_code/lib/elm_code_private.h new file mode 100644 index 0000000000..d1ff3284d4 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_private.h @@ -0,0 +1,27 @@ +#ifndef ELM_CODE_PRIVATE_H +# define ELM_CODE_PRIVATE_H + +extern int _elm_code_lib_log_dom; + +#ifdef ERR +# undef ERR +#endif +#define ERR(...) EINA_LOG_DOM_ERR(_elm_code_lib_log_dom, __VA_ARGS__) +#ifdef INF +# undef INF +#endif +#define INF(...) EINA_LOG_DOM_INFO(_elm_code_lib_log_dom, __VA_ARGS__) +#ifdef WRN +# undef WRN +#endif +#define WRN(...) EINA_LOG_DOM_WARN(_elm_code_lib_log_dom, __VA_ARGS__) +#ifdef CRIT +# undef CRIT +#endif +#define CRIT(...) EINA_LOG_DOM_CRIT(_elm_code_lib_log_dom, __VA_ARGS__) +#ifdef DBG +# undef DBG +#endif +#define DBG(...) EINA_LOG_DOM_DBG(_elm_code_lib_log_dom, __VA_ARGS__) + +#endif diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/tests/Makefile.am new file mode 100644 index 0000000000..565279993d --- /dev/null +++ b/legacy/elm_code/tests/Makefile.am @@ -0,0 +1,21 @@ + +if EFL_HAVE_TESTS + +check_PROGRAMS = elm_code_suite + +elm_code_suite_SOURCES = \ +elm_code_test_load.c \ +elm_code_suite.c + +elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/lib/ \ +-DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/tests/\" \ +-DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/tests/\" \ +@EFL_CFLAGS@ \ +@CHECK_CFLAGS@ + +elm_code_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la +elm_code_suite_DEPENDENCIES = $(top_builddir)/elm_code/lib/libelm_code.la + +endif + +EXTRA_DIST = elm_code_suite.h diff --git a/legacy/elm_code/tests/elm_code_suite.c b/legacy/elm_code/tests/elm_code_suite.c new file mode 100644 index 0000000000..7b74ec2a73 --- /dev/null +++ b/legacy/elm_code/tests/elm_code_suite.c @@ -0,0 +1,122 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "Elm_Code.h" +#include "elm_code_suite.h" + +#define COPYRIGHT "Copyright © 2014 Andy Williams and various contributors (see AUTHORS)." + +static const struct { + const char *name; + void (*build)(TCase *tc); +} tests[] = { + { "load", elm_code_test_load }, +}; + +START_TEST(elm_code_initialization) +{ + fail_if(elm_code_init() != 1); + +// TODO add other init checks here + + fail_if(elm_code_shutdown() != 0); +} +END_TEST + +void +edi_test_basic(TCase *tc) +{ + tcase_add_test(tc, elm_code_initialization); +} + +static const Ecore_Getopt optdesc = { + "elm_code", + "%prog [options]", + PACKAGE_VERSION, + COPYRIGHT, + "BSD with advertisement clause", + "Elm Code", + 0, + { + ECORE_GETOPT_STORE_TRUE('l', "list", "list available tests"), + ECORE_GETOPT_STORE_STR('t', "test", "test to run"), + ECORE_GETOPT_LICENSE('L', "license"), + ECORE_GETOPT_COPYRIGHT('C', "copyright"), + ECORE_GETOPT_VERSION('V', "version"), + ECORE_GETOPT_HELP('h', "help"), + ECORE_GETOPT_SENTINEL + } +}; + +int +main(int argc EINA_UNUSED, char **argv EINA_UNUSED) +{ + Suite *s; + SRunner *sr; + TCase *tc = NULL; + char *test = NULL; + unsigned int i; + int failed_count = -1; + int args; + Eina_Bool quit_option = EINA_FALSE; + Eina_Bool list_option = EINA_FALSE; + + Ecore_Getopt_Value values[] = { + ECORE_GETOPT_VALUE_BOOL(list_option), + ECORE_GETOPT_VALUE_STR(test), + 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 + }; + + eina_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; + } + else if (list_option) + { + fprintf(stdout, "Available tests :\n"); + for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) + fprintf(stdout, "\t%s\n", tests[i].name); + goto end; + } + + s = suite_create("Elm_Code"); + + for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) + { + if (test && strcmp(tests[i].name, test)) + continue ; + + tc = tcase_create(tests[i].name); + tcase_set_timeout(tc, 0); + + tests[i].build(tc); + suite_add_tcase(s, tc); + } + + sr = srunner_create(s); + srunner_set_xml(sr, PACKAGE_BUILD_DIR "/check-results.xml"); + + srunner_run_all(sr, CK_ENV); + failed_count = srunner_ntests_failed(sr); + srunner_free(sr); + + end: + eina_shutdown(); + + return (failed_count == 0) ? 0 : 255; +} diff --git a/legacy/elm_code/tests/elm_code_suite.h b/legacy/elm_code/tests/elm_code_suite.h new file mode 100644 index 0000000000..2cdf523169 --- /dev/null +++ b/legacy/elm_code/tests/elm_code_suite.h @@ -0,0 +1,10 @@ +#ifndef _ELM_CODE_SUITE_H +#define _ELM_CODE_SUITE_H + +#include + +#include + +void elm_code_test_load(TCase *tc); + +#endif /* _EDLM_CODE_SUITE_H */ diff --git a/legacy/elm_code/tests/elm_code_test_load.c b/legacy/elm_code/tests/elm_code_test_load.c new file mode 100644 index 0000000000..807e06ec52 --- /dev/null +++ b/legacy/elm_code/tests/elm_code_test_load.c @@ -0,0 +1,17 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "elm_code_suite.h" + +START_TEST (elm_code_load) +{ + ck_assert(1); +} +END_TEST + +void elm_code_test_load(TCase *tc) +{ + tcase_add_test(tc, elm_code_load); +} + From 6846385d44e4ed3c024a6d198dc367ca9fcd7733 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 17 Oct 2014 23:36:07 +0100 Subject: [PATCH 002/254] A pretty slim test of file loading and initial path apis --- legacy/elm_code/lib/Elm_Code.h | 24 +++++++++++++++++++ legacy/elm_code/lib/elm_code.c | 28 ++++++++++++++++++++++ legacy/elm_code/tests/elm_code_test_load.c | 11 ++++++++- legacy/elm_code/tests/testfile.txt | 5 ++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 legacy/elm_code/tests/testfile.txt diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 13f6369ab9..f560bbc0e1 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -3,6 +3,8 @@ #include +#include + #ifdef EAPI # undef EAPI #endif @@ -38,6 +40,20 @@ extern "C" { * @brief These routines are used for interacting with files using Elm Code. */ +typedef struct _Elm_Code_Line +{ + const char *content; + const char *modified; + +} Elm_Code_Line; + +typedef struct _Elm_Code_File +{ + Elm_Code_Line *lines; + Eina_File *file; + +} Elm_Code_File; + /** * @brief Init / shutdown functions. * @defgroup Init Init / Shutdown @@ -84,6 +100,14 @@ EAPI int elm_code_init(void); */ EAPI int elm_code_shutdown(void); +EAPI Elm_Code_File *elm_code_open(const char *path); + +EAPI void elm_code_close(Elm_Code_File *file); + +EAPI const char *elm_code_filename_get(Elm_Code_File *file); + +EAPI const char *elm_code_path_get(Elm_Code_File *file); + /** * @} */ diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index 0532ce6eac..44b251a36c 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -56,3 +56,31 @@ elm_code_shutdown(void) return _elm_code_init; } + +EAPI Elm_Code_File *elm_code_open(const char *path) +{ + Elm_Code_File *ret; + Eina_File *file; + + file = eina_file_open(path, EINA_FALSE); + ret = calloc(1, sizeof(ret)); + ret->file = file; + + return ret; +} + +EAPI void elm_code_close(Elm_Code_File *file) +{ + eina_file_close(file->file); + free(file); +} + +EAPI const char *elm_code_filename_get(Elm_Code_File *file) +{ + return basename(eina_file_filename_get(file->file)); +} + +EAPI const char *elm_code_path_get(Elm_Code_File *file) +{ + return eina_file_filename_get(file->file); +} \ No newline at end of file diff --git a/legacy/elm_code/tests/elm_code_test_load.c b/legacy/elm_code/tests/elm_code_test_load.c index 807e06ec52..926b2aaa1d 100644 --- a/legacy/elm_code/tests/elm_code_test_load.c +++ b/legacy/elm_code/tests/elm_code_test_load.c @@ -6,7 +6,16 @@ START_TEST (elm_code_load) { - ck_assert(1); + char *path = "elm_code/tests/testfile.txt"; + char real[EINA_PATH_MAX]; + Elm_Code_File *file; + + file = elm_code_open(path); + realpath(path, real); + + ck_assert_str_eq(basename(path), elm_code_filename_get(file)); + ck_assert_str_eq(real, elm_code_path_get(file)); + elm_code_close(file); } END_TEST diff --git a/legacy/elm_code/tests/testfile.txt b/legacy/elm_code/tests/testfile.txt new file mode 100644 index 0000000000..246d68ea4a --- /dev/null +++ b/legacy/elm_code/tests/testfile.txt @@ -0,0 +1,5 @@ +line 1 +line2 + +another line +5 From 15bc74b80a77087357e9285b35c25cf36ecaba21 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 19 Oct 2014 22:29:44 +0100 Subject: [PATCH 003/254] Load lines sequentially and insert to a structure for reference --- legacy/elm_code/lib/Elm_Code.h | 9 ++++-- legacy/elm_code/lib/elm_code.c | 33 ++++++++++++++++++++-- legacy/elm_code/tests/elm_code_test_load.c | 13 +++++++++ legacy/elm_code/tests/testfile.txt | 3 +- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index f560bbc0e1..090a900c48 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -42,15 +42,16 @@ extern "C" { typedef struct _Elm_Code_Line { - const char *content; - const char *modified; + Eina_File_Line content; + Eina_File_Line modified; } Elm_Code_Line; typedef struct _Elm_Code_File { - Elm_Code_Line *lines; + Eina_List *lines; Eina_File *file; + void *map; } Elm_Code_File; @@ -108,6 +109,8 @@ EAPI const char *elm_code_filename_get(Elm_Code_File *file); EAPI const char *elm_code_path_get(Elm_Code_File *file); +EAPI int elm_code_lines_get(Elm_Code_File *file); + /** * @} */ diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index 44b251a36c..af2b6deae7 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -61,16 +61,40 @@ EAPI Elm_Code_File *elm_code_open(const char *path) { Elm_Code_File *ret; Eina_File *file; + Eina_File_Line *line; + Eina_Iterator *it; + void *map; file = eina_file_open(path, EINA_FALSE); - ret = calloc(1, sizeof(ret)); + map = eina_file_map_all(file, EINA_FILE_WILLNEED); + ret = calloc(1, sizeof(Elm_Code_File)); ret->file = file; + ret->map = map; + + it = eina_file_map_lines(file); + EINA_ITERATOR_FOREACH(it, line) + { + Elm_Code_Line *ecl; + + ecl = calloc(1, sizeof(Elm_Code_Line)); + if (!ecl) continue; + + ecl->content = *line; + ret->lines = eina_list_append(ret->lines, ecl); + } + eina_iterator_free(it); return ret; } EAPI void elm_code_close(Elm_Code_File *file) { + Elm_Code_Line *l; + + EINA_LIST_FREE(file->lines, l) + free(l); + + eina_file_map_free(file->file, file->map); eina_file_close(file->file); free(file); } @@ -83,4 +107,9 @@ EAPI const char *elm_code_filename_get(Elm_Code_File *file) EAPI const char *elm_code_path_get(Elm_Code_File *file) { return eina_file_filename_get(file->file); -} \ No newline at end of file +} + +EAPI int elm_code_lines_get(Elm_Code_File *file) +{ + return eina_list_count(file->lines); +} diff --git a/legacy/elm_code/tests/elm_code_test_load.c b/legacy/elm_code/tests/elm_code_test_load.c index 926b2aaa1d..13610db2b0 100644 --- a/legacy/elm_code/tests/elm_code_test_load.c +++ b/legacy/elm_code/tests/elm_code_test_load.c @@ -19,8 +19,21 @@ START_TEST (elm_code_load) } END_TEST +START_TEST (elm_code_load_lines) +{ + char *path = "elm_code/tests/testfile.txt"; + Elm_Code_File *file; + + file = elm_code_open(path); + + ck_assert(4 == elm_code_lines_get(file)); + elm_code_close(file); +} +END_TEST + void elm_code_test_load(TCase *tc) { tcase_add_test(tc, elm_code_load); + tcase_add_test(tc, elm_code_load_lines); } diff --git a/legacy/elm_code/tests/testfile.txt b/legacy/elm_code/tests/testfile.txt index 246d68ea4a..8fd6a8b140 100644 --- a/legacy/elm_code/tests/testfile.txt +++ b/legacy/elm_code/tests/testfile.txt @@ -1,5 +1,4 @@ line 1 line2 - +a third another line -5 From 36299958475d0d07120f7873aca4bcd9ffaf14cf Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 19 Oct 2014 22:33:49 +0100 Subject: [PATCH 004/254] Load the content and verify from our test files. Includes an eina_file_map_lines workaround for blank lines --- legacy/elm_code/lib/Elm_Code.h | 7 +-- legacy/elm_code/lib/elm_code.c | 49 ++++++++++++++++--- legacy/elm_code/tests/elm_code_test_load.c | 27 ++++++++++ legacy/elm_code/tests/testfile-withblanks.txt | 8 +++ 4 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 legacy/elm_code/tests/testfile-withblanks.txt diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 090a900c48..e03aa26c38 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -42,8 +42,8 @@ extern "C" { typedef struct _Elm_Code_Line { - Eina_File_Line content; - Eina_File_Line modified; + char *content; + unsigned int number; } Elm_Code_Line; @@ -51,7 +51,6 @@ typedef struct _Elm_Code_File { Eina_List *lines; Eina_File *file; - void *map; } Elm_Code_File; @@ -111,6 +110,8 @@ EAPI const char *elm_code_path_get(Elm_Code_File *file); EAPI int elm_code_lines_get(Elm_Code_File *file); +EAPI char *elm_code_line_content_get(Elm_Code_File *file, int line); + /** * @} */ diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index af2b6deae7..66cb04c381 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -57,29 +57,51 @@ elm_code_shutdown(void) return _elm_code_init; } +static Elm_Code_Line *_elm_code_blank_create(int line) +{ + Elm_Code_Line *ecl; + + ecl = calloc(1, sizeof(Elm_Code_Line)); + if (!ecl) return NULL; + + ecl->number = line; + return ecl; +} + EAPI Elm_Code_File *elm_code_open(const char *path) { Elm_Code_File *ret; Eina_File *file; Eina_File_Line *line; Eina_Iterator *it; - void *map; + unsigned int lastindex; file = eina_file_open(path, EINA_FALSE); - map = eina_file_map_all(file, EINA_FILE_WILLNEED); ret = calloc(1, sizeof(Elm_Code_File)); ret->file = file; - ret->map = map; + lastindex = 1; it = eina_file_map_lines(file); EINA_ITERATOR_FOREACH(it, line) { Elm_Code_Line *ecl; - ecl = calloc(1, sizeof(Elm_Code_Line)); + /* Working around the issue that eina_file_map_lines does not trigger an item for empty lines */ + while (lastindex < line->index - 1) + { + ecl = _elm_code_blank_create(++lastindex); + if (!ecl) continue; + + ret->lines = eina_list_append(ret->lines, ecl); + } + + ecl = _elm_code_blank_create(lastindex = line->index); if (!ecl) continue; - ecl->content = *line; + ecl->content = malloc(sizeof(char) * (line->length + 1)); + strncpy(ecl->content, line->start, line->length); + ecl->content[line->length] = 0; + ret->lines = eina_list_append(ret->lines, ecl); } eina_iterator_free(it); @@ -92,16 +114,19 @@ EAPI void elm_code_close(Elm_Code_File *file) Elm_Code_Line *l; EINA_LIST_FREE(file->lines, l) - free(l); + { + if (l->content) + free(l->content); + free(l); + } - eina_file_map_free(file->file, file->map); eina_file_close(file->file); free(file); } EAPI const char *elm_code_filename_get(Elm_Code_File *file) { - return basename(eina_file_filename_get(file->file)); + return basename((char *)eina_file_filename_get(file->file)); } EAPI const char *elm_code_path_get(Elm_Code_File *file) @@ -113,3 +138,11 @@ EAPI int elm_code_lines_get(Elm_Code_File *file) { return eina_list_count(file->lines); } + +EAPI char *elm_code_line_content_get(Elm_Code_File *file, int number) +{ + Elm_Code_Line *line; + + line = eina_list_nth(file->lines, number); + return line->content; +} diff --git a/legacy/elm_code/tests/elm_code_test_load.c b/legacy/elm_code/tests/elm_code_test_load.c index 13610db2b0..2431603380 100644 --- a/legacy/elm_code/tests/elm_code_test_load.c +++ b/legacy/elm_code/tests/elm_code_test_load.c @@ -31,9 +31,36 @@ START_TEST (elm_code_load_lines) } END_TEST +START_TEST (elm_code_load_blank_lines) +{ + char *path = "elm_code/tests/testfile-withblanks.txt"; + Elm_Code_File *file; + + file = elm_code_open(path); + + ck_assert(8 == elm_code_lines_get(file)); + elm_code_close(file); +} +END_TEST + +START_TEST (elm_code_load_content) +{ + char *path = "elm_code/tests/testfile.txt"; + Elm_Code_File *file; + + file = elm_code_open(path); + + ck_assert_str_eq("line2", elm_code_line_content_get(file, 2 - 1)); + ck_assert_str_eq("another line", elm_code_line_content_get(file, 4 - 1)); + elm_code_close(file); +} +END_TEST + void elm_code_test_load(TCase *tc) { tcase_add_test(tc, elm_code_load); tcase_add_test(tc, elm_code_load_lines); + tcase_add_test(tc, elm_code_load_blank_lines); + tcase_add_test(tc, elm_code_load_content); } diff --git a/legacy/elm_code/tests/testfile-withblanks.txt b/legacy/elm_code/tests/testfile-withblanks.txt new file mode 100644 index 0000000000..0f2ead3796 --- /dev/null +++ b/legacy/elm_code/tests/testfile-withblanks.txt @@ -0,0 +1,8 @@ +line 1 +line2 + +another link + + +double blank +8 From 4584abf84ca4b7ea2c53ec84d84253441534f5dd Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 21 Oct 2014 22:27:10 +0100 Subject: [PATCH 005/254] warning-- --- legacy/elm_code/lib/elm_code.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index 66cb04c381..4dd8f9513f 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -134,7 +134,7 @@ EAPI const char *elm_code_path_get(Elm_Code_File *file) return eina_file_filename_get(file->file); } -EAPI int elm_code_lines_get(Elm_Code_File *file) +EAPI unsigned int elm_code_lines_get(Elm_Code_File *file) { return eina_list_count(file->lines); } From 9fcb769ba39b16b384a88ec473bb255386406beb Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 21 Oct 2014 22:28:12 +0100 Subject: [PATCH 006/254] Update tests to use the proper api check --- legacy/elm_code/tests/elm_code_test_load.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/tests/elm_code_test_load.c b/legacy/elm_code/tests/elm_code_test_load.c index 2431603380..7dabf18242 100644 --- a/legacy/elm_code/tests/elm_code_test_load.c +++ b/legacy/elm_code/tests/elm_code_test_load.c @@ -26,7 +26,7 @@ START_TEST (elm_code_load_lines) file = elm_code_open(path); - ck_assert(4 == elm_code_lines_get(file)); + ck_assert_uint_eq(4, elm_code_lines_get(file)); elm_code_close(file); } END_TEST @@ -38,7 +38,7 @@ START_TEST (elm_code_load_blank_lines) file = elm_code_open(path); - ck_assert(8 == elm_code_lines_get(file)); + ck_assert_uint_eq(8, elm_code_lines_get(file)); elm_code_close(file); } END_TEST From ce501b64c2caf12f398b1b1f41eb8b18ba10062c Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 26 Oct 2014 22:08:52 +0000 Subject: [PATCH 007/254] Add some documentation grouping --- legacy/elm_code/lib/Elm_Code.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index e03aa26c38..571434c468 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -100,6 +100,18 @@ EAPI int elm_code_init(void); */ EAPI int elm_code_shutdown(void); +/** + * @} + * + * @brief File handling functions. + * @defgroup File I/O at a file level + * + * @{ + * + * Functions for file handling within elm code. + * + */ + EAPI Elm_Code_File *elm_code_open(const char *path); EAPI void elm_code_close(Elm_Code_File *file); @@ -108,7 +120,19 @@ EAPI const char *elm_code_filename_get(Elm_Code_File *file); EAPI const char *elm_code_path_get(Elm_Code_File *file); -EAPI int elm_code_lines_get(Elm_Code_File *file); +/** + * @} + * + * @brief Content functions. + * @defgroup Content Functions for accessing file content + * + * @{ + * + * File content handling functions. + * + */ + +EAPI unsigned int elm_code_lines_get(Elm_Code_File *file); EAPI char *elm_code_line_content_get(Elm_Code_File *file, int line); From a76709533999706b527259d8cb7bc962a730b104 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 26 Oct 2014 22:47:27 +0000 Subject: [PATCH 008/254] Add basic structure for elm_code object - namespacing the elm_code_file properly to keep it clean --- legacy/elm_code/lib/Elm_Code.h | 54 +++------- legacy/elm_code/lib/Makefile.am | 5 +- legacy/elm_code/lib/elm_code.c | 88 ++--------------- legacy/elm_code/lib/elm_code_file.c | 98 +++++++++++++++++++ legacy/elm_code/lib/elm_code_file.h | 71 ++++++++++++++ legacy/elm_code/tests/Makefile.am | 3 +- .../elm_code/tests/elm_code_file_test_load.c | 66 +++++++++++++ legacy/elm_code/tests/elm_code_suite.c | 3 +- legacy/elm_code/tests/elm_code_suite.h | 3 +- legacy/elm_code/tests/elm_code_test_basic.c | 25 +++++ legacy/elm_code/tests/elm_code_test_load.c | 66 ------------- 11 files changed, 294 insertions(+), 188 deletions(-) create mode 100644 legacy/elm_code/lib/elm_code_file.c create mode 100644 legacy/elm_code/lib/elm_code_file.h create mode 100644 legacy/elm_code/tests/elm_code_file_test_load.c create mode 100644 legacy/elm_code/tests/elm_code_test_basic.c delete mode 100644 legacy/elm_code/tests/elm_code_test_load.c diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 571434c468..d1053105c1 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -5,6 +5,8 @@ #include +#include + #ifdef EAPI # undef EAPI #endif @@ -37,22 +39,15 @@ extern "C" { /** * @file - * @brief These routines are used for interacting with files using Elm Code. + * @brief These routines are used for loading Elm Code widgets. */ -typedef struct _Elm_Code_Line +typedef struct _Elm_Code { - char *content; - unsigned int number; + Elm_Code_File *file; + Eina_List *widgets; -} Elm_Code_Line; - -typedef struct _Elm_Code_File -{ - Eina_List *lines; - Eina_File *file; - -} Elm_Code_File; +} Elm_Code; /** * @brief Init / shutdown functions. @@ -101,40 +96,21 @@ EAPI int elm_code_init(void); EAPI int elm_code_shutdown(void); /** - * @} + * Create a new Elm Code instance for an existing file * - * @brief File handling functions. - * @defgroup File I/O at a file level - * - * @{ - * - * Functions for file handling within elm code. + * This method creates a new Elm Code instance backing to the specified file. + * 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 */ - -EAPI Elm_Code_File *elm_code_open(const char *path); - -EAPI void elm_code_close(Elm_Code_File *file); - -EAPI const char *elm_code_filename_get(Elm_Code_File *file); - -EAPI const char *elm_code_path_get(Elm_Code_File *file); +EAPI Elm_Code *elm_code_create(Elm_Code_File *file); /** - * @} - * - * @brief Content functions. - * @defgroup Content Functions for accessing file content - * - * @{ - * - * File content handling functions. + * Free an Elm Code instance * + * Releases the resources retained by the code instance and any files it references. */ - -EAPI unsigned int elm_code_lines_get(Elm_Code_File *file); - -EAPI char *elm_code_line_content_get(Elm_Code_File *file, int line); +EAPI void elm_code_free(Elm_Code *code); /** * @} diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am index 468b75abf4..43b95b7cdb 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/lib/Makefile.am @@ -10,10 +10,13 @@ AM_CPPFLAGS = \ lib_LTLIBRARIES = libelm_code.la -includes_HEADERS = Elm_Code.h +includes_HEADERS = \ +elm_code_file.h \ +Elm_Code.h includesdir = $(includedir)/edi-@VMAJ@ libelm_code_la_SOURCES = \ +elm_code_file.c \ elm_code.c libelm_code_la_LIBADD = @EFL_LIBS@ -lm libelm_code_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index 4dd8f9513f..932168ecc7 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -57,92 +57,22 @@ elm_code_shutdown(void) return _elm_code_init; } -static Elm_Code_Line *_elm_code_blank_create(int line) +EAPI Elm_Code * +elm_code_create(Elm_Code_File *file) { - Elm_Code_Line *ecl; + Elm_Code *ret; - ecl = calloc(1, sizeof(Elm_Code_Line)); - if (!ecl) return NULL; - - ecl->number = line; - return ecl; -} - -EAPI Elm_Code_File *elm_code_open(const char *path) -{ - Elm_Code_File *ret; - Eina_File *file; - Eina_File_Line *line; - Eina_Iterator *it; - unsigned int lastindex; - - file = eina_file_open(path, EINA_FALSE); - ret = calloc(1, sizeof(Elm_Code_File)); + ret = calloc(1, sizeof(Elm_Code)); ret->file = file; - lastindex = 1; - - it = eina_file_map_lines(file); - EINA_ITERATOR_FOREACH(it, line) - { - Elm_Code_Line *ecl; - - /* Working around the issue that eina_file_map_lines does not trigger an item for empty lines */ - while (lastindex < line->index - 1) - { - ecl = _elm_code_blank_create(++lastindex); - if (!ecl) continue; - - ret->lines = eina_list_append(ret->lines, ecl); - } - - ecl = _elm_code_blank_create(lastindex = line->index); - if (!ecl) continue; - - ecl->content = malloc(sizeof(char) * (line->length + 1)); - strncpy(ecl->content, line->start, line->length); - ecl->content[line->length] = 0; - - ret->lines = eina_list_append(ret->lines, ecl); - } - eina_iterator_free(it); return ret; } -EAPI void elm_code_close(Elm_Code_File *file) +EAPI void +elm_code_free(Elm_Code *code) { - Elm_Code_Line *l; + if (code->file) + free(code->file); - EINA_LIST_FREE(file->lines, l) - { - if (l->content) - free(l->content); - free(l); - } - - eina_file_close(file->file); - free(file); -} - -EAPI const char *elm_code_filename_get(Elm_Code_File *file) -{ - return basename((char *)eina_file_filename_get(file->file)); -} - -EAPI const char *elm_code_path_get(Elm_Code_File *file) -{ - return eina_file_filename_get(file->file); -} - -EAPI unsigned int elm_code_lines_get(Elm_Code_File *file) -{ - return eina_list_count(file->lines); -} - -EAPI char *elm_code_line_content_get(Elm_Code_File *file, int number) -{ - Elm_Code_Line *line; - - line = eina_list_nth(file->lines, number); - return line->content; + free(code); } diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c new file mode 100644 index 0000000000..3ad76b9e21 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_file.c @@ -0,0 +1,98 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include "Elm_Code.h" +#include "elm_code_file.h" + +#include "elm_code_private.h" + +static Elm_Code_Line *_elm_code_blank_create(int line) +{ + Elm_Code_Line *ecl; + + ecl = calloc(1, sizeof(Elm_Code_Line)); + if (!ecl) return NULL; + + ecl->number = line; + return ecl; +} + +EAPI Elm_Code_File *elm_code_file_open(const char *path) +{ + Elm_Code_File *ret; + Eina_File *file; + Eina_File_Line *line; + Eina_Iterator *it; + unsigned int lastindex; + + file = eina_file_open(path, EINA_FALSE); + ret = calloc(1, sizeof(Elm_Code_File)); + ret->file = file; + lastindex = 1; + + it = eina_file_map_lines(file); + EINA_ITERATOR_FOREACH(it, line) + { + Elm_Code_Line *ecl; + + /* Working around the issue that eina_file_map_lines does not trigger an item for empty lines */ + while (lastindex < line->index - 1) + { + ecl = _elm_code_blank_create(++lastindex); + if (!ecl) continue; + + ret->lines = eina_list_append(ret->lines, ecl); + } + + ecl = _elm_code_blank_create(lastindex = line->index); + if (!ecl) continue; + + ecl->content = malloc(sizeof(char) * (line->length + 1)); + strncpy(ecl->content, line->start, line->length); + ecl->content[line->length] = 0; + + ret->lines = eina_list_append(ret->lines, ecl); + } + eina_iterator_free(it); + + return ret; +} + +EAPI void elm_code_file_close(Elm_Code_File *file) +{ + Elm_Code_Line *l; + + EINA_LIST_FREE(file->lines, l) + { + if (l->content) + free(l->content); + free(l); + } + + eina_file_close(file->file); + free(file); +} + +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 unsigned int elm_code_file_lines_get(Elm_Code_File *file) +{ + return eina_list_count(file->lines); +} + +EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, int number) +{ + Elm_Code_Line *line; + + line = eina_list_nth(file->lines, number); + return line->content; +} diff --git a/legacy/elm_code/lib/elm_code_file.h b/legacy/elm_code/lib/elm_code_file.h new file mode 100644 index 0000000000..7ad7ff8b13 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_file.h @@ -0,0 +1,71 @@ +#ifndef ELM_CODE_FILE_H_ +# define ELM_CODE_FILE_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for interacting with files using Elm Code. + */ + +typedef struct _Elm_Code_Line +{ + char *content; + unsigned int number; + +} Elm_Code_Line; + +typedef struct _Elm_Code_File +{ + Eina_List *lines; + Eina_File *file; + +} Elm_Code_File; + +/** + * @brief File handling functions. + * @defgroup File I/O at a file level + * + * @{ + * + * Functions for file handling within elm code. + * + */ + +EAPI Elm_Code_File *elm_code_file_open(const char *path); + +EAPI void elm_code_file_close(Elm_Code_File *file); + +EAPI const char *elm_code_file_filename_get(Elm_Code_File *file); + +EAPI const char *elm_code_file_path_get(Elm_Code_File *file); + +/** + * @} + * + * @brief Content functions. + * @defgroup Content Functions for accessing file content + * + * @{ + * + * File content handling functions. + * + */ + +EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file); + +EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, int line); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ELM_CODE_FILE_H_ */ diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/tests/Makefile.am index 565279993d..a874f1c0be 100644 --- a/legacy/elm_code/tests/Makefile.am +++ b/legacy/elm_code/tests/Makefile.am @@ -4,7 +4,8 @@ if EFL_HAVE_TESTS check_PROGRAMS = elm_code_suite elm_code_suite_SOURCES = \ -elm_code_test_load.c \ +elm_code_file_test_load.c \ +elm_code_test_basic.c \ elm_code_suite.c elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/lib/ \ diff --git a/legacy/elm_code/tests/elm_code_file_test_load.c b/legacy/elm_code/tests/elm_code_file_test_load.c new file mode 100644 index 0000000000..d7933ac6c6 --- /dev/null +++ b/legacy/elm_code/tests/elm_code_file_test_load.c @@ -0,0 +1,66 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "elm_code_suite.h" + +START_TEST (elm_code_file_load) +{ + char *path = "elm_code/tests/testfile.txt"; + char real[EINA_PATH_MAX]; + Elm_Code_File *file; + + file = elm_code_file_open(path); + realpath(path, real); + + ck_assert_str_eq(basename(path), elm_code_file_filename_get(file)); + ck_assert_str_eq(real, elm_code_file_path_get(file)); + elm_code_file_close(file); +} +END_TEST + +START_TEST (elm_code_file_load_lines) +{ + char *path = "elm_code/tests/testfile.txt"; + Elm_Code_File *file; + + file = elm_code_file_open(path); + + ck_assert_uint_eq(4, elm_code_file_lines_get(file)); + elm_code_file_close(file); +} +END_TEST + +START_TEST (elm_code_file_load_blank_lines) +{ + char *path = "elm_code/tests/testfile-withblanks.txt"; + Elm_Code_File *file; + + file = elm_code_file_open(path); + + ck_assert_uint_eq(8, elm_code_file_lines_get(file)); + elm_code_file_close(file); +} +END_TEST + +START_TEST (elm_code_file_load_content) +{ + char *path = "elm_code/tests/testfile.txt"; + Elm_Code_File *file; + + file = elm_code_file_open(path); + + ck_assert_str_eq("line2", elm_code_file_line_content_get(file, 2 - 1)); + ck_assert_str_eq("another line", elm_code_file_line_content_get(file, 4 - 1)); + elm_code_file_close(file); +} +END_TEST + +void elm_code_file_test_load(TCase *tc) +{ + tcase_add_test(tc, elm_code_file_load); + tcase_add_test(tc, elm_code_file_load_lines); + tcase_add_test(tc, elm_code_file_load_blank_lines); + tcase_add_test(tc, elm_code_file_load_content); +} + diff --git a/legacy/elm_code/tests/elm_code_suite.c b/legacy/elm_code/tests/elm_code_suite.c index 7b74ec2a73..9b869e8a73 100644 --- a/legacy/elm_code/tests/elm_code_suite.c +++ b/legacy/elm_code/tests/elm_code_suite.c @@ -13,7 +13,8 @@ static const struct { const char *name; void (*build)(TCase *tc); } tests[] = { - { "load", elm_code_test_load }, + { "file_load", elm_code_file_test_load }, + { "basic", elm_code_test_basic }, }; START_TEST(elm_code_initialization) diff --git a/legacy/elm_code/tests/elm_code_suite.h b/legacy/elm_code/tests/elm_code_suite.h index 2cdf523169..2ae75a194d 100644 --- a/legacy/elm_code/tests/elm_code_suite.h +++ b/legacy/elm_code/tests/elm_code_suite.h @@ -5,6 +5,7 @@ #include -void elm_code_test_load(TCase *tc); +void elm_code_file_test_load(TCase *tc); +void elm_code_test_basic(TCase *tc); #endif /* _EDLM_CODE_SUITE_H */ diff --git a/legacy/elm_code/tests/elm_code_test_basic.c b/legacy/elm_code/tests/elm_code_test_basic.c new file mode 100644 index 0000000000..f127cfb0a6 --- /dev/null +++ b/legacy/elm_code/tests/elm_code_test_basic.c @@ -0,0 +1,25 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "elm_code_suite.h" + +START_TEST (elm_code_create_test) +{ + char *path = "elm_code/tests/testfile.txt"; + Elm_Code_File *file; + Elm_Code *code; + + file = elm_code_file_open(path); + code = elm_code_create(file); + + ck_assert(code); + elm_code_free(code); +} +END_TEST + +void elm_code_test_basic(TCase *tc) +{ + tcase_add_test(tc, elm_code_create_test); +} + diff --git a/legacy/elm_code/tests/elm_code_test_load.c b/legacy/elm_code/tests/elm_code_test_load.c deleted file mode 100644 index 7dabf18242..0000000000 --- a/legacy/elm_code/tests/elm_code_test_load.c +++ /dev/null @@ -1,66 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "elm_code_suite.h" - -START_TEST (elm_code_load) -{ - char *path = "elm_code/tests/testfile.txt"; - char real[EINA_PATH_MAX]; - Elm_Code_File *file; - - file = elm_code_open(path); - realpath(path, real); - - ck_assert_str_eq(basename(path), elm_code_filename_get(file)); - ck_assert_str_eq(real, elm_code_path_get(file)); - elm_code_close(file); -} -END_TEST - -START_TEST (elm_code_load_lines) -{ - char *path = "elm_code/tests/testfile.txt"; - Elm_Code_File *file; - - file = elm_code_open(path); - - ck_assert_uint_eq(4, elm_code_lines_get(file)); - elm_code_close(file); -} -END_TEST - -START_TEST (elm_code_load_blank_lines) -{ - char *path = "elm_code/tests/testfile-withblanks.txt"; - Elm_Code_File *file; - - file = elm_code_open(path); - - ck_assert_uint_eq(8, elm_code_lines_get(file)); - elm_code_close(file); -} -END_TEST - -START_TEST (elm_code_load_content) -{ - char *path = "elm_code/tests/testfile.txt"; - Elm_Code_File *file; - - file = elm_code_open(path); - - ck_assert_str_eq("line2", elm_code_line_content_get(file, 2 - 1)); - ck_assert_str_eq("another line", elm_code_line_content_get(file, 4 - 1)); - elm_code_close(file); -} -END_TEST - -void elm_code_test_load(TCase *tc) -{ - tcase_add_test(tc, elm_code_load); - tcase_add_test(tc, elm_code_load_lines); - tcase_add_test(tc, elm_code_load_blank_lines); - tcase_add_test(tc, elm_code_load_content); -} - From 7ed960fc5230a5093c855eabb0f94d7c80279ae1 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 4 Nov 2014 21:05:29 +0000 Subject: [PATCH 009/254] Allow appending of lines to an Elm_Code_File, allow Elm_Code_File objects to be created empty without reading from a filesystem source --- legacy/elm_code/lib/elm_code_file.c | 53 +++++++++++++++---- legacy/elm_code/lib/elm_code_file.h | 6 +++ legacy/elm_code/tests/Makefile.am | 1 + .../tests/elm_code_file_test_memory.c | 25 +++++++++ legacy/elm_code/tests/elm_code_suite.c | 1 + legacy/elm_code/tests/elm_code_suite.h | 1 + 6 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 legacy/elm_code/tests/elm_code_file_test_memory.c diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c index 3ad76b9e21..0a0854c611 100644 --- a/legacy/elm_code/lib/elm_code_file.c +++ b/legacy/elm_code/lib/elm_code_file.c @@ -18,6 +18,29 @@ static Elm_Code_Line *_elm_code_blank_create(int line) return ecl; } +static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *content, int length, int row) +{ + Elm_Code_Line *line; + + line = _elm_code_blank_create(row); + if (!line) return; + + line->content = malloc(sizeof(char) * (length + 1)); + strncpy(line->content, content, length); + line->content[length] = 0; + + file->lines = eina_list_append(file->lines, line); +} + +EAPI Elm_Code_File *elm_code_file_new() +{ + Elm_Code_File *ret; + + ret = calloc(1, sizeof(Elm_Code_File)); + + return ret; +} + EAPI Elm_Code_File *elm_code_file_open(const char *path) { Elm_Code_File *ret; @@ -26,8 +49,8 @@ EAPI Elm_Code_File *elm_code_file_open(const char *path) Eina_Iterator *it; unsigned int lastindex; + ret = elm_code_file_new(); file = eina_file_open(path, EINA_FALSE); - ret = calloc(1, sizeof(Elm_Code_File)); ret->file = file; lastindex = 1; @@ -45,21 +68,14 @@ EAPI Elm_Code_File *elm_code_file_open(const char *path) ret->lines = eina_list_append(ret->lines, ecl); } - ecl = _elm_code_blank_create(lastindex = line->index); - if (!ecl) continue; - - ecl->content = malloc(sizeof(char) * (line->length + 1)); - strncpy(ecl->content, line->start, line->length); - ecl->content[line->length] = 0; - - ret->lines = eina_list_append(ret->lines, ecl); + _elm_code_file_line_append_data(ret, line->start, line->length, lastindex = line->index); } eina_iterator_free(it); return ret; } -EAPI void elm_code_file_close(Elm_Code_File *file) +EAPI void elm_code_file_free(Elm_Code_File *file) { Elm_Code_Line *l; @@ -70,10 +86,16 @@ EAPI void elm_code_file_close(Elm_Code_File *file) free(l); } - eina_file_close(file->file); free(file); } +EAPI void elm_code_file_close(Elm_Code_File *file) +{ + eina_file_close(file->file); + + elm_code_file_free(file); +} + EAPI const char *elm_code_file_filename_get(Elm_Code_File *file) { return basename((char *)eina_file_filename_get(file->file)); @@ -89,6 +111,15 @@ EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file) return eina_list_count(file->lines); } + +EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line) +{ + int row; + + row = elm_code_file_lines_get(file); + _elm_code_file_line_append_data(file, line, strlen(line), row+1); +} + EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, int number) { Elm_Code_Line *line; diff --git a/legacy/elm_code/lib/elm_code_file.h b/legacy/elm_code/lib/elm_code_file.h index 7ad7ff8b13..4f7d095613 100644 --- a/legacy/elm_code/lib/elm_code_file.h +++ b/legacy/elm_code/lib/elm_code_file.h @@ -36,8 +36,12 @@ typedef struct _Elm_Code_File * */ +EAPI Elm_Code_File *elm_code_file_new(); + EAPI Elm_Code_File *elm_code_file_open(const char *path); +EAPI void elm_code_file_free(Elm_Code_File *file); + EAPI void elm_code_file_close(Elm_Code_File *file); EAPI const char *elm_code_file_filename_get(Elm_Code_File *file); @@ -58,6 +62,8 @@ EAPI const char *elm_code_file_path_get(Elm_Code_File *file); EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file); +EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line); + EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, int line); /** diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/tests/Makefile.am index a874f1c0be..4a5759f615 100644 --- a/legacy/elm_code/tests/Makefile.am +++ b/legacy/elm_code/tests/Makefile.am @@ -5,6 +5,7 @@ check_PROGRAMS = elm_code_suite elm_code_suite_SOURCES = \ elm_code_file_test_load.c \ +elm_code_file_test_memory.c \ elm_code_test_basic.c \ elm_code_suite.c diff --git a/legacy/elm_code/tests/elm_code_file_test_memory.c b/legacy/elm_code/tests/elm_code_file_test_memory.c new file mode 100644 index 0000000000..aa31649d6e --- /dev/null +++ b/legacy/elm_code/tests/elm_code_file_test_memory.c @@ -0,0 +1,25 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "elm_code_suite.h" + +START_TEST (elm_code_file_memory_lines) +{ + Elm_Code_File *file; + + file = elm_code_file_new(); + ck_assert_uint_eq(0, elm_code_file_lines_get(file)); + + elm_code_file_line_append(file, "a line"); + + ck_assert_uint_eq(1, elm_code_file_lines_get(file)); + elm_code_file_free(file); +} +END_TEST + +void elm_code_file_test_memory(TCase *tc) +{ + tcase_add_test(tc, elm_code_file_memory_lines); +} + diff --git a/legacy/elm_code/tests/elm_code_suite.c b/legacy/elm_code/tests/elm_code_suite.c index 9b869e8a73..1f525210ae 100644 --- a/legacy/elm_code/tests/elm_code_suite.c +++ b/legacy/elm_code/tests/elm_code_suite.c @@ -14,6 +14,7 @@ static const struct { void (*build)(TCase *tc); } tests[] = { { "file_load", elm_code_file_test_load }, + { "file_memory", elm_code_file_test_memory }, { "basic", elm_code_test_basic }, }; diff --git a/legacy/elm_code/tests/elm_code_suite.h b/legacy/elm_code/tests/elm_code_suite.h index 2ae75a194d..b9d1bdf0fb 100644 --- a/legacy/elm_code/tests/elm_code_suite.h +++ b/legacy/elm_code/tests/elm_code_suite.h @@ -6,6 +6,7 @@ #include void elm_code_file_test_load(TCase *tc); +void elm_code_file_test_memory(TCase *tc); void elm_code_test_basic(TCase *tc); #endif /* _EDLM_CODE_SUITE_H */ From 80373debf7282485f4ee7ab0b73e958960d96044 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 4 Nov 2014 22:21:49 +0000 Subject: [PATCH 010/254] Add an initial stab at an elm_code widget. It currently does not refresh at any time other than load or resize, so is not respecting content updates, but it's a start. Use it in place of the list of elm_label objects that were rendered in the log panel. Not colour highlighted yet, but one thing at a time. --- legacy/elm_code/lib/Elm_Code.h | 9 +-- legacy/elm_code/lib/Makefile.am | 2 + legacy/elm_code/lib/elm_code_common.h | 31 ++++++++ legacy/elm_code/lib/elm_code_file.c | 6 +- legacy/elm_code/lib/elm_code_widget.c | 70 +++++++++++++++++++ legacy/elm_code/lib/elm_code_widget.h | 39 +++++++++++ .../elm_code/tests/elm_code_file_test_load.c | 4 +- 7 files changed, 151 insertions(+), 10 deletions(-) create mode 100644 legacy/elm_code/lib/elm_code_common.h create mode 100644 legacy/elm_code/lib/elm_code_widget.c create mode 100644 legacy/elm_code/lib/elm_code_widget.h diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index d1053105c1..84e41094a3 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -5,7 +5,9 @@ #include +#include #include +#include #ifdef EAPI # undef EAPI @@ -42,13 +44,6 @@ extern "C" { * @brief These routines are used for loading Elm Code widgets. */ -typedef struct _Elm_Code -{ - Elm_Code_File *file; - Eina_List *widgets; - -} Elm_Code; - /** * @brief Init / shutdown functions. * @defgroup Init Init / Shutdown diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am index 43b95b7cdb..98a15f6f8e 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/lib/Makefile.am @@ -12,11 +12,13 @@ lib_LTLIBRARIES = libelm_code.la includes_HEADERS = \ elm_code_file.h \ +elm_code_widget.h \ Elm_Code.h includesdir = $(includedir)/edi-@VMAJ@ libelm_code_la_SOURCES = \ elm_code_file.c \ +elm_code_widget.c \ elm_code.c libelm_code_la_LIBADD = @EFL_LIBS@ -lm libelm_code_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h new file mode 100644 index 0000000000..ce0993bfa6 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_common.h @@ -0,0 +1,31 @@ +#ifndef ELM_CODE_COMMON_H_ +# define ELM_CODE_COMMON_H_ + +#include + +#include "elm_code_file.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief Common data structures and constants. + */ + +typedef struct _Elm_Code +{ + Elm_Code_File *file; + Eina_List *widgets; +} Elm_Code; + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ELM_CODE_COMMON_H_ */ diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c index 0a0854c611..cd6aa97c44 100644 --- a/legacy/elm_code/lib/elm_code_file.c +++ b/legacy/elm_code/lib/elm_code_file.c @@ -124,6 +124,10 @@ EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, int number) { Elm_Code_Line *line; - line = eina_list_nth(file->lines, number); + line = eina_list_nth(file->lines, number - 1); + printf("N %d\n", number); + + if (!line) + return NULL; return line->content; } diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c new file mode 100644 index 0000000000..297cd3dd6e --- /dev/null +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -0,0 +1,70 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include + +#include "elm_code_widget.h" + +#include "elm_code_private.h" + +EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code) +{ + Evas_Textgrid_Cell *cells; + const char *line, *chr; + unsigned int length; + int w, h, cw, ch; + unsigned int x, y; + + evas_object_geometry_get(o, NULL, NULL, &w, &h); + evas_object_textgrid_cell_size_get(o, &cw, &ch); + evas_object_textgrid_size_set(o, ceil(((double) w) / cw), + ceil(((double) h) / ch)); + evas_object_textgrid_size_get(o, &w, &h); + + for (y = 1; y <= elm_code_file_lines_get(code->file); y++) + { + line = elm_code_file_line_content_get(code->file, y); + chr = line; + + cells = evas_object_textgrid_cellrow_get(o, y - 1); + length = strlen(line); + + for (x = 0; x < (unsigned int) w && x < length; x++) + { + cells[x].codepoint = *chr; + cells[x].bg = 0; + cells[x].fg = 1; + + chr++; + } + } +} + +static void +_elm_code_widget_resize_cb(void *data, EINA_UNUSED Evas *e, Evas_Object *obj, + EINA_UNUSED void *event_info) +{ + Elm_Code *code; + + code = (Elm_Code *)data; + elm_code_widget_fill(obj, code); +} + +EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) +{ + Evas_Object *o; + + o = evas_object_textgrid_add(parent); + + evas_object_textgrid_font_set(o, "Mono", 10 * elm_config_scale_get()); + + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, 0, + 54, 54, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, 1, + 205, 205, 205, 255); + + evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code); + return o; +} + diff --git a/legacy/elm_code/lib/elm_code_widget.h b/legacy/elm_code/lib/elm_code_widget.h new file mode 100644 index 0000000000..dda5df8f4a --- /dev/null +++ b/legacy/elm_code/lib/elm_code_widget.h @@ -0,0 +1,39 @@ +#ifndef ELM_CODE_WIDGET_H_ +# define ELM_CODE_WIDGET_H_ + +#include +#include +#include "elm_code_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for rendering instances of Elm Code. + */ + +/** + * @brief UI Loading functions. + * @defgroup Init Creating a widget to render an Elm Code backend + * + * @{ + * + * Functions for UI loading. + * + */ + +EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code); +EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ELM_CODE_WIDGET_H_ */ diff --git a/legacy/elm_code/tests/elm_code_file_test_load.c b/legacy/elm_code/tests/elm_code_file_test_load.c index d7933ac6c6..ff41d24666 100644 --- a/legacy/elm_code/tests/elm_code_file_test_load.c +++ b/legacy/elm_code/tests/elm_code_file_test_load.c @@ -50,8 +50,8 @@ START_TEST (elm_code_file_load_content) file = elm_code_file_open(path); - ck_assert_str_eq("line2", elm_code_file_line_content_get(file, 2 - 1)); - ck_assert_str_eq("another line", elm_code_file_line_content_get(file, 4 - 1)); + ck_assert_str_eq("line2", elm_code_file_line_content_get(file, 2)); + ck_assert_str_eq("another line", elm_code_file_line_content_get(file, 4)); elm_code_file_close(file); } END_TEST From 87d360b43f4671504adfcfdea474e9feed5ae7a9 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 5 Nov 2014 00:01:28 +0000 Subject: [PATCH 011/254] Adding some initial concept of status flags for a line and default enum to start working on color pallette in our widget. Load enough colors to provide these statuses and hook into the EDI log panel implementation --- legacy/elm_code/lib/elm_code_common.h | 15 +++++++++++++++ legacy/elm_code/lib/elm_code_file.c | 11 ++++++++--- legacy/elm_code/lib/elm_code_file.h | 8 +++++++- legacy/elm_code/lib/elm_code_widget.c | 23 +++++++++++++++-------- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index ce0993bfa6..5e288bfa90 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -3,6 +3,21 @@ #include +typedef enum { + ELM_CODE_STATUS_TYPE_DEFAULT = 0, + ELM_CODE_STATUS_TYPE_ERROR, + + 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_COUNT +} Elm_Code_Token_Type; + + #include "elm_code_file.h" #ifdef __cplusplus diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c index cd6aa97c44..b05a8d06d0 100644 --- a/legacy/elm_code/lib/elm_code_file.c +++ b/legacy/elm_code/lib/elm_code_file.c @@ -15,6 +15,7 @@ static Elm_Code_Line *_elm_code_blank_create(int line) if (!ecl) return NULL; ecl->number = line; + ecl->status = ELM_CODE_STATUS_TYPE_DEFAULT; return ecl; } @@ -120,12 +121,16 @@ EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line) _elm_code_file_line_append_data(file, line, strlen(line), row+1); } -EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, int number) +EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int number) +{ + return eina_list_nth(file->lines, number - 1); +} + +EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int number) { Elm_Code_Line *line; - line = eina_list_nth(file->lines, number - 1); - printf("N %d\n", number); + line = elm_code_file_line_get(file, number); if (!line) return NULL; diff --git a/legacy/elm_code/lib/elm_code_file.h b/legacy/elm_code/lib/elm_code_file.h index 4f7d095613..726684b927 100644 --- a/legacy/elm_code/lib/elm_code_file.h +++ b/legacy/elm_code/lib/elm_code_file.h @@ -3,6 +3,8 @@ #include +#include "elm_code_common.h" + #ifdef __cplusplus extern "C" { #endif @@ -17,6 +19,8 @@ typedef struct _Elm_Code_Line char *content; unsigned int number; + Elm_Code_Status_Type status; + } Elm_Code_Line; typedef struct _Elm_Code_File @@ -64,7 +68,9 @@ EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file); EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line); -EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, int line); +EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int line); + +EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int line); /** * @} diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 297cd3dd6e..a0cb66e40c 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -10,8 +10,9 @@ EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code) { + Elm_Code_Line *line; Evas_Textgrid_Cell *cells; - const char *line, *chr; + const char *content, *chr; unsigned int length; int w, h, cw, ch; unsigned int x, y; @@ -24,17 +25,18 @@ EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code) for (y = 1; y <= elm_code_file_lines_get(code->file); y++) { - line = elm_code_file_line_content_get(code->file, y); - chr = line; + line = elm_code_file_line_get(code->file, y); + content = elm_code_file_line_content_get(code->file, y); + chr = content; cells = evas_object_textgrid_cellrow_get(o, y - 1); - length = strlen(line); + length = strlen(content); for (x = 0; x < (unsigned int) w && x < length; x++) { cells[x].codepoint = *chr; - cells[x].bg = 0; - cells[x].fg = 1; + cells[x].bg = line->status; + cells[x].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; chr++; } @@ -59,9 +61,14 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) evas_object_textgrid_font_set(o, "Mono", 10 * elm_config_scale_get()); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, 0, + // setup status colors + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, 54, 54, 54, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, 1, + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ERROR, + 205, 54, 54, 255); + + // setup token colors + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT, 205, 205, 205, 255); evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code); From 1c314d93128735fea10d57b69cccd8f6836582d1 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 5 Nov 2014 13:36:54 +0000 Subject: [PATCH 012/254] Fix a crash when resizing if the file is longer than the viewport --- legacy/elm_code/lib/elm_code_widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index a0cb66e40c..b048b47648 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -23,7 +23,7 @@ EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code) ceil(((double) h) / ch)); evas_object_textgrid_size_get(o, &w, &h); - for (y = 1; y <= elm_code_file_lines_get(code->file); y++) + for (y = 1; y <= (unsigned int) h && y <= elm_code_file_lines_get(code->file); y++) { line = elm_code_file_line_get(code->file, y); content = elm_code_file_line_content_get(code->file, y); From b1d1e370ec6b5669fc84d97a4dbbfb1e13d4a935 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 5 Nov 2014 13:55:37 +0000 Subject: [PATCH 013/254] Add a simple elm_code_test binary that loads the widget and inserts some demo text --- legacy/elm_code/Makefile.am | 2 +- legacy/elm_code/bin/Makefile.am | 19 ++ legacy/elm_code/bin/elm_code_test_main.c | 127 +++++++++ legacy/elm_code/bin/elm_code_test_private.h | 6 + legacy/elm_code/bin/gettext.h | 280 ++++++++++++++++++++ 5 files changed, 433 insertions(+), 1 deletion(-) create mode 100644 legacy/elm_code/bin/Makefile.am create mode 100644 legacy/elm_code/bin/elm_code_test_main.c create mode 100644 legacy/elm_code/bin/elm_code_test_private.h create mode 100644 legacy/elm_code/bin/gettext.h diff --git a/legacy/elm_code/Makefile.am b/legacy/elm_code/Makefile.am index d01d7e3fde..15871c99eb 100644 --- a/legacy/elm_code/Makefile.am +++ b/legacy/elm_code/Makefile.am @@ -1,4 +1,4 @@ MAINTAINERCLEANFILES = Makefile.in -SUBDIRS = lib tests +SUBDIRS = lib bin tests diff --git a/legacy/elm_code/bin/Makefile.am b/legacy/elm_code/bin/Makefile.am new file mode 100644 index 0000000000..d2a4d25557 --- /dev/null +++ b/legacy/elm_code/bin/Makefile.am @@ -0,0 +1,19 @@ +MAINTAINERCLEANFILES = Makefile.in + +bin_PROGRAMS = elm_code_test + +AM_CPPFLAGS = -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ +-I$(top_builddir)/elm_code/bin/ \ +-I$(top_srcdir)/elm_code/bin/ \ +-I$(top_builddir)/elm_code/lib/ \ +-I$(top_srcdir)/elm_code/lib/ \ +@EFL_CFLAGS@ + +elm_code_test_SOURCES = elm_code_test_main.c +elm_code_test_LDADD = @EFL_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la + +localedir = $(datadir)/locale +DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ + +EXTRA_DIST = elm_code_test_private.h + diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c new file mode 100644 index 0000000000..42c0d100fe --- /dev/null +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -0,0 +1,127 @@ +#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. */ + +#include +#include + +#include "gettext.h" + +#include + +#include "elm_code_test_private.h" + +#define COPYRIGHT "Copyright © 2014 andy 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 Evas_Object * +elm_code_test_win_setup(void) +{ + Evas_Object *win; + Elm_Code *code; + Elm_Code_Line *line; + Evas_Object *widget; + + win = elm_win_util_standard_add("main", "Elm_code_test"); + if (!win) return NULL; + + elm_win_focus_highlight_enabled_set(win, EINA_TRUE); + evas_object_smart_callback_add(win, "delete,request", _elm_code_test_win_del, NULL); + + code = elm_code_create(elm_code_file_new()); + widget = elm_code_widget_add(win, code); + elm_code_file_line_append(code->file, "Hello World, Elm Code!"); + elm_code_file_line_append(code->file, ""); + elm_code_file_line_append(code->file, "This is a demo of elm_code's capabilities."); + + elm_code_file_line_append(code->file, "*** Currently experimental ***"); + line = elm_code_file_line_get(code->file, 4); + line->status = ELM_CODE_STATUS_TYPE_ERROR; + + 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_win_resize_object_add(win, widget); + + evas_object_resize(win, 280 * elm_config_scale_get(), 70 * 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; + } + + 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() diff --git a/legacy/elm_code/bin/elm_code_test_private.h b/legacy/elm_code/bin/elm_code_test_private.h new file mode 100644 index 0000000000..04fb817a02 --- /dev/null +++ b/legacy/elm_code/bin/elm_code_test_private.h @@ -0,0 +1,6 @@ +#ifndef ELM_CODE_TEST_PRIVATE_H_ +# define ELM_CODE_TEST_PRIVATE_H_ + +// FIXME: put some private stuff related to your binary + +#endif diff --git a/legacy/elm_code/bin/gettext.h b/legacy/elm_code/bin/gettext.h new file mode 100644 index 0000000000..e76b592d08 --- /dev/null +++ b/legacy/elm_code/bin/gettext.h @@ -0,0 +1,280 @@ +/* Convenience header for conditional use of GNU . + Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#ifndef _LIBGETTEXT_H +#define _LIBGETTEXT_H 1 + +/* NLS can be disabled through the configure --disable-nls option. */ +#if ENABLE_NLS + +/* Get declarations of GNU message catalog functions. */ +# include + +/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by + the gettext() and ngettext() macros. This is an alternative to calling + textdomain(), and is useful for libraries. */ +# ifdef DEFAULT_TEXT_DOMAIN +# undef gettext +# define gettext(Msgid) \ + dgettext (DEFAULT_TEXT_DOMAIN, Msgid) +# undef ngettext +# define ngettext(Msgid1, Msgid2, N) \ + dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N) +# endif + +#else + +/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which + chokes if dcgettext is defined as a macro. So include it now, to make + later inclusions of a NOP. We don't include + as well because people using "gettext.h" will not include , + and also including would fail on SunOS 4, whereas + is OK. */ +#if defined(__sun) +# include +#endif + +/* Many header files from the libstdc++ coming with g++ 3.3 or newer include + , which chokes if dcgettext is defined as a macro. So include + it now, to make later inclusions of a NOP. */ +#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) +# include +# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H +# include +# endif +#endif + +/* Disabled NLS. + The casts to 'const char *' serve the purpose of producing warnings + for invalid uses of the value returned from these functions. + On pre-ANSI systems without 'const', the config.h file is supposed to + contain "#define const". */ +# undef gettext +# define gettext(Msgid) ((const char *) (Msgid)) +# undef dgettext +# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) +# undef dcgettext +# define dcgettext(Domainname, Msgid, Category) \ + ((void) (Category), dgettext (Domainname, Msgid)) +# undef ngettext +# define ngettext(Msgid1, Msgid2, N) \ + ((N) == 1 \ + ? ((void) (Msgid2), (const char *) (Msgid1)) \ + : ((void) (Msgid1), (const char *) (Msgid2))) +# undef dngettext +# define dngettext(Domainname, Msgid1, Msgid2, N) \ + ((void) (Domainname), ngettext (Msgid1, Msgid2, N)) +# undef dcngettext +# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ + ((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N)) +# undef textdomain +# define textdomain(Domainname) ((const char *) (Domainname)) +# undef bindtextdomain +# define bindtextdomain(Domainname, Dirname) \ + ((void) (Domainname), (const char *) (Dirname)) +# undef bind_textdomain_codeset +# define bind_textdomain_codeset(Domainname, Codeset) \ + ((void) (Domainname), (const char *) (Codeset)) + +#endif + +/* A pseudo function call that serves as a marker for the automated + extraction of messages, but does not call gettext(). The run-time + translation is done at a different place in the code. + The argument, String, should be a literal string. Concatenated strings + and other string expressions won't work. + The macro's expansion is not parenthesized, so that it is suitable as + initializer for static 'char[]' or 'const char[]' variables. */ +#define gettext_noop(String) String + +/* The separator between msgctxt and msgid in a .mo file. */ +#define GETTEXT_CONTEXT_GLUE "\004" + +/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a + MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be + short and rarely need to change. + The letter 'p' stands for 'particular' or 'special'. */ +#ifdef DEFAULT_TEXT_DOMAIN +# define pgettext(Msgctxt, Msgid) \ + pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) +#else +# define pgettext(Msgctxt, Msgid) \ + pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) +#endif +#define dpgettext(Domainname, Msgctxt, Msgid) \ + pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) +#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \ + pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category) +#ifdef DEFAULT_TEXT_DOMAIN +# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ + npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) +#else +# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ + npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) +#endif +#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ + npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) +#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \ + npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category) + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +pgettext_aux (const char *domain, + const char *msg_ctxt_id, const char *msgid, + int category) +{ + const char *translation = dcgettext (domain, msg_ctxt_id, category); + if (translation == msg_ctxt_id) + return msgid; + else + return translation; +} + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +npgettext_aux (const char *domain, + const char *msg_ctxt_id, const char *msgid, + const char *msgid_plural, unsigned long int n, + int category) +{ + const char *translation = + dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); + if (translation == msg_ctxt_id || translation == msgid_plural) + return (n == 1 ? msgid : msgid_plural); + else + return translation; +} + +/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID + can be arbitrary expressions. But for string literals these macros are + less efficient than those above. */ + +#include + +#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \ + (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \ + /* || __STDC_VERSION__ >= 199901L */ ) + +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +#include +#endif + +#define pgettext_expr(Msgctxt, Msgid) \ + dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) +#define dpgettext_expr(Domainname, Msgctxt, Msgid) \ + dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +dcpgettext_expr (const char *domain, + const char *msgctxt, const char *msgid, + int category) +{ + size_t msgctxt_len = strlen (msgctxt) + 1; + size_t msgid_len = strlen (msgid) + 1; + const char *translation; +#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + char msg_ctxt_id[msgctxt_len + msgid_len]; +#else + char buf[1024]; + char *msg_ctxt_id = + (msgctxt_len + msgid_len <= sizeof (buf) + ? buf + : (char *) malloc (msgctxt_len + msgid_len)); + if (msg_ctxt_id != NULL) +#endif + { + memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); + msg_ctxt_id[msgctxt_len - 1] = '\004'; + memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); + translation = dcgettext (domain, msg_ctxt_id, category); +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + if (msg_ctxt_id != buf) + free (msg_ctxt_id); +#endif + if (translation != msg_ctxt_id) + return translation; + } + return msgid; +} + +#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ + dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) +#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ + dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +dcnpgettext_expr (const char *domain, + const char *msgctxt, const char *msgid, + const char *msgid_plural, unsigned long int n, + int category) +{ + size_t msgctxt_len = strlen (msgctxt) + 1; + size_t msgid_len = strlen (msgid) + 1; + const char *translation; +#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + char msg_ctxt_id[msgctxt_len + msgid_len]; +#else + char buf[1024]; + char *msg_ctxt_id = + (msgctxt_len + msgid_len <= sizeof (buf) + ? buf + : (char *) malloc (msgctxt_len + msgid_len)); + if (msg_ctxt_id != NULL) +#endif + { + memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); + msg_ctxt_id[msgctxt_len - 1] = '\004'; + memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); + translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + if (msg_ctxt_id != buf) + free (msg_ctxt_id); +#endif + if (!(translation == msg_ctxt_id || translation == msgid_plural)) + return translation; + } + return (n == 1 ? msgid : msgid_plural); +} + +#endif /* _LIBGETTEXT_H */ From d110515fb12e35abdd48c54c24740567a2abb633 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 6 Nov 2014 23:43:56 +0000 Subject: [PATCH 014/254] Passing Eo events from Elm_Code to the Evas_Object when the backend data changes. Track a list of all widgets connected to the Elm_Code so we can signal them all. Add API to change status of a line which will refresh the widget too. --- legacy/elm_code/lib/Elm_Code.h | 15 ++++++++ legacy/elm_code/lib/elm_code.c | 28 ++++++++++++++- legacy/elm_code/lib/elm_code_common.h | 10 +++++- legacy/elm_code/lib/elm_code_file.c | 18 ++++++++++ legacy/elm_code/lib/elm_code_file.h | 4 +++ legacy/elm_code/lib/elm_code_widget.c | 50 +++++++++++++++++++++++++-- 6 files changed, 120 insertions(+), 5 deletions(-) diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 84e41094a3..8e0528de08 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -107,6 +107,21 @@ EAPI Elm_Code *elm_code_create(Elm_Code_File *file); */ 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 char *signal, void *data); + + /** * @} */ diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index 932168ecc7..7f43b7ee96 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -2,6 +2,9 @@ # include "config.h" #endif +#define EFL_BETA_API_SUPPORT +#include + #include "Elm_Code.h" #include "elm_code_private.h" @@ -64,6 +67,7 @@ elm_code_create(Elm_Code_File *file) ret = calloc(1, sizeof(Elm_Code)); ret->file = file; + file->parent = ret; return ret; } @@ -71,8 +75,30 @@ elm_code_create(Elm_Code_File *file) EAPI void elm_code_free(Elm_Code *code) { + Eina_List *item; + Evas_Object *widget; + if (code->file) - free(code->file); + elm_code_file_free(code->file); + + EINA_LIST_FOREACH(code->widgets, item, widget) + { + evas_object_hide(widget); + evas_object_del(widget); + } free(code); } + +EAPI void +elm_code_callback_fire(Elm_Code *code, const char *signal, void *data) +{ + Eina_List *item; + Evas_Object *widget; + + EINA_LIST_FOREACH(code->widgets, item, widget) + { + eo_do(widget, eo_event_callback_call(ELM_CODE_EVENT_LINE_SET_DONE, data)); + } +} + diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index 5e288bfa90..aac0969f77 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -3,6 +3,13 @@ #include +#define EFL_BETA_API_SUPPORT +#include + +#define ELM_CODE_EVENT_LINE_SET_DONE "line,set,done" +//EAPI const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE = +// EO_EVENT_DESCRIPTION("line,set,done", ""); + typedef enum { ELM_CODE_STATUS_TYPE_DEFAULT = 0, ELM_CODE_STATUS_TYPE_ERROR, @@ -17,13 +24,14 @@ typedef enum { ELM_CODE_TOKEN_TYPE_COUNT } Elm_Code_Token_Type; - #include "elm_code_file.h" #ifdef __cplusplus extern "C" { #endif + + /** * @file * @brief Common data structures and constants. diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c index b05a8d06d0..585465eca0 100644 --- a/legacy/elm_code/lib/elm_code_file.c +++ b/legacy/elm_code/lib/elm_code_file.c @@ -31,6 +31,9 @@ static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *con line->content[length] = 0; file->lines = eina_list_append(file->lines, line); + + if (file->parent) + elm_code_callback_fire(file->parent, ELM_CODE_EVENT_LINE_SET_DONE, line); } EAPI Elm_Code_File *elm_code_file_new() @@ -136,3 +139,18 @@ EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int numb return NULL; return line->content; } + +EAPI void elm_code_file_line_status_set(Elm_Code_File *file, unsigned int number, Elm_Code_Status_Type status) +{ + Elm_Code_Line *line; + + line = elm_code_file_line_get(file, number); + + if (!line) + return; + + line->status = status; + + if (file->parent) + elm_code_callback_fire(file->parent, ELM_CODE_EVENT_LINE_SET_DONE, line); +} diff --git a/legacy/elm_code/lib/elm_code_file.h b/legacy/elm_code/lib/elm_code_file.h index 726684b927..3ea1e4bd73 100644 --- a/legacy/elm_code/lib/elm_code_file.h +++ b/legacy/elm_code/lib/elm_code_file.h @@ -25,6 +25,8 @@ typedef struct _Elm_Code_Line typedef struct _Elm_Code_File { + void *parent; + Eina_List *lines; Eina_File *file; @@ -72,6 +74,8 @@ EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int lin EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int line); +EAPI void elm_code_file_line_status_set(Elm_Code_File *file, unsigned int line, Elm_Code_Status_Type status); + /** * @} */ diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index b048b47648..52be408123 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -2,6 +2,9 @@ # include "config.h" #endif +#define EFL_BETA_API_SUPPORT +#include + #include #include "elm_code_widget.h" @@ -12,7 +15,8 @@ EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code) { Elm_Code_Line *line; Evas_Textgrid_Cell *cells; - const char *content, *chr; + const char *content; + char *chr; unsigned int length; int w, h, cw, ch; unsigned int x, y; @@ -41,11 +45,47 @@ EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code) chr++; } } + + evas_object_textgrid_update_add(o, 0, 0, w, h); } static void -_elm_code_widget_resize_cb(void *data, EINA_UNUSED Evas *e, Evas_Object *obj, - EINA_UNUSED void *event_info) +_elm_code_widget_line_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, + void *event_info) +{ + Elm_Code *code; + Elm_Code_Line *line; + Evas_Object *o; + + Evas_Textgrid_Cell *cells; + char *chr; + unsigned int length, x; + int w; + + code = (Elm_Code *)data; + line = (Elm_Code_Line *)event_info; + o = (Evas_Object *)obj; + + cells = evas_object_textgrid_cellrow_get(o, line->number - 1); + length = strlen(line->content); + evas_object_textgrid_size_get(o, &w, NULL); + + chr = line->content; + for (x = 0; x < (unsigned int) w && x < length; x++) + { + cells[x].codepoint = *chr; + cells[x].bg = line->status; + cells[x].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; + + chr++; + } + + evas_object_textgrid_update_add(o, 0, line->number - 1, w, 1); +} + +static void +_elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, + void *event_info EINA_UNUSED) { Elm_Code *code; @@ -72,6 +112,10 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) 205, 205, 205, 255); evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code); + + eo_do(o,eo_event_callback_add(ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, code)); + + code->widgets = eina_list_append(code->widgets, o); return o; } From 279602400543c07cde0a8dabb6030caeb0505310 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 9 Nov 2014 00:47:00 +0000 Subject: [PATCH 015/254] Take line coloring to the end of the line --- legacy/elm_code/lib/elm_code_widget.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 52be408123..16ea4e2845 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -44,6 +44,12 @@ EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code) chr++; } + for (; x < (unsigned int) w; x++) + { + cells[x].codepoint = 0; + cells[x].bg = line->status; + cells[x].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; + } } evas_object_textgrid_update_add(o, 0, 0, w, h); @@ -79,6 +85,12 @@ _elm_code_widget_line_cb(void *data, Eo *obj, const Eo_Event_Description *desc E chr++; } + for (; x < (unsigned int) w; x++) + { + cells[x].codepoint = 0; + cells[x].bg = line->status; + cells[x].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; + } evas_object_textgrid_update_add(o, 0, line->number - 1, w, 1); } From a3e6ec68768cee0de57a0c0c80dda3b83375feec Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 9 Nov 2014 14:44:35 +0000 Subject: [PATCH 016/254] Add some simple version control status for lines too. Add a simple display of how that could work to elm_code_tesst --- legacy/elm_code/bin/elm_code_test_main.c | 98 ++++++++++++++++++++---- legacy/elm_code/lib/elm_code_common.h | 4 + legacy/elm_code/lib/elm_code_widget.c | 11 ++- 3 files changed, 97 insertions(+), 16 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 42c0d100fe..c88f9850e5 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -24,36 +24,106 @@ _elm_code_test_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi } static Evas_Object * -elm_code_test_win_setup(void) +_elm_code_test_welcome_setup(Evas_Object *parent) { - Evas_Object *win; Elm_Code *code; - Elm_Code_Line *line; Evas_Object *widget; - win = elm_win_util_standard_add("main", "Elm_code_test"); - if (!win) return NULL; - - elm_win_focus_highlight_enabled_set(win, EINA_TRUE); - evas_object_smart_callback_add(win, "delete,request", _elm_code_test_win_del, NULL); - code = elm_code_create(elm_code_file_new()); - widget = elm_code_widget_add(win, code); + widget = elm_code_widget_add(parent, code); elm_code_file_line_append(code->file, "Hello World, Elm Code!"); elm_code_file_line_append(code->file, ""); elm_code_file_line_append(code->file, "This is a demo of elm_code's capabilities."); elm_code_file_line_append(code->file, "*** Currently experimental ***"); - line = elm_code_file_line_get(code->file, 4); - line->status = ELM_CODE_STATUS_TYPE_ERROR; + elm_code_file_line_status_set(code->file, 4, ELM_CODE_STATUS_TYPE_ERROR); 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_win_resize_object_add(win, widget); + return widget; +} - evas_object_resize(win, 280 * elm_config_scale_get(), 70 * elm_config_scale_get()); +static Evas_Object * +_elm_code_test_diff_setup(Evas_Object *parent) +{ + Elm_Code *code; + Evas_Object *widget, *hbox; + + hbox = elm_box_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_box_homogeneous_set(hbox, EINA_TRUE); + elm_box_horizontal_set(hbox, EINA_TRUE); + evas_object_show(hbox); + + // left side of diff + code = elm_code_create(elm_code_file_new()); + widget = elm_code_widget_add(parent, code); + + elm_code_file_line_append(code->file, "Some content to diff"); + elm_code_file_line_append(code->file, ""); + elm_code_file_line_append(code->file, "more"); + elm_code_file_line_append(code->file, "removed"); + elm_code_file_line_append(code->file, "will change"); + elm_code_file_line_append(code->file, "unchanged"); + + elm_code_file_line_status_set(code->file, 4, ELM_CODE_STATUS_TYPE_REMOVED); + elm_code_file_line_status_set(code->file, 5, ELM_CODE_STATUS_TYPE_CHANGED); + + 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_box_pack_end(hbox, widget); + + // right side of diff + code = elm_code_create(elm_code_file_new()); + widget = elm_code_widget_add(parent, code); + + elm_code_file_line_append(code->file, "Some content to diff"); + elm_code_file_line_append(code->file, "added"); + elm_code_file_line_append(code->file, "more"); + elm_code_file_line_append(code->file, ""); + elm_code_file_line_append(code->file, "changed"); + elm_code_file_line_append(code->file, "unchanged"); + + elm_code_file_line_status_set(code->file, 2, ELM_CODE_STATUS_TYPE_ADDED); + elm_code_file_line_status_set(code->file, 5, ELM_CODE_STATUS_TYPE_CHANGED); + + 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_box_pack_end(hbox, widget); + + return hbox; +} + +static Evas_Object * +elm_code_test_win_setup(void) +{ + Evas_Object *win; + Evas_Object *vbox; + + win = elm_win_util_standard_add("main", "Elm_code_test"); + if (!win) return NULL; + + 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); + elm_box_homogeneous_set(vbox, EINA_TRUE); + evas_object_show(vbox); + + elm_win_focus_highlight_enabled_set(win, EINA_TRUE); + evas_object_smart_callback_add(win, "delete,request", _elm_code_test_win_del, NULL); + + elm_box_pack_end(vbox, _elm_code_test_welcome_setup(vbox)); + + elm_box_pack_end(vbox, _elm_code_test_diff_setup(vbox)); + + elm_win_resize_object_add(win, vbox); + + evas_object_resize(win, 320 * elm_config_scale_get(), 180 * elm_config_scale_get()); evas_object_show(win); return win; diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index aac0969f77..76cfa2c00d 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -14,6 +14,10 @@ typedef enum { ELM_CODE_STATUS_TYPE_DEFAULT = 0, ELM_CODE_STATUS_TYPE_ERROR, + ELM_CODE_STATUS_TYPE_ADDED, + ELM_CODE_STATUS_TYPE_REMOVED, + ELM_CODE_STATUS_TYPE_CHANGED, + ELM_CODE_STATUS_TYPE_COUNT } Elm_Code_Status_Type; diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 16ea4e2845..51331725c1 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -115,9 +115,16 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) // setup status colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, - 54, 54, 54, 255); + 54, 54, 54, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ERROR, - 205, 54, 54, 255); + 205, 54, 54, 255); + + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ADDED, + 54, 125, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_REMOVED, + 125, 54, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CHANGED, + 54, 54, 125, 255); // setup token colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT, From 1a2f4d1ad4037df2f1fc2b2ae4174d40e5e9e0f7 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 9 Nov 2014 18:07:03 +0000 Subject: [PATCH 017/254] Fixing some warnings. Not ideal handling of the Eo_Event_Description but it's less warn-tastic --- legacy/elm_code/lib/elm_code.c | 2 +- legacy/elm_code/lib/elm_code_common.h | 4 +--- legacy/elm_code/lib/elm_code_widget.c | 15 +++++++-------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index 7f43b7ee96..0186f83915 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -98,7 +98,7 @@ elm_code_callback_fire(Elm_Code *code, const char *signal, void *data) EINA_LIST_FOREACH(code->widgets, item, widget) { - eo_do(widget, eo_event_callback_call(ELM_CODE_EVENT_LINE_SET_DONE, data)); + eo_do(widget, eo_event_callback_call((Eo_Event_Description *)signal, data)); } } diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index 76cfa2c00d..436bd454d3 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -3,9 +3,7 @@ #include -#define EFL_BETA_API_SUPPORT -#include - +// TODO figure out how this can be fixed #define ELM_CODE_EVENT_LINE_SET_DONE "line,set,done" //EAPI const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE = // EO_EVENT_DESCRIPTION("line,set,done", ""); diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 51331725c1..02a4f87e3d 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -31,7 +31,7 @@ EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code) { line = elm_code_file_line_get(code->file, y); content = elm_code_file_line_content_get(code->file, y); - chr = content; + chr = (char *)content; cells = evas_object_textgrid_cellrow_get(o, y - 1); length = strlen(content); @@ -55,11 +55,10 @@ EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code) evas_object_textgrid_update_add(o, 0, 0, w, h); } -static void -_elm_code_widget_line_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, - void *event_info) +static Eina_Bool +_elm_code_widget_line_cb(void *data EINA_UNUSED, Eo *obj, + const Eo_Event_Description *desc EINA_UNUSED, void *event_info) { - Elm_Code *code; Elm_Code_Line *line; Evas_Object *o; @@ -68,7 +67,6 @@ _elm_code_widget_line_cb(void *data, Eo *obj, const Eo_Event_Description *desc E unsigned int length, x; int w; - code = (Elm_Code *)data; line = (Elm_Code_Line *)event_info; o = (Evas_Object *)obj; @@ -76,7 +74,7 @@ _elm_code_widget_line_cb(void *data, Eo *obj, const Eo_Event_Description *desc E length = strlen(line->content); evas_object_textgrid_size_get(o, &w, NULL); - chr = line->content; + chr = (char *)line->content; for (x = 0; x < (unsigned int) w && x < length; x++) { cells[x].codepoint = *chr; @@ -93,6 +91,7 @@ _elm_code_widget_line_cb(void *data, Eo *obj, const Eo_Event_Description *desc E } evas_object_textgrid_update_add(o, 0, line->number - 1, w, 1); + return EINA_TRUE; } static void @@ -132,7 +131,7 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code); - eo_do(o,eo_event_callback_add(ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, code)); + eo_do(o,eo_event_callback_add((Eo_Event_Description *)ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, code)); code->widgets = eina_list_append(code->widgets, o); return o; From 0e901e5352d129571f9a1e04611bf3fdac6234f2 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 9 Nov 2014 21:53:30 +0000 Subject: [PATCH 018/254] Fix the types of Eo Events - addresses lots of compiler warnings --- legacy/elm_code/bin/Makefile.am | 1 + legacy/elm_code/lib/Elm_Code.h | 4 ++-- legacy/elm_code/lib/Makefile.am | 1 + legacy/elm_code/lib/elm_code.c | 8 +++++--- legacy/elm_code/lib/elm_code_common.h | 6 ++---- legacy/elm_code/lib/elm_code_file.c | 4 ++-- legacy/elm_code/lib/elm_code_widget.c | 4 +--- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/legacy/elm_code/bin/Makefile.am b/legacy/elm_code/bin/Makefile.am index d2a4d25557..363beb8fb8 100644 --- a/legacy/elm_code/bin/Makefile.am +++ b/legacy/elm_code/bin/Makefile.am @@ -7,6 +7,7 @@ AM_CPPFLAGS = -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ -I$(top_srcdir)/elm_code/bin/ \ -I$(top_builddir)/elm_code/lib/ \ -I$(top_srcdir)/elm_code/lib/ \ +-DEFL_BETA_API_SUPPORT \ @EFL_CFLAGS@ elm_code_test_SOURCES = elm_code_test_main.c diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 8e0528de08..fbc0a4b2f6 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -2,7 +2,7 @@ # define ELM_CODE_H_ #include - +#include #include #include @@ -119,7 +119,7 @@ EAPI void elm_code_free(Elm_Code *code); */ -EAPI void elm_code_callback_fire(Elm_Code *code, const char *signal, void *data); +EAPI void elm_code_callback_fire(Elm_Code *code, const Eo_Event_Description *signal, void *data); /** diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am index 98a15f6f8e..8329e65091 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/lib/Makefile.am @@ -5,6 +5,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/elm_code/lib \ -DPACKAGE_LIB_DIR=\"$(libdir)\" \ -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ +-DEFL_BETA_API_SUPPORT \ @EFL_CFLAGS@ \ -DEFL_EFL_BUILD diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index 0186f83915..9ae1ade2ac 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -2,7 +2,6 @@ # include "config.h" #endif -#define EFL_BETA_API_SUPPORT #include #include "Elm_Code.h" @@ -12,6 +11,9 @@ static int _elm_code_init = 0; int _elm_code_lib_log_dom = -1; +const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE = + EO_EVENT_DESCRIPTION("line,set,done", ""); + EAPI int elm_code_init(void) { @@ -91,14 +93,14 @@ elm_code_free(Elm_Code *code) } EAPI void -elm_code_callback_fire(Elm_Code *code, const char *signal, void *data) +elm_code_callback_fire(Elm_Code *code, const Eo_Event_Description *signal, void *data) { Eina_List *item; Evas_Object *widget; EINA_LIST_FOREACH(code->widgets, item, widget) { - eo_do(widget, eo_event_callback_call((Eo_Event_Description *)signal, data)); + eo_do(widget, eo_event_callback_call(signal, data)); } } diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index 436bd454d3..11149fe24f 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -1,12 +1,10 @@ #ifndef ELM_CODE_COMMON_H_ # define ELM_CODE_COMMON_H_ +#include #include -// TODO figure out how this can be fixed -#define ELM_CODE_EVENT_LINE_SET_DONE "line,set,done" -//EAPI const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE = -// EO_EVENT_DESCRIPTION("line,set,done", ""); +EAPI extern const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE; typedef enum { ELM_CODE_STATUS_TYPE_DEFAULT = 0, diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c index 585465eca0..1f5f8a8de7 100644 --- a/legacy/elm_code/lib/elm_code_file.c +++ b/legacy/elm_code/lib/elm_code_file.c @@ -33,7 +33,7 @@ static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *con file->lines = eina_list_append(file->lines, line); if (file->parent) - elm_code_callback_fire(file->parent, ELM_CODE_EVENT_LINE_SET_DONE, line); + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_SET_DONE, line); } EAPI Elm_Code_File *elm_code_file_new() @@ -152,5 +152,5 @@ EAPI void elm_code_file_line_status_set(Elm_Code_File *file, unsigned int number line->status = status; if (file->parent) - elm_code_callback_fire(file->parent, ELM_CODE_EVENT_LINE_SET_DONE, line); + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_SET_DONE, line); } diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 02a4f87e3d..ba254619bd 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -2,9 +2,7 @@ # include "config.h" #endif -#define EFL_BETA_API_SUPPORT #include - #include #include "elm_code_widget.h" @@ -131,7 +129,7 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code); - eo_do(o,eo_event_callback_add((Eo_Event_Description *)ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, code)); + eo_do(o,eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, code)); code->widgets = eina_list_append(code->widgets, o); return o; From 6465de9ca633fbccaa8966933f2b6771ec82f41b Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 12 Nov 2014 14:05:56 +0000 Subject: [PATCH 019/254] Fix compilation of tests --- legacy/elm_code/tests/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/tests/Makefile.am index 4a5759f615..aa71521987 100644 --- a/legacy/elm_code/tests/Makefile.am +++ b/legacy/elm_code/tests/Makefile.am @@ -12,6 +12,7 @@ elm_code_suite.c elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/lib/ \ -DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/tests/\" \ -DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/tests/\" \ +-DEFL_BETA_API_SUPPORT \ @EFL_CFLAGS@ \ @CHECK_CFLAGS@ From 269409f5cd5e302d5a39710cac2d42a9d8b9bd16 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 12 Nov 2014 22:59:05 +0000 Subject: [PATCH 020/254] Add a file load callback also - respect that with a widget refresh when called --- legacy/elm_code/lib/elm_code.c | 2 ++ legacy/elm_code/lib/elm_code_common.h | 1 + legacy/elm_code/lib/elm_code_file.c | 2 ++ legacy/elm_code/lib/elm_code_widget.c | 16 ++++++++++++++++ 4 files changed, 21 insertions(+) diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index 9ae1ade2ac..fb40c9f34b 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -13,6 +13,8 @@ int _elm_code_lib_log_dom = -1; const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE = EO_EVENT_DESCRIPTION("line,set,done", ""); +const Eo_Event_Description ELM_CODE_EVENT_FILE_LOAD_DONE = + EO_EVENT_DESCRIPTION("file, load,done", ""); EAPI int elm_code_init(void) diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index 11149fe24f..bae3599102 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -5,6 +5,7 @@ #include EAPI extern const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE; +EAPI extern const Eo_Event_Description ELM_CODE_EVENT_FILE_LOAD_DONE; typedef enum { ELM_CODE_STATUS_TYPE_DEFAULT = 0, diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c index 1f5f8a8de7..9650b334d7 100644 --- a/legacy/elm_code/lib/elm_code_file.c +++ b/legacy/elm_code/lib/elm_code_file.c @@ -76,6 +76,8 @@ EAPI Elm_Code_File *elm_code_file_open(const char *path) } eina_iterator_free(it); + if (ret->parent) + elm_code_callback_fire(ret->parent, &ELM_CODE_EVENT_FILE_LOAD_DONE, ret); return ret; } diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index ba254619bd..760334f6eb 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -92,6 +92,21 @@ _elm_code_widget_line_cb(void *data EINA_UNUSED, Eo *obj, return EINA_TRUE; } + +static Eina_Bool +_elm_code_widget_file_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + Evas_Object *o; + Elm_Code *code; + + code = (Elm_Code *)data; + o = (Evas_Object *)obj; + + elm_code_widget_fill(o, code); + return EINA_TRUE; +} + static void _elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED) @@ -130,6 +145,7 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code); eo_do(o,eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, code)); + eo_do(o,eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, code)); code->widgets = eina_list_append(code->widgets, o); return o; From f7e0ad9dd856e4887e001a678874b012bdcd4f60 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 13 Nov 2014 21:34:47 +0000 Subject: [PATCH 021/254] Add a simple token system to allow us to render some text styles --- legacy/elm_code/bin/elm_code_test_main.c | 1 + legacy/elm_code/lib/elm_code_common.h | 1 + legacy/elm_code/lib/elm_code_file.c | 20 +++ legacy/elm_code/lib/elm_code_file.h | 13 ++ legacy/elm_code/lib/elm_code_widget.c | 125 +++++++++++------- .../tests/elm_code_file_test_memory.c | 17 +++ 6 files changed, 128 insertions(+), 49 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index c88f9850e5..40f73bf66c 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -32,6 +32,7 @@ _elm_code_test_welcome_setup(Evas_Object *parent) code = elm_code_create(elm_code_file_new()); widget = elm_code_widget_add(parent, code); elm_code_file_line_append(code->file, "Hello World, Elm Code!"); + elm_code_file_line_token_add(code->file, 1, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); elm_code_file_line_append(code->file, ""); elm_code_file_line_append(code->file, "This is a demo of elm_code's capabilities."); diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index bae3599102..e19a6b372c 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -21,6 +21,7 @@ typedef enum { typedef enum { ELM_CODE_TOKEN_TYPE_DEFAULT = ELM_CODE_STATUS_TYPE_COUNT, + ELM_CODE_TOKEN_TYPE_COMMENT, ELM_CODE_TOKEN_TYPE_COUNT } Elm_Code_Token_Type; diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c index 9650b334d7..e649b2858b 100644 --- a/legacy/elm_code/lib/elm_code_file.c +++ b/legacy/elm_code/lib/elm_code_file.c @@ -156,3 +156,23 @@ EAPI void elm_code_file_line_status_set(Elm_Code_File *file, unsigned int number if (file->parent) elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_SET_DONE, line); } + +EAPI void elm_code_file_line_token_add(Elm_Code_File *file, unsigned int number, int start, int end, + Elm_Code_Token_Type type) +{ + Elm_Code_Line *line; + Elm_Code_Token *tok; + + line = elm_code_file_line_get(file, number); + tok = calloc(1, sizeof(Elm_Code_Token)); + + tok->start = start; + tok->end = end; + tok->type = type; + + line->tokens = eina_list_append(line->tokens, tok); + + if (file->parent) + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_SET_DONE, line); +} + diff --git a/legacy/elm_code/lib/elm_code_file.h b/legacy/elm_code/lib/elm_code_file.h index 3ea1e4bd73..0950ed96aa 100644 --- a/legacy/elm_code/lib/elm_code_file.h +++ b/legacy/elm_code/lib/elm_code_file.h @@ -14,12 +14,22 @@ extern "C" { * @brief These routines are used for interacting with files using Elm Code. */ +typedef struct _Elm_Code_Token +{ + int start, end; + + Elm_Code_Token_Type type; + +} Elm_Code_Token; + typedef struct _Elm_Code_Line { char *content; unsigned int number; Elm_Code_Status_Type status; + Eina_List *tokens; + } Elm_Code_Line; @@ -76,6 +86,9 @@ EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int line EAPI void elm_code_file_line_status_set(Elm_Code_File *file, unsigned int line, Elm_Code_Status_Type status); +EAPI void elm_code_file_line_token_add(Elm_Code_File *file, unsigned int number, int start, int end, + Elm_Code_Token_Type type); + /** * @} */ diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 760334f6eb..011afdbb57 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -9,48 +9,93 @@ #include "elm_code_private.h" -EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code) +static Eina_Bool _elm_code_widget_resize(Evas_Object *o) { - Elm_Code_Line *line; - Evas_Textgrid_Cell *cells; - const char *content; - char *chr; - unsigned int length; int w, h, cw, ch; - unsigned int x, y; evas_object_geometry_get(o, NULL, NULL, &w, &h); evas_object_textgrid_cell_size_get(o, &cw, &ch); evas_object_textgrid_size_set(o, ceil(((double) w) / cw), ceil(((double) h) / ch)); + + return h > 0 && w > 0; +} + +static void _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start, int end, Elm_Code_Token_Type type) +{ + int x; + + for (x = start - 1; x < end && x < count; x++) + { + cells[x].fg = type; + } +} + +static void _elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) +{ + Eina_List *item; + Elm_Code_Token *token; + + char *chr; + unsigned int length, x; + int w, start; + + if (!_elm_code_widget_resize(o)) + return; + + length = strlen(line->content); + evas_object_textgrid_size_get(o, &w, NULL); + + chr = (char *)line->content; + for (x = 0; x < (unsigned int) w && x < length; x++) + { + cells[x].codepoint = *chr; + cells[x].bg = line->status; + + chr++; + } + for (; x < (unsigned int) w; x++) + { + cells[x].codepoint = 0; + cells[x].bg = line->status; + } + + start = 1; + + EINA_LIST_FOREACH(line->tokens, item, token) + { + + _elm_code_widget_fill_line_token(cells, w, start, token->start, ELM_CODE_TOKEN_TYPE_DEFAULT); + + // TODO handle a token starting before the previous finishes + _elm_code_widget_fill_line_token(cells, w, token->start, token->end, token->type); + + start = token->end + 1; + } + + _elm_code_widget_fill_line_token(cells, w, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); + + evas_object_textgrid_update_add(o, 0, line->number - 1, w, 1); +} + +EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code) +{ + Elm_Code_Line *line; + Evas_Textgrid_Cell *cells; + int w, h; + unsigned int y; + + if (!_elm_code_widget_resize(o)) + return; evas_object_textgrid_size_get(o, &w, &h); for (y = 1; y <= (unsigned int) h && y <= elm_code_file_lines_get(code->file); y++) { line = elm_code_file_line_get(code->file, y); - content = elm_code_file_line_content_get(code->file, y); - chr = (char *)content; cells = evas_object_textgrid_cellrow_get(o, y - 1); - length = strlen(content); - - for (x = 0; x < (unsigned int) w && x < length; x++) - { - cells[x].codepoint = *chr; - cells[x].bg = line->status; - cells[x].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; - - chr++; - } - for (; x < (unsigned int) w; x++) - { - cells[x].codepoint = 0; - cells[x].bg = line->status; - cells[x].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; - } + _elm_code_widget_fill_line(o, cells, line); } - - evas_object_textgrid_update_add(o, 0, 0, w, h); } static Eina_Bool @@ -61,34 +106,13 @@ _elm_code_widget_line_cb(void *data EINA_UNUSED, Eo *obj, Evas_Object *o; Evas_Textgrid_Cell *cells; - char *chr; - unsigned int length, x; - int w; line = (Elm_Code_Line *)event_info; o = (Evas_Object *)obj; cells = evas_object_textgrid_cellrow_get(o, line->number - 1); - length = strlen(line->content); - evas_object_textgrid_size_get(o, &w, NULL); + _elm_code_widget_fill_line(o, cells, line); - chr = (char *)line->content; - for (x = 0; x < (unsigned int) w && x < length; x++) - { - cells[x].codepoint = *chr; - cells[x].bg = line->status; - cells[x].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; - - chr++; - } - for (; x < (unsigned int) w; x++) - { - cells[x].codepoint = 0; - cells[x].bg = line->status; - cells[x].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; - } - - evas_object_textgrid_update_add(o, 0, line->number - 1, w, 1); return EINA_TRUE; } @@ -114,6 +138,7 @@ _elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, Elm_Code *code; code = (Elm_Code *)data; + elm_code_widget_fill(obj, code); } @@ -141,6 +166,8 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) // setup token colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT, 205, 205, 205, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_COMMENT, + 54, 205, 255, 255); evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code); diff --git a/legacy/elm_code/tests/elm_code_file_test_memory.c b/legacy/elm_code/tests/elm_code_file_test_memory.c index aa31649d6e..21d2ce54b5 100644 --- a/legacy/elm_code/tests/elm_code_file_test_memory.c +++ b/legacy/elm_code/tests/elm_code_file_test_memory.c @@ -18,8 +18,25 @@ START_TEST (elm_code_file_memory_lines) } END_TEST +START_TEST (elm_code_file_memory_tokens) +{ + Elm_Code_File *file; + Elm_Code_Line *line; + + file = elm_code_file_new(); + + elm_code_file_line_append(file, "a line"); + elm_code_file_line_token_add(file, 1, 2, 5, ELM_CODE_TOKEN_TYPE_COMMENT); + + line = elm_code_file_line_get(file, 1); + ck_assert_uint_eq(1, eina_list_count(line->tokens)); + elm_code_file_free(file); +} +END_TEST + void elm_code_file_test_memory(TCase *tc) { tcase_add_test(tc, elm_code_file_memory_lines); + tcase_add_test(tc, elm_code_file_memory_tokens); } From d568992493aa2d4850dec1d7527f9954f226fab7 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 13 Nov 2014 21:51:23 +0000 Subject: [PATCH 022/254] A little more markup to the diff example with character add/rem/change highlighting --- legacy/elm_code/bin/elm_code_test_main.c | 4 ++++ legacy/elm_code/lib/elm_code_common.h | 5 +++++ legacy/elm_code/lib/elm_code_widget.c | 15 +++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 40f73bf66c..33ab70cd99 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -71,7 +71,9 @@ _elm_code_test_diff_setup(Evas_Object *parent) elm_code_file_line_append(code->file, "unchanged"); elm_code_file_line_status_set(code->file, 4, ELM_CODE_STATUS_TYPE_REMOVED); + elm_code_file_line_token_add(code->file, 4, 1, 7, ELM_CODE_TOKEN_TYPE_REMOVED); elm_code_file_line_status_set(code->file, 5, ELM_CODE_STATUS_TYPE_CHANGED); + elm_code_file_line_token_add(code->file, 5, 1, 5, ELM_CODE_TOKEN_TYPE_REMOVED); 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); @@ -90,7 +92,9 @@ _elm_code_test_diff_setup(Evas_Object *parent) elm_code_file_line_append(code->file, "unchanged"); elm_code_file_line_status_set(code->file, 2, ELM_CODE_STATUS_TYPE_ADDED); + elm_code_file_line_token_add(code->file, 2, 1, 5, ELM_CODE_TOKEN_TYPE_ADDED); elm_code_file_line_status_set(code->file, 5, ELM_CODE_STATUS_TYPE_CHANGED); + elm_code_file_line_token_add(code->file, 5, 7, 7, ELM_CODE_TOKEN_TYPE_ADDED); 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); diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index e19a6b372c..3e39c7b612 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -23,6 +23,11 @@ typedef enum { ELM_CODE_TOKEN_TYPE_DEFAULT = ELM_CODE_STATUS_TYPE_COUNT, ELM_CODE_TOKEN_TYPE_COMMENT, + + ELM_CODE_TOKEN_TYPE_ADDED, + ELM_CODE_TOKEN_TYPE_REMOVED, + ELM_CODE_TOKEN_TYPE_CHANGED, + ELM_CODE_TOKEN_TYPE_COUNT } Elm_Code_Token_Type; diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 011afdbb57..ce7eb86425 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -152,16 +152,16 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) // setup status colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, - 54, 54, 54, 255); + 36, 36, 36, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ERROR, 205, 54, 54, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ADDED, - 54, 125, 54, 255); + 36, 96, 36, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_REMOVED, - 125, 54, 54, 255); + 96, 36, 36, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CHANGED, - 54, 54, 125, 255); + 36, 36, 96, 255); // setup token colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT, @@ -169,6 +169,13 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_COMMENT, 54, 205, 255, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_ADDED, + 54, 255, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_REMOVED, + 255, 54, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CHANGED, + 54, 54, 255, 255); + evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code); eo_do(o,eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, code)); From dc2e25fbb6473c838bba7398518d3102cd5ce0aa Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 13 Nov 2014 23:26:30 +0000 Subject: [PATCH 023/254] Refactor the widget token parsing so we can put it under test. Add simple test that demonstrates tokens split by space. --- legacy/elm_code/lib/elm_code_widget.c | 39 ++++++++++------- legacy/elm_code/lib/elm_code_widget.h | 1 + legacy/elm_code/tests/Makefile.am | 1 + legacy/elm_code/tests/elm_code_suite.c | 1 + legacy/elm_code/tests/elm_code_suite.h | 1 + legacy/elm_code/tests/elm_code_test_widget.c | 44 ++++++++++++++++++++ 6 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 legacy/elm_code/tests/elm_code_test_widget.c diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index ce7eb86425..32e00de873 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -31,14 +31,34 @@ static void _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int coun } } -static void _elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) +EAPI void elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, int count, Elm_Code_Line *line) { Eina_List *item; Elm_Code_Token *token; + int start, length; + start = 1; + length = strlen(line->content); + + EINA_LIST_FOREACH(line->tokens, item, token) + { + + _elm_code_widget_fill_line_token(cells, count, start, token->start, ELM_CODE_TOKEN_TYPE_DEFAULT); + + // TODO handle a token starting before the previous finishes + _elm_code_widget_fill_line_token(cells, count, token->start, token->end, token->type); + + start = token->end + 1; + } + + _elm_code_widget_fill_line_token(cells, count, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); +} + +static void _elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) +{ char *chr; unsigned int length, x; - int w, start; + int w; if (!_elm_code_widget_resize(o)) return; @@ -60,20 +80,7 @@ static void _elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells cells[x].bg = line->status; } - start = 1; - - EINA_LIST_FOREACH(line->tokens, item, token) - { - - _elm_code_widget_fill_line_token(cells, w, start, token->start, ELM_CODE_TOKEN_TYPE_DEFAULT); - - // TODO handle a token starting before the previous finishes - _elm_code_widget_fill_line_token(cells, w, token->start, token->end, token->type); - - start = token->end + 1; - } - - _elm_code_widget_fill_line_token(cells, w, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); + elm_code_widget_fill_line_tokens(cells, w, line); evas_object_textgrid_update_add(o, 0, line->number - 1, w, 1); } diff --git a/legacy/elm_code/lib/elm_code_widget.h b/legacy/elm_code/lib/elm_code_widget.h index dda5df8f4a..8c2bf77a6b 100644 --- a/legacy/elm_code/lib/elm_code_widget.h +++ b/legacy/elm_code/lib/elm_code_widget.h @@ -27,6 +27,7 @@ extern "C" { EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code); EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code); +EAPI void elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, int count, Elm_Code_Line *line); /** * @} diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/tests/Makefile.am index aa71521987..75ae85cd88 100644 --- a/legacy/elm_code/tests/Makefile.am +++ b/legacy/elm_code/tests/Makefile.am @@ -7,6 +7,7 @@ elm_code_suite_SOURCES = \ elm_code_file_test_load.c \ elm_code_file_test_memory.c \ elm_code_test_basic.c \ +elm_code_test_widget.c \ elm_code_suite.c elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/lib/ \ diff --git a/legacy/elm_code/tests/elm_code_suite.c b/legacy/elm_code/tests/elm_code_suite.c index 1f525210ae..1d9763bdc4 100644 --- a/legacy/elm_code/tests/elm_code_suite.c +++ b/legacy/elm_code/tests/elm_code_suite.c @@ -15,6 +15,7 @@ static const struct { } tests[] = { { "file_load", elm_code_file_test_load }, { "file_memory", elm_code_file_test_memory }, + { "widget", elm_code_test_widget }, { "basic", elm_code_test_basic }, }; diff --git a/legacy/elm_code/tests/elm_code_suite.h b/legacy/elm_code/tests/elm_code_suite.h index b9d1bdf0fb..bc2cc89f22 100644 --- a/legacy/elm_code/tests/elm_code_suite.h +++ b/legacy/elm_code/tests/elm_code_suite.h @@ -7,6 +7,7 @@ void elm_code_file_test_load(TCase *tc); void elm_code_file_test_memory(TCase *tc); +void elm_code_test_widget(TCase *tc); void elm_code_test_basic(TCase *tc); #endif /* _EDLM_CODE_SUITE_H */ diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/tests/elm_code_test_widget.c new file mode 100644 index 0000000000..77bedd1266 --- /dev/null +++ b/legacy/elm_code/tests/elm_code_test_widget.c @@ -0,0 +1,44 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "elm_code_suite.h" + +static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type) +{ + ck_assert(cell.fg == type); +} + +START_TEST (elm_code_widget_token_render_simple_test) +{ + Elm_Code_File *file; + Elm_Code_Line *line; + int length; + + Evas_Textgrid_Cell cells[25]; + + file = elm_code_file_new(); + elm_code_file_line_append(file, "some \"test content\", 45"); + line = elm_code_file_line_get(file, 1); + length = strlen(line->content); + + elm_code_file_line_token_add(file, 1, 6+1, 18+1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_file_line_token_add(file, 1, 22+1, 23+1, ELM_CODE_TOKEN_TYPE_COMMENT); + + elm_code_widget_fill_line_tokens(cells, length, line); + _assert_cell_type(cells[0], ELM_CODE_TOKEN_TYPE_DEFAULT); + _assert_cell_type(cells[3], ELM_CODE_TOKEN_TYPE_DEFAULT); + _assert_cell_type(cells[5], ELM_CODE_TOKEN_TYPE_DEFAULT); + _assert_cell_type(cells[15], ELM_CODE_TOKEN_TYPE_COMMENT); + _assert_cell_type(cells[19], ELM_CODE_TOKEN_TYPE_DEFAULT); + _assert_cell_type(cells[22], ELM_CODE_TOKEN_TYPE_COMMENT); + + elm_code_file_free(file); +} +END_TEST + +void elm_code_test_widget(TCase *tc) +{ + tcase_add_test(tc, elm_code_widget_token_render_simple_test); +} + From 649c98a53b7a569ba98d174d115980fe28feb0a5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 16 Nov 2014 23:52:41 +0000 Subject: [PATCH 024/254] Add parse hooks for lines and files within elm_code. This required changing the load order so file opens would read the elm_code->parsers setup. This makes for a better setup anyhow --- legacy/elm_code/bin/elm_code_test_main.c | 9 ++- legacy/elm_code/lib/Elm_Code.h | 7 +- legacy/elm_code/lib/Makefile.am | 2 + legacy/elm_code/lib/elm_code.c | 14 ++-- legacy/elm_code/lib/elm_code_common.h | 7 +- legacy/elm_code/lib/elm_code_file.c | 21 ++++-- legacy/elm_code/lib/elm_code_file.h | 4 +- legacy/elm_code/lib/elm_code_parse.c | 47 +++++++++++++ legacy/elm_code/lib/elm_code_parse.h | 49 +++++++++++++ legacy/elm_code/tests/Makefile.am | 1 + .../elm_code/tests/elm_code_file_test_load.c | 20 ++++-- .../tests/elm_code_file_test_memory.c | 12 ++-- legacy/elm_code/tests/elm_code_suite.c | 3 +- legacy/elm_code/tests/elm_code_suite.h | 3 +- legacy/elm_code/tests/elm_code_test_basic.c | 5 +- legacy/elm_code/tests/elm_code_test_parse.c | 68 +++++++++++++++++++ legacy/elm_code/tests/elm_code_test_widget.c | 6 +- 17 files changed, 241 insertions(+), 37 deletions(-) create mode 100644 legacy/elm_code/lib/elm_code_parse.c create mode 100644 legacy/elm_code/lib/elm_code_parse.h create mode 100644 legacy/elm_code/tests/elm_code_test_parse.c diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 33ab70cd99..95a52143a3 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -29,7 +29,8 @@ _elm_code_test_welcome_setup(Evas_Object *parent) Elm_Code *code; Evas_Object *widget; - code = elm_code_create(elm_code_file_new()); + code = elm_code_create(); + elm_code_file_new(code); widget = elm_code_widget_add(parent, code); elm_code_file_line_append(code->file, "Hello World, Elm Code!"); elm_code_file_line_token_add(code->file, 1, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); @@ -60,7 +61,8 @@ _elm_code_test_diff_setup(Evas_Object *parent) evas_object_show(hbox); // left side of diff - code = elm_code_create(elm_code_file_new()); + code = elm_code_create(); + elm_code_file_new(code); widget = elm_code_widget_add(parent, code); elm_code_file_line_append(code->file, "Some content to diff"); @@ -81,7 +83,8 @@ _elm_code_test_diff_setup(Evas_Object *parent) elm_box_pack_end(hbox, widget); // right side of diff - code = elm_code_create(elm_code_file_new()); + code = elm_code_create(); + elm_code_file_new(code); widget = elm_code_widget_add(parent, code); elm_code_file_line_append(code->file, "Some content to diff"); diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index fbc0a4b2f6..3ed59fb343 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -91,14 +91,15 @@ EAPI int elm_code_init(void); EAPI int elm_code_shutdown(void); /** - * Create a new Elm Code instance for an existing file + * Create a new Elm Code instance * - * This method creates a new Elm Code instance backing to the specified file. + * This method creates a new Elm Code instance which will need a + * backing file set for storage. * 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 */ -EAPI Elm_Code *elm_code_create(Elm_Code_File *file); +EAPI Elm_Code *elm_code_create(); /** * Free an Elm Code instance diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am index 8329e65091..5339cc58a0 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/lib/Makefile.am @@ -13,12 +13,14 @@ lib_LTLIBRARIES = libelm_code.la includes_HEADERS = \ elm_code_file.h \ +elm_code_parse.h \ elm_code_widget.h \ Elm_Code.h includesdir = $(includedir)/edi-@VMAJ@ libelm_code_la_SOURCES = \ elm_code_file.c \ +elm_code_parse.c \ elm_code_widget.c \ elm_code.c libelm_code_la_LIBADD = @EFL_LIBS@ -lm diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index fb40c9f34b..bd4a148706 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -5,6 +5,7 @@ #include #include "Elm_Code.h" +#include "elm_code_parse.h" #include "elm_code_private.h" @@ -65,13 +66,11 @@ elm_code_shutdown(void) } EAPI Elm_Code * -elm_code_create(Elm_Code_File *file) +elm_code_create() { Elm_Code *ret; ret = calloc(1, sizeof(Elm_Code)); - ret->file = file; - file->parent = ret; return ret; } @@ -79,18 +78,23 @@ elm_code_create(Elm_Code_File *file) EAPI void elm_code_free(Elm_Code *code) { - Eina_List *item; Evas_Object *widget; + Elm_Code_Parser *parser; if (code->file) elm_code_file_free(code->file); - EINA_LIST_FOREACH(code->widgets, item, widget) + EINA_LIST_FREE(code->widgets, widget) { evas_object_hide(widget); evas_object_del(widget); } + EINA_LIST_FREE(code->parsers, parser) + { + free(parser); + } + free(code); } diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index 3e39c7b612..3dc00ede53 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -4,6 +4,8 @@ #include #include +typedef struct _Elm_Code Elm_Code; + EAPI extern const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE; EAPI extern const Eo_Event_Description ELM_CODE_EVENT_FILE_LOAD_DONE; @@ -44,11 +46,12 @@ extern "C" { * @brief Common data structures and constants. */ -typedef struct _Elm_Code +struct _Elm_Code { Elm_Code_File *file; Eina_List *widgets; -} Elm_Code; + Eina_List *parsers; +}; /** * @} diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c index e649b2858b..07ae9e2f28 100644 --- a/legacy/elm_code/lib/elm_code_file.c +++ b/legacy/elm_code/lib/elm_code_file.c @@ -4,6 +4,7 @@ #include "Elm_Code.h" #include "elm_code_file.h" +#include "elm_code_parse.h" #include "elm_code_private.h" @@ -33,19 +34,24 @@ static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *con file->lines = eina_list_append(file->lines, line); if (file->parent) - elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_SET_DONE, line); + { + elm_code_parse_line(file->parent, line); + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_SET_DONE, line); + } } -EAPI Elm_Code_File *elm_code_file_new() +EAPI Elm_Code_File *elm_code_file_new(Elm_Code *code) { Elm_Code_File *ret; ret = calloc(1, sizeof(Elm_Code_File)); + code->file = ret; + ret->parent = code; return ret; } -EAPI Elm_Code_File *elm_code_file_open(const char *path) +EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) { Elm_Code_File *ret; Eina_File *file; @@ -53,7 +59,7 @@ EAPI Elm_Code_File *elm_code_file_open(const char *path) Eina_Iterator *it; unsigned int lastindex; - ret = elm_code_file_new(); + ret = elm_code_file_new(code); file = eina_file_open(path, EINA_FALSE); ret->file = file; lastindex = 1; @@ -77,7 +83,10 @@ EAPI Elm_Code_File *elm_code_file_open(const char *path) eina_iterator_free(it); if (ret->parent) - elm_code_callback_fire(ret->parent, &ELM_CODE_EVENT_FILE_LOAD_DONE, ret); + { + elm_code_parse_file(ret->parent, ret); + elm_code_callback_fire(ret->parent, &ELM_CODE_EVENT_FILE_LOAD_DONE, ret); + } return ret; } @@ -98,8 +107,6 @@ EAPI void elm_code_file_free(Elm_Code_File *file) EAPI void elm_code_file_close(Elm_Code_File *file) { eina_file_close(file->file); - - elm_code_file_free(file); } EAPI const char *elm_code_file_filename_get(Elm_Code_File *file) diff --git a/legacy/elm_code/lib/elm_code_file.h b/legacy/elm_code/lib/elm_code_file.h index 0950ed96aa..19a47258be 100644 --- a/legacy/elm_code/lib/elm_code_file.h +++ b/legacy/elm_code/lib/elm_code_file.h @@ -52,9 +52,9 @@ typedef struct _Elm_Code_File * */ -EAPI Elm_Code_File *elm_code_file_new(); +EAPI Elm_Code_File *elm_code_file_new(Elm_Code *code); -EAPI Elm_Code_File *elm_code_file_open(const char *path); +EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path); EAPI void elm_code_file_free(Elm_Code_File *file); diff --git a/legacy/elm_code/lib/elm_code_parse.c b/legacy/elm_code/lib/elm_code_parse.c new file mode 100644 index 0000000000..2b1ddc28fa --- /dev/null +++ b/legacy/elm_code/lib/elm_code_parse.c @@ -0,0 +1,47 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include "Elm_Code.h" +#include "elm_code_parse.h" + +#include "elm_code_private.h" + +EAPI void elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line) +{ + Elm_Code_Parser *parser; + Eina_List *item; + + EINA_LIST_FOREACH(code->parsers, item, parser) + { + parser->parse_line(line); + } +} + +EAPI void elm_code_parse_file(Elm_Code *code, Elm_Code_File *file) +{ + Elm_Code_Parser *parser; + Eina_List *item; + + EINA_LIST_FOREACH(code->parsers, item, parser) + { + parser->parse_file(file); + } +} + +EAPI void elm_code_parser_add(Elm_Code *code, + void (*parse_line)(Elm_Code_Line *), + void (*parse_file)(Elm_Code_File *)) +{ + Elm_Code_Parser *parser; + + parser = calloc(1, sizeof(Elm_Code_Parser)); + if (!parser) + return; + + parser->parse_line = parse_line; + parser->parse_file = parse_file; + + code->parsers = eina_list_append(code->parsers, parser); +} + diff --git a/legacy/elm_code/lib/elm_code_parse.h b/legacy/elm_code/lib/elm_code_parse.h new file mode 100644 index 0000000000..ab50c3419b --- /dev/null +++ b/legacy/elm_code/lib/elm_code_parse.h @@ -0,0 +1,49 @@ +#ifndef ELM_CODE_PARSE_H_ +# define ELM_CODE_PARSE_H_ + +#include + +#include "elm_code_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for handling the parsing of Elm Code content. + */ + +typedef struct _Elm_Code_Parser +{ + void (*parse_line)(Elm_Code_Line *); + + void (*parse_file)(Elm_Code_File *); +} Elm_Code_Parser; + +/** + * @brief Parser helper functions. + * @defgroup Parser Hooking in and launching parsers + * + * @{ + * + * Parser functions for marking up elm code. + * + */ + +EAPI void elm_code_parser_add(Elm_Code *code, void (*parse_line)(Elm_Code_Line *), + void (*parse_file)(Elm_Code_File *)); + +EAPI void elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line); + +EAPI void elm_code_parse_file(Elm_Code *code, Elm_Code_File *file); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ELM_CODE_PARSE_H_ */ diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/tests/Makefile.am index 75ae85cd88..d1edb30027 100644 --- a/legacy/elm_code/tests/Makefile.am +++ b/legacy/elm_code/tests/Makefile.am @@ -7,6 +7,7 @@ elm_code_suite_SOURCES = \ elm_code_file_test_load.c \ elm_code_file_test_memory.c \ elm_code_test_basic.c \ +elm_code_test_parse.c \ elm_code_test_widget.c \ elm_code_suite.c diff --git a/legacy/elm_code/tests/elm_code_file_test_load.c b/legacy/elm_code/tests/elm_code_file_test_load.c index ff41d24666..ad7dc38b34 100644 --- a/legacy/elm_code/tests/elm_code_file_test_load.c +++ b/legacy/elm_code/tests/elm_code_file_test_load.c @@ -9,13 +9,16 @@ START_TEST (elm_code_file_load) char *path = "elm_code/tests/testfile.txt"; char real[EINA_PATH_MAX]; Elm_Code_File *file; + Elm_Code *code; - file = elm_code_file_open(path); + code = elm_code_create(); + file = elm_code_file_open(code, path); realpath(path, real); ck_assert_str_eq(basename(path), elm_code_file_filename_get(file)); ck_assert_str_eq(real, elm_code_file_path_get(file)); elm_code_file_close(file); + elm_code_free(code); } END_TEST @@ -23,11 +26,14 @@ START_TEST (elm_code_file_load_lines) { char *path = "elm_code/tests/testfile.txt"; Elm_Code_File *file; + Elm_Code *code; - file = elm_code_file_open(path); + code = elm_code_create(); + file = elm_code_file_open(code, path); ck_assert_uint_eq(4, elm_code_file_lines_get(file)); elm_code_file_close(file); + elm_code_free(code); } END_TEST @@ -35,11 +41,14 @@ START_TEST (elm_code_file_load_blank_lines) { char *path = "elm_code/tests/testfile-withblanks.txt"; Elm_Code_File *file; + Elm_Code *code; - file = elm_code_file_open(path); + code = elm_code_create(); + file = elm_code_file_open(code, path); ck_assert_uint_eq(8, elm_code_file_lines_get(file)); elm_code_file_close(file); + elm_code_free(code); } END_TEST @@ -47,12 +56,15 @@ START_TEST (elm_code_file_load_content) { char *path = "elm_code/tests/testfile.txt"; Elm_Code_File *file; + Elm_Code *code; - file = elm_code_file_open(path); + code = elm_code_create(); + file = elm_code_file_open(code, path); ck_assert_str_eq("line2", elm_code_file_line_content_get(file, 2)); ck_assert_str_eq("another line", elm_code_file_line_content_get(file, 4)); elm_code_file_close(file); + elm_code_free(code); } END_TEST diff --git a/legacy/elm_code/tests/elm_code_file_test_memory.c b/legacy/elm_code/tests/elm_code_file_test_memory.c index 21d2ce54b5..b3598682e0 100644 --- a/legacy/elm_code/tests/elm_code_file_test_memory.c +++ b/legacy/elm_code/tests/elm_code_file_test_memory.c @@ -7,14 +7,16 @@ START_TEST (elm_code_file_memory_lines) { Elm_Code_File *file; + Elm_Code *code; - file = elm_code_file_new(); + code = elm_code_create(); + file = elm_code_file_new(code); ck_assert_uint_eq(0, elm_code_file_lines_get(file)); elm_code_file_line_append(file, "a line"); ck_assert_uint_eq(1, elm_code_file_lines_get(file)); - elm_code_file_free(file); + elm_code_free(code); } END_TEST @@ -22,15 +24,17 @@ START_TEST (elm_code_file_memory_tokens) { Elm_Code_File *file; Elm_Code_Line *line; + Elm_Code *code; - file = elm_code_file_new(); + code = elm_code_create(); + file = elm_code_file_new(code); elm_code_file_line_append(file, "a line"); elm_code_file_line_token_add(file, 1, 2, 5, ELM_CODE_TOKEN_TYPE_COMMENT); line = elm_code_file_line_get(file, 1); ck_assert_uint_eq(1, eina_list_count(line->tokens)); - elm_code_file_free(file); + elm_code_free(code); } END_TEST diff --git a/legacy/elm_code/tests/elm_code_suite.c b/legacy/elm_code/tests/elm_code_suite.c index 1d9763bdc4..e2250cd591 100644 --- a/legacy/elm_code/tests/elm_code_suite.c +++ b/legacy/elm_code/tests/elm_code_suite.c @@ -15,8 +15,9 @@ static const struct { } tests[] = { { "file_load", elm_code_file_test_load }, { "file_memory", elm_code_file_test_memory }, - { "widget", elm_code_test_widget }, + { "parse", elm_code_test_parse }, { "basic", elm_code_test_basic }, + { "widget", elm_code_test_widget }, }; START_TEST(elm_code_initialization) diff --git a/legacy/elm_code/tests/elm_code_suite.h b/legacy/elm_code/tests/elm_code_suite.h index bc2cc89f22..58d6317dcc 100644 --- a/legacy/elm_code/tests/elm_code_suite.h +++ b/legacy/elm_code/tests/elm_code_suite.h @@ -7,7 +7,8 @@ void elm_code_file_test_load(TCase *tc); void elm_code_file_test_memory(TCase *tc); -void elm_code_test_widget(TCase *tc); void elm_code_test_basic(TCase *tc); +void elm_code_test_parse(TCase *tc); +void elm_code_test_widget(TCase *tc); #endif /* _EDLM_CODE_SUITE_H */ diff --git a/legacy/elm_code/tests/elm_code_test_basic.c b/legacy/elm_code/tests/elm_code_test_basic.c index f127cfb0a6..81a34bbe60 100644 --- a/legacy/elm_code/tests/elm_code_test_basic.c +++ b/legacy/elm_code/tests/elm_code_test_basic.c @@ -7,11 +7,10 @@ START_TEST (elm_code_create_test) { char *path = "elm_code/tests/testfile.txt"; - Elm_Code_File *file; Elm_Code *code; - file = elm_code_file_open(path); - code = elm_code_create(file); + code = elm_code_create(); + elm_code_file_open(code, path); ck_assert(code); elm_code_free(code); diff --git a/legacy/elm_code/tests/elm_code_test_parse.c b/legacy/elm_code/tests/elm_code_test_parse.c new file mode 100644 index 0000000000..3c4868e771 --- /dev/null +++ b/legacy/elm_code/tests/elm_code_test_parse.c @@ -0,0 +1,68 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "elm_code_suite.h" +#include "elm_code_parse.h" + +static int line_calls, file_calls; + +static void _parser_line_callback(Elm_Code_Line *line EINA_UNUSED) +{ + line_calls++; +} + +static void _parser_file_callback(Elm_Code_File *file EINA_UNUSED) +{ + file_calls++; +} + +START_TEST (elm_code_parse_hook_memory_test) +{ + Elm_Code *code; + Elm_Code_File *file; + + line_calls = 0; + file_calls = 0; + + code = elm_code_create(); + file = elm_code_file_new(code); + + elm_code_parser_add(code, _parser_line_callback, _parser_file_callback); + elm_code_file_line_append(file, "some \"test content\" for parsing"); + + ck_assert_int_eq(1, line_calls); + ck_assert_int_eq(0, file_calls); + + elm_code_free(code); +} +END_TEST + +START_TEST (elm_code_parse_hook_file_test) +{ + Elm_Code *code; + Elm_Code_File *file; + char *path = "elm_code/tests/testfile.txt"; + + line_calls = 0; + file_calls = 0; + + code = elm_code_create(); + + elm_code_parser_add(code, _parser_line_callback, _parser_file_callback); + file = elm_code_file_open(code, path); + + ck_assert_int_eq(4, line_calls); + ck_assert_int_eq(1, file_calls); + + elm_code_file_close(file); + elm_code_free(code); +} +END_TEST + +void elm_code_test_parse(TCase *tc) +{ + tcase_add_test(tc, elm_code_parse_hook_memory_test); + tcase_add_test(tc, elm_code_parse_hook_file_test); +} + diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/tests/elm_code_test_widget.c index 77bedd1266..27b867e567 100644 --- a/legacy/elm_code/tests/elm_code_test_widget.c +++ b/legacy/elm_code/tests/elm_code_test_widget.c @@ -13,11 +13,13 @@ START_TEST (elm_code_widget_token_render_simple_test) { Elm_Code_File *file; Elm_Code_Line *line; + Elm_Code *code; int length; Evas_Textgrid_Cell cells[25]; - file = elm_code_file_new(); + code = elm_code_create(); + file = elm_code_file_new(code); elm_code_file_line_append(file, "some \"test content\", 45"); line = elm_code_file_line_get(file, 1); length = strlen(line->content); @@ -33,7 +35,7 @@ START_TEST (elm_code_widget_token_render_simple_test) _assert_cell_type(cells[19], ELM_CODE_TOKEN_TYPE_DEFAULT); _assert_cell_type(cells[22], ELM_CODE_TOKEN_TYPE_COMMENT); - elm_code_file_free(file); + elm_code_free(code); } END_TEST From 229913041030d93bd3ebde5aa8ef848b517afd95 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 18 Nov 2014 20:56:47 +0000 Subject: [PATCH 025/254] Fix crash when appending a line off and the body is already larger than the viewport --- legacy/elm_code/lib/elm_code_widget.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 32e00de873..ba096e44a1 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -111,12 +111,18 @@ _elm_code_widget_line_cb(void *data EINA_UNUSED, Eo *obj, { Elm_Code_Line *line; Evas_Object *o; + int h; Evas_Textgrid_Cell *cells; line = (Elm_Code_Line *)event_info; o = (Evas_Object *)obj; + evas_object_textgrid_size_get(o, NULL, &h); + + if (line->number > (unsigned int) h) + return EINA_TRUE; + cells = evas_object_textgrid_cellrow_get(o, line->number - 1); _elm_code_widget_fill_line(o, cells, line); From 62fd0bb3f70fc9b4a2b96363389f749e50d193a5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 18 Nov 2014 21:11:10 +0000 Subject: [PATCH 026/254] Add tests PASSED and FAILED to elm_code statuses and the widget rendering. Use this in EDI to add a test summarising panel. Tests are executed in verbose mode so we can list all the tests that have been run - can summarise later if we wish... --- legacy/elm_code/lib/Elm_Code.h | 1 + legacy/elm_code/lib/elm_code_common.h | 3 +++ legacy/elm_code/lib/elm_code_file.c | 15 +++++++++++++++ legacy/elm_code/lib/elm_code_file.h | 2 ++ legacy/elm_code/lib/elm_code_widget.c | 5 +++++ 5 files changed, 26 insertions(+) diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 3ed59fb343..eadf59da44 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -7,6 +7,7 @@ #include #include +#include #include #ifdef EAPI diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index 3dc00ede53..79f5d6c12c 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -17,6 +17,9 @@ typedef enum { ELM_CODE_STATUS_TYPE_REMOVED, ELM_CODE_STATUS_TYPE_CHANGED, + ELM_CODE_STATUS_TYPE_PASSED, + ELM_CODE_STATUS_TYPE_FAILED, + ELM_CODE_STATUS_TYPE_COUNT } Elm_Code_Status_Type; diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c index 07ae9e2f28..e2d9daae56 100644 --- a/legacy/elm_code/lib/elm_code_file.c +++ b/legacy/elm_code/lib/elm_code_file.c @@ -119,6 +119,21 @@ EAPI const char *elm_code_file_path_get(Elm_Code_File *file) return eina_file_filename_get(file->file); } +EAPI void elm_code_file_clear(Elm_Code_File *file) +{ + Elm_Code_Line *l; + + EINA_LIST_FREE(file->lines, l) + { + if (l->content) + free(l->content); + free(l); + } + + if (file->parent) + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_FILE_LOAD_DONE, file); +} + EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file) { return eina_list_count(file->lines); diff --git a/legacy/elm_code/lib/elm_code_file.h b/legacy/elm_code/lib/elm_code_file.h index 19a47258be..c3ebfb9893 100644 --- a/legacy/elm_code/lib/elm_code_file.h +++ b/legacy/elm_code/lib/elm_code_file.h @@ -76,6 +76,8 @@ EAPI const char *elm_code_file_path_get(Elm_Code_File *file); * */ +EAPI void elm_code_file_clear(Elm_Code_File *file); + EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file); EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line); diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index ba096e44a1..e555468c56 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -176,6 +176,11 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CHANGED, 36, 36, 96, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_PASSED, + 54, 96, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FAILED, + 96, 54, 54, 255); + // setup token colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT, 205, 205, 205, 255); From 147a7ddd391158528442ca293aabd4fd3161abd4 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 18 Nov 2014 22:48:37 +0000 Subject: [PATCH 027/254] Add some text mode icons to markup the lines for now --- legacy/elm_code/lib/elm_code_widget.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index e555468c56..9d441638a2 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -9,6 +9,20 @@ #include "elm_code_private.h" +Eina_Unicode status_icons[] = { + ' ', + '!', + + '+', + '-', + ' ', + + 0x2713, + 0x2717, + + 0 +}; + static Eina_Bool _elm_code_widget_resize(Evas_Object *o) { int w, h, cw, ch; @@ -25,7 +39,7 @@ static void _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int coun { int x; - for (x = start - 1; x < end && x < count; x++) + for (x = start; x <= end && x < count; x++) { cells[x].fg = type; } @@ -66,8 +80,13 @@ static void _elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells length = strlen(line->content); evas_object_textgrid_size_get(o, &w, NULL); + cells[0].codepoint = status_icons[line->status]; + cells[0].bold = 1; + cells[0].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; + cells[0].bg = line->status; + chr = (char *)line->content; - for (x = 0; x < (unsigned int) w && x < length; x++) + for (x = 1; x < (unsigned int) w && x <= length; x++) { cells[x].codepoint = *chr; cells[x].bg = line->status; From ad14b512514ecb00d2016407ed54883db6133b81 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 18 Nov 2014 23:46:24 +0000 Subject: [PATCH 028/254] Fix render test and an end of line corner case --- legacy/elm_code/lib/elm_code_widget.c | 2 +- legacy/elm_code/tests/elm_code_test_widget.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 9d441638a2..572fd3a351 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -39,7 +39,7 @@ static void _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int coun { int x; - for (x = start; x <= end && x < count; x++) + for (x = start; x <= end && x <= count; x++) { cells[x].fg = type; } diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/tests/elm_code_test_widget.c index 27b867e567..9f499acba8 100644 --- a/legacy/elm_code/tests/elm_code_test_widget.c +++ b/legacy/elm_code/tests/elm_code_test_widget.c @@ -28,12 +28,12 @@ START_TEST (elm_code_widget_token_render_simple_test) elm_code_file_line_token_add(file, 1, 22+1, 23+1, ELM_CODE_TOKEN_TYPE_COMMENT); elm_code_widget_fill_line_tokens(cells, length, line); - _assert_cell_type(cells[0], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[3], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[5], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[15], ELM_CODE_TOKEN_TYPE_COMMENT); - _assert_cell_type(cells[19], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[22], ELM_CODE_TOKEN_TYPE_COMMENT); + _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT); + _assert_cell_type(cells[4], ELM_CODE_TOKEN_TYPE_DEFAULT); + _assert_cell_type(cells[6], ELM_CODE_TOKEN_TYPE_DEFAULT); + _assert_cell_type(cells[16], ELM_CODE_TOKEN_TYPE_COMMENT); + _assert_cell_type(cells[20], ELM_CODE_TOKEN_TYPE_DEFAULT); + _assert_cell_type(cells[23], ELM_CODE_TOKEN_TYPE_COMMENT); elm_code_free(code); } From 5f20154258a860ae74df06be27171253346c8fdc Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 18 Nov 2014 23:46:24 +0000 Subject: [PATCH 029/254] Fix render test and an end of line corner case --- legacy/elm_code/lib/elm_code_widget.c | 2 +- legacy/elm_code/tests/elm_code_test_widget.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 9d441638a2..572fd3a351 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -39,7 +39,7 @@ static void _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int coun { int x; - for (x = start; x <= end && x < count; x++) + for (x = start; x <= end && x <= count; x++) { cells[x].fg = type; } diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/tests/elm_code_test_widget.c index 27b867e567..9f499acba8 100644 --- a/legacy/elm_code/tests/elm_code_test_widget.c +++ b/legacy/elm_code/tests/elm_code_test_widget.c @@ -28,12 +28,12 @@ START_TEST (elm_code_widget_token_render_simple_test) elm_code_file_line_token_add(file, 1, 22+1, 23+1, ELM_CODE_TOKEN_TYPE_COMMENT); elm_code_widget_fill_line_tokens(cells, length, line); - _assert_cell_type(cells[0], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[3], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[5], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[15], ELM_CODE_TOKEN_TYPE_COMMENT); - _assert_cell_type(cells[19], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[22], ELM_CODE_TOKEN_TYPE_COMMENT); + _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT); + _assert_cell_type(cells[4], ELM_CODE_TOKEN_TYPE_DEFAULT); + _assert_cell_type(cells[6], ELM_CODE_TOKEN_TYPE_DEFAULT); + _assert_cell_type(cells[16], ELM_CODE_TOKEN_TYPE_COMMENT); + _assert_cell_type(cells[20], ELM_CODE_TOKEN_TYPE_DEFAULT); + _assert_cell_type(cells[23], ELM_CODE_TOKEN_TYPE_COMMENT); elm_code_free(code); } From b5288b42232896caaafa2293285dc6823c70a74b Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 19 Nov 2014 22:35:01 +0000 Subject: [PATCH 030/254] Fix a memory corruption issue on some systems --- legacy/elm_code/lib/elm_code_widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 572fd3a351..9d441638a2 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -39,7 +39,7 @@ static void _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int coun { int x; - for (x = start; x <= end && x <= count; x++) + for (x = start; x <= end && x < count; x++) { cells[x].fg = type; } From aa5b70972c9c0f9924c3931efe05cb3d3b4b19d7 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 19 Nov 2014 22:37:00 +0000 Subject: [PATCH 031/254] Fix minor issues I saw in passing --- legacy/elm_code/bin/elm_code_test_main.c | 2 +- legacy/elm_code/lib/elm_code.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 95a52143a3..be8887474e 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -113,7 +113,7 @@ elm_code_test_win_setup(void) Evas_Object *win; Evas_Object *vbox; - win = elm_win_util_standard_add("main", "Elm_code_test"); + win = elm_win_util_standard_add("main", "Elm_Code Test"); if (!win) return NULL; vbox = elm_box_add(win); diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index bd4a148706..1c04f53947 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -15,7 +15,7 @@ int _elm_code_lib_log_dom = -1; const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE = EO_EVENT_DESCRIPTION("line,set,done", ""); const Eo_Event_Description ELM_CODE_EVENT_FILE_LOAD_DONE = - EO_EVENT_DESCRIPTION("file, load,done", ""); + EO_EVENT_DESCRIPTION("file,load,done", ""); EAPI int elm_code_init(void) From 65b67ec898772f9ecac90141426c0fbcdfd4e102 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 19 Nov 2014 22:39:00 +0000 Subject: [PATCH 032/254] Actually use the eina_file memory mapping Any appended or modified lines need to be stored seperately. Always check for modified content before using the memory map from the backing file. --- legacy/elm_code/bin/elm_code_test_main.c | 40 +++++++++------- legacy/elm_code/lib/elm_code_file.c | 47 ++++++++++++++----- legacy/elm_code/lib/elm_code_file.h | 9 ++-- legacy/elm_code/lib/elm_code_widget.c | 9 ++-- .../elm_code/tests/elm_code_file_test_load.c | 16 ++++++- .../tests/elm_code_file_test_memory.c | 4 +- legacy/elm_code/tests/elm_code_test_parse.c | 2 +- legacy/elm_code/tests/elm_code_test_widget.c | 2 +- 8 files changed, 89 insertions(+), 40 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index be8887474e..9654b93101 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -23,6 +23,14 @@ _elm_code_test_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi 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); +} + static Evas_Object * _elm_code_test_welcome_setup(Evas_Object *parent) { @@ -32,12 +40,12 @@ _elm_code_test_welcome_setup(Evas_Object *parent) code = elm_code_create(); elm_code_file_new(code); widget = elm_code_widget_add(parent, code); - elm_code_file_line_append(code->file, "Hello World, Elm Code!"); + _append_line(code->file, "Hello World, Elm Code!"); elm_code_file_line_token_add(code->file, 1, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); - elm_code_file_line_append(code->file, ""); - elm_code_file_line_append(code->file, "This is a demo of elm_code's capabilities."); + _append_line(code->file, ""); + _append_line(code->file, "This is a demo of elm_code's capabilities."); - elm_code_file_line_append(code->file, "*** Currently experimental ***"); + _append_line(code->file, "*** Currently experimental ***"); elm_code_file_line_status_set(code->file, 4, ELM_CODE_STATUS_TYPE_ERROR); evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -65,12 +73,12 @@ _elm_code_test_diff_setup(Evas_Object *parent) elm_code_file_new(code); widget = elm_code_widget_add(parent, code); - elm_code_file_line_append(code->file, "Some content to diff"); - elm_code_file_line_append(code->file, ""); - elm_code_file_line_append(code->file, "more"); - elm_code_file_line_append(code->file, "removed"); - elm_code_file_line_append(code->file, "will change"); - elm_code_file_line_append(code->file, "unchanged"); + _append_line(code->file, "Some content to diff"); + _append_line(code->file, ""); + _append_line(code->file, "more"); + _append_line(code->file, "removed"); + _append_line(code->file, "will change"); + _append_line(code->file, "unchanged"); elm_code_file_line_status_set(code->file, 4, ELM_CODE_STATUS_TYPE_REMOVED); elm_code_file_line_token_add(code->file, 4, 1, 7, ELM_CODE_TOKEN_TYPE_REMOVED); @@ -87,12 +95,12 @@ _elm_code_test_diff_setup(Evas_Object *parent) elm_code_file_new(code); widget = elm_code_widget_add(parent, code); - elm_code_file_line_append(code->file, "Some content to diff"); - elm_code_file_line_append(code->file, "added"); - elm_code_file_line_append(code->file, "more"); - elm_code_file_line_append(code->file, ""); - elm_code_file_line_append(code->file, "changed"); - elm_code_file_line_append(code->file, "unchanged"); + _append_line(code->file, "Some content to diff"); + _append_line(code->file, "added"); + _append_line(code->file, "more"); + _append_line(code->file, ""); + _append_line(code->file, "changed"); + _append_line(code->file, "unchanged"); elm_code_file_line_status_set(code->file, 2, ELM_CODE_STATUS_TYPE_ADDED); elm_code_file_line_token_add(code->file, 2, 1, 5, ELM_CODE_TOKEN_TYPE_ADDED); diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c index e2d9daae56..9a431d09d5 100644 --- a/legacy/elm_code/lib/elm_code_file.c +++ b/legacy/elm_code/lib/elm_code_file.c @@ -20,16 +20,25 @@ static Elm_Code_Line *_elm_code_blank_create(int line) return ecl; } -static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *content, int length, int row) +static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *content, int length, int row, Eina_Bool mapped) { Elm_Code_Line *line; line = _elm_code_blank_create(row); if (!line) return; - line->content = malloc(sizeof(char) * (length + 1)); - strncpy(line->content, content, length); - line->content[length] = 0; + 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; + } file->lines = eina_list_append(file->lines, line); @@ -64,6 +73,7 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) 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) { @@ -78,7 +88,7 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) ret->lines = eina_list_append(ret->lines, ecl); } - _elm_code_file_line_append_data(ret, line->start, line->length, lastindex = line->index); + _elm_code_file_line_append_data(ret, line->start, line->length, lastindex = line->index, EINA_TRUE); } eina_iterator_free(it); @@ -96,11 +106,18 @@ EAPI void elm_code_file_free(Elm_Code_File *file) EINA_LIST_FREE(file->lines, l) { - if (l->content) - free(l->content); + if (l->modified) + free(l->modified); free(l); } + if (file->file) + { + if (file->map) + eina_file_map_free(file->file, file->map); + + eina_file_close(file->file); + } free(file); } @@ -125,8 +142,9 @@ EAPI void elm_code_file_clear(Elm_Code_File *file) EINA_LIST_FREE(file->lines, l) { - if (l->content) - free(l->content); + if (l->modified) + free(l->modified); + free(l); } @@ -140,12 +158,12 @@ EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file) } -EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line) +EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length) { int row; row = elm_code_file_lines_get(file); - _elm_code_file_line_append_data(file, line, strlen(line), row+1); + _elm_code_file_line_append_data(file, line, length, row+1, EINA_FALSE); } EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int number) @@ -153,7 +171,7 @@ EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int num return eina_list_nth(file->lines, number - 1); } -EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int number) +EAPI const char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int number, int *length) { Elm_Code_Line *line; @@ -161,6 +179,11 @@ EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int numb if (!line) return NULL; + + *length = line->length; + + if (line->modified) + return line->modified; return line->content; } diff --git a/legacy/elm_code/lib/elm_code_file.h b/legacy/elm_code/lib/elm_code_file.h index c3ebfb9893..ee177ed254 100644 --- a/legacy/elm_code/lib/elm_code_file.h +++ b/legacy/elm_code/lib/elm_code_file.h @@ -24,8 +24,10 @@ typedef struct _Elm_Code_Token typedef struct _Elm_Code_Line { - char *content; + const char *content; + int length; unsigned int number; + char *modified; Elm_Code_Status_Type status; Eina_List *tokens; @@ -39,6 +41,7 @@ typedef struct _Elm_Code_File Eina_List *lines; Eina_File *file; + void *map; } Elm_Code_File; @@ -80,11 +83,11 @@ EAPI void elm_code_file_clear(Elm_Code_File *file); EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file); -EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line); +EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length); EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int line); -EAPI char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int line); +EAPI const char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int line, int *length); EAPI void elm_code_file_line_status_set(Elm_Code_File *file, unsigned int line, Elm_Code_Status_Type status); diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 9d441638a2..e2171447b1 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -52,7 +52,7 @@ EAPI void elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, int count, int start, length; start = 1; - length = strlen(line->content); + length = line->length; EINA_LIST_FOREACH(line->tokens, item, token) { @@ -77,7 +77,7 @@ static void _elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells if (!_elm_code_widget_resize(o)) return; - length = strlen(line->content); + length = line->length; evas_object_textgrid_size_get(o, &w, NULL); cells[0].codepoint = status_icons[line->status]; @@ -85,7 +85,10 @@ static void _elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells cells[0].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; cells[0].bg = line->status; - chr = (char *)line->content; + if (line->modified) + chr = line->modified; + else + chr = (char *)line->content; for (x = 1; x < (unsigned int) w && x <= length; x++) { cells[x].codepoint = *chr; diff --git a/legacy/elm_code/tests/elm_code_file_test_load.c b/legacy/elm_code/tests/elm_code_file_test_load.c index ad7dc38b34..474981d254 100644 --- a/legacy/elm_code/tests/elm_code_file_test_load.c +++ b/legacy/elm_code/tests/elm_code_file_test_load.c @@ -52,6 +52,18 @@ START_TEST (elm_code_file_load_blank_lines) } END_TEST +static void _assert_line_content_eq(const char *content, Elm_Code_Line *line) +{ + int length; + int c; + + length = strlen(content); + ck_assert_int_eq(length, line->length); + + for (c = 0; c < length; c++) + ck_assert_uint_eq(content[c], line->content[c]); +} + START_TEST (elm_code_file_load_content) { char *path = "elm_code/tests/testfile.txt"; @@ -61,8 +73,8 @@ START_TEST (elm_code_file_load_content) code = elm_code_create(); file = elm_code_file_open(code, path); - ck_assert_str_eq("line2", elm_code_file_line_content_get(file, 2)); - ck_assert_str_eq("another line", elm_code_file_line_content_get(file, 4)); + _assert_line_content_eq("line2", elm_code_file_line_get(file, 2)); + _assert_line_content_eq("another line", elm_code_file_line_get(file, 4)); elm_code_file_close(file); elm_code_free(code); } diff --git a/legacy/elm_code/tests/elm_code_file_test_memory.c b/legacy/elm_code/tests/elm_code_file_test_memory.c index b3598682e0..ab7c063f0d 100644 --- a/legacy/elm_code/tests/elm_code_file_test_memory.c +++ b/legacy/elm_code/tests/elm_code_file_test_memory.c @@ -13,7 +13,7 @@ START_TEST (elm_code_file_memory_lines) file = elm_code_file_new(code); ck_assert_uint_eq(0, elm_code_file_lines_get(file)); - elm_code_file_line_append(file, "a line"); + elm_code_file_line_append(file, "a line", 6); ck_assert_uint_eq(1, elm_code_file_lines_get(file)); elm_code_free(code); @@ -29,7 +29,7 @@ START_TEST (elm_code_file_memory_tokens) code = elm_code_create(); file = elm_code_file_new(code); - elm_code_file_line_append(file, "a line"); + elm_code_file_line_append(file, "a line", 6); elm_code_file_line_token_add(file, 1, 2, 5, ELM_CODE_TOKEN_TYPE_COMMENT); line = elm_code_file_line_get(file, 1); diff --git a/legacy/elm_code/tests/elm_code_test_parse.c b/legacy/elm_code/tests/elm_code_test_parse.c index 3c4868e771..aed0a12e06 100644 --- a/legacy/elm_code/tests/elm_code_test_parse.c +++ b/legacy/elm_code/tests/elm_code_test_parse.c @@ -29,7 +29,7 @@ START_TEST (elm_code_parse_hook_memory_test) file = elm_code_file_new(code); elm_code_parser_add(code, _parser_line_callback, _parser_file_callback); - elm_code_file_line_append(file, "some \"test content\" for parsing"); + elm_code_file_line_append(file, "some \"test content\" for parsing", 31); ck_assert_int_eq(1, line_calls); ck_assert_int_eq(0, file_calls); diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/tests/elm_code_test_widget.c index 9f499acba8..2b712f097c 100644 --- a/legacy/elm_code/tests/elm_code_test_widget.c +++ b/legacy/elm_code/tests/elm_code_test_widget.c @@ -20,7 +20,7 @@ START_TEST (elm_code_widget_token_render_simple_test) code = elm_code_create(); file = elm_code_file_new(code); - elm_code_file_line_append(file, "some \"test content\", 45"); + elm_code_file_line_append(file, "some \"test content\", 45", 23); line = elm_code_file_line_get(file, 1); length = strlen(line->content); From 77f17fa26a772745d257fb53b96b1a7af7b5d70e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 19 Nov 2014 22:35:01 +0000 Subject: [PATCH 033/254] Fix a memory corruption issue on some systems --- legacy/elm_code/lib/elm_code_widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 572fd3a351..9d441638a2 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -39,7 +39,7 @@ static void _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int coun { int x; - for (x = start; x <= end && x <= count; x++) + for (x = start; x <= end && x < count; x++) { cells[x].fg = type; } From bce66677cb202360859c9667a0e6b4067564f04d Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 19 Nov 2014 22:37:00 +0000 Subject: [PATCH 034/254] Fix minor issues I saw in passing --- legacy/elm_code/bin/elm_code_test_main.c | 2 +- legacy/elm_code/lib/elm_code.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 95a52143a3..be8887474e 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -113,7 +113,7 @@ elm_code_test_win_setup(void) Evas_Object *win; Evas_Object *vbox; - win = elm_win_util_standard_add("main", "Elm_code_test"); + win = elm_win_util_standard_add("main", "Elm_Code Test"); if (!win) return NULL; vbox = elm_box_add(win); diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index bd4a148706..1c04f53947 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -15,7 +15,7 @@ int _elm_code_lib_log_dom = -1; const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE = EO_EVENT_DESCRIPTION("line,set,done", ""); const Eo_Event_Description ELM_CODE_EVENT_FILE_LOAD_DONE = - EO_EVENT_DESCRIPTION("file, load,done", ""); + EO_EVENT_DESCRIPTION("file,load,done", ""); EAPI int elm_code_init(void) From e3610e160267c07f1163cd070798f03c7f01dc7d Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 19 Nov 2014 23:20:23 +0000 Subject: [PATCH 035/254] Fix a test missed in move to mem-mapping --- legacy/elm_code/tests/elm_code_test_widget.c | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/tests/elm_code_test_widget.c index 2b712f097c..c79c66a6ca 100644 --- a/legacy/elm_code/tests/elm_code_test_widget.c +++ b/legacy/elm_code/tests/elm_code_test_widget.c @@ -4,9 +4,9 @@ #include "elm_code_suite.h" -static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type) +static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type, int id) { - ck_assert(cell.fg == type); + ck_assert_msg(cell.fg == type, "Wrong type for cell %d", id); } START_TEST (elm_code_widget_token_render_simple_test) @@ -22,18 +22,18 @@ START_TEST (elm_code_widget_token_render_simple_test) file = elm_code_file_new(code); elm_code_file_line_append(file, "some \"test content\", 45", 23); line = elm_code_file_line_get(file, 1); - length = strlen(line->content); + length = line->length; - elm_code_file_line_token_add(file, 1, 6+1, 18+1, ELM_CODE_TOKEN_TYPE_COMMENT); - elm_code_file_line_token_add(file, 1, 22+1, 23+1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_file_line_token_add(file, 1, 6+1, 17+1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_file_line_token_add(file, 1, 21+1, 22+1, ELM_CODE_TOKEN_TYPE_COMMENT); - elm_code_widget_fill_line_tokens(cells, length, line); - _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[4], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[6], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[16], ELM_CODE_TOKEN_TYPE_COMMENT); - _assert_cell_type(cells[20], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[23], ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_widget_fill_line_tokens(cells, length+1, line); + _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT, 1); + _assert_cell_type(cells[4], ELM_CODE_TOKEN_TYPE_DEFAULT, 4); + _assert_cell_type(cells[6], ELM_CODE_TOKEN_TYPE_DEFAULT, 6); + _assert_cell_type(cells[16], ELM_CODE_TOKEN_TYPE_COMMENT, 16); + _assert_cell_type(cells[20], ELM_CODE_TOKEN_TYPE_DEFAULT, 20); + _assert_cell_type(cells[23], ELM_CODE_TOKEN_TYPE_COMMENT, 23); elm_code_free(code); } From 846d2d2fbd3b8cd637cb9c1da89af830e9205205 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 19 Nov 2014 23:20:23 +0000 Subject: [PATCH 036/254] Fix a test missed in move to mem-mapping --- legacy/elm_code/tests/elm_code_test_widget.c | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/tests/elm_code_test_widget.c index 9f499acba8..aa3e537bf9 100644 --- a/legacy/elm_code/tests/elm_code_test_widget.c +++ b/legacy/elm_code/tests/elm_code_test_widget.c @@ -4,9 +4,9 @@ #include "elm_code_suite.h" -static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type) +static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type, int id) { - ck_assert(cell.fg == type); + ck_assert_msg(cell.fg == type, "Wrong type for cell %d", id); } START_TEST (elm_code_widget_token_render_simple_test) @@ -22,18 +22,18 @@ START_TEST (elm_code_widget_token_render_simple_test) file = elm_code_file_new(code); elm_code_file_line_append(file, "some \"test content\", 45"); line = elm_code_file_line_get(file, 1); - length = strlen(line->content); + length = line->length; - elm_code_file_line_token_add(file, 1, 6+1, 18+1, ELM_CODE_TOKEN_TYPE_COMMENT); - elm_code_file_line_token_add(file, 1, 22+1, 23+1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_file_line_token_add(file, 1, 6+1, 17+1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_file_line_token_add(file, 1, 21+1, 22+1, ELM_CODE_TOKEN_TYPE_COMMENT); - elm_code_widget_fill_line_tokens(cells, length, line); - _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[4], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[6], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[16], ELM_CODE_TOKEN_TYPE_COMMENT); - _assert_cell_type(cells[20], ELM_CODE_TOKEN_TYPE_DEFAULT); - _assert_cell_type(cells[23], ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_widget_fill_line_tokens(cells, length+1, line); + _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT, 1); + _assert_cell_type(cells[4], ELM_CODE_TOKEN_TYPE_DEFAULT, 4); + _assert_cell_type(cells[6], ELM_CODE_TOKEN_TYPE_DEFAULT, 6); + _assert_cell_type(cells[16], ELM_CODE_TOKEN_TYPE_COMMENT, 16); + _assert_cell_type(cells[20], ELM_CODE_TOKEN_TYPE_DEFAULT, 20); + _assert_cell_type(cells[23], ELM_CODE_TOKEN_TYPE_COMMENT, 23); elm_code_free(code); } From 5bd7cc9bbc471311ab4932b65041a3e9f4fb256e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 22 Nov 2014 19:14:53 +0000 Subject: [PATCH 037/254] Add an option to change the font size of our widget demonstrate in the test and use it to make the logs more readable in edi --- legacy/elm_code/bin/elm_code_test_main.c | 3 ++- legacy/elm_code/lib/elm_code_widget.c | 7 ++++++- legacy/elm_code/lib/elm_code_widget.h | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 9654b93101..69a30344b2 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -40,6 +40,7 @@ _elm_code_test_welcome_setup(Evas_Object *parent) code = elm_code_create(); elm_code_file_new(code); widget = elm_code_widget_add(parent, code); + elm_code_widget_font_size_set(widget, 14); _append_line(code->file, "Hello World, Elm Code!"); elm_code_file_line_token_add(code->file, 1, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); _append_line(code->file, ""); @@ -139,7 +140,7 @@ elm_code_test_win_setup(void) elm_win_resize_object_add(win, vbox); - evas_object_resize(win, 320 * elm_config_scale_get(), 180 * elm_config_scale_get()); + evas_object_resize(win, 380 * elm_config_scale_get(), 240 * elm_config_scale_get()); evas_object_show(win); return win; diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index e2171447b1..24a70d6d78 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -183,7 +183,7 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) o = evas_object_textgrid_add(parent); - evas_object_textgrid_font_set(o, "Mono", 10 * elm_config_scale_get()); + elm_code_widget_font_size_set(o, 10); // setup status colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, @@ -225,3 +225,8 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) return o; } +EAPI void elm_code_widget_font_size_set(Evas_Object *widget, int size) +{ + evas_object_textgrid_font_set(widget, "Mono", size * elm_config_scale_get()); +} + diff --git a/legacy/elm_code/lib/elm_code_widget.h b/legacy/elm_code/lib/elm_code_widget.h index 8c2bf77a6b..a9075ab01e 100644 --- a/legacy/elm_code/lib/elm_code_widget.h +++ b/legacy/elm_code/lib/elm_code_widget.h @@ -25,7 +25,10 @@ extern "C" { */ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code); -EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code); + +EAPI void elm_code_widget_font_size_set(Evas_Object *widget, int size); + +EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code); EAPI void elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, int count, Elm_Code_Line *line); From b4a64ccc40e464b1c7282681c41d3cb486287d2f Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 22 Nov 2014 22:36:57 +0000 Subject: [PATCH 038/254] Add a simple diff widget based on an incoming diff file. Load that into edi if we load a diff or patch file --- legacy/elm_code/bin/elm_code_test_main.c | 57 +--------- legacy/elm_code/lib/Elm_Code.h | 1 + legacy/elm_code/lib/Makefile.am | 2 + legacy/elm_code/lib/elm_code_diff_widget.c | 122 +++++++++++++++++++++ legacy/elm_code/lib/elm_code_diff_widget.h | 39 +++++++ legacy/elm_code/lib/elm_code_widget.h | 1 - legacy/elm_code/tests/testdiff.diff | 10 ++ 7 files changed, 180 insertions(+), 52 deletions(-) create mode 100644 legacy/elm_code/lib/elm_code_diff_widget.c create mode 100644 legacy/elm_code/lib/elm_code_diff_widget.h create mode 100644 legacy/elm_code/tests/testdiff.diff diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 69a30344b2..713598fee9 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -59,61 +59,16 @@ _elm_code_test_welcome_setup(Evas_Object *parent) static Evas_Object * _elm_code_test_diff_setup(Evas_Object *parent) { + char *path = "elm_code/tests/testdiff.diff"; + Evas_Object *diff; + Elm_Code_File *file; Elm_Code *code; - Evas_Object *widget, *hbox; - hbox = elm_box_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_box_homogeneous_set(hbox, EINA_TRUE); - elm_box_horizontal_set(hbox, EINA_TRUE); - evas_object_show(hbox); - - // left side of diff code = elm_code_create(); - elm_code_file_new(code); - widget = elm_code_widget_add(parent, code); + file = elm_code_file_open(code, path); - _append_line(code->file, "Some content to diff"); - _append_line(code->file, ""); - _append_line(code->file, "more"); - _append_line(code->file, "removed"); - _append_line(code->file, "will change"); - _append_line(code->file, "unchanged"); - - elm_code_file_line_status_set(code->file, 4, ELM_CODE_STATUS_TYPE_REMOVED); - elm_code_file_line_token_add(code->file, 4, 1, 7, ELM_CODE_TOKEN_TYPE_REMOVED); - elm_code_file_line_status_set(code->file, 5, ELM_CODE_STATUS_TYPE_CHANGED); - elm_code_file_line_token_add(code->file, 5, 1, 5, ELM_CODE_TOKEN_TYPE_REMOVED); - - 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_box_pack_end(hbox, widget); - - // right side of diff - code = elm_code_create(); - elm_code_file_new(code); - widget = elm_code_widget_add(parent, code); - - _append_line(code->file, "Some content to diff"); - _append_line(code->file, "added"); - _append_line(code->file, "more"); - _append_line(code->file, ""); - _append_line(code->file, "changed"); - _append_line(code->file, "unchanged"); - - elm_code_file_line_status_set(code->file, 2, ELM_CODE_STATUS_TYPE_ADDED); - elm_code_file_line_token_add(code->file, 2, 1, 5, ELM_CODE_TOKEN_TYPE_ADDED); - elm_code_file_line_status_set(code->file, 5, ELM_CODE_STATUS_TYPE_CHANGED); - elm_code_file_line_token_add(code->file, 5, 7, 7, ELM_CODE_TOKEN_TYPE_ADDED); - - 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_box_pack_end(hbox, widget); - - return hbox; + diff = elm_code_diff_widget_add(parent, code); + return diff; } static Evas_Object * diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index eadf59da44..30f323a4e7 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -9,6 +9,7 @@ #include #include #include +#include #ifdef EAPI # undef EAPI diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am index 5339cc58a0..c2b4d99291 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/lib/Makefile.am @@ -15,6 +15,7 @@ includes_HEADERS = \ elm_code_file.h \ elm_code_parse.h \ elm_code_widget.h \ +elm_code_diff_widget.h \ Elm_Code.h includesdir = $(includedir)/edi-@VMAJ@ @@ -22,6 +23,7 @@ libelm_code_la_SOURCES = \ elm_code_file.c \ elm_code_parse.c \ elm_code_widget.c \ +elm_code_diff_widget.c \ elm_code.c libelm_code_la_LIBADD = @EFL_LIBS@ -lm libelm_code_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ diff --git a/legacy/elm_code/lib/elm_code_diff_widget.c b/legacy/elm_code/lib/elm_code_diff_widget.c new file mode 100644 index 0000000000..95eeb573e3 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_diff_widget.c @@ -0,0 +1,122 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include +#include + +#include "Elm_Code.h" +#include "elm_code_diff_widget.h" + +#include "elm_code_private.h" + +#define ELM_CODE_DIFF_WIDGET_LEFT "diffwidgetleft" +#define ELM_CODE_DIFF_WIDGET_RIGHT "diffwidgetright" + +static void _elm_code_diff_widget_parse_diff_line(Elm_Code_Line *line, int number, Elm_Code_File *left, Elm_Code_File *right) +{ + if (line->length < 1) + { + elm_code_file_line_append(left, "", 0); + elm_code_file_line_append(right, "", 0); + } + + if (line->content[0] == '+') + { + elm_code_file_line_append(left, "", 0); + elm_code_file_line_append(right, line->content+1, line->length-1); + elm_code_file_line_status_set(right, number, ELM_CODE_STATUS_TYPE_ADDED); + } + else if (line->content[0] == '-') + { + elm_code_file_line_append(left, line->content+1, line->length-1); + elm_code_file_line_append(right, "", 0); + elm_code_file_line_status_set(left, number, ELM_CODE_STATUS_TYPE_REMOVED); + } + else + { + elm_code_file_line_append(left, line->content+1, line->length-1); + elm_code_file_line_append(right, line->content+1, line->length-1); + } +} + +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; + int number; + + number = 0; + EINA_LIST_FOREACH(diff->lines, item, line) + { + + if (line->length > 0 && number < 2) + { + if (line->content[0] == 'd' || line->content[0] == 'i') + continue; + } + + if (number == 0) + { + elm_code_file_line_append(left, line->content+4, line->length-4); + elm_code_file_line_status_set(left, 1, ELM_CODE_STATUS_TYPE_CHANGED); + } + else if (number == 1) + { + elm_code_file_line_append(right, line->content+4, line->length-4); + elm_code_file_line_status_set(right, 1, ELM_CODE_STATUS_TYPE_CHANGED); + } + else + _elm_code_diff_widget_parse_diff_line(line, number, left, right); + + number++; + } +} + +EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) +{ + Elm_Code *wcode1, *wcode2; + Evas_Object *widget_left, *widget_right, *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_file_new(wcode1); + widget_left = elm_code_widget_add(parent, 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_file_new(wcode2); + widget_right = elm_code_widget_add(parent, 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_size_set(Evas_Object *widget, int size) +{ + Evas_Object *child; + + child = evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_LEFT); + elm_code_widget_font_size_set(child, size); + child = evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_RIGHT); + elm_code_widget_font_size_set(child, size); +} + diff --git a/legacy/elm_code/lib/elm_code_diff_widget.h b/legacy/elm_code/lib/elm_code_diff_widget.h new file mode 100644 index 0000000000..ac9f6d474b --- /dev/null +++ b/legacy/elm_code/lib/elm_code_diff_widget.h @@ -0,0 +1,39 @@ +#ifndef ELM_CODE_DIFF_WIDGET_H_ +# define ELM_CODE_DIFF_WIDGET_H_ + +#include +#include "elm_code_common.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_size_set(Evas_Object *widget, int size); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ELM_CODE_DIFF_WIDGET_H_ */ diff --git a/legacy/elm_code/lib/elm_code_widget.h b/legacy/elm_code/lib/elm_code_widget.h index a9075ab01e..2302914ab9 100644 --- a/legacy/elm_code/lib/elm_code_widget.h +++ b/legacy/elm_code/lib/elm_code_widget.h @@ -1,7 +1,6 @@ #ifndef ELM_CODE_WIDGET_H_ # define ELM_CODE_WIDGET_H_ -#include #include #include "elm_code_common.h" diff --git a/legacy/elm_code/tests/testdiff.diff b/legacy/elm_code/tests/testdiff.diff new file mode 100644 index 0000000000..157cbb7b98 --- /dev/null +++ b/legacy/elm_code/tests/testdiff.diff @@ -0,0 +1,10 @@ +--- testdiff1.txt 2014-11-22 21:16:16.279872989 +0000 ++++ testdiff2.txt 2014-11-22 21:16:34.406052375 +0000 +@@ -1,5 +1,5 @@ + Some content to diff ++added + more +-removed +-will change ++changed + unchanged From 724c9a5a66451967bcd65bbceeba86ecc9cad7f8 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 22 Nov 2014 22:44:37 +0000 Subject: [PATCH 039/254] Fix warning --- legacy/elm_code/bin/elm_code_test_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 713598fee9..38c5ab04a2 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -61,11 +61,10 @@ _elm_code_test_diff_setup(Evas_Object *parent) { char *path = "elm_code/tests/testdiff.diff"; Evas_Object *diff; - Elm_Code_File *file; Elm_Code *code; code = elm_code_create(); - file = elm_code_file_open(code, path); + elm_code_file_open(code, path); diff = elm_code_diff_widget_add(parent, code); return diff; From c7a238894abf5bd2586039a43aae172f6ea0384e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 23 Nov 2014 00:19:36 +0000 Subject: [PATCH 040/254] Render all filename headers in a diff widget --- legacy/elm_code/lib/elm_code_diff_widget.c | 42 +++++++++++++--------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_diff_widget.c b/legacy/elm_code/lib/elm_code_diff_widget.c index 95eeb573e3..e833f855b5 100644 --- a/legacy/elm_code/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/lib/elm_code_diff_widget.c @@ -44,32 +44,40 @@ static void _elm_code_diff_widget_parse_diff(Elm_Code_File *diff, Elm_Code_File { Eina_List *item; Elm_Code_Line *line; - int number; + int number, offset; number = 0; + offset = 0; EINA_LIST_FOREACH(diff->lines, item, line) { - if (line->length > 0 && number < 2) + if (line->length > 0) { - if (line->content[0] == 'd' || line->content[0] == 'i') - continue; + if (line->content[0] == 'd' || line->content[0] == 'i' || line->content[0] == 'n') + { + offset = 0; + continue; + } } - if (number == 0) - { - elm_code_file_line_append(left, line->content+4, line->length-4); - elm_code_file_line_status_set(left, 1, ELM_CODE_STATUS_TYPE_CHANGED); - } - else if (number == 1) - { - elm_code_file_line_append(right, line->content+4, line->length-4); - elm_code_file_line_status_set(right, 1, ELM_CODE_STATUS_TYPE_CHANGED); - } - else - _elm_code_diff_widget_parse_diff_line(line, number, left, right); - number++; + if (offset == 0) + { + elm_code_file_line_append(left, line->content+4, line->length-4); + elm_code_file_line_status_set(left, number, ELM_CODE_STATUS_TYPE_CHANGED); + } + else if (offset == 1) + { + number--; + elm_code_file_line_append(right, line->content+4, line->length-4); + elm_code_file_line_status_set(right, number, ELM_CODE_STATUS_TYPE_CHANGED); + } + else + { + _elm_code_diff_widget_parse_diff_line(line, number, left, right); + } + + offset++; } } From 70ec5e065d7a96760a9218bad4644418d3716b9d Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 25 Nov 2014 23:07:50 +0000 Subject: [PATCH 041/254] Heading to a working windows build. Copy fixes into Skeleton file too so that it creates libraries that work in the same way --- legacy/elm_code/lib/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am index c2b4d99291..36ecc74164 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/lib/Makefile.am @@ -7,7 +7,7 @@ AM_CPPFLAGS = \ -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ -DEFL_BETA_API_SUPPORT \ @EFL_CFLAGS@ \ --DEFL_EFL_BUILD +-DEFL_ELM_CODE_BUILD lib_LTLIBRARIES = libelm_code.la @@ -26,4 +26,4 @@ elm_code_widget.c \ elm_code_diff_widget.c \ elm_code.c libelm_code_la_LIBADD = @EFL_LIBS@ -lm -libelm_code_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ +libelm_code_la_LDFLAGS = -no-undefined @EFL_LTLIBRARY_FLAGS@ From 888e4217ec044e839c641cd1426f50df0bbceec9 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 28 Nov 2014 08:55:42 +0000 Subject: [PATCH 042/254] Use an in-memory file for new elm_codes by default. This is overridden as before by calling elm_code_file_open which will free the previously set file on that elm_code instance --- legacy/elm_code/bin/elm_code_test_main.c | 1 - legacy/elm_code/lib/Elm_Code.h | 9 +++++---- legacy/elm_code/lib/elm_code.c | 2 ++ legacy/elm_code/lib/elm_code_diff_widget.c | 2 -- legacy/elm_code/lib/elm_code_file.c | 3 +++ legacy/elm_code/tests/elm_code_file_test_memory.c | 11 ++++------- legacy/elm_code/tests/elm_code_test_widget.c | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 38c5ab04a2..698e411d26 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -38,7 +38,6 @@ _elm_code_test_welcome_setup(Evas_Object *parent) Evas_Object *widget; code = elm_code_create(); - elm_code_file_new(code); widget = elm_code_widget_add(parent, code); elm_code_widget_font_size_set(widget, 14); _append_line(code->file, "Hello World, Elm Code!"); diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 30f323a4e7..866ccc787a 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -86,7 +86,7 @@ EAPI int elm_code_init(void); * * @return Elm Code's init counter value. * - * @see elm_code_init(). + * @see elm_code_init() * * @ingroup Init */ @@ -95,11 +95,12 @@ EAPI int elm_code_shutdown(void); /** * Create a new Elm Code instance * - * This method creates a new Elm Code instance which will need a - * backing file set for storage. + * 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 + * @return an allocated Elm_Code that references the given file + * @see elm_code_file_open() */ EAPI Elm_Code *elm_code_create(); diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index 1c04f53947..9b895f5bcc 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -72,6 +72,8 @@ elm_code_create() ret = calloc(1, sizeof(Elm_Code)); + // create an in-memory backing for this elm_code by default + elm_code_file_new(ret); return ret; } diff --git a/legacy/elm_code/lib/elm_code_diff_widget.c b/legacy/elm_code/lib/elm_code_diff_widget.c index e833f855b5..7e577ed992 100644 --- a/legacy/elm_code/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/lib/elm_code_diff_widget.c @@ -94,7 +94,6 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // left side of diff wcode1 = elm_code_create(); - elm_code_file_new(wcode1); widget_left = elm_code_widget_add(parent, wcode1); evas_object_size_hint_weight_set(widget_left, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -105,7 +104,6 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // right side of diff wcode2 = elm_code_create(); - elm_code_file_new(wcode2); widget_right = elm_code_widget_add(parent, wcode2); evas_object_size_hint_weight_set(widget_right, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c index 9a431d09d5..6c1944ec57 100644 --- a/legacy/elm_code/lib/elm_code_file.c +++ b/legacy/elm_code/lib/elm_code_file.c @@ -53,6 +53,9 @@ 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; diff --git a/legacy/elm_code/tests/elm_code_file_test_memory.c b/legacy/elm_code/tests/elm_code_file_test_memory.c index ab7c063f0d..cf4de295a7 100644 --- a/legacy/elm_code/tests/elm_code_file_test_memory.c +++ b/legacy/elm_code/tests/elm_code_file_test_memory.c @@ -6,16 +6,14 @@ START_TEST (elm_code_file_memory_lines) { - Elm_Code_File *file; Elm_Code *code; code = elm_code_create(); - file = elm_code_file_new(code); - ck_assert_uint_eq(0, elm_code_file_lines_get(file)); + ck_assert_uint_eq(0, elm_code_file_lines_get(code->file)); - elm_code_file_line_append(file, "a line", 6); + elm_code_file_line_append(code->file, "a line", 6); - ck_assert_uint_eq(1, elm_code_file_lines_get(file)); + ck_assert_uint_eq(1, elm_code_file_lines_get(code->file)); elm_code_free(code); } END_TEST @@ -27,8 +25,7 @@ START_TEST (elm_code_file_memory_tokens) Elm_Code *code; code = elm_code_create(); - file = elm_code_file_new(code); - + file = code->file; elm_code_file_line_append(file, "a line", 6); elm_code_file_line_token_add(file, 1, 2, 5, ELM_CODE_TOKEN_TYPE_COMMENT); diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/tests/elm_code_test_widget.c index c79c66a6ca..f6b0a4601c 100644 --- a/legacy/elm_code/tests/elm_code_test_widget.c +++ b/legacy/elm_code/tests/elm_code_test_widget.c @@ -19,7 +19,7 @@ START_TEST (elm_code_widget_token_render_simple_test) Evas_Textgrid_Cell cells[25]; code = elm_code_create(); - file = elm_code_file_new(code); + file = code->file; elm_code_file_line_append(file, "some \"test content\", 45", 23); line = elm_code_file_line_get(file, 1); length = line->length; From 13064e06c60d8f9aa943f9608779331831877591 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 5 Dec 2014 09:20:11 -0600 Subject: [PATCH 043/254] Add a cursor to the view. Create a backing data structure to start tracking more useful widget information --- legacy/elm_code/bin/elm_code_test_main.c | 2 ++ legacy/elm_code/lib/elm_code_common.h | 1 + legacy/elm_code/lib/elm_code_widget.c | 36 ++++++++++++++++++++---- legacy/elm_code/lib/elm_code_widget.h | 31 ++++++++++++++++++-- 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 698e411d26..bfb13bb357 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -40,6 +40,8 @@ _elm_code_test_welcome_setup(Evas_Object *parent) code = elm_code_create(); widget = elm_code_widget_add(parent, code); elm_code_widget_font_size_set(widget, 14); + elm_code_widget_editable_set(widget, EINA_TRUE); + _append_line(code->file, "Hello World, Elm Code!"); elm_code_file_line_token_add(code->file, 1, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); _append_line(code->file, ""); diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index 79f5d6c12c..2520356588 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -33,6 +33,7 @@ typedef enum { ELM_CODE_TOKEN_TYPE_REMOVED, ELM_CODE_TOKEN_TYPE_CHANGED, + ELM_CODE_TOKEN_TYPE_CURSOR, // a pseudo type used for styling but may not be set on a cell ELM_CODE_TOKEN_TYPE_COUNT } Elm_Code_Token_Type; diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 24a70d6d78..2b633e8d38 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -45,7 +45,7 @@ static void _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int coun } } -EAPI void elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, int count, Elm_Code_Line *line) +EAPI void elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, unsigned int count, Elm_Code_Line *line) { Eina_List *item; Elm_Code_Token *token; @@ -73,6 +73,7 @@ static void _elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells char *chr; unsigned int length, x; int w; + ELM_CODE_WIDGET_DATA_GET(o, widget); if (!_elm_code_widget_resize(o)) return; @@ -103,6 +104,11 @@ static void _elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells } elm_code_widget_fill_line_tokens(cells, w, line); + if (widget->editable && widget->cursor_line == line->number) + { + if (widget->cursor_col < (unsigned int) w) + cells[widget->cursor_col].bg = ELM_CODE_TOKEN_TYPE_CURSOR; + } evas_object_textgrid_update_add(o, 0, line->number - 1, w, 1); } @@ -180,11 +186,10 @@ _elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) { Evas_Object *o; + Elm_Code_Widget *widget; o = evas_object_textgrid_add(parent); - elm_code_widget_font_size_set(o, 10); - // setup status colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, 36, 36, 36, 255); @@ -216,17 +221,38 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CHANGED, 54, 54, 255, 255); + // the style for a cursor - this is a special token and will be applied to the background + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CURSOR, + 205, 205, 54, 255); evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code); eo_do(o,eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, code)); eo_do(o,eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, code)); + widget = calloc(1, sizeof(*widget)); + widget->code = code; + widget->cursor_line = 1; + widget->cursor_col = 1; + evas_object_data_set(o, ELM_CODE_WIDGET_DATA_KEY, widget); code->widgets = eina_list_append(code->widgets, o); + + elm_code_widget_font_size_set(o, 10); return o; } -EAPI void elm_code_widget_font_size_set(Evas_Object *widget, int size) +EAPI void elm_code_widget_font_size_set(Evas_Object *obj, Evas_Font_Size size) { - evas_object_textgrid_font_set(widget, "Mono", size * elm_config_scale_get()); + ELM_CODE_WIDGET_DATA_GET(obj, widget); + + widget->font_size = size; + evas_object_textgrid_font_set(obj, "Mono", size * elm_config_scale_get()); } +EAPI void elm_code_widget_editable_set(Evas_Object *obj, Eina_Bool editable) +{ + ELM_CODE_WIDGET_DATA_GET(obj, widget); + + widget->editable = editable; +} + + diff --git a/legacy/elm_code/lib/elm_code_widget.h b/legacy/elm_code/lib/elm_code_widget.h index 2302914ab9..286fcabc41 100644 --- a/legacy/elm_code/lib/elm_code_widget.h +++ b/legacy/elm_code/lib/elm_code_widget.h @@ -13,6 +13,31 @@ extern "C" { * @brief These routines are used for rendering instances of Elm Code. */ +typedef struct _Elm_Code_Widget +{ + Elm_Code *code; + + Evas_Font_Size font_size; + unsigned int cursor_line, cursor_col; + Eina_Bool editable; + +} Elm_Code_Widget; + +#define ELM_CODE_WIDGET_DATA_KEY "Elm_Code_Widget" +#define ELM_CODE_WIDGET_DATA_GET(o, ptr, ...) \ + Elm_Code_Widget *ptr; \ + ptr = evas_object_data_get(o, ELM_CODE_WIDGET_DATA_KEY); + +#define ELM_CODE_WIDGET_DATA_GET_OR_RETURN(o, ptr, ...) \ + Elm_Code_Widget *ptr; \ + ptr = evas_object_data_get(o, ELM_CODE_WIDGET_DATA_KEY);\ + if (EINA_UNLIKELY(!ptr)) \ + { \ + CRI("no widget data for object %p (%s)", \ + o, evas_object_type_get(o)); \ + return __VA_ARGS__; \ + } + /** * @brief UI Loading functions. * @defgroup Init Creating a widget to render an Elm Code backend @@ -25,11 +50,13 @@ extern "C" { EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code); -EAPI void elm_code_widget_font_size_set(Evas_Object *widget, int size); +EAPI void elm_code_widget_font_size_set(Evas_Object *widget, Evas_Font_Size size); + +EAPI void elm_code_widget_editable_set(Evas_Object *widget, Eina_Bool editable); EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code); -EAPI void elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, int count, Elm_Code_Line *line); +EAPI void elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, unsigned int count, Elm_Code_Line *line); /** * @} From ad3d545415dc66c2caad8411c9956e7ffc7f2e37 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 5 Dec 2014 09:39:40 -0600 Subject: [PATCH 044/254] Fix up headers and tests to remove the exposure of some private methods. Add some documentation whilst we're there too --- legacy/elm_code/lib/elm_code_widget.c | 30 +++++++++------ legacy/elm_code/lib/elm_code_widget.h | 40 ++++++++++++++++++-- legacy/elm_code/tests/elm_code_test_widget.c | 4 +- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 2b633e8d38..bce5d61839 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -23,7 +23,8 @@ Eina_Unicode status_icons[] = { 0 }; -static Eina_Bool _elm_code_widget_resize(Evas_Object *o) +static Eina_Bool +_elm_code_widget_resize(Evas_Object *o) { int w, h, cw, ch; @@ -35,7 +36,8 @@ static Eina_Bool _elm_code_widget_resize(Evas_Object *o) return h > 0 && w > 0; } -static void _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start, int end, Elm_Code_Token_Type type) +static void +_elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start, int end, Elm_Code_Token_Type type) { int x; @@ -45,7 +47,8 @@ static void _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int coun } } -EAPI void elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, unsigned int count, Elm_Code_Line *line) +static void +_elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, unsigned int count, Elm_Code_Line *line) { Eina_List *item; Elm_Code_Token *token; @@ -68,7 +71,8 @@ EAPI void elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, unsigned i _elm_code_widget_fill_line_token(cells, count, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); } -static void _elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) +static void +_elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) { char *chr; unsigned int length, x; @@ -103,7 +107,7 @@ static void _elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells cells[x].bg = line->status; } - elm_code_widget_fill_line_tokens(cells, w, line); + _elm_code_widget_fill_line_tokens(cells, w, line); if (widget->editable && widget->cursor_line == line->number) { if (widget->cursor_col < (unsigned int) w) @@ -113,7 +117,8 @@ static void _elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells evas_object_textgrid_update_add(o, 0, line->number - 1, w, 1); } -EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code) +static void +_elm_code_widget_fill(Evas_Object *o, Elm_Code *code) { Elm_Code_Line *line; Evas_Textgrid_Cell *cells; @@ -168,7 +173,7 @@ _elm_code_widget_file_cb(void *data, Eo *obj, const Eo_Event_Description *desc E code = (Elm_Code *)data; o = (Evas_Object *)obj; - elm_code_widget_fill(o, code); + _elm_code_widget_fill(o, code); return EINA_TRUE; } @@ -180,10 +185,11 @@ _elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, code = (Elm_Code *)data; - elm_code_widget_fill(obj, code); + _elm_code_widget_fill(obj, code); } -EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) +EAPI Evas_Object * +elm_code_widget_add(Evas_Object *parent, Elm_Code *code) { Evas_Object *o; Elm_Code_Widget *widget; @@ -240,7 +246,8 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) return o; } -EAPI void elm_code_widget_font_size_set(Evas_Object *obj, Evas_Font_Size size) +EAPI void +elm_code_widget_font_size_set(Evas_Object *obj, Evas_Font_Size size) { ELM_CODE_WIDGET_DATA_GET(obj, widget); @@ -248,7 +255,8 @@ EAPI void elm_code_widget_font_size_set(Evas_Object *obj, Evas_Font_Size size) evas_object_textgrid_font_set(obj, "Mono", size * elm_config_scale_get()); } -EAPI void elm_code_widget_editable_set(Evas_Object *obj, Eina_Bool editable) +EAPI void +elm_code_widget_editable_set(Evas_Object *obj, Eina_Bool editable) { ELM_CODE_WIDGET_DATA_GET(obj, widget); diff --git a/legacy/elm_code/lib/elm_code_widget.h b/legacy/elm_code/lib/elm_code_widget.h index 286fcabc41..b173a828fd 100644 --- a/legacy/elm_code/lib/elm_code_widget.h +++ b/legacy/elm_code/lib/elm_code_widget.h @@ -50,14 +50,46 @@ typedef struct _Elm_Code_Widget EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code); +/** + * @} + * + * @brief UI Manipulation functions. + * @defgroup UI Manage aspects of an Elm_Code widget + * + * @{ + * + * Functions for UI manipulation. + * + */ + +/** + * Set the font size of a widget + * + * Change the size of the monospaced font used by this widget instance. + * 10 pt is the default font size for an elm_code widget. + * + * @param widget The widget to change + * @param size The font size to set on this widget + * + * @ingroup UI + */ EAPI void elm_code_widget_font_size_set(Evas_Object *widget, Evas_Font_Size size); +/** + * Set this widget to be editable + * + * An editable widget displays a cursor and accepts user input. + * It will also accept focus. + * If EINA_FALSE is passed this widget will return to being read-only. + * EINA_FALSE is the default value for editable. + * + * @param widget The widget to change + * @param editable Whether or not this widget should be editable + * + * @ingroup UI + */ EAPI void elm_code_widget_editable_set(Evas_Object *widget, Eina_Bool editable); -EAPI void elm_code_widget_fill(Evas_Object *o, Elm_Code *code); - -EAPI void elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, unsigned int count, Elm_Code_Line *line); - /** * @} */ diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/tests/elm_code_test_widget.c index f6b0a4601c..6efdce8715 100644 --- a/legacy/elm_code/tests/elm_code_test_widget.c +++ b/legacy/elm_code/tests/elm_code_test_widget.c @@ -4,6 +4,8 @@ #include "elm_code_suite.h" +#include "elm_code_widget.c" + static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type, int id) { ck_assert_msg(cell.fg == type, "Wrong type for cell %d", id); @@ -27,7 +29,7 @@ START_TEST (elm_code_widget_token_render_simple_test) elm_code_file_line_token_add(file, 1, 6+1, 17+1, ELM_CODE_TOKEN_TYPE_COMMENT); elm_code_file_line_token_add(file, 1, 21+1, 22+1, ELM_CODE_TOKEN_TYPE_COMMENT); - elm_code_widget_fill_line_tokens(cells, length+1, line); + _elm_code_widget_fill_line_tokens(cells, length+1, line); _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT, 1); _assert_cell_type(cells[4], ELM_CODE_TOKEN_TYPE_DEFAULT, 4); _assert_cell_type(cells[6], ELM_CODE_TOKEN_TYPE_DEFAULT, 6); From 344e2e8ecadd318c599145478514a575ff3e3c0c Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 24 Dec 2014 18:06:51 +0000 Subject: [PATCH 045/254] Remove circular include of the elm_code_file.h header --- legacy/elm_code/lib/elm_code_common.h | 3 +-- legacy/elm_code/lib/elm_code_file.h | 4 ++-- legacy/elm_code/lib/elm_code_widget.h | 2 ++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index 79f5d6c12c..eafe10687a 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -5,6 +5,7 @@ #include typedef struct _Elm_Code Elm_Code; +typedef struct _Elm_Code_File Elm_Code_File; EAPI extern const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE; EAPI extern const Eo_Event_Description ELM_CODE_EVENT_FILE_LOAD_DONE; @@ -36,8 +37,6 @@ typedef enum { ELM_CODE_TOKEN_TYPE_COUNT } Elm_Code_Token_Type; -#include "elm_code_file.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/legacy/elm_code/lib/elm_code_file.h b/legacy/elm_code/lib/elm_code_file.h index ee177ed254..2a1d082ec1 100644 --- a/legacy/elm_code/lib/elm_code_file.h +++ b/legacy/elm_code/lib/elm_code_file.h @@ -35,7 +35,7 @@ typedef struct _Elm_Code_Line } Elm_Code_Line; -typedef struct _Elm_Code_File +struct _Elm_Code_File { void *parent; @@ -43,7 +43,7 @@ typedef struct _Elm_Code_File Eina_File *file; void *map; -} Elm_Code_File; +}; /** * @brief File handling functions. diff --git a/legacy/elm_code/lib/elm_code_widget.h b/legacy/elm_code/lib/elm_code_widget.h index 2302914ab9..6e374402cb 100644 --- a/legacy/elm_code/lib/elm_code_widget.h +++ b/legacy/elm_code/lib/elm_code_widget.h @@ -2,7 +2,9 @@ # define ELM_CODE_WIDGET_H_ #include + #include "elm_code_common.h" +#include "elm_code_file.h" #ifdef __cplusplus extern "C" { From 74a13336203cb2a494d237237a4232c56db7e808 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 24 Dec 2014 18:16:38 +0000 Subject: [PATCH 046/254] Update various headers to use Elm_Code to load all our public headers and fix a few build glitches --- legacy/elm_code/lib/elm_code.c | 7 ++++--- legacy/elm_code/lib/elm_code_file.c | 2 -- legacy/elm_code/lib/elm_code_parse.c | 1 - legacy/elm_code/lib/elm_code_widget.c | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index 9b895f5bcc..d1e32826af 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -3,20 +3,21 @@ #endif #include +#include #include "Elm_Code.h" -#include "elm_code_parse.h" #include "elm_code_private.h" static int _elm_code_init = 0; int _elm_code_lib_log_dom = -1; -const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE = +EAPI const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE = EO_EVENT_DESCRIPTION("line,set,done", ""); -const Eo_Event_Description ELM_CODE_EVENT_FILE_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) { diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/lib/elm_code_file.c index 6c1944ec57..b4d783339e 100644 --- a/legacy/elm_code/lib/elm_code_file.c +++ b/legacy/elm_code/lib/elm_code_file.c @@ -3,8 +3,6 @@ #endif #include "Elm_Code.h" -#include "elm_code_file.h" -#include "elm_code_parse.h" #include "elm_code_private.h" diff --git a/legacy/elm_code/lib/elm_code_parse.c b/legacy/elm_code/lib/elm_code_parse.c index 2b1ddc28fa..0503aa07dd 100644 --- a/legacy/elm_code/lib/elm_code_parse.c +++ b/legacy/elm_code/lib/elm_code_parse.c @@ -3,7 +3,6 @@ #endif #include "Elm_Code.h" -#include "elm_code_parse.h" #include "elm_code_private.h" diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 24a70d6d78..e7bcd7bb71 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -5,7 +5,7 @@ #include #include -#include "elm_code_widget.h" +#include "Elm_Code.h" #include "elm_code_private.h" From d11e94f0fed4f842a09f92a7478458193ff1caa3 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 4 Jan 2015 12:00:40 +0000 Subject: [PATCH 047/254] Elm_Code now compiling on Windows, thanks to Vincent Torri for the patch. Next to tackle some non-standard EDI code to complete the compilation --- legacy/elm_code/bin/Makefile.am | 16 +++++++--------- legacy/elm_code/lib/Elm_Code.h | 16 ++++++++-------- legacy/elm_code/lib/Makefile.am | 6 ++---- legacy/elm_code/lib/elm_code_common.h | 3 --- legacy/elm_code/lib/elm_code_diff_widget.c | 4 ---- legacy/elm_code/lib/elm_code_diff_widget.h | 3 --- legacy/elm_code/lib/elm_code_file.h | 4 ---- legacy/elm_code/lib/elm_code_parse.h | 4 ---- legacy/elm_code/lib/elm_code_widget.c | 3 --- legacy/elm_code/lib/elm_code_widget.h | 5 ----- 10 files changed, 17 insertions(+), 47 deletions(-) diff --git a/legacy/elm_code/bin/Makefile.am b/legacy/elm_code/bin/Makefile.am index 363beb8fb8..b204d987b0 100644 --- a/legacy/elm_code/bin/Makefile.am +++ b/legacy/elm_code/bin/Makefile.am @@ -2,19 +2,17 @@ MAINTAINERCLEANFILES = Makefile.in bin_PROGRAMS = elm_code_test -AM_CPPFLAGS = -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ --I$(top_builddir)/elm_code/bin/ \ --I$(top_srcdir)/elm_code/bin/ \ --I$(top_builddir)/elm_code/lib/ \ +AM_CPPFLAGS = \ -I$(top_srcdir)/elm_code/lib/ \ +-DLOCALEDIR=\"$(datadir)/locale\" \ -DEFL_BETA_API_SUPPORT \ @EFL_CFLAGS@ -elm_code_test_SOURCES = elm_code_test_main.c -elm_code_test_LDADD = @EFL_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la +elm_code_test_SOURCES = \ +elm_code_test_main.c \ +elm_code_test_private.h -localedir = $(datadir)/locale -DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ +elm_code_test_LDADD = @EFL_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la -lintl -EXTRA_DIST = elm_code_test_private.h +elm_code_test_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 866ccc787a..35071a2173 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -1,15 +1,9 @@ #ifndef ELM_CODE_H_ # define ELM_CODE_H_ -#include -#include #include - -#include -#include -#include -#include -#include +#include +#include #ifdef EAPI # undef EAPI @@ -37,6 +31,12 @@ # endif #endif /* ! _WIN32 */ +#include "elm_code_common.h" +#include "elm_code_file.h" +#include "elm_code_parse.h" +#include "elm_code_widget.h" +#include "elm_code_diff_widget.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am index 36ecc74164..9510cade83 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/lib/Makefile.am @@ -2,9 +2,6 @@ MAINTAINERCLEANFILES = Makefile.in AM_CPPFLAGS = \ -I$(top_srcdir)/elm_code/lib \ --I$(top_builddir)/elm_code/lib \ --DPACKAGE_LIB_DIR=\"$(libdir)\" \ --DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ -DEFL_BETA_API_SUPPORT \ @EFL_CFLAGS@ \ -DEFL_ELM_CODE_BUILD @@ -24,6 +21,7 @@ elm_code_file.c \ elm_code_parse.c \ elm_code_widget.c \ elm_code_diff_widget.c \ -elm_code.c +elm_code.c \ +elm_code_private.h libelm_code_la_LIBADD = @EFL_LIBS@ -lm libelm_code_la_LDFLAGS = -no-undefined @EFL_LTLIBRARY_FLAGS@ diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index eafe10687a..a409bffe7e 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -1,9 +1,6 @@ #ifndef ELM_CODE_COMMON_H_ # define ELM_CODE_COMMON_H_ -#include -#include - typedef struct _Elm_Code Elm_Code; typedef struct _Elm_Code_File Elm_Code_File; diff --git a/legacy/elm_code/lib/elm_code_diff_widget.c b/legacy/elm_code/lib/elm_code_diff_widget.c index 7e577ed992..f008159c5b 100644 --- a/legacy/elm_code/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/lib/elm_code_diff_widget.c @@ -2,11 +2,7 @@ # include "config.h" #endif -#include -#include - #include "Elm_Code.h" -#include "elm_code_diff_widget.h" #include "elm_code_private.h" diff --git a/legacy/elm_code/lib/elm_code_diff_widget.h b/legacy/elm_code/lib/elm_code_diff_widget.h index ac9f6d474b..b6605bbd56 100644 --- a/legacy/elm_code/lib/elm_code_diff_widget.h +++ b/legacy/elm_code/lib/elm_code_diff_widget.h @@ -1,9 +1,6 @@ #ifndef ELM_CODE_DIFF_WIDGET_H_ # define ELM_CODE_DIFF_WIDGET_H_ -#include -#include "elm_code_common.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/legacy/elm_code/lib/elm_code_file.h b/legacy/elm_code/lib/elm_code_file.h index 2a1d082ec1..b37de52c5b 100644 --- a/legacy/elm_code/lib/elm_code_file.h +++ b/legacy/elm_code/lib/elm_code_file.h @@ -1,10 +1,6 @@ #ifndef ELM_CODE_FILE_H_ # define ELM_CODE_FILE_H_ -#include - -#include "elm_code_common.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/legacy/elm_code/lib/elm_code_parse.h b/legacy/elm_code/lib/elm_code_parse.h index ab50c3419b..1c58d27b74 100644 --- a/legacy/elm_code/lib/elm_code_parse.h +++ b/legacy/elm_code/lib/elm_code_parse.h @@ -1,10 +1,6 @@ #ifndef ELM_CODE_PARSE_H_ # define ELM_CODE_PARSE_H_ -#include - -#include "elm_code_common.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index e7bcd7bb71..b0790201ce 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -2,9 +2,6 @@ # include "config.h" #endif -#include -#include - #include "Elm_Code.h" #include "elm_code_private.h" diff --git a/legacy/elm_code/lib/elm_code_widget.h b/legacy/elm_code/lib/elm_code_widget.h index 6e374402cb..a24e577a27 100644 --- a/legacy/elm_code/lib/elm_code_widget.h +++ b/legacy/elm_code/lib/elm_code_widget.h @@ -1,11 +1,6 @@ #ifndef ELM_CODE_WIDGET_H_ # define ELM_CODE_WIDGET_H_ -#include - -#include "elm_code_common.h" -#include "elm_code_file.h" - #ifdef __cplusplus extern "C" { #endif From e179b349bd4fd54fd98d25de5f66515da6376ed4 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 4 Jan 2015 14:07:35 +0000 Subject: [PATCH 048/254] Disable NLS by default when cross compiling, remove broken need for libintl --- legacy/elm_code/bin/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/bin/Makefile.am b/legacy/elm_code/bin/Makefile.am index b204d987b0..b081d5fb9e 100644 --- a/legacy/elm_code/bin/Makefile.am +++ b/legacy/elm_code/bin/Makefile.am @@ -12,7 +12,7 @@ elm_code_test_SOURCES = \ elm_code_test_main.c \ elm_code_test_private.h -elm_code_test_LDADD = @EFL_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la -lintl +elm_code_test_LDADD = @EFL_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la elm_code_test_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ From d7a9c351f4489a8d7967753ed63961f999c430b9 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 27 Jan 2015 14:34:11 +0000 Subject: [PATCH 049/254] Allow up/down/left/right to participate in focus control. When we cannot move within the cursor availability then note it the callback from elm will see if the event should be propagated so we report the veto when we're contained or allow propagation when we overrun --- legacy/elm_code/lib/elm_code_widget.c | 74 ++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 0e74afe27c..ca471d78e7 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -19,6 +19,7 @@ typedef struct Evas_Font_Size font_size; unsigned int cursor_line, cursor_col; + Eina_Bool cursor_move_vetoed; Eina_Bool editable, focussed; } Elm_Code_Widget_Data; @@ -44,6 +45,7 @@ _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUS pd->cursor_line = 1; pd->cursor_col = 1; + pd->cursor_move_vetoed = EINA_TRUE; } EOLIAN static void @@ -349,16 +351,64 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) _elm_code_widget_fill(pd); } +static Eina_Bool +_elm_code_widget_cursor_key_can_control(Evas_Event_Key_Down *event) +{ + if (!strcmp(event->key, "Up")) + return EINA_TRUE; + else if (!strcmp(event->key, "Down")) + return EINA_TRUE; + else if (!strcmp(event->key, "Left")) + return EINA_TRUE; + else if (!strcmp(event->key, "Right")) + return EINA_TRUE; + else + return EINA_FALSE; +} + +static Eina_Bool +_elm_code_widget_cursor_key_will_move(Elm_Code_Widget *widget, Evas_Event_Key_Down *event) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + line = elm_code_file_line_get(pd->code->file, pd->cursor_line); + + if (!strcmp(event->key, "Up")) + return pd->cursor_line > 1; + else if (!strcmp(event->key, "Down")) + return pd->cursor_line < elm_code_file_lines_get(pd->code->file); + else if (!strcmp(event->key, "Left")) + return pd->cursor_col > 1; + else if (!strcmp(event->key, "Right")) + return pd->cursor_col < (unsigned int) line->length + 1; + else + return EINA_FALSE; +} + static void _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) { Elm_Code_Widget *widget; + Elm_Code_Widget_Data *pd; widget = (Elm_Code_Widget *)data; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); Evas_Event_Key_Down *ev = event_info; + if (!pd->editable) + return; + + pd->cursor_move_vetoed = EINA_TRUE; + if (_elm_code_widget_cursor_key_can_control(ev) && !_elm_code_widget_cursor_key_will_move(widget, ev)) + { + pd->cursor_move_vetoed = EINA_FALSE; + return; + } + if (!strcmp(ev->key, "Up")) _elm_code_widget_cursor_move_up(widget); else if (!strcmp(ev->key, "Down")) @@ -372,17 +422,28 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, } static Eina_Bool -_elm_code_widget_event_veto_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, +_elm_code_widget_event_veto_cb(void *data, Evas_Object *obj EINA_UNUSED, Evas_Object *src EINA_UNUSED, Evas_Callback_Type type, void *event_info EINA_UNUSED) { - Eina_Bool veto = EINA_FALSE; + Elm_Code_Widget *widget; + Elm_Code_Widget_Data *pd; + Eina_Bool vetoed; -// TODO determine if we should allow up/down to be sent to our focus manager + widget = (Elm_Code_Widget *)data; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (!pd->editable) + return EINA_FALSE; + + vetoed = EINA_TRUE; if (type == EVAS_CALLBACK_KEY_DOWN) - veto = EINA_TRUE; + { + vetoed = pd->cursor_move_vetoed; + pd->cursor_move_vetoed = EINA_TRUE; + } - return veto; + return vetoed; } EOLIAN static Eina_Bool @@ -435,9 +496,10 @@ _elm_code_widget_code_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) } EOLIAN static void -_elm_code_widget_editable_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Eina_Bool editable) +_elm_code_widget_editable_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool editable) { pd->editable = editable; + elm_object_focus_allow_set(obj, editable); } EOLIAN static Eina_Bool From 8a9c64535367096135c45c76c79448e05845e954 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 10 Jan 2015 17:55:04 +0000 Subject: [PATCH 050/254] Tidying some more headers to try and get windows builds working --- legacy/elm_code/lib/Elm_Code.h | 2 ++ legacy/elm_code/lib/elm_code_widget.c | 7 ------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 21384c978a..016f315c78 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -4,6 +4,8 @@ #include #include #include +#define ELM_INTERNAL_API_ARGESFSDFEFC +#include #ifdef EAPI # undef EAPI diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index ca471d78e7..9da73ec6e0 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -2,14 +2,7 @@ # include "config.h" #endif -#include -#include -#include -#define ELM_INTERNAL_API_ARGESFSDFEFC -#include - #include -#include "elm_code_widget.eo.h" #include "elm_code_private.h" typedef struct From a7cf4ffdbff4c718ec912ff9f3a921a000cd837d Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 17 Jan 2015 19:54:56 +0000 Subject: [PATCH 051/254] Add a click handler for lines in a widget --- legacy/elm_code/bin/elm_code_test_main.c | 14 ++++++++++++ legacy/elm_code/lib/elm_code_widget.c | 27 ++++++++++++++++++++++++ legacy/elm_code/lib/elm_code_widget.h | 2 ++ 3 files changed, 43 insertions(+) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 698e411d26..e81a4e5e30 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -31,6 +31,18 @@ static void _append_line(Elm_Code_File *file, const char *line) elm_code_file_line_append(file, line, length); } +static Eina_Bool +_elm_code_test_line_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, + const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +{ + Elm_Code_Line *line; + + line = (Elm_Code_Line *)event_info; + + printf("CLICKED line %d\n", line->number); + return EINA_TRUE; +} + static Evas_Object * _elm_code_test_welcome_setup(Evas_Object *parent) { @@ -40,6 +52,8 @@ _elm_code_test_welcome_setup(Evas_Object *parent) code = elm_code_create(); widget = elm_code_widget_add(parent, code); elm_code_widget_font_size_set(widget, 14); + eo_do(widget,eo_event_callback_add(&ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_cb, code)); + _append_line(code->file, "Hello World, Elm Code!"); elm_code_file_line_token_add(code->file, 1, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); _append_line(code->file, ""); diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index b0790201ce..69fa2a97c3 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -6,6 +6,9 @@ #include "elm_code_private.h" +EAPI const Eo_Event_Description ELM_CODE_WIDGET_EVENT_LINE_CLICKED = + EO_EVENT_DESCRIPTION("line,clicked", ""); + Eina_Unicode status_icons[] = { ' ', '!', @@ -174,6 +177,29 @@ _elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, elm_code_widget_fill(obj, code); } +static void +_elm_code_widget_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, + void *event_info) +{ + Elm_Code *code; + Elm_Code_Line *line; + Evas_Event_Mouse_Up *event; + Evas_Coord y; + int ch; + unsigned int row; + + code = (Elm_Code *)data; + event = (Evas_Event_Mouse_Up *)event_info; + y = event->canvas.y; + + evas_object_textgrid_cell_size_get(obj, NULL, &ch); + row = ((double) y / ch) + 1; + + line = elm_code_file_line_get(code->file, row); + if (line) + elm_code_callback_fire(code, &ELM_CODE_WIDGET_EVENT_LINE_CLICKED, line); +} + EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) { Evas_Object *o; @@ -214,6 +240,7 @@ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) 54, 54, 255, 255); evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code); + evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_clicked_cb, code); eo_do(o,eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, code)); eo_do(o,eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, code)); diff --git a/legacy/elm_code/lib/elm_code_widget.h b/legacy/elm_code/lib/elm_code_widget.h index a24e577a27..6aa7b87603 100644 --- a/legacy/elm_code/lib/elm_code_widget.h +++ b/legacy/elm_code/lib/elm_code_widget.h @@ -1,6 +1,8 @@ #ifndef ELM_CODE_WIDGET_H_ # define ELM_CODE_WIDGET_H_ +EAPI extern const Eo_Event_Description ELM_CODE_WIDGET_EVENT_LINE_CLICKED; + #ifdef __cplusplus extern "C" { #endif From 49512b1d31eb381b7bd13ab8f8034ea5c3a0f9f7 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 23 Jan 2015 22:55:13 +0000 Subject: [PATCH 052/254] Experimental eo commit - structure in place and it's resizing but won't render --- legacy/elm_code/bin/elm_code_test_main.c | 11 +++ legacy/elm_code/lib/Makefile.am | 3 + legacy/elm_code/lib/elm_code_widget2.c | 82 +++++++++++++++++++++++ legacy/elm_code/lib/elm_code_widget2.eo | 30 +++++++++ legacy/elm_code/lib/elm_code_widget2.eo.c | 53 +++++++++++++++ legacy/elm_code/lib/elm_code_widget2.eo.h | 50 ++++++++++++++ legacy/elm_code/lib/regen.sh | 7 ++ 7 files changed, 236 insertions(+) create mode 100644 legacy/elm_code/lib/elm_code_widget2.c create mode 100644 legacy/elm_code/lib/elm_code_widget2.eo create mode 100644 legacy/elm_code/lib/elm_code_widget2.eo.c create mode 100644 legacy/elm_code/lib/elm_code_widget2.eo.h create mode 100755 legacy/elm_code/lib/regen.sh diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index c422c7dce4..b462ef077b 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -12,6 +12,7 @@ #include "gettext.h" #include +#include "elm_code_widget2.eo.h" #include "elm_code_test_private.h" @@ -50,6 +51,16 @@ _elm_code_test_welcome_setup(Evas_Object *parent) Evas_Object *widget; code = elm_code_create(); + + Elm_Code_Widget2 *obj = eo_add(ELM_CODE_WIDGET2_CLASS, parent); + eo_do(obj, + elm_code_widget2_font_size_set(14)); + + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(obj); +return obj; +// TODO - add all this good stuff into the eo api widget = elm_code_widget_add(parent, code); elm_code_widget_font_size_set(widget, 14); elm_code_widget_editable_set(widget, EINA_TRUE); diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am index 9510cade83..193b9e4650 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/lib/Makefile.am @@ -3,6 +3,7 @@ MAINTAINERCLEANFILES = Makefile.in AM_CPPFLAGS = \ -I$(top_srcdir)/elm_code/lib \ -DEFL_BETA_API_SUPPORT \ +-DEFL_EO_API_SUPPORT \ @EFL_CFLAGS@ \ -DEFL_ELM_CODE_BUILD @@ -20,8 +21,10 @@ libelm_code_la_SOURCES = \ elm_code_file.c \ elm_code_parse.c \ elm_code_widget.c \ +elm_code_widget2.c \ elm_code_diff_widget.c \ elm_code.c \ elm_code_private.h + libelm_code_la_LIBADD = @EFL_LIBS@ -lm libelm_code_la_LDFLAGS = -no-undefined @EFL_LTLIBRARY_FLAGS@ diff --git a/legacy/elm_code/lib/elm_code_widget2.c b/legacy/elm_code/lib/elm_code_widget2.c new file mode 100644 index 0000000000..24dc8dfb55 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_widget2.c @@ -0,0 +1,82 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include +#include +#include +#include +#include "elm_code_widget2.eo.h" + +typedef struct +{ + Elm_Code *code; + + Evas_Font_Size font_size; + unsigned int cursor_line, cursor_col; + Eina_Bool editable; + +} Elm_Code_Widget2_Data; + +EOLIAN static void +_elm_code_widget2_eo_base_constructor(Eo *obj, Elm_Code_Widget2_Data *pd) +{ + eo_do_super(obj, ELM_CODE_WIDGET2_CLASS, eo_constructor()); +printf("constr\n"); +} + +EOLIAN static void +_elm_code_widget2_evas_object_smart_resize(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Coord w, Evas_Coord h) +{ +printf("size %d, %d\n", w, h); +} + +EOLIAN static void +_elm_code_widget2_class_constructor(Eo_Class *klass) +{ + +} + +EOLIAN static void +_elm_code_widget2_elm_interface_scrollable_content_pos_set(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Coord x, Evas_Coord y, Eina_Bool sig) +{ + +} + +EOLIAN static void +_elm_code_widget2_evas_object_smart_add(Eo *obj, Elm_Code_Widget2_Data *pd) +{ + Evas_Object *text; + +printf("add\n"); + eo_do_super(obj, ELM_CODE_WIDGET2_CLASS, evas_obj_smart_add()); + elm_widget_sub_object_parent_add(obj); +// elm_widget_can_focus_set(obj, EINA_TRUE); + + text = elm_label_add(obj); + elm_object_text_set(text, "HELLO"); + elm_widget_sub_object_add(obj, text); + + evas_object_size_hint_weight_set(text, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(text, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(text); + + eo_do(obj, elm_obj_widget_theme_apply()); + + elm_layout_sizing_eval(obj); +} + +EOLIAN static void +_elm_code_widget2_font_size_set(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Font_Size font_size) +{ + printf("set\n"); + pd->font_size = font_size; +} + +EOLIAN static Evas_Font_Size +_elm_code_widget2_font_size_get(Eo *obj, Elm_Code_Widget2_Data *pd) +{ + return pd->font_size; +} + +#include "elm_code_widget2.eo.c" diff --git a/legacy/elm_code/lib/elm_code_widget2.eo b/legacy/elm_code/lib/elm_code_widget2.eo new file mode 100644 index 0000000000..9104233b15 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_widget2.eo @@ -0,0 +1,30 @@ +class Elm_Code_Widget2 (Elm_Layout, Elm_Interface_Scrollable, + Elm_Interface_Atspi_Text) +{ + eo_prefix: elm_code_widget2; + properties { + font_size { + set { + } + get { + } + values { + Evas_Font_Size font_size; + } + } + } + methods { + } + implements { + class.constructor; + Eo.Base.constructor; + Evas.Object_Smart.add; + Evas.Object_Smart.resize; + Elm_Interface_Scrollable.content_pos_set; + } + events { + focused; + unfocused; + } + +} diff --git a/legacy/elm_code/lib/elm_code_widget2.eo.c b/legacy/elm_code/lib/elm_code_widget2.eo.c new file mode 100644 index 0000000000..2b3a597070 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_widget2.eo.c @@ -0,0 +1,53 @@ +EOAPI const Eo_Event_Description _ELM_CODE_WIDGET2_EVENT_FOCUSED = + EO_EVENT_DESCRIPTION("focused", ""); +EOAPI const Eo_Event_Description _ELM_CODE_WIDGET2_EVENT_UNFOCUSED = + EO_EVENT_DESCRIPTION("unfocused", ""); + +void _elm_code_widget2_font_size_set(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Font_Size font_size); + +EOAPI EO_VOID_FUNC_BODYV(elm_code_widget2_font_size_set, EO_FUNC_CALL(font_size), Evas_Font_Size font_size); + +Evas_Font_Size _elm_code_widget2_font_size_get(Eo *obj, Elm_Code_Widget2_Data *pd); + +EOAPI EO_FUNC_BODY(elm_code_widget2_font_size_get, Evas_Font_Size, 0); + +void _elm_code_widget2_eo_base_constructor(Eo *obj, Elm_Code_Widget2_Data *pd); + + +void _elm_code_widget2_evas_object_smart_add(Eo *obj, Elm_Code_Widget2_Data *pd); + + +void _elm_code_widget2_evas_object_smart_resize(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Coord w, Evas_Coord h); + + +void _elm_code_widget2_elm_interface_scrollable_content_pos_set(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Coord x, Evas_Coord y, Eina_Bool sig); + + +static Eo_Op_Description _elm_code_widget2_op_desc[] = { + EO_OP_FUNC_OVERRIDE(eo_constructor, _elm_code_widget2_eo_base_constructor), + EO_OP_FUNC_OVERRIDE(evas_obj_smart_add, _elm_code_widget2_evas_object_smart_add), + EO_OP_FUNC_OVERRIDE(evas_obj_smart_resize, _elm_code_widget2_evas_object_smart_resize), + EO_OP_FUNC_OVERRIDE(elm_interface_scrollable_content_pos_set, _elm_code_widget2_elm_interface_scrollable_content_pos_set), + EO_OP_FUNC(elm_code_widget2_font_size_set, _elm_code_widget2_font_size_set, ""), + EO_OP_FUNC(elm_code_widget2_font_size_get, _elm_code_widget2_font_size_get, ""), + EO_OP_SENTINEL +}; + +static const Eo_Event_Description *_elm_code_widget2_event_desc[] = { + ELM_CODE_WIDGET2_EVENT_FOCUSED, + ELM_CODE_WIDGET2_EVENT_UNFOCUSED, + NULL +}; + +static const Eo_Class_Description _elm_code_widget2_class_desc = { + EO_VERSION, + "Elm_Code_Widget2", + EO_CLASS_TYPE_REGULAR, + EO_CLASS_DESCRIPTION_OPS(_elm_code_widget2_op_desc), + _elm_code_widget2_event_desc, + sizeof(Elm_Code_Widget2_Data), + _elm_code_widget2_class_constructor, + NULL +}; + +EO_DEFINE_CLASS(elm_code_widget2_class_get, &_elm_code_widget2_class_desc, ELM_LAYOUT_CLASS, ELM_INTERFACE_SCROLLABLE_MIXIN, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); \ No newline at end of file diff --git a/legacy/elm_code/lib/elm_code_widget2.eo.h b/legacy/elm_code/lib/elm_code_widget2.eo.h new file mode 100644 index 0000000000..75d1b4daa3 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_widget2.eo.h @@ -0,0 +1,50 @@ +#ifndef _ELM_CODE_WIDGET2_EO_H_ +#define _ELM_CODE_WIDGET2_EO_H_ + +#ifndef _ELM_CODE_WIDGET2_EO_CLASS_TYPE +#define _ELM_CODE_WIDGET2_EO_CLASS_TYPE + +typedef Eo Elm_Code_Widget2; + +#endif + +#ifndef _ELM_CODE_WIDGET2_EO_TYPES +#define _ELM_CODE_WIDGET2_EO_TYPES + + +#endif +#define ELM_CODE_WIDGET2_CLASS elm_code_widget2_class_get() + +const Eo_Class *elm_code_widget2_class_get(void) EINA_CONST; + +/** + * + * No description supplied. + * + * @param[in] font_size No description supplied. + * + */ +EOAPI void elm_code_widget2_font_size_set(Evas_Font_Size font_size); + +/** + * + * No description supplied. + * + * + */ +EOAPI Evas_Font_Size elm_code_widget2_font_size_get(void); + +EOAPI extern const Eo_Event_Description _ELM_CODE_WIDGET2_EVENT_FOCUSED; +EOAPI extern const Eo_Event_Description _ELM_CODE_WIDGET2_EVENT_UNFOCUSED; + +/** + * No description + */ +#define ELM_CODE_WIDGET2_EVENT_FOCUSED (&(_ELM_CODE_WIDGET2_EVENT_FOCUSED)) + +/** + * No description + */ +#define ELM_CODE_WIDGET2_EVENT_UNFOCUSED (&(_ELM_CODE_WIDGET2_EVENT_UNFOCUSED)) + +#endif diff --git a/legacy/elm_code/lib/regen.sh b/legacy/elm_code/lib/regen.sh new file mode 100755 index 0000000000..51acc50f38 --- /dev/null +++ b/legacy/elm_code/lib/regen.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +INCLUDE="-I /usr/local/share/eolian/include/eo-1 -I /usr/local/share/eolian/include/elementary-1 -I /usr/local/share/eolian/include/evas-1 -I /usr/local/share/eolian/include/efl-1" + +eolian_gen $INCLUDE --gh --eo -o elm_code_widget2.eo.h elm_code_widget2.eo +eolian_gen $INCLUDE --gc --eo -o elm_code_widget2.eo.c elm_code_widget2.eo +eolian_gen $INCLUDE --gi --eo -o elm_code_widget2.c elm_code_widget2.eo From 1bd963c084dd92d5d35bf826ddd2f5d7893e9726 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 23 Jan 2015 23:41:53 +0000 Subject: [PATCH 053/254] install our test diff for elm_code_test binaries --- legacy/elm_code/bin/elm_code_test_main.c | 4 +++- legacy/elm_code/tests/Makefile.am | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index e81a4e5e30..0bb60921dd 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -72,10 +72,12 @@ _elm_code_test_welcome_setup(Evas_Object *parent) static Evas_Object * _elm_code_test_diff_setup(Evas_Object *parent) { - char *path = "elm_code/tests/testdiff.diff"; + char path[PATH_MAX]; Evas_Object *diff; Elm_Code *code; + snprintf(path, sizeof(path), "%s/../edi/data/testdiff.diff", elm_app_data_dir_get()); + code = elm_code_create(); elm_code_file_open(code, path); diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/tests/Makefile.am index d1edb30027..2f63f38892 100644 --- a/legacy/elm_code/tests/Makefile.am +++ b/legacy/elm_code/tests/Makefile.am @@ -23,4 +23,7 @@ elm_code_suite_DEPENDENCIES = $(top_builddir)/elm_code/lib/libelm_code.la endif -EXTRA_DIST = elm_code_suite.h +testdir = $(datadir)/$(PACKAGE)/data +test_DATA = testdiff.diff + +EXTRA_DIST = elm_code_suite.h $(test_DATA) From 82e57792ca3b1379521fd897ade4c50b31dbf2d3 Mon Sep 17 00:00:00 2001 From: Stephen Houston Date: Fri, 23 Jan 2015 20:35:14 -0600 Subject: [PATCH 054/254] Elm_Code_Widget2: Inherit from box instead of layout since a layout is not provided. --- legacy/elm_code/lib/elm_code_widget2.c | 5 +---- legacy/elm_code/lib/elm_code_widget2.eo.c | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget2.c b/legacy/elm_code/lib/elm_code_widget2.c index 24dc8dfb55..b9ba337396 100644 --- a/legacy/elm_code/lib/elm_code_widget2.c +++ b/legacy/elm_code/lib/elm_code_widget2.c @@ -55,15 +55,12 @@ printf("add\n"); text = elm_label_add(obj); elm_object_text_set(text, "HELLO"); - elm_widget_sub_object_add(obj, text); - evas_object_size_hint_weight_set(text, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(text, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(text); + elm_box_pack_end(obj, text); eo_do(obj, elm_obj_widget_theme_apply()); - - elm_layout_sizing_eval(obj); } EOLIAN static void diff --git a/legacy/elm_code/lib/elm_code_widget2.eo.c b/legacy/elm_code/lib/elm_code_widget2.eo.c index 2b3a597070..827bba3be0 100644 --- a/legacy/elm_code/lib/elm_code_widget2.eo.c +++ b/legacy/elm_code/lib/elm_code_widget2.eo.c @@ -26,7 +26,7 @@ void _elm_code_widget2_elm_interface_scrollable_content_pos_set(Eo *obj, Elm_Cod static Eo_Op_Description _elm_code_widget2_op_desc[] = { EO_OP_FUNC_OVERRIDE(eo_constructor, _elm_code_widget2_eo_base_constructor), EO_OP_FUNC_OVERRIDE(evas_obj_smart_add, _elm_code_widget2_evas_object_smart_add), - EO_OP_FUNC_OVERRIDE(evas_obj_smart_resize, _elm_code_widget2_evas_object_smart_resize), +// EO_OP_FUNC_OVERRIDE(evas_obj_smart_resize, _elm_code_widget2_evas_object_smart_resize), EO_OP_FUNC_OVERRIDE(elm_interface_scrollable_content_pos_set, _elm_code_widget2_elm_interface_scrollable_content_pos_set), EO_OP_FUNC(elm_code_widget2_font_size_set, _elm_code_widget2_font_size_set, ""), EO_OP_FUNC(elm_code_widget2_font_size_get, _elm_code_widget2_font_size_get, ""), @@ -50,4 +50,4 @@ static const Eo_Class_Description _elm_code_widget2_class_desc = { NULL }; -EO_DEFINE_CLASS(elm_code_widget2_class_get, &_elm_code_widget2_class_desc, ELM_LAYOUT_CLASS, ELM_INTERFACE_SCROLLABLE_MIXIN, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); \ No newline at end of file +EO_DEFINE_CLASS(elm_code_widget2_class_get, &_elm_code_widget2_class_desc, ELM_BOX_CLASS, ELM_INTERFACE_SCROLLABLE_MIXIN, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); From eec17b5904f273ca94c02c5aea51d73636566bd3 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 24 Jan 2015 08:26:09 +0000 Subject: [PATCH 055/254] Fix eo and regen to generate the right code based on okra's changes. We need to inherit from Elm_Box and not get in the way of smart resizing... --- legacy/elm_code/lib/elm_code_widget2.eo | 3 +-- legacy/elm_code/lib/elm_code_widget2.eo.c | 6 +----- legacy/elm_code/lib/regen.sh | 1 + 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget2.eo b/legacy/elm_code/lib/elm_code_widget2.eo index 9104233b15..63bc5d23f8 100644 --- a/legacy/elm_code/lib/elm_code_widget2.eo +++ b/legacy/elm_code/lib/elm_code_widget2.eo @@ -1,4 +1,4 @@ -class Elm_Code_Widget2 (Elm_Layout, Elm_Interface_Scrollable, +class Elm_Code_Widget2 (Elm_Box, Elm_Interface_Scrollable, Elm_Interface_Atspi_Text) { eo_prefix: elm_code_widget2; @@ -19,7 +19,6 @@ class Elm_Code_Widget2 (Elm_Layout, Elm_Interface_Scrollable, class.constructor; Eo.Base.constructor; Evas.Object_Smart.add; - Evas.Object_Smart.resize; Elm_Interface_Scrollable.content_pos_set; } events { diff --git a/legacy/elm_code/lib/elm_code_widget2.eo.c b/legacy/elm_code/lib/elm_code_widget2.eo.c index 827bba3be0..b689d764b0 100644 --- a/legacy/elm_code/lib/elm_code_widget2.eo.c +++ b/legacy/elm_code/lib/elm_code_widget2.eo.c @@ -17,16 +17,12 @@ void _elm_code_widget2_eo_base_constructor(Eo *obj, Elm_Code_Widget2_Data *pd); void _elm_code_widget2_evas_object_smart_add(Eo *obj, Elm_Code_Widget2_Data *pd); -void _elm_code_widget2_evas_object_smart_resize(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Coord w, Evas_Coord h); - - void _elm_code_widget2_elm_interface_scrollable_content_pos_set(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Coord x, Evas_Coord y, Eina_Bool sig); static Eo_Op_Description _elm_code_widget2_op_desc[] = { EO_OP_FUNC_OVERRIDE(eo_constructor, _elm_code_widget2_eo_base_constructor), EO_OP_FUNC_OVERRIDE(evas_obj_smart_add, _elm_code_widget2_evas_object_smart_add), -// EO_OP_FUNC_OVERRIDE(evas_obj_smart_resize, _elm_code_widget2_evas_object_smart_resize), EO_OP_FUNC_OVERRIDE(elm_interface_scrollable_content_pos_set, _elm_code_widget2_elm_interface_scrollable_content_pos_set), EO_OP_FUNC(elm_code_widget2_font_size_set, _elm_code_widget2_font_size_set, ""), EO_OP_FUNC(elm_code_widget2_font_size_get, _elm_code_widget2_font_size_get, ""), @@ -50,4 +46,4 @@ static const Eo_Class_Description _elm_code_widget2_class_desc = { NULL }; -EO_DEFINE_CLASS(elm_code_widget2_class_get, &_elm_code_widget2_class_desc, ELM_BOX_CLASS, ELM_INTERFACE_SCROLLABLE_MIXIN, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); +EO_DEFINE_CLASS(elm_code_widget2_class_get, &_elm_code_widget2_class_desc, ELM_BOX_CLASS, ELM_INTERFACE_SCROLLABLE_MIXIN, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); \ No newline at end of file diff --git a/legacy/elm_code/lib/regen.sh b/legacy/elm_code/lib/regen.sh index 51acc50f38..055f8e70c2 100755 --- a/legacy/elm_code/lib/regen.sh +++ b/legacy/elm_code/lib/regen.sh @@ -1,4 +1,5 @@ #!/bin/sh +cd `dirname $0` INCLUDE="-I /usr/local/share/eolian/include/eo-1 -I /usr/local/share/eolian/include/elementary-1 -I /usr/local/share/eolian/include/evas-1 -I /usr/local/share/eolian/include/efl-1" From 29d31ad9f1174c9e11888c18a25279e226013902 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 24 Jan 2015 22:07:00 +0000 Subject: [PATCH 056/254] Complete port of elm_code widget to eo as widget2 --- legacy/elm_code/bin/elm_code_test_main.c | 22 +- legacy/elm_code/lib/elm_code.c | 2 +- legacy/elm_code/lib/elm_code_widget2.c | 339 +++++++++++++++++++--- legacy/elm_code/lib/elm_code_widget2.eo | 21 +- legacy/elm_code/lib/elm_code_widget2.eo.c | 29 +- legacy/elm_code/lib/elm_code_widget2.eo.h | 44 ++- 6 files changed, 392 insertions(+), 65 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 7180eb796f..755c5329d0 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -48,23 +48,15 @@ static Evas_Object * _elm_code_test_welcome_setup(Evas_Object *parent) { Elm_Code *code; - Evas_Object *widget; + Elm_Code_Widget2 *widget; code = elm_code_create(); - - Elm_Code_Widget2 *obj = eo_add(ELM_CODE_WIDGET2_CLASS, parent); - eo_do(obj, - elm_code_widget2_font_size_set(14)); - - evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(obj); -return obj; -// TODO - add all this good stuff into the eo api - widget = elm_code_widget_add(parent, code); - elm_code_widget_font_size_set(widget, 14); - elm_code_widget_editable_set(widget, EINA_TRUE); - eo_do(widget,eo_event_callback_add(&ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_cb, code)); + widget = eo_add(ELM_CODE_WIDGET2_CLASS, parent); + eo_do(widget, + elm_code_widget2_code_set(code); + elm_code_widget2_font_size_set(14); + elm_code_widget2_editable_set(EINA_TRUE); + eo_event_callback_add(ELM_CODE_WIDGET2_EVENT_LINE_CLICKED, _elm_code_test_line_cb, code)); _append_line(code->file, "Hello World, Elm Code!"); elm_code_file_line_token_add(code->file, 1, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/lib/elm_code.c index d1e32826af..1f965120e7 100644 --- a/legacy/elm_code/lib/elm_code.c +++ b/legacy/elm_code/lib/elm_code.c @@ -105,7 +105,7 @@ EAPI void elm_code_callback_fire(Elm_Code *code, const Eo_Event_Description *signal, void *data) { Eina_List *item; - Evas_Object *widget; + Eo *widget; EINA_LIST_FOREACH(code->widgets, item, widget) { diff --git a/legacy/elm_code/lib/elm_code_widget2.c b/legacy/elm_code/lib/elm_code_widget2.c index b9ba337396..fa165320b6 100644 --- a/legacy/elm_code/lib/elm_code_widget2.c +++ b/legacy/elm_code/lib/elm_code_widget2.c @@ -11,69 +11,342 @@ typedef struct { Elm_Code *code; + Evas_Object *grid; Evas_Font_Size font_size; unsigned int cursor_line, cursor_col; Eina_Bool editable; - } Elm_Code_Widget2_Data; +Eina_Unicode status_icons2[] = { + ' ', + '!', + + '+', + '-', + ' ', + + 0x2713, + 0x2717, + + 0 +}; + + EOLIAN static void -_elm_code_widget2_eo_base_constructor(Eo *obj, Elm_Code_Widget2_Data *pd) +_elm_code_widget2_eo_base_constructor(Eo *obj, Elm_Code_Widget2_Data *pd EINA_UNUSED) { eo_do_super(obj, ELM_CODE_WIDGET2_CLASS, eo_constructor()); -printf("constr\n"); + + pd->cursor_line = 1; + pd->cursor_col = 1; } EOLIAN static void -_elm_code_widget2_evas_object_smart_resize(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Coord w, Evas_Coord h) -{ -printf("size %d, %d\n", w, h); -} - -EOLIAN static void -_elm_code_widget2_class_constructor(Eo_Class *klass) +_elm_code_widget2_class_constructor(Eo_Class *klass EINA_UNUSED) { } -EOLIAN static void -_elm_code_widget2_elm_interface_scrollable_content_pos_set(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Coord x, Evas_Coord y, Eina_Bool sig) +static Eina_Bool +_elm_code_widget_resize(Evas_Object *o) { + int w, h, cw, ch; + evas_object_geometry_get(o, NULL, NULL, &w, &h); + evas_object_textgrid_cell_size_get(o, &cw, &ch); + + evas_object_textgrid_size_set(o, ceil(((double) w) / cw), + ceil(((double) h) / ch)); + + return h > 0 && w > 0; +} + +static void +_elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start, int end, Elm_Code_Token_Type type) +{ + int x; + + for (x = start; x <= end && x < count; x++) + { + cells[x].fg = type; + } +} + +static void +_elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, unsigned int count, Elm_Code_Line *line) +{ + Eina_List *item; + Elm_Code_Token *token; + int start, length; + + start = 1; + length = line->length; + + EINA_LIST_FOREACH(line->tokens, item, token) + { + + _elm_code_widget_fill_line_token(cells, count, start, token->start, ELM_CODE_TOKEN_TYPE_DEFAULT); + + // TODO handle a token starting before the previous finishes + _elm_code_widget_fill_line_token(cells, count, token->start, token->end, token->type); + + start = token->end + 1; + } + + _elm_code_widget_fill_line_token(cells, count, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); +} + +static void +_elm_code_widget_fill_line(Elm_Code_Widget2_Data *pd, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) +{ + char *chr; + unsigned int length, x; + int w; + + if (!_elm_code_widget_resize(pd->grid)) + return; + + length = line->length; + evas_object_textgrid_size_get(pd->grid, &w, NULL); + + cells[0].codepoint = status_icons2[line->status]; + cells[0].bold = 1; + cells[0].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; + cells[0].bg = line->status; + + if (line->modified) + chr = line->modified; + else + chr = (char *)line->content; + for (x = 1; x < (unsigned int) w && x <= length; x++) + { + cells[x].codepoint = *chr; + cells[x].bg = line->status; + + chr++; + } + for (; x < (unsigned int) w; x++) + { + cells[x].codepoint = 0; + cells[x].bg = line->status; + } + + _elm_code_widget_fill_line_tokens(cells, w, line); + if (pd->editable && pd->cursor_line == line->number) + { + if (pd->cursor_col < (unsigned int) w) + cells[pd->cursor_col].bg = ELM_CODE_TOKEN_TYPE_CURSOR; + } + + evas_object_textgrid_update_add(pd->grid, 0, line->number - 1, w, 1); +} + +static void +_elm_code_widget_fill(Elm_Code_Widget2_Data *pd) +{ + Elm_Code_Line *line; + Evas_Textgrid_Cell *cells; + int w, h; + unsigned int y; + + if (!_elm_code_widget_resize(pd->grid)) + return; + evas_object_textgrid_size_get(pd->grid, &w, &h); + + for (y = 1; y <= (unsigned int) h && y <= elm_code_file_lines_get(pd->code->file); y++) + { + line = elm_code_file_line_get(pd->code->file, y); + + cells = evas_object_textgrid_cellrow_get(pd->grid, y - 1); + _elm_code_widget_fill_line(pd, cells, line); + } +} + +static Eina_Bool +_elm_code_widget2_line_cb(void *data, Eo *obj EINA_UNUSED, + const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +{ + Elm_Code_Widget2_Data *widget; + Elm_Code_Line *line; + int h; + + Evas_Textgrid_Cell *cells; + + widget = (Elm_Code_Widget2_Data *)data; + line = (Elm_Code_Line *)event_info; + + evas_object_textgrid_size_get(widget->grid, NULL, &h); + + if (line->number > (unsigned int) h) + return EINA_TRUE; + + cells = evas_object_textgrid_cellrow_get(widget->grid, line->number - 1); + _elm_code_widget_fill_line(widget, cells, line); + + return EINA_TRUE; +} + + +static Eina_Bool +_elm_code_widget2_file_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + Elm_Code_Widget2_Data *widget; + + widget = (Elm_Code_Widget2_Data *)data; + + _elm_code_widget_fill(widget); + return EINA_TRUE; +} + +static void +_elm_code_widget2_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + Elm_Code_Widget2_Data *widget; + + widget = (Elm_Code_Widget2_Data *)data; + + _elm_code_widget_fill(widget); +} + +static void +_elm_code_widget2_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, + void *event_info) +{ + Elm_Code_Widget2 *widget; + Elm_Code_Widget2_Data *pd; + Elm_Code_Line *line; + Evas_Event_Mouse_Up *event; + Evas_Coord y; + int ch; + unsigned int row; + + widget = (Elm_Code_Widget2 *)data; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET2_CLASS); + event = (Evas_Event_Mouse_Up *)event_info; + y = event->canvas.y; + + evas_object_textgrid_cell_size_get(pd->grid, NULL, &ch); + row = ((double) y / ch) + 1; + + line = elm_code_file_line_get(pd->code->file, row); + if (line) + eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET2_EVENT_LINE_CLICKED, line)); +} + +EOLIAN static void +_elm_code_widget2_elm_interface_scrollable_content_pos_set(Eo *obj EINA_UNUSED, + Elm_Code_Widget2_Data *pd EINA_UNUSED, + Evas_Coord x, Evas_Coord y, + Eina_Bool sig EINA_UNUSED) +{ + printf("scroll to %d, %d\n", x, y); +} + +EOLIAN static void +_elm_code_widget2_font_size_set(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd, Evas_Font_Size font_size) +{ + evas_object_textgrid_font_set(pd->grid, "Mono", font_size * elm_config_scale_get()); + pd->font_size = font_size; +} + +EOLIAN static Evas_Font_Size +_elm_code_widget2_font_size_get(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd) +{ + return pd->font_size; +} + +EOLIAN static void +_elm_code_widget2_code_set(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd, Elm_Code *code) +{ + pd->code = code; + + code->widgets = eina_list_append(code->widgets, pd); +} + +EOLIAN static Elm_Code * +_elm_code_widget2_code_get(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd) +{ + return pd->code; +} + +EOLIAN static void +_elm_code_widget2_editable_set(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd, Eina_Bool editable) +{ + pd->editable = editable; +} + +EOLIAN static Eina_Bool +_elm_code_widget2_editable_get(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd) +{ + return pd->editable; +} + +static void +_elm_code_widget2_setup_palette(Evas_Object *o) +{ + // setup status colors + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, + 36, 36, 36, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ERROR, + 205, 54, 54, 255); + + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ADDED, + 36, 96, 36, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_REMOVED, + 96, 36, 36, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CHANGED, + 36, 36, 96, 255); + + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_PASSED, + 54, 96, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FAILED, + 96, 54, 54, 255); + + // setup token colors + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT, + 205, 205, 205, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_COMMENT, + 54, 205, 255, 255); + + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_ADDED, + 54, 255, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_REMOVED, + 255, 54, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CHANGED, + 54, 54, 255, 255); + + // the style for a cursor - this is a special token and will be applied to the background + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CURSOR, + 205, 205, 54, 255); } EOLIAN static void _elm_code_widget2_evas_object_smart_add(Eo *obj, Elm_Code_Widget2_Data *pd) { - Evas_Object *text; + Evas_Object *grid; -printf("add\n"); eo_do_super(obj, ELM_CODE_WIDGET2_CLASS, evas_obj_smart_add()); - elm_widget_sub_object_parent_add(obj); // elm_widget_can_focus_set(obj, EINA_TRUE); - text = elm_label_add(obj); - elm_object_text_set(text, "HELLO"); - evas_object_size_hint_weight_set(text, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(text, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(text); - elm_box_pack_end(obj, text); + grid = evas_object_textgrid_add(obj); + evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(grid); + elm_box_pack_end(obj, grid); + pd->grid = grid; + _elm_code_widget2_setup_palette(grid); - eo_do(obj, elm_obj_widget_theme_apply()); -} + evas_object_event_callback_add(grid, EVAS_CALLBACK_RESIZE, _elm_code_widget2_resize_cb, pd); + evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget2_clicked_cb, obj); -EOLIAN static void -_elm_code_widget2_font_size_set(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Font_Size font_size) -{ - printf("set\n"); - pd->font_size = font_size; -} + eo_do(obj, + eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget2_line_cb, pd); + eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget2_file_cb, pd)); -EOLIAN static Evas_Font_Size -_elm_code_widget2_font_size_get(Eo *obj, Elm_Code_Widget2_Data *pd) -{ - return pd->font_size; + _elm_code_widget2_font_size_set(obj, pd, 10); } #include "elm_code_widget2.eo.c" diff --git a/legacy/elm_code/lib/elm_code_widget2.eo b/legacy/elm_code/lib/elm_code_widget2.eo index 63bc5d23f8..d71f78f677 100644 --- a/legacy/elm_code/lib/elm_code_widget2.eo +++ b/legacy/elm_code/lib/elm_code_widget2.eo @@ -3,6 +3,15 @@ class Elm_Code_Widget2 (Elm_Box, Elm_Interface_Scrollable, { eo_prefix: elm_code_widget2; properties { + code { + set { + } + get { + } + values { + Elm_Code *code; + } + } font_size { set { } @@ -12,6 +21,15 @@ class Elm_Code_Widget2 (Elm_Box, Elm_Interface_Scrollable, Evas_Font_Size font_size; } } + editable { + set { + } + get { + } + values { + Eina_Bool editable; + } + } } methods { } @@ -22,8 +40,7 @@ class Elm_Code_Widget2 (Elm_Box, Elm_Interface_Scrollable, Elm_Interface_Scrollable.content_pos_set; } events { - focused; - unfocused; + line,clicked; } } diff --git a/legacy/elm_code/lib/elm_code_widget2.eo.c b/legacy/elm_code/lib/elm_code_widget2.eo.c index b689d764b0..bf34af5eb9 100644 --- a/legacy/elm_code/lib/elm_code_widget2.eo.c +++ b/legacy/elm_code/lib/elm_code_widget2.eo.c @@ -1,7 +1,13 @@ -EOAPI const Eo_Event_Description _ELM_CODE_WIDGET2_EVENT_FOCUSED = - EO_EVENT_DESCRIPTION("focused", ""); -EOAPI const Eo_Event_Description _ELM_CODE_WIDGET2_EVENT_UNFOCUSED = - EO_EVENT_DESCRIPTION("unfocused", ""); +EOAPI const Eo_Event_Description _ELM_CODE_WIDGET2_EVENT_LINE_CLICKED = + EO_EVENT_DESCRIPTION("line,clicked", ""); + +void _elm_code_widget2_code_set(Eo *obj, Elm_Code_Widget2_Data *pd, Elm_Code *code); + +EOAPI EO_VOID_FUNC_BODYV(elm_code_widget2_code_set, EO_FUNC_CALL(code), Elm_Code *code); + +Elm_Code * _elm_code_widget2_code_get(Eo *obj, Elm_Code_Widget2_Data *pd); + +EOAPI EO_FUNC_BODY(elm_code_widget2_code_get, Elm_Code *, 0); void _elm_code_widget2_font_size_set(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Font_Size font_size); @@ -11,6 +17,14 @@ Evas_Font_Size _elm_code_widget2_font_size_get(Eo *obj, Elm_Code_Widget2_Data *p EOAPI EO_FUNC_BODY(elm_code_widget2_font_size_get, Evas_Font_Size, 0); +void _elm_code_widget2_editable_set(Eo *obj, Elm_Code_Widget2_Data *pd, Eina_Bool editable); + +EOAPI EO_VOID_FUNC_BODYV(elm_code_widget2_editable_set, EO_FUNC_CALL(editable), Eina_Bool editable); + +Eina_Bool _elm_code_widget2_editable_get(Eo *obj, Elm_Code_Widget2_Data *pd); + +EOAPI EO_FUNC_BODY(elm_code_widget2_editable_get, Eina_Bool, 0); + void _elm_code_widget2_eo_base_constructor(Eo *obj, Elm_Code_Widget2_Data *pd); @@ -24,14 +38,17 @@ static Eo_Op_Description _elm_code_widget2_op_desc[] = { EO_OP_FUNC_OVERRIDE(eo_constructor, _elm_code_widget2_eo_base_constructor), EO_OP_FUNC_OVERRIDE(evas_obj_smart_add, _elm_code_widget2_evas_object_smart_add), EO_OP_FUNC_OVERRIDE(elm_interface_scrollable_content_pos_set, _elm_code_widget2_elm_interface_scrollable_content_pos_set), + EO_OP_FUNC(elm_code_widget2_code_set, _elm_code_widget2_code_set, ""), + EO_OP_FUNC(elm_code_widget2_code_get, _elm_code_widget2_code_get, ""), EO_OP_FUNC(elm_code_widget2_font_size_set, _elm_code_widget2_font_size_set, ""), EO_OP_FUNC(elm_code_widget2_font_size_get, _elm_code_widget2_font_size_get, ""), + EO_OP_FUNC(elm_code_widget2_editable_set, _elm_code_widget2_editable_set, ""), + EO_OP_FUNC(elm_code_widget2_editable_get, _elm_code_widget2_editable_get, ""), EO_OP_SENTINEL }; static const Eo_Event_Description *_elm_code_widget2_event_desc[] = { - ELM_CODE_WIDGET2_EVENT_FOCUSED, - ELM_CODE_WIDGET2_EVENT_UNFOCUSED, + ELM_CODE_WIDGET2_EVENT_LINE_CLICKED, NULL }; diff --git a/legacy/elm_code/lib/elm_code_widget2.eo.h b/legacy/elm_code/lib/elm_code_widget2.eo.h index 75d1b4daa3..cbad231fcd 100644 --- a/legacy/elm_code/lib/elm_code_widget2.eo.h +++ b/legacy/elm_code/lib/elm_code_widget2.eo.h @@ -17,6 +17,23 @@ typedef Eo Elm_Code_Widget2; const Eo_Class *elm_code_widget2_class_get(void) EINA_CONST; +/** + * + * No description supplied. + * + * @param[in] code No description supplied. + * + */ +EOAPI void elm_code_widget2_code_set(Elm_Code *code); + +/** + * + * No description supplied. + * + * + */ +EOAPI Elm_Code * elm_code_widget2_code_get(void); + /** * * No description supplied. @@ -34,17 +51,28 @@ EOAPI void elm_code_widget2_font_size_set(Evas_Font_Size font_size); */ EOAPI Evas_Font_Size elm_code_widget2_font_size_get(void); -EOAPI extern const Eo_Event_Description _ELM_CODE_WIDGET2_EVENT_FOCUSED; -EOAPI extern const Eo_Event_Description _ELM_CODE_WIDGET2_EVENT_UNFOCUSED; +/** + * + * No description supplied. + * + * @param[in] editable No description supplied. + * + */ +EOAPI void elm_code_widget2_editable_set(Eina_Bool editable); + +/** + * + * No description supplied. + * + * + */ +EOAPI Eina_Bool elm_code_widget2_editable_get(void); + +EOAPI extern const Eo_Event_Description _ELM_CODE_WIDGET2_EVENT_LINE_CLICKED; /** * No description */ -#define ELM_CODE_WIDGET2_EVENT_FOCUSED (&(_ELM_CODE_WIDGET2_EVENT_FOCUSED)) - -/** - * No description - */ -#define ELM_CODE_WIDGET2_EVENT_UNFOCUSED (&(_ELM_CODE_WIDGET2_EVENT_UNFOCUSED)) +#define ELM_CODE_WIDGET2_EVENT_LINE_CLICKED (&(_ELM_CODE_WIDGET2_EVENT_LINE_CLICKED)) #endif From 3c9e554b7b03c0681f74fce82591068efdf2727b Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 25 Jan 2015 17:18:21 +0000 Subject: [PATCH 057/254] elm_code: Add focus support for the elm_code widget. Hook into the internal elementary API to be part of the focus chain --- legacy/elm_code/bin/elm_code_test_main.c | 9 ++------ legacy/elm_code/lib/elm_code_widget2.c | 26 ++++++++++++++++++++--- legacy/elm_code/lib/elm_code_widget2.eo | 1 + legacy/elm_code/lib/elm_code_widget2.eo.c | 4 ++++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 755c5329d0..d83c11643d 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -92,8 +92,7 @@ _elm_code_test_diff_setup(Evas_Object *parent) static Evas_Object * elm_code_test_win_setup(void) { - Evas_Object *win; - Evas_Object *vbox; + Evas_Object *win,*vbox; win = elm_win_util_standard_add("main", "Elm_Code Test"); if (!win) return NULL; @@ -104,15 +103,11 @@ elm_code_test_win_setup(void) elm_box_homogeneous_set(vbox, EINA_TRUE); evas_object_show(vbox); - elm_win_focus_highlight_enabled_set(win, EINA_TRUE); - evas_object_smart_callback_add(win, "delete,request", _elm_code_test_win_del, NULL); - elm_box_pack_end(vbox, _elm_code_test_welcome_setup(vbox)); - elm_box_pack_end(vbox, _elm_code_test_diff_setup(vbox)); - elm_win_resize_object_add(win, vbox); + evas_object_smart_callback_add(win, "delete,request", _elm_code_test_win_del, NULL); evas_object_resize(win, 380 * elm_config_scale_get(), 240 * elm_config_scale_get()); evas_object_show(win); diff --git a/legacy/elm_code/lib/elm_code_widget2.c b/legacy/elm_code/lib/elm_code_widget2.c index fa165320b6..0856012414 100644 --- a/legacy/elm_code/lib/elm_code_widget2.c +++ b/legacy/elm_code/lib/elm_code_widget2.c @@ -5,6 +5,9 @@ #include #include #include +#define ELM_INTERNAL_API_ARGESFSDFEFC +#include + #include #include "elm_code_widget2.eo.h" @@ -15,7 +18,7 @@ typedef struct Evas_Font_Size font_size; unsigned int cursor_line, cursor_col; - Eina_Bool editable; + Eina_Bool editable, focussed; } Elm_Code_Widget2_Data; Eina_Unicode status_icons2[] = { @@ -133,7 +136,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget2_Data *pd, Evas_Textgrid_Cell *cells, } _elm_code_widget_fill_line_tokens(cells, w, line); - if (pd->editable && pd->cursor_line == line->number) + if (pd->editable && pd->focussed && pd->cursor_line == line->number) { if (pd->cursor_col < (unsigned int) w) cells[pd->cursor_col].bg = ELM_CODE_TOKEN_TYPE_CURSOR; @@ -225,6 +228,10 @@ _elm_code_widget2_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj E widget = (Elm_Code_Widget2 *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET2_CLASS); + + if (pd->editable && !pd->focussed) + return; + event = (Evas_Event_Mouse_Up *)event_info; y = event->canvas.y; @@ -236,6 +243,19 @@ _elm_code_widget2_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj E eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET2_EVENT_LINE_CLICKED, line)); } +EOLIAN static Eina_Bool +_elm_code_widget2_elm_widget_on_focus(Eo *obj, Elm_Code_Widget2_Data *pd) +{ + Eina_Bool int_ret = EINA_FALSE; + eo_do_super(obj, ELM_CODE_WIDGET2_CLASS, int_ret = elm_obj_widget_on_focus()); + if (!int_ret) return EINA_TRUE; + + pd->focussed = elm_widget_focus_get(obj); + + _elm_code_widget_fill(pd); + return EINA_TRUE; +} + EOLIAN static void _elm_code_widget2_elm_interface_scrollable_content_pos_set(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd EINA_UNUSED, @@ -329,7 +349,7 @@ _elm_code_widget2_evas_object_smart_add(Eo *obj, Elm_Code_Widget2_Data *pd) Evas_Object *grid; eo_do_super(obj, ELM_CODE_WIDGET2_CLASS, evas_obj_smart_add()); -// elm_widget_can_focus_set(obj, EINA_TRUE); + elm_widget_can_focus_set(obj, EINA_TRUE); grid = evas_object_textgrid_add(obj); evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); diff --git a/legacy/elm_code/lib/elm_code_widget2.eo b/legacy/elm_code/lib/elm_code_widget2.eo index d71f78f677..39f6f4dfb8 100644 --- a/legacy/elm_code/lib/elm_code_widget2.eo +++ b/legacy/elm_code/lib/elm_code_widget2.eo @@ -37,6 +37,7 @@ class Elm_Code_Widget2 (Elm_Box, Elm_Interface_Scrollable, class.constructor; Eo.Base.constructor; Evas.Object_Smart.add; + Elm_Widget.on_focus; Elm_Interface_Scrollable.content_pos_set; } events { diff --git a/legacy/elm_code/lib/elm_code_widget2.eo.c b/legacy/elm_code/lib/elm_code_widget2.eo.c index bf34af5eb9..0aa2208880 100644 --- a/legacy/elm_code/lib/elm_code_widget2.eo.c +++ b/legacy/elm_code/lib/elm_code_widget2.eo.c @@ -31,12 +31,16 @@ void _elm_code_widget2_eo_base_constructor(Eo *obj, Elm_Code_Widget2_Data *pd); void _elm_code_widget2_evas_object_smart_add(Eo *obj, Elm_Code_Widget2_Data *pd); +Eina_Bool _elm_code_widget2_elm_widget_on_focus(Eo *obj, Elm_Code_Widget2_Data *pd); + + void _elm_code_widget2_elm_interface_scrollable_content_pos_set(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Coord x, Evas_Coord y, Eina_Bool sig); static Eo_Op_Description _elm_code_widget2_op_desc[] = { EO_OP_FUNC_OVERRIDE(eo_constructor, _elm_code_widget2_eo_base_constructor), EO_OP_FUNC_OVERRIDE(evas_obj_smart_add, _elm_code_widget2_evas_object_smart_add), + EO_OP_FUNC_OVERRIDE(elm_obj_widget_on_focus, _elm_code_widget2_elm_widget_on_focus), EO_OP_FUNC_OVERRIDE(elm_interface_scrollable_content_pos_set, _elm_code_widget2_elm_interface_scrollable_content_pos_set), EO_OP_FUNC(elm_code_widget2_code_set, _elm_code_widget2_code_set, ""), EO_OP_FUNC(elm_code_widget2_code_get, _elm_code_widget2_code_get, ""), From 6e57210c3a9961b8693de15eff651334eee7ae75 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 25 Jan 2015 23:15:37 +0000 Subject: [PATCH 058/254] Manipulate the position of the cursor. When clicking in edit mode just change the position of it to where was clicked. Known issue that this does not work with the keyboard --- legacy/elm_code/lib/elm_code_widget2.c | 112 ++++++++++++++++++++++--- 1 file changed, 99 insertions(+), 13 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget2.c b/legacy/elm_code/lib/elm_code_widget2.c index 0856012414..834201ca5e 100644 --- a/legacy/elm_code/lib/elm_code_widget2.c +++ b/legacy/elm_code/lib/elm_code_widget2.c @@ -215,26 +215,45 @@ _elm_code_widget2_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EI } static void -_elm_code_widget2_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, - void *event_info) +_elm_code_widget2_clicked_editable_cb(Elm_Code_Widget2 *widget, Evas_Coord x, Evas_Coord y) +{ + Elm_Code_Widget2_Data *pd; + Elm_Code_Line *line; + int cw, ch; + unsigned int row, col; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET2_CLASS); + + evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); + col = ((double) x / cw) + 2; + row = ((double) y / ch) + 1; + + line = elm_code_file_line_get(pd->code->file, row); + if (line) + { + pd->cursor_line = row; + + if (col <= (unsigned int) line->length + 2) + pd->cursor_col = col - 2; + else + pd->cursor_col = line->length + 1; + } + if (pd->cursor_col == 0) + pd->cursor_col = 1; + + _elm_code_widget_fill(pd); +} + +static void +_elm_code_widget2_clicked_readonly_cb(Elm_Code_Widget2 *widget, Evas_Coord y) { - Elm_Code_Widget2 *widget; Elm_Code_Widget2_Data *pd; Elm_Code_Line *line; - Evas_Event_Mouse_Up *event; - Evas_Coord y; int ch; unsigned int row; - widget = (Elm_Code_Widget2 *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET2_CLASS); - if (pd->editable && !pd->focussed) - return; - - event = (Evas_Event_Mouse_Up *)event_info; - y = event->canvas.y; - evas_object_textgrid_cell_size_get(pd->grid, NULL, &ch); row = ((double) y / ch) + 1; @@ -243,6 +262,71 @@ _elm_code_widget2_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj E eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET2_EVENT_LINE_CLICKED, line)); } +static void +_elm_code_widget2_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, + void *event_info) +{ + Elm_Code_Widget2 *widget; + Elm_Code_Widget2_Data *pd; + Evas_Event_Mouse_Up *event; + Evas_Coord x, y; + + widget = (Elm_Code_Widget2 *)data; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET2_CLASS); + event = (Evas_Event_Mouse_Up *)event_info; + + x = event->canvas.x; + y = event->canvas.y; + + if (pd->editable) + _elm_code_widget2_clicked_editable_cb(widget, x, y); + else + _elm_code_widget2_clicked_readonly_cb(widget, y); +} + +static void +_elm_code_widget2_cursor_move_up(Elm_Code_Widget2 *widget) +{ + Elm_Code_Widget2_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET2_CLASS); + + if (pd->cursor_line > 1) + pd->cursor_line--; + + _elm_code_widget_fill(pd); +} + +static void +_elm_code_widget2_cursor_move_down(Elm_Code_Widget2 *widget) +{ + Elm_Code_Widget2_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET2_CLASS); + + if (pd->cursor_line < elm_code_file_lines_get(pd->code->file)) + pd->cursor_line++; + + _elm_code_widget_fill(pd); +} + +static void +_elm_code_widget2_key_down_cb(void *data, Evas *evas EINA_UNUSED, + Evas_Object *obj EINA_UNUSED, void *event_info) +{ + Elm_Code_Widget2 *widget; + + widget = (Elm_Code_Widget2 *)data; + + Evas_Event_Key_Down *ev = event_info; + + printf("KEY %s\n", ev->key); + if (!(strcmp(ev->key, "Up"))) + _elm_code_widget2_cursor_move_up(widget); + if (!(strcmp(ev->key, "Down"))) + _elm_code_widget2_cursor_move_down(widget); +} + EOLIAN static Eina_Bool _elm_code_widget2_elm_widget_on_focus(Eo *obj, Elm_Code_Widget2_Data *pd) { @@ -349,7 +433,7 @@ _elm_code_widget2_evas_object_smart_add(Eo *obj, Elm_Code_Widget2_Data *pd) Evas_Object *grid; eo_do_super(obj, ELM_CODE_WIDGET2_CLASS, evas_obj_smart_add()); - elm_widget_can_focus_set(obj, EINA_TRUE); + elm_object_focus_allow_set(obj, EINA_TRUE); grid = evas_object_textgrid_add(obj); evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -361,6 +445,8 @@ _elm_code_widget2_evas_object_smart_add(Eo *obj, Elm_Code_Widget2_Data *pd) evas_object_event_callback_add(grid, EVAS_CALLBACK_RESIZE, _elm_code_widget2_resize_cb, pd); evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget2_clicked_cb, obj); +// FIXME find why obj is not getting key_down events + evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget2_key_down_cb, obj); eo_do(obj, eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget2_line_cb, pd); From ebcbde488250ecdeffbbc14fbf7b841977f005e1 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 26 Jan 2015 14:00:37 +0000 Subject: [PATCH 059/254] Port everything to use new widget API. Remove old widget API --- legacy/elm_code/lib/Elm_Code.h | 2 +- legacy/elm_code/lib/Makefile.am | 3 +- legacy/elm_code/lib/elm_code_diff_widget.c | 21 +- legacy/elm_code/lib/elm_code_widget.c | 289 ------------------- legacy/elm_code/lib/elm_code_widget.h | 100 ------- legacy/elm_code/tests/Makefile.am | 2 + legacy/elm_code/tests/elm_code_test_widget.c | 2 +- 7 files changed, 18 insertions(+), 401 deletions(-) delete mode 100644 legacy/elm_code/lib/elm_code_widget.c delete mode 100644 legacy/elm_code/lib/elm_code_widget.h diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 35071a2173..8a30dfed7e 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -34,7 +34,7 @@ #include "elm_code_common.h" #include "elm_code_file.h" #include "elm_code_parse.h" -#include "elm_code_widget.h" +#include "elm_code_widget2.eo.h" #include "elm_code_diff_widget.h" #ifdef __cplusplus diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am index 193b9e4650..bf848116d8 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/lib/Makefile.am @@ -12,7 +12,7 @@ lib_LTLIBRARIES = libelm_code.la includes_HEADERS = \ elm_code_file.h \ elm_code_parse.h \ -elm_code_widget.h \ +elm_code_widget2.eo.h \ elm_code_diff_widget.h \ Elm_Code.h includesdir = $(includedir)/edi-@VMAJ@ @@ -20,7 +20,6 @@ includesdir = $(includedir)/edi-@VMAJ@ libelm_code_la_SOURCES = \ elm_code_file.c \ elm_code_parse.c \ -elm_code_widget.c \ elm_code_widget2.c \ elm_code_diff_widget.c \ elm_code.c \ diff --git a/legacy/elm_code/lib/elm_code_diff_widget.c b/legacy/elm_code/lib/elm_code_diff_widget.c index f008159c5b..3db4fbbb26 100644 --- a/legacy/elm_code/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/lib/elm_code_diff_widget.c @@ -80,7 +80,8 @@ static void _elm_code_diff_widget_parse_diff(Elm_Code_File *diff, Elm_Code_File EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) { Elm_Code *wcode1, *wcode2; - Evas_Object *widget_left, *widget_right, *hbox; + Elm_Code_Widget2 *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); @@ -90,7 +91,9 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // left side of diff wcode1 = elm_code_create(); - widget_left = elm_code_widget_add(parent, wcode1); + widget_left = eo_add(ELM_CODE_WIDGET2_CLASS, parent); + eo_do(widget_left, + elm_code_widget2_code_set(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); @@ -100,7 +103,9 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // right side of diff wcode2 = elm_code_create(); - widget_right = elm_code_widget_add(parent, wcode2); + widget_right = eo_add(ELM_CODE_WIDGET2_CLASS, parent); + eo_do(widget_right, + elm_code_widget2_code_set(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); @@ -114,11 +119,11 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) EAPI void elm_code_diff_widget_font_size_set(Evas_Object *widget, int size) { - Evas_Object *child; + Elm_Code_Widget2 *child; - child = evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_LEFT); - elm_code_widget_font_size_set(child, size); - child = evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_RIGHT); - elm_code_widget_font_size_set(child, size); + child = (Elm_Code_Widget2 *) evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_LEFT); + eo_do(child, elm_code_widget2_font_size_set(size)); + child = (Elm_Code_Widget2 *) evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_RIGHT); + eo_do(child, elm_code_widget2_font_size_set(size)); } diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c deleted file mode 100644 index d91412a91a..0000000000 --- a/legacy/elm_code/lib/elm_code_widget.c +++ /dev/null @@ -1,289 +0,0 @@ -#ifdef HAVE_CONFIG -# include "config.h" -#endif - -#include "Elm_Code.h" - -#include "elm_code_private.h" - -EAPI const Eo_Event_Description ELM_CODE_WIDGET_EVENT_LINE_CLICKED = - EO_EVENT_DESCRIPTION("line,clicked", ""); - -Eina_Unicode status_icons[] = { - ' ', - '!', - - '+', - '-', - ' ', - - 0x2713, - 0x2717, - - 0 -}; - -static Eina_Bool -_elm_code_widget_resize(Evas_Object *o) -{ - int w, h, cw, ch; - - evas_object_geometry_get(o, NULL, NULL, &w, &h); - evas_object_textgrid_cell_size_get(o, &cw, &ch); - evas_object_textgrid_size_set(o, ceil(((double) w) / cw), - ceil(((double) h) / ch)); - - return h > 0 && w > 0; -} - -static void -_elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start, int end, Elm_Code_Token_Type type) -{ - int x; - - for (x = start; x <= end && x < count; x++) - { - cells[x].fg = type; - } -} - -static void -_elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, unsigned int count, Elm_Code_Line *line) -{ - Eina_List *item; - Elm_Code_Token *token; - int start, length; - - start = 1; - length = line->length; - - EINA_LIST_FOREACH(line->tokens, item, token) - { - - _elm_code_widget_fill_line_token(cells, count, start, token->start, ELM_CODE_TOKEN_TYPE_DEFAULT); - - // TODO handle a token starting before the previous finishes - _elm_code_widget_fill_line_token(cells, count, token->start, token->end, token->type); - - start = token->end + 1; - } - - _elm_code_widget_fill_line_token(cells, count, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); -} - -static void -_elm_code_widget_fill_line(Evas_Object *o, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) -{ - char *chr; - unsigned int length, x; - int w; - ELM_CODE_WIDGET_DATA_GET(o, widget); - - if (!_elm_code_widget_resize(o)) - return; - - length = line->length; - evas_object_textgrid_size_get(o, &w, NULL); - - cells[0].codepoint = status_icons[line->status]; - cells[0].bold = 1; - cells[0].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; - cells[0].bg = line->status; - - if (line->modified) - chr = line->modified; - else - chr = (char *)line->content; - for (x = 1; x < (unsigned int) w && x <= length; x++) - { - cells[x].codepoint = *chr; - cells[x].bg = line->status; - - chr++; - } - for (; x < (unsigned int) w; x++) - { - cells[x].codepoint = 0; - cells[x].bg = line->status; - } - - _elm_code_widget_fill_line_tokens(cells, w, line); - if (widget->editable && widget->cursor_line == line->number) - { - if (widget->cursor_col < (unsigned int) w) - cells[widget->cursor_col].bg = ELM_CODE_TOKEN_TYPE_CURSOR; - } - - evas_object_textgrid_update_add(o, 0, line->number - 1, w, 1); -} - -static void -_elm_code_widget_fill(Evas_Object *o, Elm_Code *code) -{ - Elm_Code_Line *line; - Evas_Textgrid_Cell *cells; - int w, h; - unsigned int y; - - if (!_elm_code_widget_resize(o)) - return; - evas_object_textgrid_size_get(o, &w, &h); - - for (y = 1; y <= (unsigned int) h && y <= elm_code_file_lines_get(code->file); y++) - { - line = elm_code_file_line_get(code->file, y); - - cells = evas_object_textgrid_cellrow_get(o, y - 1); - _elm_code_widget_fill_line(o, cells, line); - } -} - -static Eina_Bool -_elm_code_widget_line_cb(void *data EINA_UNUSED, Eo *obj, - const Eo_Event_Description *desc EINA_UNUSED, void *event_info) -{ - Elm_Code_Line *line; - Evas_Object *o; - int h; - - Evas_Textgrid_Cell *cells; - - line = (Elm_Code_Line *)event_info; - o = (Evas_Object *)obj; - - evas_object_textgrid_size_get(o, NULL, &h); - - if (line->number > (unsigned int) h) - return EINA_TRUE; - - cells = evas_object_textgrid_cellrow_get(o, line->number - 1); - _elm_code_widget_fill_line(o, cells, line); - - return EINA_TRUE; -} - - -static Eina_Bool -_elm_code_widget_file_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, - void *event_info EINA_UNUSED) -{ - Evas_Object *o; - Elm_Code *code; - - code = (Elm_Code *)data; - o = (Evas_Object *)obj; - - _elm_code_widget_fill(o, code); - return EINA_TRUE; -} - -static void -_elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, - void *event_info EINA_UNUSED) -{ - Elm_Code *code; - - code = (Elm_Code *)data; - - _elm_code_widget_fill(obj, code); -} - -static void -_elm_code_widget_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, - void *event_info) -{ - Elm_Code *code; - Elm_Code_Line *line; - Evas_Event_Mouse_Up *event; - Evas_Coord y; - int ch; - unsigned int row; - - code = (Elm_Code *)data; - event = (Evas_Event_Mouse_Up *)event_info; - y = event->canvas.y; - - evas_object_textgrid_cell_size_get(obj, NULL, &ch); - row = ((double) y / ch) + 1; - - line = elm_code_file_line_get(code->file, row); - if (line) - elm_code_callback_fire(code, &ELM_CODE_WIDGET_EVENT_LINE_CLICKED, line); -} - -EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code) -{ - Evas_Object *o; - Elm_Code_Widget *widget; - - o = evas_object_textgrid_add(parent); - - // setup status colors - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, - 36, 36, 36, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ERROR, - 205, 54, 54, 255); - - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ADDED, - 36, 96, 36, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_REMOVED, - 96, 36, 36, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CHANGED, - 36, 36, 96, 255); - - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_PASSED, - 54, 96, 54, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FAILED, - 96, 54, 54, 255); - - // setup token colors - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT, - 205, 205, 205, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_COMMENT, - 54, 205, 255, 255); - - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_ADDED, - 54, 255, 54, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_REMOVED, - 255, 54, 54, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CHANGED, - 54, 54, 255, 255); - - // the style for a cursor - this is a special token and will be applied to the background - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CURSOR, - 205, 205, 54, 255); - evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, code); - evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_clicked_cb, code); - - eo_do(o,eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, code)); - eo_do(o,eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, code)); - - widget = calloc(1, sizeof(*widget)); - widget->code = code; - widget->cursor_line = 1; - widget->cursor_col = 1; - evas_object_data_set(o, ELM_CODE_WIDGET_DATA_KEY, widget); - code->widgets = eina_list_append(code->widgets, o); - - elm_code_widget_font_size_set(o, 10); - return o; -} - -EAPI void -elm_code_widget_font_size_set(Evas_Object *obj, Evas_Font_Size size) -{ - ELM_CODE_WIDGET_DATA_GET(obj, widget); - - widget->font_size = size; - evas_object_textgrid_font_set(obj, "Mono", size * elm_config_scale_get()); -} - -EAPI void -elm_code_widget_editable_set(Evas_Object *obj, Eina_Bool editable) -{ - ELM_CODE_WIDGET_DATA_GET(obj, widget); - - widget->editable = editable; -} - - diff --git a/legacy/elm_code/lib/elm_code_widget.h b/legacy/elm_code/lib/elm_code_widget.h deleted file mode 100644 index 1a172036c7..0000000000 --- a/legacy/elm_code/lib/elm_code_widget.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef ELM_CODE_WIDGET_H_ -# define ELM_CODE_WIDGET_H_ - -EAPI extern const Eo_Event_Description ELM_CODE_WIDGET_EVENT_LINE_CLICKED; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @file - * @brief These routines are used for rendering instances of Elm Code. - */ - -typedef struct _Elm_Code_Widget -{ - Elm_Code *code; - - Evas_Font_Size font_size; - unsigned int cursor_line, cursor_col; - Eina_Bool editable; - -} Elm_Code_Widget; - -#define ELM_CODE_WIDGET_DATA_KEY "Elm_Code_Widget" -#define ELM_CODE_WIDGET_DATA_GET(o, ptr, ...) \ - Elm_Code_Widget *ptr; \ - ptr = evas_object_data_get(o, ELM_CODE_WIDGET_DATA_KEY); - -#define ELM_CODE_WIDGET_DATA_GET_OR_RETURN(o, ptr, ...) \ - Elm_Code_Widget *ptr; \ - ptr = evas_object_data_get(o, ELM_CODE_WIDGET_DATA_KEY);\ - if (EINA_UNLIKELY(!ptr)) \ - { \ - CRI("no widget data for object %p (%s)", \ - o, evas_object_type_get(o)); \ - return __VA_ARGS__; \ - } - -/** - * @brief UI Loading functions. - * @defgroup Init Creating a widget to render an Elm Code backend - * - * @{ - * - * Functions for UI loading. - * - */ - -EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code); - -/** - * @} - * - * @brief UI Manipulation functions. - * @defgroup UI Manage aspects of an Elm_Code widget - * - * @{ - * - * Functions for UI manipulation. - * - */ - -/** - * Set the font size of a widget - * - * Change the size of the monospaced font used by this widget instance. - * 10 pt is the default font size for an elm_code widget. - * - * @param widget The widget to change - * @param size The font size to set on this widget - * - * @ingroup UI - */ -EAPI void elm_code_widget_font_size_set(Evas_Object *widget, Evas_Font_Size size); - -/** - * Set this widget to be editable - * - * An editable widget displays a cursor and accepts user input. - * It will also accept focus. - * If EINA_FALSE is passed this widget will return to being read-only. - * EINA_FALSE is the default value for editable. - * - * @param widget The widget to change - * @param editable Whether or not this widget should be editable - * - * @ingroup UI - */ -EAPI void elm_code_widget_editable_set(Evas_Object *widget, Eina_Bool editable); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* ELM_CODE_WIDGET_H_ */ diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/tests/Makefile.am index 2f63f38892..712c389029 100644 --- a/legacy/elm_code/tests/Makefile.am +++ b/legacy/elm_code/tests/Makefile.am @@ -12,6 +12,8 @@ elm_code_test_widget.c \ elm_code_suite.c elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/lib/ \ +-DEFL_BETA_API_SUPPORT \ +-DEFL_EO_API_SUPPORT \ -DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/tests/\" \ -DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/tests/\" \ -DEFL_BETA_API_SUPPORT \ diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/tests/elm_code_test_widget.c index 6efdce8715..3b598a972f 100644 --- a/legacy/elm_code/tests/elm_code_test_widget.c +++ b/legacy/elm_code/tests/elm_code_test_widget.c @@ -4,7 +4,7 @@ #include "elm_code_suite.h" -#include "elm_code_widget.c" +#include "elm_code_widget2.c" static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type, int id) { From 0a279a34df82d576348315d62a323a30a2749dd2 Mon Sep 17 00:00:00 2001 From: Stephen Houston Date: Mon, 26 Jan 2015 10:28:04 -0600 Subject: [PATCH 060/254] Elm_Code: For box to get key down, it needs to have a child receiving key down. --- legacy/elm_code/lib/elm_code_widget2.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget2.c b/legacy/elm_code/lib/elm_code_widget2.c index 834201ca5e..3a70015f51 100644 --- a/legacy/elm_code/lib/elm_code_widget2.c +++ b/legacy/elm_code/lib/elm_code_widget2.c @@ -430,16 +430,22 @@ _elm_code_widget2_setup_palette(Evas_Object *o) EOLIAN static void _elm_code_widget2_evas_object_smart_add(Eo *obj, Elm_Code_Widget2_Data *pd) { - Evas_Object *grid; + Evas_Object *grid, *scroller; eo_do_super(obj, ELM_CODE_WIDGET2_CLASS, evas_obj_smart_add()); elm_object_focus_allow_set(obj, EINA_TRUE); - grid = evas_object_textgrid_add(obj); + scroller = elm_scroller_add(obj); + evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(scroller); + elm_box_pack_end(obj, scroller); + + grid = evas_object_textgrid_add(obj); evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(grid); - elm_box_pack_end(obj, grid); + elm_object_content_set(scroller, grid); pd->grid = grid; _elm_code_widget2_setup_palette(grid); From bc69b360bcd7ae6087051bbdff1207b21205b62f Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 26 Jan 2015 19:05:34 +0000 Subject: [PATCH 061/254] Refactor eo widget2 to widget - update in edi too --- legacy/elm_code/bin/elm_code_test_main.c | 14 +- legacy/elm_code/lib/Elm_Code.h | 2 +- legacy/elm_code/lib/Makefile.am | 4 +- legacy/elm_code/lib/elm_code_diff_widget.c | 20 +-- .../{elm_code_widget2.c => elm_code_widget.c} | 130 +++++++++--------- ...elm_code_widget2.eo => elm_code_widget.eo} | 6 +- legacy/elm_code/lib/elm_code_widget.eo.c | 70 ++++++++++ legacy/elm_code/lib/elm_code_widget.eo.h | 78 +++++++++++ legacy/elm_code/lib/elm_code_widget2.eo.c | 70 ---------- legacy/elm_code/lib/elm_code_widget2.eo.h | 78 ----------- legacy/elm_code/lib/regen.sh | 6 +- legacy/elm_code/tests/elm_code_test_widget.c | 2 +- 12 files changed, 240 insertions(+), 240 deletions(-) rename legacy/elm_code/lib/{elm_code_widget2.c => elm_code_widget.c} (72%) rename legacy/elm_code/lib/{elm_code_widget2.eo => elm_code_widget.eo} (82%) create mode 100644 legacy/elm_code/lib/elm_code_widget.eo.c create mode 100644 legacy/elm_code/lib/elm_code_widget.eo.h delete mode 100644 legacy/elm_code/lib/elm_code_widget2.eo.c delete mode 100644 legacy/elm_code/lib/elm_code_widget2.eo.h diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index d83c11643d..2897c3c12b 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -12,7 +12,7 @@ #include "gettext.h" #include -#include "elm_code_widget2.eo.h" +#include "elm_code_widget.eo.h" #include "elm_code_test_private.h" @@ -48,15 +48,15 @@ static Evas_Object * _elm_code_test_welcome_setup(Evas_Object *parent) { Elm_Code *code; - Elm_Code_Widget2 *widget; + Elm_Code_Widget *widget; code = elm_code_create(); - widget = eo_add(ELM_CODE_WIDGET2_CLASS, parent); + widget = eo_add(ELM_CODE_WIDGET_CLASS, parent); eo_do(widget, - elm_code_widget2_code_set(code); - elm_code_widget2_font_size_set(14); - elm_code_widget2_editable_set(EINA_TRUE); - eo_event_callback_add(ELM_CODE_WIDGET2_EVENT_LINE_CLICKED, _elm_code_test_line_cb, code)); + elm_code_widget_code_set(code); + elm_code_widget_font_size_set(14); + elm_code_widget_editable_set(EINA_TRUE); + eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_cb, code)); _append_line(code->file, "Hello World, Elm Code!"); elm_code_file_line_token_add(code->file, 1, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 8a30dfed7e..21384c978a 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -34,7 +34,7 @@ #include "elm_code_common.h" #include "elm_code_file.h" #include "elm_code_parse.h" -#include "elm_code_widget2.eo.h" +#include "elm_code_widget.eo.h" #include "elm_code_diff_widget.h" #ifdef __cplusplus diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am index bf848116d8..447e052bd2 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/lib/Makefile.am @@ -12,7 +12,7 @@ lib_LTLIBRARIES = libelm_code.la includes_HEADERS = \ elm_code_file.h \ elm_code_parse.h \ -elm_code_widget2.eo.h \ +elm_code_widget.eo.h \ elm_code_diff_widget.h \ Elm_Code.h includesdir = $(includedir)/edi-@VMAJ@ @@ -20,7 +20,7 @@ includesdir = $(includedir)/edi-@VMAJ@ libelm_code_la_SOURCES = \ elm_code_file.c \ elm_code_parse.c \ -elm_code_widget2.c \ +elm_code_widget.c \ elm_code_diff_widget.c \ elm_code.c \ elm_code_private.h diff --git a/legacy/elm_code/lib/elm_code_diff_widget.c b/legacy/elm_code/lib/elm_code_diff_widget.c index 3db4fbbb26..2315d0a59e 100644 --- a/legacy/elm_code/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/lib/elm_code_diff_widget.c @@ -80,7 +80,7 @@ static void _elm_code_diff_widget_parse_diff(Elm_Code_File *diff, Elm_Code_File EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) { Elm_Code *wcode1, *wcode2; - Elm_Code_Widget2 *widget_left, *widget_right; + Elm_Code_Widget *widget_left, *widget_right; Evas_Object *hbox; hbox = elm_panes_add(parent); @@ -91,9 +91,9 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // left side of diff wcode1 = elm_code_create(); - widget_left = eo_add(ELM_CODE_WIDGET2_CLASS, parent); + widget_left = eo_add(ELM_CODE_WIDGET_CLASS, parent); eo_do(widget_left, - elm_code_widget2_code_set(wcode1)); + elm_code_widget_code_set(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); @@ -103,9 +103,9 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // right side of diff wcode2 = elm_code_create(); - widget_right = eo_add(ELM_CODE_WIDGET2_CLASS, parent); + widget_right = eo_add(ELM_CODE_WIDGET_CLASS, parent); eo_do(widget_right, - elm_code_widget2_code_set(wcode2)); + elm_code_widget_code_set(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); @@ -119,11 +119,11 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) EAPI void elm_code_diff_widget_font_size_set(Evas_Object *widget, int size) { - Elm_Code_Widget2 *child; + Elm_Code_Widget *child; - child = (Elm_Code_Widget2 *) evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_LEFT); - eo_do(child, elm_code_widget2_font_size_set(size)); - child = (Elm_Code_Widget2 *) evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_RIGHT); - eo_do(child, elm_code_widget2_font_size_set(size)); + child = (Elm_Code_Widget *) evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_LEFT); + eo_do(child, elm_code_widget_font_size_set(size)); + child = (Elm_Code_Widget *) evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_RIGHT); + eo_do(child, elm_code_widget_font_size_set(size)); } diff --git a/legacy/elm_code/lib/elm_code_widget2.c b/legacy/elm_code/lib/elm_code_widget.c similarity index 72% rename from legacy/elm_code/lib/elm_code_widget2.c rename to legacy/elm_code/lib/elm_code_widget.c index 834201ca5e..22ace877b2 100644 --- a/legacy/elm_code/lib/elm_code_widget2.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -9,7 +9,7 @@ #include #include -#include "elm_code_widget2.eo.h" +#include "elm_code_widget.eo.h" typedef struct { @@ -19,9 +19,9 @@ typedef struct Evas_Font_Size font_size; unsigned int cursor_line, cursor_col; Eina_Bool editable, focussed; -} Elm_Code_Widget2_Data; +} Elm_Code_Widget_Data; -Eina_Unicode status_icons2[] = { +Eina_Unicode status_icons[] = { ' ', '!', @@ -37,16 +37,16 @@ Eina_Unicode status_icons2[] = { EOLIAN static void -_elm_code_widget2_eo_base_constructor(Eo *obj, Elm_Code_Widget2_Data *pd EINA_UNUSED) +_elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED) { - eo_do_super(obj, ELM_CODE_WIDGET2_CLASS, eo_constructor()); + eo_do_super(obj, ELM_CODE_WIDGET_CLASS, eo_constructor()); pd->cursor_line = 1; pd->cursor_col = 1; } EOLIAN static void -_elm_code_widget2_class_constructor(Eo_Class *klass EINA_UNUSED) +_elm_code_widget_class_constructor(Eo_Class *klass EINA_UNUSED) { } @@ -101,7 +101,7 @@ _elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, unsigned int count, } static void -_elm_code_widget_fill_line(Elm_Code_Widget2_Data *pd, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) +_elm_code_widget_fill_line(Elm_Code_Widget_Data *pd, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) { char *chr; unsigned int length, x; @@ -113,7 +113,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget2_Data *pd, Evas_Textgrid_Cell *cells, length = line->length; evas_object_textgrid_size_get(pd->grid, &w, NULL); - cells[0].codepoint = status_icons2[line->status]; + cells[0].codepoint = status_icons[line->status]; cells[0].bold = 1; cells[0].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; cells[0].bg = line->status; @@ -146,7 +146,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget2_Data *pd, Evas_Textgrid_Cell *cells, } static void -_elm_code_widget_fill(Elm_Code_Widget2_Data *pd) +_elm_code_widget_fill(Elm_Code_Widget_Data *pd) { Elm_Code_Line *line; Evas_Textgrid_Cell *cells; @@ -167,16 +167,16 @@ _elm_code_widget_fill(Elm_Code_Widget2_Data *pd) } static Eina_Bool -_elm_code_widget2_line_cb(void *data, Eo *obj EINA_UNUSED, +_elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info) { - Elm_Code_Widget2_Data *widget; + Elm_Code_Widget_Data *widget; Elm_Code_Line *line; int h; Evas_Textgrid_Cell *cells; - widget = (Elm_Code_Widget2_Data *)data; + widget = (Elm_Code_Widget_Data *)data; line = (Elm_Code_Line *)event_info; evas_object_textgrid_size_get(widget->grid, NULL, &h); @@ -192,37 +192,37 @@ _elm_code_widget2_line_cb(void *data, Eo *obj EINA_UNUSED, static Eina_Bool -_elm_code_widget2_file_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, +_elm_code_widget_file_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) { - Elm_Code_Widget2_Data *widget; + Elm_Code_Widget_Data *widget; - widget = (Elm_Code_Widget2_Data *)data; + widget = (Elm_Code_Widget_Data *)data; _elm_code_widget_fill(widget); return EINA_TRUE; } static void -_elm_code_widget2_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, +_elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - Elm_Code_Widget2_Data *widget; + Elm_Code_Widget_Data *widget; - widget = (Elm_Code_Widget2_Data *)data; + widget = (Elm_Code_Widget_Data *)data; _elm_code_widget_fill(widget); } static void -_elm_code_widget2_clicked_editable_cb(Elm_Code_Widget2 *widget, Evas_Coord x, Evas_Coord y) +_elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas_Coord y) { - Elm_Code_Widget2_Data *pd; + Elm_Code_Widget_Data *pd; Elm_Code_Line *line; int cw, ch; unsigned int row, col; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET2_CLASS); + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); col = ((double) x / cw) + 2; @@ -245,51 +245,51 @@ _elm_code_widget2_clicked_editable_cb(Elm_Code_Widget2 *widget, Evas_Coord x, Ev } static void -_elm_code_widget2_clicked_readonly_cb(Elm_Code_Widget2 *widget, Evas_Coord y) +_elm_code_widget_clicked_readonly_cb(Elm_Code_Widget *widget, Evas_Coord y) { - Elm_Code_Widget2_Data *pd; + Elm_Code_Widget_Data *pd; Elm_Code_Line *line; int ch; unsigned int row; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET2_CLASS); + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); evas_object_textgrid_cell_size_get(pd->grid, NULL, &ch); row = ((double) y / ch) + 1; line = elm_code_file_line_get(pd->code->file, row); if (line) - eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET2_EVENT_LINE_CLICKED, line)); + eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, line)); } static void -_elm_code_widget2_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, +_elm_code_widget_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) { - Elm_Code_Widget2 *widget; - Elm_Code_Widget2_Data *pd; + Elm_Code_Widget *widget; + Elm_Code_Widget_Data *pd; Evas_Event_Mouse_Up *event; Evas_Coord x, y; - widget = (Elm_Code_Widget2 *)data; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET2_CLASS); + widget = (Elm_Code_Widget *)data; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); event = (Evas_Event_Mouse_Up *)event_info; x = event->canvas.x; y = event->canvas.y; if (pd->editable) - _elm_code_widget2_clicked_editable_cb(widget, x, y); + _elm_code_widget_clicked_editable_cb(widget, x, y); else - _elm_code_widget2_clicked_readonly_cb(widget, y); + _elm_code_widget_clicked_readonly_cb(widget, y); } static void -_elm_code_widget2_cursor_move_up(Elm_Code_Widget2 *widget) +_elm_code_widget_cursor_move_up(Elm_Code_Widget *widget) { - Elm_Code_Widget2_Data *pd; + Elm_Code_Widget_Data *pd; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET2_CLASS); + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (pd->cursor_line > 1) pd->cursor_line--; @@ -298,11 +298,11 @@ _elm_code_widget2_cursor_move_up(Elm_Code_Widget2 *widget) } static void -_elm_code_widget2_cursor_move_down(Elm_Code_Widget2 *widget) +_elm_code_widget_cursor_move_down(Elm_Code_Widget *widget) { - Elm_Code_Widget2_Data *pd; + Elm_Code_Widget_Data *pd; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET2_CLASS); + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (pd->cursor_line < elm_code_file_lines_get(pd->code->file)) pd->cursor_line++; @@ -311,27 +311,27 @@ _elm_code_widget2_cursor_move_down(Elm_Code_Widget2 *widget) } static void -_elm_code_widget2_key_down_cb(void *data, Evas *evas EINA_UNUSED, +_elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) { - Elm_Code_Widget2 *widget; + Elm_Code_Widget *widget; - widget = (Elm_Code_Widget2 *)data; + widget = (Elm_Code_Widget *)data; Evas_Event_Key_Down *ev = event_info; printf("KEY %s\n", ev->key); if (!(strcmp(ev->key, "Up"))) - _elm_code_widget2_cursor_move_up(widget); + _elm_code_widget_cursor_move_up(widget); if (!(strcmp(ev->key, "Down"))) - _elm_code_widget2_cursor_move_down(widget); + _elm_code_widget_cursor_move_down(widget); } EOLIAN static Eina_Bool -_elm_code_widget2_elm_widget_on_focus(Eo *obj, Elm_Code_Widget2_Data *pd) +_elm_code_widget_elm_widget_on_focus(Eo *obj, Elm_Code_Widget_Data *pd) { Eina_Bool int_ret = EINA_FALSE; - eo_do_super(obj, ELM_CODE_WIDGET2_CLASS, int_ret = elm_obj_widget_on_focus()); + eo_do_super(obj, ELM_CODE_WIDGET_CLASS, int_ret = elm_obj_widget_on_focus()); if (!int_ret) return EINA_TRUE; pd->focussed = elm_widget_focus_get(obj); @@ -341,8 +341,8 @@ _elm_code_widget2_elm_widget_on_focus(Eo *obj, Elm_Code_Widget2_Data *pd) } EOLIAN static void -_elm_code_widget2_elm_interface_scrollable_content_pos_set(Eo *obj EINA_UNUSED, - Elm_Code_Widget2_Data *pd EINA_UNUSED, +_elm_code_widget_elm_interface_scrollable_content_pos_set(Eo *obj EINA_UNUSED, + Elm_Code_Widget_Data *pd EINA_UNUSED, Evas_Coord x, Evas_Coord y, Eina_Bool sig EINA_UNUSED) { @@ -350,46 +350,46 @@ _elm_code_widget2_elm_interface_scrollable_content_pos_set(Eo *obj EINA_UNUSED, } EOLIAN static void -_elm_code_widget2_font_size_set(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd, Evas_Font_Size font_size) +_elm_code_widget_font_size_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Evas_Font_Size font_size) { evas_object_textgrid_font_set(pd->grid, "Mono", font_size * elm_config_scale_get()); pd->font_size = font_size; } EOLIAN static Evas_Font_Size -_elm_code_widget2_font_size_get(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd) +_elm_code_widget_font_size_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) { return pd->font_size; } EOLIAN static void -_elm_code_widget2_code_set(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd, Elm_Code *code) +_elm_code_widget_code_set(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm_Code *code) { pd->code = code; - code->widgets = eina_list_append(code->widgets, pd); + code->widgets = eina_list_append(code->widgets, obj); } EOLIAN static Elm_Code * -_elm_code_widget2_code_get(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd) +_elm_code_widget_code_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) { return pd->code; } EOLIAN static void -_elm_code_widget2_editable_set(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd, Eina_Bool editable) +_elm_code_widget_editable_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Eina_Bool editable) { pd->editable = editable; } EOLIAN static Eina_Bool -_elm_code_widget2_editable_get(Eo *obj EINA_UNUSED, Elm_Code_Widget2_Data *pd) +_elm_code_widget_editable_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) { return pd->editable; } static void -_elm_code_widget2_setup_palette(Evas_Object *o) +_elm_code_widget_setup_palette(Evas_Object *o) { // setup status colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, @@ -428,11 +428,11 @@ _elm_code_widget2_setup_palette(Evas_Object *o) } EOLIAN static void -_elm_code_widget2_evas_object_smart_add(Eo *obj, Elm_Code_Widget2_Data *pd) +_elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) { Evas_Object *grid; - eo_do_super(obj, ELM_CODE_WIDGET2_CLASS, evas_obj_smart_add()); + eo_do_super(obj, ELM_CODE_WIDGET_CLASS, evas_obj_smart_add()); elm_object_focus_allow_set(obj, EINA_TRUE); grid = evas_object_textgrid_add(obj); @@ -441,18 +441,18 @@ _elm_code_widget2_evas_object_smart_add(Eo *obj, Elm_Code_Widget2_Data *pd) evas_object_show(grid); elm_box_pack_end(obj, grid); pd->grid = grid; - _elm_code_widget2_setup_palette(grid); + _elm_code_widget_setup_palette(grid); - evas_object_event_callback_add(grid, EVAS_CALLBACK_RESIZE, _elm_code_widget2_resize_cb, pd); - evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget2_clicked_cb, obj); + evas_object_event_callback_add(grid, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, pd); + evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_clicked_cb, obj); // FIXME find why obj is not getting key_down events - evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget2_key_down_cb, obj); + evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget_key_down_cb, obj); eo_do(obj, - eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget2_line_cb, pd); - eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget2_file_cb, pd)); + eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, pd); + eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, pd)); - _elm_code_widget2_font_size_set(obj, pd, 10); + _elm_code_widget_font_size_set(obj, pd, 10); } -#include "elm_code_widget2.eo.c" +#include "elm_code_widget.eo.c" diff --git a/legacy/elm_code/lib/elm_code_widget2.eo b/legacy/elm_code/lib/elm_code_widget.eo similarity index 82% rename from legacy/elm_code/lib/elm_code_widget2.eo rename to legacy/elm_code/lib/elm_code_widget.eo index 39f6f4dfb8..491c436d0a 100644 --- a/legacy/elm_code/lib/elm_code_widget2.eo +++ b/legacy/elm_code/lib/elm_code_widget.eo @@ -1,7 +1,7 @@ -class Elm_Code_Widget2 (Elm_Box, Elm_Interface_Scrollable, - Elm_Interface_Atspi_Text) +class Elm_Code_Widget (Elm_Box, Elm_Interface_Scrollable, + Elm_Interface_Atspi_Text) { - eo_prefix: elm_code_widget2; + eo_prefix: elm_code_widget; properties { code { set { diff --git a/legacy/elm_code/lib/elm_code_widget.eo.c b/legacy/elm_code/lib/elm_code_widget.eo.c new file mode 100644 index 0000000000..67fff69e21 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_widget.eo.c @@ -0,0 +1,70 @@ +EOAPI const Eo_Event_Description _ELM_CODE_WIDGET_EVENT_LINE_CLICKED = + EO_EVENT_DESCRIPTION("line,clicked", ""); + +void _elm_code_widget_code_set(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code *code); + +EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_code_set, EO_FUNC_CALL(code), Elm_Code *code); + +Elm_Code * _elm_code_widget_code_get(Eo *obj, Elm_Code_Widget_Data *pd); + +EOAPI EO_FUNC_BODY(elm_code_widget_code_get, Elm_Code *, 0); + +void _elm_code_widget_font_size_set(Eo *obj, Elm_Code_Widget_Data *pd, Evas_Font_Size font_size); + +EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_font_size_set, EO_FUNC_CALL(font_size), Evas_Font_Size font_size); + +Evas_Font_Size _elm_code_widget_font_size_get(Eo *obj, Elm_Code_Widget_Data *pd); + +EOAPI EO_FUNC_BODY(elm_code_widget_font_size_get, Evas_Font_Size, 0); + +void _elm_code_widget_editable_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool editable); + +EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_editable_set, EO_FUNC_CALL(editable), Eina_Bool editable); + +Eina_Bool _elm_code_widget_editable_get(Eo *obj, Elm_Code_Widget_Data *pd); + +EOAPI EO_FUNC_BODY(elm_code_widget_editable_get, Eina_Bool, 0); + +void _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd); + + +void _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd); + + +Eina_Bool _elm_code_widget_elm_widget_on_focus(Eo *obj, Elm_Code_Widget_Data *pd); + + +void _elm_code_widget_elm_interface_scrollable_content_pos_set(Eo *obj, Elm_Code_Widget_Data *pd, Evas_Coord x, Evas_Coord y, Eina_Bool sig); + + +static Eo_Op_Description _elm_code_widget_op_desc[] = { + EO_OP_FUNC_OVERRIDE(eo_constructor, _elm_code_widget_eo_base_constructor), + EO_OP_FUNC_OVERRIDE(evas_obj_smart_add, _elm_code_widget_evas_object_smart_add), + EO_OP_FUNC_OVERRIDE(elm_obj_widget_on_focus, _elm_code_widget_elm_widget_on_focus), + EO_OP_FUNC_OVERRIDE(elm_interface_scrollable_content_pos_set, _elm_code_widget_elm_interface_scrollable_content_pos_set), + EO_OP_FUNC(elm_code_widget_code_set, _elm_code_widget_code_set, ""), + EO_OP_FUNC(elm_code_widget_code_get, _elm_code_widget_code_get, ""), + EO_OP_FUNC(elm_code_widget_font_size_set, _elm_code_widget_font_size_set, ""), + EO_OP_FUNC(elm_code_widget_font_size_get, _elm_code_widget_font_size_get, ""), + EO_OP_FUNC(elm_code_widget_editable_set, _elm_code_widget_editable_set, ""), + EO_OP_FUNC(elm_code_widget_editable_get, _elm_code_widget_editable_get, ""), + EO_OP_SENTINEL +}; + +static const Eo_Event_Description *_elm_code_widget_event_desc[] = { + ELM_CODE_WIDGET_EVENT_LINE_CLICKED, + NULL +}; + +static const Eo_Class_Description _elm_code_widget_class_desc = { + EO_VERSION, + "Elm_Code_Widget", + EO_CLASS_TYPE_REGULAR, + EO_CLASS_DESCRIPTION_OPS(_elm_code_widget_op_desc), + _elm_code_widget_event_desc, + sizeof(Elm_Code_Widget_Data), + _elm_code_widget_class_constructor, + NULL +}; + +EO_DEFINE_CLASS(elm_code_widget_class_get, &_elm_code_widget_class_desc, ELM_BOX_CLASS, ELM_INTERFACE_SCROLLABLE_MIXIN, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); diff --git a/legacy/elm_code/lib/elm_code_widget.eo.h b/legacy/elm_code/lib/elm_code_widget.eo.h new file mode 100644 index 0000000000..44496018d8 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_widget.eo.h @@ -0,0 +1,78 @@ +#ifndef _ELM_CODE_WIDGET_EO_H_ +#define _ELM_CODE_WIDGET_EO_H_ + +#ifndef _ELM_CODE_WIDGET_EO_CLASS_TYPE +#define _ELM_CODE_WIDGET_EO_CLASS_TYPE + +typedef Eo Elm_Code_Widget; + +#endif + +#ifndef _ELM_CODE_WIDGET_EO_TYPES +#define _ELM_CODE_WIDGET_EO_TYPES + + +#endif +#define ELM_CODE_WIDGET_CLASS elm_code_widget_class_get() + +const Eo_Class *elm_code_widget_class_get(void) EINA_CONST; + +/** + * + * No description supplied. + * + * @param[in] code No description supplied. + * + */ +EOAPI void elm_code_widget_code_set(Elm_Code *code); + +/** + * + * No description supplied. + * + * + */ +EOAPI Elm_Code * elm_code_widget_code_get(void); + +/** + * + * No description supplied. + * + * @param[in] font_size No description supplied. + * + */ +EOAPI void elm_code_widget_font_size_set(Evas_Font_Size font_size); + +/** + * + * No description supplied. + * + * + */ +EOAPI Evas_Font_Size elm_code_widget_font_size_get(void); + +/** + * + * No description supplied. + * + * @param[in] editable No description supplied. + * + */ +EOAPI void elm_code_widget_editable_set(Eina_Bool editable); + +/** + * + * No description supplied. + * + * + */ +EOAPI Eina_Bool elm_code_widget_editable_get(void); + +EOAPI extern const Eo_Event_Description _ELM_CODE_WIDGET_EVENT_LINE_CLICKED; + +/** + * No description + */ +#define ELM_CODE_WIDGET_EVENT_LINE_CLICKED (&(_ELM_CODE_WIDGET_EVENT_LINE_CLICKED)) + +#endif diff --git a/legacy/elm_code/lib/elm_code_widget2.eo.c b/legacy/elm_code/lib/elm_code_widget2.eo.c deleted file mode 100644 index 0aa2208880..0000000000 --- a/legacy/elm_code/lib/elm_code_widget2.eo.c +++ /dev/null @@ -1,70 +0,0 @@ -EOAPI const Eo_Event_Description _ELM_CODE_WIDGET2_EVENT_LINE_CLICKED = - EO_EVENT_DESCRIPTION("line,clicked", ""); - -void _elm_code_widget2_code_set(Eo *obj, Elm_Code_Widget2_Data *pd, Elm_Code *code); - -EOAPI EO_VOID_FUNC_BODYV(elm_code_widget2_code_set, EO_FUNC_CALL(code), Elm_Code *code); - -Elm_Code * _elm_code_widget2_code_get(Eo *obj, Elm_Code_Widget2_Data *pd); - -EOAPI EO_FUNC_BODY(elm_code_widget2_code_get, Elm_Code *, 0); - -void _elm_code_widget2_font_size_set(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Font_Size font_size); - -EOAPI EO_VOID_FUNC_BODYV(elm_code_widget2_font_size_set, EO_FUNC_CALL(font_size), Evas_Font_Size font_size); - -Evas_Font_Size _elm_code_widget2_font_size_get(Eo *obj, Elm_Code_Widget2_Data *pd); - -EOAPI EO_FUNC_BODY(elm_code_widget2_font_size_get, Evas_Font_Size, 0); - -void _elm_code_widget2_editable_set(Eo *obj, Elm_Code_Widget2_Data *pd, Eina_Bool editable); - -EOAPI EO_VOID_FUNC_BODYV(elm_code_widget2_editable_set, EO_FUNC_CALL(editable), Eina_Bool editable); - -Eina_Bool _elm_code_widget2_editable_get(Eo *obj, Elm_Code_Widget2_Data *pd); - -EOAPI EO_FUNC_BODY(elm_code_widget2_editable_get, Eina_Bool, 0); - -void _elm_code_widget2_eo_base_constructor(Eo *obj, Elm_Code_Widget2_Data *pd); - - -void _elm_code_widget2_evas_object_smart_add(Eo *obj, Elm_Code_Widget2_Data *pd); - - -Eina_Bool _elm_code_widget2_elm_widget_on_focus(Eo *obj, Elm_Code_Widget2_Data *pd); - - -void _elm_code_widget2_elm_interface_scrollable_content_pos_set(Eo *obj, Elm_Code_Widget2_Data *pd, Evas_Coord x, Evas_Coord y, Eina_Bool sig); - - -static Eo_Op_Description _elm_code_widget2_op_desc[] = { - EO_OP_FUNC_OVERRIDE(eo_constructor, _elm_code_widget2_eo_base_constructor), - EO_OP_FUNC_OVERRIDE(evas_obj_smart_add, _elm_code_widget2_evas_object_smart_add), - EO_OP_FUNC_OVERRIDE(elm_obj_widget_on_focus, _elm_code_widget2_elm_widget_on_focus), - EO_OP_FUNC_OVERRIDE(elm_interface_scrollable_content_pos_set, _elm_code_widget2_elm_interface_scrollable_content_pos_set), - EO_OP_FUNC(elm_code_widget2_code_set, _elm_code_widget2_code_set, ""), - EO_OP_FUNC(elm_code_widget2_code_get, _elm_code_widget2_code_get, ""), - EO_OP_FUNC(elm_code_widget2_font_size_set, _elm_code_widget2_font_size_set, ""), - EO_OP_FUNC(elm_code_widget2_font_size_get, _elm_code_widget2_font_size_get, ""), - EO_OP_FUNC(elm_code_widget2_editable_set, _elm_code_widget2_editable_set, ""), - EO_OP_FUNC(elm_code_widget2_editable_get, _elm_code_widget2_editable_get, ""), - EO_OP_SENTINEL -}; - -static const Eo_Event_Description *_elm_code_widget2_event_desc[] = { - ELM_CODE_WIDGET2_EVENT_LINE_CLICKED, - NULL -}; - -static const Eo_Class_Description _elm_code_widget2_class_desc = { - EO_VERSION, - "Elm_Code_Widget2", - EO_CLASS_TYPE_REGULAR, - EO_CLASS_DESCRIPTION_OPS(_elm_code_widget2_op_desc), - _elm_code_widget2_event_desc, - sizeof(Elm_Code_Widget2_Data), - _elm_code_widget2_class_constructor, - NULL -}; - -EO_DEFINE_CLASS(elm_code_widget2_class_get, &_elm_code_widget2_class_desc, ELM_BOX_CLASS, ELM_INTERFACE_SCROLLABLE_MIXIN, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); \ No newline at end of file diff --git a/legacy/elm_code/lib/elm_code_widget2.eo.h b/legacy/elm_code/lib/elm_code_widget2.eo.h deleted file mode 100644 index cbad231fcd..0000000000 --- a/legacy/elm_code/lib/elm_code_widget2.eo.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef _ELM_CODE_WIDGET2_EO_H_ -#define _ELM_CODE_WIDGET2_EO_H_ - -#ifndef _ELM_CODE_WIDGET2_EO_CLASS_TYPE -#define _ELM_CODE_WIDGET2_EO_CLASS_TYPE - -typedef Eo Elm_Code_Widget2; - -#endif - -#ifndef _ELM_CODE_WIDGET2_EO_TYPES -#define _ELM_CODE_WIDGET2_EO_TYPES - - -#endif -#define ELM_CODE_WIDGET2_CLASS elm_code_widget2_class_get() - -const Eo_Class *elm_code_widget2_class_get(void) EINA_CONST; - -/** - * - * No description supplied. - * - * @param[in] code No description supplied. - * - */ -EOAPI void elm_code_widget2_code_set(Elm_Code *code); - -/** - * - * No description supplied. - * - * - */ -EOAPI Elm_Code * elm_code_widget2_code_get(void); - -/** - * - * No description supplied. - * - * @param[in] font_size No description supplied. - * - */ -EOAPI void elm_code_widget2_font_size_set(Evas_Font_Size font_size); - -/** - * - * No description supplied. - * - * - */ -EOAPI Evas_Font_Size elm_code_widget2_font_size_get(void); - -/** - * - * No description supplied. - * - * @param[in] editable No description supplied. - * - */ -EOAPI void elm_code_widget2_editable_set(Eina_Bool editable); - -/** - * - * No description supplied. - * - * - */ -EOAPI Eina_Bool elm_code_widget2_editable_get(void); - -EOAPI extern const Eo_Event_Description _ELM_CODE_WIDGET2_EVENT_LINE_CLICKED; - -/** - * No description - */ -#define ELM_CODE_WIDGET2_EVENT_LINE_CLICKED (&(_ELM_CODE_WIDGET2_EVENT_LINE_CLICKED)) - -#endif diff --git a/legacy/elm_code/lib/regen.sh b/legacy/elm_code/lib/regen.sh index 055f8e70c2..b3c682e66a 100755 --- a/legacy/elm_code/lib/regen.sh +++ b/legacy/elm_code/lib/regen.sh @@ -3,6 +3,6 @@ cd `dirname $0` INCLUDE="-I /usr/local/share/eolian/include/eo-1 -I /usr/local/share/eolian/include/elementary-1 -I /usr/local/share/eolian/include/evas-1 -I /usr/local/share/eolian/include/efl-1" -eolian_gen $INCLUDE --gh --eo -o elm_code_widget2.eo.h elm_code_widget2.eo -eolian_gen $INCLUDE --gc --eo -o elm_code_widget2.eo.c elm_code_widget2.eo -eolian_gen $INCLUDE --gi --eo -o elm_code_widget2.c elm_code_widget2.eo +eolian_gen $INCLUDE --gh --eo -o elm_code_widget.eo.h elm_code_widget.eo +eolian_gen $INCLUDE --gc --eo -o elm_code_widget.eo.c elm_code_widget.eo +eolian_gen $INCLUDE --gi --eo -o elm_code_widget.c elm_code_widget.eo diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/tests/elm_code_test_widget.c index 3b598a972f..6efdce8715 100644 --- a/legacy/elm_code/tests/elm_code_test_widget.c +++ b/legacy/elm_code/tests/elm_code_test_widget.c @@ -4,7 +4,7 @@ #include "elm_code_suite.h" -#include "elm_code_widget2.c" +#include "elm_code_widget.c" static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type, int id) { From c91fb02a5a48549c9e013e0f0557ad36fef8855c Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 26 Jan 2015 19:46:30 +0000 Subject: [PATCH 062/254] Bind up/down/left/right to cursor control. Add a veto callback that blocks the up/down hitting the focus manager. This needs to be improved so once we hit the top / bottom it will pass on --- legacy/elm_code/lib/elm_code_widget.c | 67 +++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 6c83170bc2..0e74afe27c 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -10,6 +10,7 @@ #include #include "elm_code_widget.eo.h" +#include "elm_code_private.h" typedef struct { @@ -288,12 +289,17 @@ static void _elm_code_widget_cursor_move_up(Elm_Code_Widget *widget) { Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (pd->cursor_line > 1) pd->cursor_line--; + line = elm_code_file_line_get(pd->code->file, pd->cursor_line); + if (pd->cursor_col > (unsigned int) line->length + 1) + pd->cursor_col = line->length + 1; + _elm_code_widget_fill(pd); } @@ -301,12 +307,45 @@ static void _elm_code_widget_cursor_move_down(Elm_Code_Widget *widget) { Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (pd->cursor_line < elm_code_file_lines_get(pd->code->file)) pd->cursor_line++; + line = elm_code_file_line_get(pd->code->file, pd->cursor_line); + if (pd->cursor_col > (unsigned int) line->length + 1) + pd->cursor_col = line->length + 1; + + _elm_code_widget_fill(pd); +} + +static void +_elm_code_widget_cursor_move_left(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (pd->cursor_col > 1) + pd->cursor_col--; + + _elm_code_widget_fill(pd); +} + +static void +_elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + line = elm_code_file_line_get(pd->code->file, pd->cursor_line); + if (pd->cursor_col <= (unsigned int) line->length) + pd->cursor_col++; + _elm_code_widget_fill(pd); } @@ -320,11 +359,30 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Event_Key_Down *ev = event_info; - printf("KEY %s\n", ev->key); - if (!(strcmp(ev->key, "Up"))) + if (!strcmp(ev->key, "Up")) _elm_code_widget_cursor_move_up(widget); - if (!(strcmp(ev->key, "Down"))) + else if (!strcmp(ev->key, "Down")) _elm_code_widget_cursor_move_down(widget); + else if (!strcmp(ev->key, "Left")) + _elm_code_widget_cursor_move_left(widget); + else if (!strcmp(ev->key, "Right")) + _elm_code_widget_cursor_move_right(widget); + else + INF("Unhandled key %s", ev->key); +} + +static Eina_Bool +_elm_code_widget_event_veto_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, + Evas_Object *src EINA_UNUSED, Evas_Callback_Type type, + void *event_info EINA_UNUSED) +{ + Eina_Bool veto = EINA_FALSE; + +// TODO determine if we should allow up/down to be sent to our focus manager + if (type == EVAS_CALLBACK_KEY_DOWN) + veto = EINA_TRUE; + + return veto; } EOLIAN static Eina_Bool @@ -451,9 +509,10 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) evas_object_event_callback_add(grid, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, pd); evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_clicked_cb, obj); -// FIXME find why obj is not getting key_down events evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget_key_down_cb, obj); + elm_object_event_callback_add(obj, _elm_code_widget_event_veto_cb, obj); + eo_do(obj, eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, pd); eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, pd)); From 45a6b3880b6ae593505a57944f6c23a250d69ab8 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 26 Jan 2015 23:09:22 +0000 Subject: [PATCH 063/254] And document the wiget API --- legacy/elm_code/lib/elm_code_widget.eo | 39 ++++++++++++++++++++++-- legacy/elm_code/lib/elm_code_widget.eo.c | 14 ++++----- legacy/elm_code/lib/elm_code_widget.eo.h | 39 ++++++++++++++++++------ 3 files changed, 73 insertions(+), 19 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.eo b/legacy/elm_code/lib/elm_code_widget.eo index 491c436d0a..d274c145ec 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo +++ b/legacy/elm_code/lib/elm_code_widget.eo @@ -5,29 +5,62 @@ class Elm_Code_Widget (Elm_Box, Elm_Interface_Scrollable, properties { code { set { + /*@ + Set the underlying code object that this widget renders + + @ingroup Data */ } get { + /*@ + Get the underlying code object we are rendering + + @ingroup Data */ } values { - Elm_Code *code; + Elm_Code *code; /*@ Our underlying Elm_Code object */ } } font_size { set { + /*@ + Set the font size that this widget uses, the font will always be a system monospaced font + + @ingroup Style */ } get { + /*@ + Get the font size currently in use + + @ingroup Style */ } values { - Evas_Font_Size font_size; + Evas_Font_Size font_size; /*@ The font size of the widgget */ } } editable { set { + /*@ + Set whether this widget allows editing + + If @a editable then the widget will allow user input to manipulate + the underlying Elm_Code_File of this Elm_Code instance. + Any other Elm_Code_Widget's connected to this Elm_Code will + update to reflect the changes. + + @ingroup Features */ } get { + /*@ + Get the current editable state of this widget + + @return EINA_TRUE if the widget is editable, EINA_FALSE otherwise. + If this widget is not editable the underlying Elm_Code_File could + still be manipulated by a different widget or the filesystem. + + @ingroup Features */ } values { - Eina_Bool editable; + Eina_Bool editable; /*@ The editable state of the widget */ } } } diff --git a/legacy/elm_code/lib/elm_code_widget.eo.c b/legacy/elm_code/lib/elm_code_widget.eo.c index 67fff69e21..a71356c2b0 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo.c +++ b/legacy/elm_code/lib/elm_code_widget.eo.c @@ -42,12 +42,12 @@ static Eo_Op_Description _elm_code_widget_op_desc[] = { EO_OP_FUNC_OVERRIDE(evas_obj_smart_add, _elm_code_widget_evas_object_smart_add), EO_OP_FUNC_OVERRIDE(elm_obj_widget_on_focus, _elm_code_widget_elm_widget_on_focus), EO_OP_FUNC_OVERRIDE(elm_interface_scrollable_content_pos_set, _elm_code_widget_elm_interface_scrollable_content_pos_set), - EO_OP_FUNC(elm_code_widget_code_set, _elm_code_widget_code_set, ""), - EO_OP_FUNC(elm_code_widget_code_get, _elm_code_widget_code_get, ""), - EO_OP_FUNC(elm_code_widget_font_size_set, _elm_code_widget_font_size_set, ""), - EO_OP_FUNC(elm_code_widget_font_size_get, _elm_code_widget_font_size_get, ""), - EO_OP_FUNC(elm_code_widget_editable_set, _elm_code_widget_editable_set, ""), - EO_OP_FUNC(elm_code_widget_editable_get, _elm_code_widget_editable_get, ""), + EO_OP_FUNC(elm_code_widget_code_set, _elm_code_widget_code_set, "Set the underlying code object that this widget renders"), + EO_OP_FUNC(elm_code_widget_code_get, _elm_code_widget_code_get, "Get the underlying code object we are rendering"), + EO_OP_FUNC(elm_code_widget_font_size_set, _elm_code_widget_font_size_set, "Set the font size that this widget uses, the font will always be a system monospaced font"), + EO_OP_FUNC(elm_code_widget_font_size_get, _elm_code_widget_font_size_get, "Get the font size currently in use"), + EO_OP_FUNC(elm_code_widget_editable_set, _elm_code_widget_editable_set, "Set whether this widget allows editing"), + EO_OP_FUNC(elm_code_widget_editable_get, _elm_code_widget_editable_get, "Get the current editable state of this widget"), EO_OP_SENTINEL }; @@ -67,4 +67,4 @@ static const Eo_Class_Description _elm_code_widget_class_desc = { NULL }; -EO_DEFINE_CLASS(elm_code_widget_class_get, &_elm_code_widget_class_desc, ELM_BOX_CLASS, ELM_INTERFACE_SCROLLABLE_MIXIN, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); +EO_DEFINE_CLASS(elm_code_widget_class_get, &_elm_code_widget_class_desc, ELM_BOX_CLASS, ELM_INTERFACE_SCROLLABLE_MIXIN, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); \ No newline at end of file diff --git a/legacy/elm_code/lib/elm_code_widget.eo.h b/legacy/elm_code/lib/elm_code_widget.eo.h index 44496018d8..4ea26c8e35 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo.h +++ b/legacy/elm_code/lib/elm_code_widget.eo.h @@ -19,16 +19,20 @@ const Eo_Class *elm_code_widget_class_get(void) EINA_CONST; /** * - * No description supplied. + * Set the underlying code object that this widget renders * - * @param[in] code No description supplied. + * @ingroup Data + * + * @param[in] code Our underlying Elm_Code object * */ EOAPI void elm_code_widget_code_set(Elm_Code *code); /** * - * No description supplied. + * Get the underlying code object we are rendering + * + * @ingroup Data * * */ @@ -36,16 +40,20 @@ EOAPI Elm_Code * elm_code_widget_code_get(void); /** * - * No description supplied. + * Set the font size that this widget uses, the font will always be a system monospaced font * - * @param[in] font_size No description supplied. + * @ingroup Style + * + * @param[in] font_size The font size of the widgget * */ EOAPI void elm_code_widget_font_size_set(Evas_Font_Size font_size); /** * - * No description supplied. + * Get the font size currently in use + * + * @ingroup Style * * */ @@ -53,16 +61,29 @@ EOAPI Evas_Font_Size elm_code_widget_font_size_get(void); /** * - * No description supplied. + * Set whether this widget allows editing * - * @param[in] editable No description supplied. + * If @a editable then the widget will allow user input to manipulate + * the underlying Elm_Code_File of this Elm_Code instance. + * Any other Elm_Code_Widget's connected to this Elm_Code will + * update to reflect the changes. + * + * @ingroup Features + * + * @param[in] editable The editable state of the widget * */ EOAPI void elm_code_widget_editable_set(Eina_Bool editable); /** * - * No description supplied. + * Get the current editable state of this widget + * + * @return EINA_TRUE if the widget is editable, EINA_FALSE otherwise. + * If this widget is not editable the underlying Elm_Code_File could + * still be manipulated by a different widget or the filesystem. + * + * @ingroup Features * * */ From 78790f8fd3419f5b109a3293ac88005c8dc3a728 Mon Sep 17 00:00:00 2001 From: Stephen Houston Date: Tue, 27 Jan 2015 10:43:32 -0600 Subject: [PATCH 064/254] Elm_Code: Keep up with min size so scroller works properly. --- legacy/elm_code/lib/elm_code_widget.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 0e74afe27c..cec8fdb2ce 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -151,7 +151,7 @@ _elm_code_widget_fill(Elm_Code_Widget_Data *pd) { Elm_Code_Line *line; Evas_Textgrid_Cell *cells; - int w, h; + int w, h, cw, ch; unsigned int y; if (!_elm_code_widget_resize(pd->grid)) @@ -165,6 +165,8 @@ _elm_code_widget_fill(Elm_Code_Widget_Data *pd) cells = evas_object_textgrid_cellrow_get(pd->grid, y - 1); _elm_code_widget_fill_line(pd, cells, line); } + evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); + evas_object_size_hint_min_set(pd->grid, w*cw, y*ch); } static Eina_Bool From ad0d199f368b8eb61a9dc2bfdb712e9a6233ebcf Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 27 Jan 2015 14:34:11 +0000 Subject: [PATCH 065/254] Allow up/down/left/right to participate in focus control. When we cannot move within the cursor availability then note it the callback from elm will see if the event should be propagated so we report the veto when we're contained or allow propagation when we overrun --- legacy/elm_code/lib/elm_code_widget.c | 74 ++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index cec8fdb2ce..96ec32b1dd 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -19,6 +19,7 @@ typedef struct Evas_Font_Size font_size; unsigned int cursor_line, cursor_col; + Eina_Bool cursor_move_vetoed; Eina_Bool editable, focussed; } Elm_Code_Widget_Data; @@ -44,6 +45,7 @@ _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUS pd->cursor_line = 1; pd->cursor_col = 1; + pd->cursor_move_vetoed = EINA_TRUE; } EOLIAN static void @@ -351,16 +353,64 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) _elm_code_widget_fill(pd); } +static Eina_Bool +_elm_code_widget_cursor_key_can_control(Evas_Event_Key_Down *event) +{ + if (!strcmp(event->key, "Up")) + return EINA_TRUE; + else if (!strcmp(event->key, "Down")) + return EINA_TRUE; + else if (!strcmp(event->key, "Left")) + return EINA_TRUE; + else if (!strcmp(event->key, "Right")) + return EINA_TRUE; + else + return EINA_FALSE; +} + +static Eina_Bool +_elm_code_widget_cursor_key_will_move(Elm_Code_Widget *widget, Evas_Event_Key_Down *event) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + line = elm_code_file_line_get(pd->code->file, pd->cursor_line); + + if (!strcmp(event->key, "Up")) + return pd->cursor_line > 1; + else if (!strcmp(event->key, "Down")) + return pd->cursor_line < elm_code_file_lines_get(pd->code->file); + else if (!strcmp(event->key, "Left")) + return pd->cursor_col > 1; + else if (!strcmp(event->key, "Right")) + return pd->cursor_col < (unsigned int) line->length + 1; + else + return EINA_FALSE; +} + static void _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) { Elm_Code_Widget *widget; + Elm_Code_Widget_Data *pd; widget = (Elm_Code_Widget *)data; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); Evas_Event_Key_Down *ev = event_info; + if (!pd->editable) + return; + + pd->cursor_move_vetoed = EINA_TRUE; + if (_elm_code_widget_cursor_key_can_control(ev) && !_elm_code_widget_cursor_key_will_move(widget, ev)) + { + pd->cursor_move_vetoed = EINA_FALSE; + return; + } + if (!strcmp(ev->key, "Up")) _elm_code_widget_cursor_move_up(widget); else if (!strcmp(ev->key, "Down")) @@ -374,17 +424,28 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, } static Eina_Bool -_elm_code_widget_event_veto_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, +_elm_code_widget_event_veto_cb(void *data, Evas_Object *obj EINA_UNUSED, Evas_Object *src EINA_UNUSED, Evas_Callback_Type type, void *event_info EINA_UNUSED) { - Eina_Bool veto = EINA_FALSE; + Elm_Code_Widget *widget; + Elm_Code_Widget_Data *pd; + Eina_Bool vetoed; -// TODO determine if we should allow up/down to be sent to our focus manager + widget = (Elm_Code_Widget *)data; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (!pd->editable) + return EINA_FALSE; + + vetoed = EINA_TRUE; if (type == EVAS_CALLBACK_KEY_DOWN) - veto = EINA_TRUE; + { + vetoed = pd->cursor_move_vetoed; + pd->cursor_move_vetoed = EINA_TRUE; + } - return veto; + return vetoed; } EOLIAN static Eina_Bool @@ -437,9 +498,10 @@ _elm_code_widget_code_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) } EOLIAN static void -_elm_code_widget_editable_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Eina_Bool editable) +_elm_code_widget_editable_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool editable) { pd->editable = editable; + elm_object_focus_allow_set(obj, editable); } EOLIAN static Eina_Bool From fc43214208448cc028d2af8b20917ab4724de165 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 27 Jan 2015 22:13:45 +0000 Subject: [PATCH 066/254] elm_code: Update resizing to reflect only the space that's required --- legacy/elm_code/lib/elm_code_widget.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 96ec32b1dd..7231e40f6a 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -55,15 +55,24 @@ _elm_code_widget_class_constructor(Eo_Class *klass EINA_UNUSED) } static Eina_Bool -_elm_code_widget_resize(Evas_Object *o) +_elm_code_widget_resize(Elm_Code_Widget_Data *pd) { + Elm_Code_Line *line; + Eina_List *item; int w, h, cw, ch; - evas_object_geometry_get(o, NULL, NULL, &w, &h); - evas_object_textgrid_cell_size_get(o, &cw, &ch); + if (!pd->code) + return EINA_FALSE; + evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); - evas_object_textgrid_size_set(o, ceil(((double) w) / cw), - ceil(((double) h) / ch)); + w = 0; + h = elm_code_file_lines_get(pd->code->file); + EINA_LIST_FOREACH(pd->code->file->lines, item, line) + if (line->length + 2 > w) + w = line->length + 2; + + evas_object_textgrid_size_set(pd->grid, w, h); + evas_object_size_hint_min_set(pd->grid, w*cw, h*ch); return h > 0 && w > 0; } @@ -110,7 +119,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget_Data *pd, Evas_Textgrid_Cell *cells, unsigned int length, x; int w; - if (!_elm_code_widget_resize(pd->grid)) + if (!_elm_code_widget_resize(pd)) return; length = line->length; @@ -153,10 +162,10 @@ _elm_code_widget_fill(Elm_Code_Widget_Data *pd) { Elm_Code_Line *line; Evas_Textgrid_Cell *cells; - int w, h, cw, ch; + int w, h; unsigned int y; - if (!_elm_code_widget_resize(pd->grid)) + if (!_elm_code_widget_resize(pd)) return; evas_object_textgrid_size_get(pd->grid, &w, &h); @@ -167,8 +176,6 @@ _elm_code_widget_fill(Elm_Code_Widget_Data *pd) cells = evas_object_textgrid_cellrow_get(pd->grid, y - 1); _elm_code_widget_fill_line(pd, cells, line); } - evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); - evas_object_size_hint_min_set(pd->grid, w*cw, y*ch); } static Eina_Bool From 4b0350c20509a7867e374eb42da2a729f483fa71 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 28 Jan 2015 00:20:58 +0000 Subject: [PATCH 067/254] elm_code: When appending lines ignore widget size now we're scrolling --- legacy/elm_code/lib/elm_code_widget.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 7231e40f6a..e57543d69b 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -184,16 +184,13 @@ _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, { Elm_Code_Widget_Data *widget; Elm_Code_Line *line; - int h; Evas_Textgrid_Cell *cells; widget = (Elm_Code_Widget_Data *)data; line = (Elm_Code_Line *)event_info; - evas_object_textgrid_size_get(widget->grid, NULL, &h); - - if (line->number > (unsigned int) h) + if (!_elm_code_widget_resize(widget)) return EINA_TRUE; cells = evas_object_textgrid_cellrow_get(widget->grid, line->number - 1); From 876faa4eb5eb9693395bac021e315fa0b9d6b3fb Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 28 Jan 2015 00:39:56 +0000 Subject: [PATCH 068/254] elm_code: update scroller so content fills space. We want to extend backgrounds under scrollbars but only scroll if it's too big. --- legacy/elm_code/lib/elm_code_widget.c | 65 +++++++++++++++++---------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index e57543d69b..87a0e5c36c 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -55,14 +55,20 @@ _elm_code_widget_class_constructor(Eo_Class *klass EINA_UNUSED) } static Eina_Bool -_elm_code_widget_resize(Elm_Code_Widget_Data *pd) +_elm_code_widget_resize(Elm_Code_Widget *widget) { Elm_Code_Line *line; Eina_List *item; + Evas_Coord ww, wh; int w, h, cw, ch; + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (!pd->code) return EINA_FALSE; + + evas_object_geometry_get(widget, NULL, NULL, &ww, &wh); evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); w = 0; @@ -71,7 +77,12 @@ _elm_code_widget_resize(Elm_Code_Widget_Data *pd) if (line->length + 2 > w) w = line->length + 2; - evas_object_textgrid_size_set(pd->grid, w, h); + if (w*cw > ww) + ww = w*cw; + if (h*ch > wh) + wh = h*ch; + + evas_object_textgrid_size_set(pd->grid, ww/cw+1, wh/ch+1); evas_object_size_hint_min_set(pd->grid, w*cw, h*ch); return h > 0 && w > 0; @@ -113,13 +124,16 @@ _elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, unsigned int count, } static void -_elm_code_widget_fill_line(Elm_Code_Widget_Data *pd, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) +_elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) { char *chr; unsigned int length, x; int w; + Elm_Code_Widget_Data *pd; - if (!_elm_code_widget_resize(pd)) + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (!_elm_code_widget_resize(widget)) return; length = line->length; @@ -158,14 +172,17 @@ _elm_code_widget_fill_line(Elm_Code_Widget_Data *pd, Evas_Textgrid_Cell *cells, } static void -_elm_code_widget_fill(Elm_Code_Widget_Data *pd) +_elm_code_widget_fill(Elm_Code_Widget *widget) { Elm_Code_Line *line; Evas_Textgrid_Cell *cells; int w, h; unsigned int y; + Elm_Code_Widget_Data *pd; - if (!_elm_code_widget_resize(pd)) + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (!_elm_code_widget_resize(widget)) return; evas_object_textgrid_size_get(pd->grid, &w, &h); @@ -174,7 +191,7 @@ _elm_code_widget_fill(Elm_Code_Widget_Data *pd) line = elm_code_file_line_get(pd->code->file, y); cells = evas_object_textgrid_cellrow_get(pd->grid, y - 1); - _elm_code_widget_fill_line(pd, cells, line); + _elm_code_widget_fill_line(widget, cells, line); } } @@ -182,18 +199,20 @@ static Eina_Bool _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info) { - Elm_Code_Widget_Data *widget; + Elm_Code_Widget *widget; Elm_Code_Line *line; Evas_Textgrid_Cell *cells; + Elm_Code_Widget_Data *pd; - widget = (Elm_Code_Widget_Data *)data; + widget = (Elm_Code_Widget *)data; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); line = (Elm_Code_Line *)event_info; if (!_elm_code_widget_resize(widget)) return EINA_TRUE; - cells = evas_object_textgrid_cellrow_get(widget->grid, line->number - 1); + cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); _elm_code_widget_fill_line(widget, cells, line); return EINA_TRUE; @@ -204,9 +223,9 @@ static Eina_Bool _elm_code_widget_file_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) { - Elm_Code_Widget_Data *widget; + Elm_Code_Widget *widget; - widget = (Elm_Code_Widget_Data *)data; + widget = (Elm_Code_Widget *)data; _elm_code_widget_fill(widget); return EINA_TRUE; @@ -216,9 +235,9 @@ static void _elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - Elm_Code_Widget_Data *widget; + Elm_Code_Widget *widget; - widget = (Elm_Code_Widget_Data *)data; + widget = (Elm_Code_Widget *)data; _elm_code_widget_fill(widget); } @@ -250,7 +269,7 @@ _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas if (pd->cursor_col == 0) pd->cursor_col = 1; - _elm_code_widget_fill(pd); + _elm_code_widget_fill(widget); } static void @@ -308,7 +327,7 @@ _elm_code_widget_cursor_move_up(Elm_Code_Widget *widget) if (pd->cursor_col > (unsigned int) line->length + 1) pd->cursor_col = line->length + 1; - _elm_code_widget_fill(pd); + _elm_code_widget_fill(widget); } static void @@ -326,7 +345,7 @@ _elm_code_widget_cursor_move_down(Elm_Code_Widget *widget) if (pd->cursor_col > (unsigned int) line->length + 1) pd->cursor_col = line->length + 1; - _elm_code_widget_fill(pd); + _elm_code_widget_fill(widget); } static void @@ -339,7 +358,7 @@ _elm_code_widget_cursor_move_left(Elm_Code_Widget *widget) if (pd->cursor_col > 1) pd->cursor_col--; - _elm_code_widget_fill(pd); + _elm_code_widget_fill(widget); } static void @@ -354,7 +373,7 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) if (pd->cursor_col <= (unsigned int) line->length) pd->cursor_col++; - _elm_code_widget_fill(pd); + _elm_code_widget_fill(widget); } static Eina_Bool @@ -461,7 +480,7 @@ _elm_code_widget_elm_widget_on_focus(Eo *obj, Elm_Code_Widget_Data *pd) pd->focussed = elm_widget_focus_get(obj); - _elm_code_widget_fill(pd); + _elm_code_widget_fill(obj); return EINA_TRUE; } @@ -575,15 +594,15 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) pd->grid = grid; _elm_code_widget_setup_palette(grid); - evas_object_event_callback_add(grid, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, pd); + evas_object_event_callback_add(grid, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, obj); evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_clicked_cb, obj); evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget_key_down_cb, obj); elm_object_event_callback_add(obj, _elm_code_widget_event_veto_cb, obj); eo_do(obj, - eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, pd); - eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, pd)); + eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, obj); + eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj)); _elm_code_widget_font_size_set(obj, pd, 10); } From 545ecc5182e6211dbdc8da03f4edcaf5f7a34874 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 28 Jan 2015 14:16:46 +0000 Subject: [PATCH 069/254] Add proper gravity control when lines are being added to the widget. Most useful will be (0.0, 1.0) which will cause the display to act like 'tail'. --- legacy/elm_code/lib/elm_code_widget.c | 42 ++++++++++++++++++++++-- legacy/elm_code/lib/elm_code_widget.eo | 21 ++++++++++++ legacy/elm_code/lib/elm_code_widget.eo.c | 10 ++++++ legacy/elm_code/lib/elm_code_widget.eo.h | 28 ++++++++++++++++ 4 files changed, 99 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index dc702f7d36..100851fccf 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -8,9 +8,11 @@ typedef struct { Elm_Code *code; - Evas_Object *grid; + Evas_Object *grid, *scroller; Evas_Font_Size font_size; + double gravity_x, gravity_y; + unsigned int cursor_line, cursor_col; Eina_Bool cursor_move_vetoed; Eina_Bool editable, focussed; @@ -47,12 +49,26 @@ _elm_code_widget_class_constructor(Eo_Class *klass EINA_UNUSED) } +static void +_elm_code_widget_scroll_by(Elm_Code_Widget *widget, int by_x, int by_y) +{ + Elm_Code_Widget_Data *pd; + Evas_Coord x, y, w, h; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + elm_scroller_region_get(pd->scroller, &x, &y, &w, &h); + x += by_x; + y += by_y; + elm_scroller_region_show(pd->scroller, x, y, w, h); +} + static Eina_Bool _elm_code_widget_resize(Elm_Code_Widget *widget) { Elm_Code_Line *line; Eina_List *item; - Evas_Coord ww, wh; + Evas_Coord ww, wh, old_width, old_height; int w, h, cw, ch; Elm_Code_Widget_Data *pd; @@ -63,6 +79,8 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) evas_object_geometry_get(widget, NULL, NULL, &ww, &wh); evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); + old_width = ww; + old_height = wh; w = 0; h = elm_code_file_lines_get(pd->code->file); @@ -78,6 +96,11 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) evas_object_textgrid_size_set(pd->grid, ww/cw+1, wh/ch+1); evas_object_size_hint_min_set(pd->grid, w*cw, h*ch); + if (pd->gravity_x == 1.0 || pd->gravity_y == 1.0) + _elm_code_widget_scroll_by(widget, + (pd->gravity_x == 1.0 && ww > old_width) ? ww - old_width : 0, + (pd->gravity_y == 1.0 && wh > old_height) ? wh - old_height : 0); + return h > 0 && w > 0; } @@ -519,6 +542,20 @@ _elm_code_widget_code_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) return pd->code; } +EOLIAN static void +_elm_code_widget_gravity_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, double x, double y) +{ + pd->gravity_x = x; + pd->gravity_y = y; +} + +EOLIAN static void +_elm_code_widget_gravity_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, double *x, double *y) +{ + *x = pd->gravity_x; + *y = pd->gravity_y; +} + EOLIAN static void _elm_code_widget_editable_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool editable) { @@ -584,6 +621,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(scroller); elm_box_pack_end(obj, scroller); + pd->scroller = scroller; grid = evas_object_textgrid_add(obj); evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); diff --git a/legacy/elm_code/lib/elm_code_widget.eo b/legacy/elm_code/lib/elm_code_widget.eo index d274c145ec..804b40e566 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo +++ b/legacy/elm_code/lib/elm_code_widget.eo @@ -37,6 +37,27 @@ class Elm_Code_Widget (Elm_Box, Elm_Interface_Scrollable, Evas_Font_Size font_size; /*@ The font size of the widgget */ } } + gravity { + set { + /*@ + Set how this widget's scroller should respond to new lines being added. + + An x value of 0.0 will maintain the distance from the left edge, 1.0 will ensure the rightmost edge (of the longest line) is respected + With 0.0 for y the view will keep it's position relative to the top whereas 1.0 will scroll downward as lines are added. + + @ingroup Layout */ + } + get { + /*@ + Get the current x and y gravity of the widget's scroller + + @ingroup Layout */ + } + values { + double x; /*@ The horizontal value of the scroller gravity - valid values are 0.0 and 1.0 */ + double y; /*@ The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 */ + } + } editable { set { /*@ diff --git a/legacy/elm_code/lib/elm_code_widget.eo.c b/legacy/elm_code/lib/elm_code_widget.eo.c index a71356c2b0..ed7092fcc7 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo.c +++ b/legacy/elm_code/lib/elm_code_widget.eo.c @@ -17,6 +17,14 @@ Evas_Font_Size _elm_code_widget_font_size_get(Eo *obj, Elm_Code_Widget_Data *pd) EOAPI EO_FUNC_BODY(elm_code_widget_font_size_get, Evas_Font_Size, 0); +void _elm_code_widget_gravity_set(Eo *obj, Elm_Code_Widget_Data *pd, double x, double y); + +EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_gravity_set, EO_FUNC_CALL(x, y), double x, double y); + +void _elm_code_widget_gravity_get(Eo *obj, Elm_Code_Widget_Data *pd, double *x, double *y); + +EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_gravity_get, EO_FUNC_CALL(x, y), double *x, double *y); + void _elm_code_widget_editable_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool editable); EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_editable_set, EO_FUNC_CALL(editable), Eina_Bool editable); @@ -46,6 +54,8 @@ static Eo_Op_Description _elm_code_widget_op_desc[] = { EO_OP_FUNC(elm_code_widget_code_get, _elm_code_widget_code_get, "Get the underlying code object we are rendering"), EO_OP_FUNC(elm_code_widget_font_size_set, _elm_code_widget_font_size_set, "Set the font size that this widget uses, the font will always be a system monospaced font"), EO_OP_FUNC(elm_code_widget_font_size_get, _elm_code_widget_font_size_get, "Get the font size currently in use"), + EO_OP_FUNC(elm_code_widget_gravity_set, _elm_code_widget_gravity_set, "Set how this widget's scroller should respond to new lines being added."), + EO_OP_FUNC(elm_code_widget_gravity_get, _elm_code_widget_gravity_get, "Get the current x and y gravity of the widget's scroller"), EO_OP_FUNC(elm_code_widget_editable_set, _elm_code_widget_editable_set, "Set whether this widget allows editing"), EO_OP_FUNC(elm_code_widget_editable_get, _elm_code_widget_editable_get, "Get the current editable state of this widget"), EO_OP_SENTINEL diff --git a/legacy/elm_code/lib/elm_code_widget.eo.h b/legacy/elm_code/lib/elm_code_widget.eo.h index 4ea26c8e35..8dadcc0d9f 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo.h +++ b/legacy/elm_code/lib/elm_code_widget.eo.h @@ -59,6 +59,34 @@ EOAPI void elm_code_widget_font_size_set(Evas_Font_Size font_size); */ EOAPI Evas_Font_Size elm_code_widget_font_size_get(void); +/** + * + * Set how this widget's scroller should respond to new lines being added. + * + * An x value of 0.0 will maintain the distance from the left edge, 1.0 + will ensure the rightmost edge (of the longest line) is respected + * With 0.0 for y the view will keep it's position relative to the top whereas 1.0 will scroll downward as lines are added. + * + * @ingroup Layout + * + * @param[in] x The horizontal value of the scroller gravity - valid values are 0.0 and 1.0 + * @param[in] y The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 + * + */ +EOAPI void elm_code_widget_gravity_set(double x, double y); + +/** + * + * Get the current x and y gravity of the widget's scroller + * + * @ingroup Layout + * + * @param[out] x The horizontal value of the scroller gravity, currently ignored + * @param[out] y The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 + * + */ +EOAPI void elm_code_widget_gravity_get(double *x, double *y); + /** * * Set whether this widget allows editing From cc495a2131775d65cb392923d8bf1ec5668d4940 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 28 Jan 2015 22:38:49 +0000 Subject: [PATCH 070/254] elm_code: Fix click calculations. We must take into account our scroll position and also where we are positioned within the screen layout --- legacy/elm_code/lib/elm_code_widget.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 100851fccf..1dcd35116a 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -313,14 +313,16 @@ _elm_code_widget_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EI Elm_Code_Widget *widget; Elm_Code_Widget_Data *pd; Evas_Event_Mouse_Up *event; - Evas_Coord x, y; + Evas_Coord x, y, ox, oy, sx, sy; widget = (Elm_Code_Widget *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); event = (Evas_Event_Mouse_Up *)event_info; - x = event->canvas.x; - y = event->canvas.y; + evas_object_geometry_get(widget, &ox, &oy, NULL, NULL); + elm_scroller_region_get(pd->scroller, &sx, &sy, NULL, NULL); + x = event->canvas.x + sx - ox; + y = event->canvas.y + sy - oy; if (pd->editable) _elm_code_widget_clicked_editable_cb(widget, x, y); From 4486e7244b98eb18b3361247e64e672cda1b8743 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 29 Jan 2015 00:36:28 +0000 Subject: [PATCH 071/254] elm_code: initial work on line numbers --- legacy/elm_code/bin/elm_code_test_main.c | 7 ++- legacy/elm_code/lib/Elm_Code.h | 1 + legacy/elm_code/lib/Makefile.am | 1 + legacy/elm_code/lib/elm_code_private.h | 14 +++++ legacy/elm_code/lib/elm_code_widget.c | 73 +++++++++++++--------- legacy/elm_code/lib/elm_code_widget.eo | 20 ++++++ legacy/elm_code/lib/elm_code_widget.eo.c | 10 +++ legacy/elm_code/lib/elm_code_widget.eo.h | 29 ++++++++- legacy/elm_code/lib/elm_code_widget_text.c | 35 +++++++++++ legacy/elm_code/lib/elm_code_widget_text.h | 30 +++++++++ 10 files changed, 183 insertions(+), 37 deletions(-) create mode 100644 legacy/elm_code/lib/elm_code_widget_text.c create mode 100644 legacy/elm_code/lib/elm_code_widget_text.h diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 2897c3c12b..b15bea8d18 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -53,9 +53,10 @@ _elm_code_test_welcome_setup(Evas_Object *parent) code = elm_code_create(); widget = eo_add(ELM_CODE_WIDGET_CLASS, parent); eo_do(widget, - elm_code_widget_code_set(code); - elm_code_widget_font_size_set(14); - elm_code_widget_editable_set(EINA_TRUE); + elm_code_widget_code_set(code), + elm_code_widget_font_size_set(14), + elm_code_widget_editable_set(EINA_TRUE), + elm_code_widget_line_numbers_set(EINA_TRUE), eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_cb, code)); _append_line(code->file, "Hello World, Elm Code!"); diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/lib/Elm_Code.h index 016f315c78..d60f2f47ca 100644 --- a/legacy/elm_code/lib/Elm_Code.h +++ b/legacy/elm_code/lib/Elm_Code.h @@ -37,6 +37,7 @@ #include "elm_code_file.h" #include "elm_code_parse.h" #include "elm_code_widget.eo.h" +#include "elm_code_widget_text.h" #include "elm_code_diff_widget.h" #ifdef __cplusplus diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am index 447e052bd2..932696aa34 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/lib/Makefile.am @@ -20,6 +20,7 @@ includesdir = $(includedir)/edi-@VMAJ@ libelm_code_la_SOURCES = \ elm_code_file.c \ elm_code_parse.c \ +elm_code_widget_text.c \ elm_code_widget.c \ elm_code_diff_widget.c \ elm_code.c \ diff --git a/legacy/elm_code/lib/elm_code_private.h b/legacy/elm_code/lib/elm_code_private.h index d1ff3284d4..c464d95013 100644 --- a/legacy/elm_code/lib/elm_code_private.h +++ b/legacy/elm_code/lib/elm_code_private.h @@ -25,3 +25,17 @@ extern int _elm_code_lib_log_dom; #define DBG(...) EINA_LOG_DOM_DBG(_elm_code_lib_log_dom, __VA_ARGS__) #endif + +typedef struct +{ + Elm_Code *code; + Evas_Object *grid, *scroller; + + Evas_Font_Size font_size; + double gravity_x, gravity_y; + + unsigned int cursor_line, cursor_col; + Eina_Bool cursor_move_vetoed; + Eina_Bool editable, focussed; + Eina_Bool show_line_numbers; +} Elm_Code_Widget_Data; diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 1dcd35116a..2a3cb368d3 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -5,19 +5,6 @@ #include #include "elm_code_private.h" -typedef struct -{ - Elm_Code *code; - Evas_Object *grid, *scroller; - - Evas_Font_Size font_size; - double gravity_x, gravity_y; - - unsigned int cursor_line, cursor_col; - Eina_Bool cursor_move_vetoed; - Eina_Bool editable, focussed; -} Elm_Code_Widget_Data; - Eina_Unicode status_icons[] = { ' ', '!', @@ -69,10 +56,11 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) Elm_Code_Line *line; Eina_List *item; Evas_Coord ww, wh, old_width, old_height; - int w, h, cw, ch; + int w, h, cw, ch, gutter; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + gutter = elm_code_widget_text_left_gutter_width_get(widget); if (!pd->code) return EINA_FALSE; @@ -85,8 +73,8 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) w = 0; h = elm_code_file_lines_get(pd->code->file); EINA_LIST_FOREACH(pd->code->file->lines, item, line) - if (line->length + 2 > w) - w = line->length + 2; + if (line->length + gutter + 1 > w) + w = line->length + gutter + 1; if (w*cw > ww) ww = w*cw; @@ -116,24 +104,26 @@ _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start } static void -_elm_code_widget_fill_line_tokens(Evas_Textgrid_Cell *cells, unsigned int count, Elm_Code_Line *line) +_elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, + unsigned int count, Elm_Code_Line *line) { Eina_List *item; Elm_Code_Token *token; - int start, length; + int start, length, offset; - start = 1; - length = line->length; + offset = elm_code_widget_text_left_gutter_width_get(widget) - 1; + start = offset + 1; + length = line->length + offset; EINA_LIST_FOREACH(line->tokens, item, token) { - _elm_code_widget_fill_line_token(cells, count, start, token->start, ELM_CODE_TOKEN_TYPE_DEFAULT); + _elm_code_widget_fill_line_token(cells, count, start, token->start + offset, ELM_CODE_TOKEN_TYPE_DEFAULT); // TODO handle a token starting before the previous finishes - _elm_code_widget_fill_line_token(cells, count, token->start, token->end, token->type); + _elm_code_widget_fill_line_token(cells, count, token->start + offset, token->end + offset, token->type); - start = token->end + 1; + start = token->end + offset + 1; } _elm_code_widget_fill_line_token(cells, count, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); @@ -144,10 +134,11 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, E { char *chr; unsigned int length, x; - int w; + int w, gutter, g; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + gutter = elm_code_widget_text_left_gutter_width_get(widget); if (!_elm_code_widget_resize(widget)) return; @@ -160,11 +151,19 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, E cells[0].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; cells[0].bg = line->status; + for (g = 1; g < gutter; g++) + { +// TODO figure what our actual line number is as a string! (of length g) + cells[g].codepoint = (g == gutter - 1) ? '|' : '_'; + cells[g].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; + cells[g].bg = ELM_CODE_STATUS_TYPE_DEFAULT; + } + if (line->modified) chr = line->modified; else chr = (char *)line->content; - for (x = 1; x < (unsigned int) w && x <= length; x++) + for (x = gutter; x < (unsigned int) w && x < length + gutter; x++) { cells[x].codepoint = *chr; cells[x].bg = line->status; @@ -177,11 +176,11 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, E cells[x].bg = line->status; } - _elm_code_widget_fill_line_tokens(cells, w, line); + _elm_code_widget_fill_line_tokens(widget, cells, w, line); if (pd->editable && pd->focussed && pd->cursor_line == line->number) { - if (pd->cursor_col < (unsigned int) w) - cells[pd->cursor_col].bg = ELM_CODE_TOKEN_TYPE_CURSOR; + if (pd->cursor_col + gutter - 1 < (unsigned int) w) + cells[pd->cursor_col + gutter - 1].bg = ELM_CODE_TOKEN_TYPE_CURSOR; } evas_object_textgrid_update_add(pd->grid, 0, line->number - 1, w, 1); @@ -269,7 +268,7 @@ _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); - col = ((double) x / cw) + 2; + col = ((double) x / cw) - elm_code_widget_text_left_gutter_width_get(widget) + 1; row = ((double) y / ch) + 1; line = elm_code_file_line_get(pd->code->file, row); @@ -277,8 +276,8 @@ _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas { pd->cursor_line = row; - if (col <= (unsigned int) line->length + 2) - pd->cursor_col = col - 2; + if (col <= (unsigned int) line->length + 1) + pd->cursor_col = col; else pd->cursor_col = line->length + 1; } @@ -571,6 +570,18 @@ _elm_code_widget_editable_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) return pd->editable; } +EOLIAN static void +_elm_code_widget_line_numbers_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Eina_Bool line_numbers) +{ + pd->show_line_numbers = line_numbers; +} + +EOLIAN static Eina_Bool +_elm_code_widget_line_numbers_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) +{ + return pd->show_line_numbers; +} + static void _elm_code_widget_setup_palette(Evas_Object *o) { diff --git a/legacy/elm_code/lib/elm_code_widget.eo b/legacy/elm_code/lib/elm_code_widget.eo index 804b40e566..2d92386697 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo +++ b/legacy/elm_code/lib/elm_code_widget.eo @@ -84,6 +84,26 @@ class Elm_Code_Widget (Elm_Box, Elm_Interface_Scrollable, Eina_Bool editable; /*@ The editable state of the widget */ } } + line_numbers { + set { + /*@ + Set whether line numbers should be displayed in the left gutter. + + Passing EINA_TRUE will reserve a space for showing line numbers, + EINA_FALSE will turn this off. + + @ingroup Features */ + } + get { + /*@ + Get the status of line number display for this widget. + + @ingroup Features */ + } + values { + Eina_Bool line_numbers; /*@ Whether or not line numbers (or their placeholder) should be shown */ + } + } } methods { } diff --git a/legacy/elm_code/lib/elm_code_widget.eo.c b/legacy/elm_code/lib/elm_code_widget.eo.c index ed7092fcc7..0affce2bdc 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo.c +++ b/legacy/elm_code/lib/elm_code_widget.eo.c @@ -33,6 +33,14 @@ Eina_Bool _elm_code_widget_editable_get(Eo *obj, Elm_Code_Widget_Data *pd); EOAPI EO_FUNC_BODY(elm_code_widget_editable_get, Eina_Bool, 0); +void _elm_code_widget_line_numbers_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool line_numbers); + +EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_line_numbers_set, EO_FUNC_CALL(line_numbers), Eina_Bool line_numbers); + +Eina_Bool _elm_code_widget_line_numbers_get(Eo *obj, Elm_Code_Widget_Data *pd); + +EOAPI EO_FUNC_BODY(elm_code_widget_line_numbers_get, Eina_Bool, 0); + void _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd); @@ -58,6 +66,8 @@ static Eo_Op_Description _elm_code_widget_op_desc[] = { EO_OP_FUNC(elm_code_widget_gravity_get, _elm_code_widget_gravity_get, "Get the current x and y gravity of the widget's scroller"), EO_OP_FUNC(elm_code_widget_editable_set, _elm_code_widget_editable_set, "Set whether this widget allows editing"), EO_OP_FUNC(elm_code_widget_editable_get, _elm_code_widget_editable_get, "Get the current editable state of this widget"), + EO_OP_FUNC(elm_code_widget_line_numbers_set, _elm_code_widget_line_numbers_set, "Set whether line numbers should be displayed in the left gutter."), + EO_OP_FUNC(elm_code_widget_line_numbers_get, _elm_code_widget_line_numbers_get, "Get the status of line number display for this widget."), EO_OP_SENTINEL }; diff --git a/legacy/elm_code/lib/elm_code_widget.eo.h b/legacy/elm_code/lib/elm_code_widget.eo.h index 8dadcc0d9f..2730ddd396 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo.h +++ b/legacy/elm_code/lib/elm_code_widget.eo.h @@ -63,8 +63,7 @@ EOAPI Evas_Font_Size elm_code_widget_font_size_get(void); * * Set how this widget's scroller should respond to new lines being added. * - * An x value of 0.0 will maintain the distance from the left edge, 1.0 - will ensure the rightmost edge (of the longest line) is respected + * An x value of 0.0 will maintain the distance from the left edge, 1.0 will ensure the rightmost edge (of the longest line) is respected * With 0.0 for y the view will keep it's position relative to the top whereas 1.0 will scroll downward as lines are added. * * @ingroup Layout @@ -81,7 +80,7 @@ EOAPI void elm_code_widget_gravity_set(double x, double y); * * @ingroup Layout * - * @param[out] x The horizontal value of the scroller gravity, currently ignored + * @param[out] x The horizontal value of the scroller gravity - valid values are 0.0 and 1.0 * @param[out] y The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 * */ @@ -117,6 +116,30 @@ EOAPI void elm_code_widget_editable_set(Eina_Bool editable); */ EOAPI Eina_Bool elm_code_widget_editable_get(void); +/** + * + * Set whether line numbers should be displayed in the left gutter. + * + * Passing EINA_TRUE will reserve a space for showing line numbers, + * EINA_FALSE will turn this off. + * + * @ingroup Features + * + * @param[in] line_numbers Whether or not line numbers (or their placeholder) should be shown + * + */ +EOAPI void elm_code_widget_line_numbers_set(Eina_Bool line_numbers); + +/** + * + * Get the status of line number display for this widget. + * + * @ingroup Features + * + * + */ +EOAPI Eina_Bool elm_code_widget_line_numbers_get(void); + EOAPI extern const Eo_Event_Description _ELM_CODE_WIDGET_EVENT_LINE_CLICKED; /** diff --git a/legacy/elm_code/lib/elm_code_widget_text.c b/legacy/elm_code/lib/elm_code_widget_text.c new file mode 100644 index 0000000000..53d2ef5669 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_widget_text.c @@ -0,0 +1,35 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include "Elm_Code.h" + +#include "elm_code_private.h" + +EAPI int +elm_code_widget_text_line_number_width_get(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + int max; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + max = elm_code_file_lines_get(pd->code->file); + if (max < 1) + max = 1; + + return ceil(log10(max)); +} + +EAPI int +elm_code_widget_text_left_gutter_width_get(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + int width = 1; // the status icon, for now + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (pd->show_line_numbers) + width += elm_code_widget_text_line_number_width_get(widget) + 1; + + return width; +} diff --git a/legacy/elm_code/lib/elm_code_widget_text.h b/legacy/elm_code/lib/elm_code_widget_text.h new file mode 100644 index 0000000000..5ac983e610 --- /dev/null +++ b/legacy/elm_code/lib/elm_code_widget_text.h @@ -0,0 +1,30 @@ +#ifndef ELM_CODE_WIDGET_TEXT_H_ +# define ELM_CODE_WIDGET_TEXT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Text layout handling functions. + * @defgroup Managing the complexities of layout out text in an Elm_Code_Widget + * + * @{ + * + * Functions for text layout handling + * + */ + +EAPI int elm_code_widget_text_left_gutter_width_get(Elm_Code_Widget *widget); + +EAPI int elm_code_widget_text_line_number_width_get(Elm_Code_Widget *widget); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ELM_CODE_WIDGET_TEXT_H_ */ From ff72fa0651226090d63c27d6610c361aef185b33 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 29 Jan 2015 00:50:07 +0000 Subject: [PATCH 072/254] elm_code: And complete the line number render first case. Next some styling would indeed be nice... --- legacy/elm_code/lib/elm_code_widget.c | 19 +++++++++++++------ legacy/elm_code/lib/elm_code_widget_text.c | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 2a3cb368d3..1e294f402f 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -132,7 +132,7 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c static void _elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) { - char *chr; + char *chr, *number; unsigned int length, x; int w, gutter, g; Elm_Code_Widget_Data *pd; @@ -151,12 +151,19 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, E cells[0].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; cells[0].bg = line->status; - for (g = 1; g < gutter; g++) + if (pd->show_line_numbers) { -// TODO figure what our actual line number is as a string! (of length g) - cells[g].codepoint = (g == gutter - 1) ? '|' : '_'; - cells[g].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; - cells[g].bg = ELM_CODE_STATUS_TYPE_DEFAULT; + number = malloc(sizeof(char) * gutter); + snprintf(number, gutter, "%d", line->number); + + for (g = 1; g < gutter; g++) + { +// TODO style this properly + cells[g].codepoint = (g == gutter - 1) ? '|' : *(number + g - 1); + cells[g].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; + cells[g].bg = ELM_CODE_STATUS_TYPE_DEFAULT; + } + free(number); } if (line->modified) diff --git a/legacy/elm_code/lib/elm_code_widget_text.c b/legacy/elm_code/lib/elm_code_widget_text.c index 53d2ef5669..328177c187 100644 --- a/legacy/elm_code/lib/elm_code_widget_text.c +++ b/legacy/elm_code/lib/elm_code_widget_text.c @@ -17,7 +17,7 @@ elm_code_widget_text_line_number_width_get(Elm_Code_Widget *widget) if (max < 1) max = 1; - return ceil(log10(max)); + return floor(log10(max)) + 1; } EAPI int From c22f0d2a0a5efd50bf56020dcba1b7a68a252911 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 29 Jan 2015 14:05:20 +0000 Subject: [PATCH 073/254] elm_code: Update style and alignment of gutter --- legacy/elm_code/bin/elm_code_test_main.c | 1 - legacy/elm_code/lib/elm_code_common.h | 2 -- legacy/elm_code/lib/elm_code_widget.c | 37 ++++++++++++++-------- legacy/elm_code/lib/elm_code_widget_text.c | 2 +- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index b15bea8d18..3bfd857ac7 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -63,7 +63,6 @@ _elm_code_test_welcome_setup(Evas_Object *parent) elm_code_file_line_token_add(code->file, 1, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); _append_line(code->file, ""); _append_line(code->file, "This is a demo of elm_code's capabilities."); - _append_line(code->file, "*** Currently experimental ***"); elm_code_file_line_status_set(code->file, 4, ELM_CODE_STATUS_TYPE_ERROR); diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/lib/elm_code_common.h index 617e8377f0..12ab5befa7 100644 --- a/legacy/elm_code/lib/elm_code_common.h +++ b/legacy/elm_code/lib/elm_code_common.h @@ -26,12 +26,10 @@ typedef enum { ELM_CODE_TOKEN_TYPE_DEFAULT = ELM_CODE_STATUS_TYPE_COUNT, ELM_CODE_TOKEN_TYPE_COMMENT, - ELM_CODE_TOKEN_TYPE_ADDED, ELM_CODE_TOKEN_TYPE_REMOVED, ELM_CODE_TOKEN_TYPE_CHANGED, - ELM_CODE_TOKEN_TYPE_CURSOR, // a pseudo type used for styling but may not be set on a cell ELM_CODE_TOKEN_TYPE_COUNT } Elm_Code_Token_Type; diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 1e294f402f..609d62cdf2 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -5,6 +5,14 @@ #include #include "elm_code_private.h" +typedef enum { + ELM_CODE_WIDGET_COLOR_GUTTER_BG = ELM_CODE_TOKEN_TYPE_COUNT, + ELM_CODE_WIDGET_COLOR_GUTTER_FG, + ELM_CODE_WIDGET_COLOR_CURSOR, + + ELM_CODE_WIDGET_COLOR_COUNT +} Elm_Code_Widget_Colors; + Eina_Unicode status_icons[] = { ' ', '!', @@ -146,22 +154,21 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, E length = line->length; evas_object_textgrid_size_get(pd->grid, &w, NULL); - cells[0].codepoint = status_icons[line->status]; - cells[0].bold = 1; - cells[0].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; - cells[0].bg = line->status; + cells[gutter-1].codepoint = status_icons[line->status]; + cells[gutter-1].bold = 1; + cells[gutter-1].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG; + cells[gutter-1].bg = (line->status == ELM_CODE_STATUS_TYPE_DEFAULT) ? ELM_CODE_WIDGET_COLOR_GUTTER_BG : line->status; if (pd->show_line_numbers) { number = malloc(sizeof(char) * gutter); - snprintf(number, gutter, "%d", line->number); + snprintf(number, gutter, "%*d", gutter - 1, line->number); - for (g = 1; g < gutter; g++) + for (g = 0; g < gutter - 1; g++) { -// TODO style this properly - cells[g].codepoint = (g == gutter - 1) ? '|' : *(number + g - 1); - cells[g].fg = ELM_CODE_TOKEN_TYPE_DEFAULT; - cells[g].bg = ELM_CODE_STATUS_TYPE_DEFAULT; + cells[g].codepoint = *(number + g); + cells[g].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG; + cells[g].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG; } free(number); } @@ -187,7 +194,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, E if (pd->editable && pd->focussed && pd->cursor_line == line->number) { if (pd->cursor_col + gutter - 1 < (unsigned int) w) - cells[pd->cursor_col + gutter - 1].bg = ELM_CODE_TOKEN_TYPE_CURSOR; + cells[pd->cursor_col + gutter - 1].bg = ELM_CODE_WIDGET_COLOR_CURSOR; } evas_object_textgrid_update_add(pd->grid, 0, line->number - 1, w, 1); @@ -623,9 +630,13 @@ _elm_code_widget_setup_palette(Evas_Object *o) evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CHANGED, 54, 54, 255, 255); - // the style for a cursor - this is a special token and will be applied to the background - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CURSOR, + // other styles that the widget uses + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_CURSOR, 205, 205, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_BG, + 75, 75, 75, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_FG, + 139, 139, 139, 255); } EOLIAN static void diff --git a/legacy/elm_code/lib/elm_code_widget_text.c b/legacy/elm_code/lib/elm_code_widget_text.c index 328177c187..30872c8b07 100644 --- a/legacy/elm_code/lib/elm_code_widget_text.c +++ b/legacy/elm_code/lib/elm_code_widget_text.c @@ -29,7 +29,7 @@ elm_code_widget_text_left_gutter_width_get(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (pd->show_line_numbers) - width += elm_code_widget_text_line_number_width_get(widget) + 1; + width += elm_code_widget_text_line_number_width_get(widget); return width; } From dd47f60ed52dc86e03010b02fe09005c1c26e631 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 2 Feb 2015 23:52:04 +0000 Subject: [PATCH 074/254] Correctly lookup icon paths - @fix T2044. Set up elm with the appropriate compile option variables. --- legacy/elm_code/bin/Makefile.am | 3 +++ legacy/elm_code/bin/elm_code_test_main.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/legacy/elm_code/bin/Makefile.am b/legacy/elm_code/bin/Makefile.am index b081d5fb9e..0e6d5ba047 100644 --- a/legacy/elm_code/bin/Makefile.am +++ b/legacy/elm_code/bin/Makefile.am @@ -3,6 +3,9 @@ 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/lib/ \ -DLOCALEDIR=\"$(datadir)/locale\" \ -DEFL_BETA_API_SUPPORT \ diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 2897c3c12b..6888459fc0 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -166,6 +166,10 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) 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())) From fb8a4351b7d7dcebd5a63bb4183b1e5ec0b3e0eb Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 3 Feb 2015 13:55:20 +0000 Subject: [PATCH 075/254] Fix the tests to work with widget improvements --- legacy/elm_code/lib/elm_code_widget_text.c | 3 +++ legacy/elm_code/tests/elm_code_test_widget.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/lib/elm_code_widget_text.c b/legacy/elm_code/lib/elm_code_widget_text.c index 30872c8b07..e96b5d1cbe 100644 --- a/legacy/elm_code/lib/elm_code_widget_text.c +++ b/legacy/elm_code/lib/elm_code_widget_text.c @@ -26,6 +26,9 @@ elm_code_widget_text_left_gutter_width_get(Elm_Code_Widget *widget) Elm_Code_Widget_Data *pd; int width = 1; // the status icon, for now + if (!widget) + return width; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (pd->show_line_numbers) diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/tests/elm_code_test_widget.c index 6efdce8715..22ab5b51f5 100644 --- a/legacy/elm_code/tests/elm_code_test_widget.c +++ b/legacy/elm_code/tests/elm_code_test_widget.c @@ -29,7 +29,7 @@ START_TEST (elm_code_widget_token_render_simple_test) elm_code_file_line_token_add(file, 1, 6+1, 17+1, ELM_CODE_TOKEN_TYPE_COMMENT); elm_code_file_line_token_add(file, 1, 21+1, 22+1, ELM_CODE_TOKEN_TYPE_COMMENT); - _elm_code_widget_fill_line_tokens(cells, length+1, line); + _elm_code_widget_fill_line_tokens(NULL, cells, length+1, line); _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT, 1); _assert_cell_type(cells[4], ELM_CODE_TOKEN_TYPE_DEFAULT, 4); _assert_cell_type(cells[6], ELM_CODE_TOKEN_TYPE_DEFAULT, 6); From e146890b40bd9cfb58e6e11fdc91d79995839b06 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 6 Feb 2015 23:45:50 +0000 Subject: [PATCH 076/254] Fix issues with distcheck. Only remaining is a permissions problem with skeleton - will be fixed soon. --- legacy/elm_code/bin/elm_code_test_main.c | 2 - legacy/elm_code/bin/gettext.h | 280 ------------------ legacy/elm_code/lib/Makefile.am | 23 ++ legacy/elm_code/lib/regen.sh | 8 - legacy/elm_code/tests/Makefile.am | 13 +- .../elm_code/tests/elm_code_file_test_load.c | 8 +- legacy/elm_code/tests/elm_code_test_parse.c | 2 +- 7 files changed, 37 insertions(+), 299 deletions(-) delete mode 100644 legacy/elm_code/bin/gettext.h delete mode 100755 legacy/elm_code/lib/regen.sh diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index f77e77edfc..5f33ffdcb8 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -9,8 +9,6 @@ #include #include -#include "gettext.h" - #include #include "elm_code_widget.eo.h" diff --git a/legacy/elm_code/bin/gettext.h b/legacy/elm_code/bin/gettext.h deleted file mode 100644 index e76b592d08..0000000000 --- a/legacy/elm_code/bin/gettext.h +++ /dev/null @@ -1,280 +0,0 @@ -/* Convenience header for conditional use of GNU . - Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. */ - -#ifndef _LIBGETTEXT_H -#define _LIBGETTEXT_H 1 - -/* NLS can be disabled through the configure --disable-nls option. */ -#if ENABLE_NLS - -/* Get declarations of GNU message catalog functions. */ -# include - -/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by - the gettext() and ngettext() macros. This is an alternative to calling - textdomain(), and is useful for libraries. */ -# ifdef DEFAULT_TEXT_DOMAIN -# undef gettext -# define gettext(Msgid) \ - dgettext (DEFAULT_TEXT_DOMAIN, Msgid) -# undef ngettext -# define ngettext(Msgid1, Msgid2, N) \ - dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N) -# endif - -#else - -/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which - chokes if dcgettext is defined as a macro. So include it now, to make - later inclusions of a NOP. We don't include - as well because people using "gettext.h" will not include , - and also including would fail on SunOS 4, whereas - is OK. */ -#if defined(__sun) -# include -#endif - -/* Many header files from the libstdc++ coming with g++ 3.3 or newer include - , which chokes if dcgettext is defined as a macro. So include - it now, to make later inclusions of a NOP. */ -#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) -# include -# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H -# include -# endif -#endif - -/* Disabled NLS. - The casts to 'const char *' serve the purpose of producing warnings - for invalid uses of the value returned from these functions. - On pre-ANSI systems without 'const', the config.h file is supposed to - contain "#define const". */ -# undef gettext -# define gettext(Msgid) ((const char *) (Msgid)) -# undef dgettext -# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) -# undef dcgettext -# define dcgettext(Domainname, Msgid, Category) \ - ((void) (Category), dgettext (Domainname, Msgid)) -# undef ngettext -# define ngettext(Msgid1, Msgid2, N) \ - ((N) == 1 \ - ? ((void) (Msgid2), (const char *) (Msgid1)) \ - : ((void) (Msgid1), (const char *) (Msgid2))) -# undef dngettext -# define dngettext(Domainname, Msgid1, Msgid2, N) \ - ((void) (Domainname), ngettext (Msgid1, Msgid2, N)) -# undef dcngettext -# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ - ((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N)) -# undef textdomain -# define textdomain(Domainname) ((const char *) (Domainname)) -# undef bindtextdomain -# define bindtextdomain(Domainname, Dirname) \ - ((void) (Domainname), (const char *) (Dirname)) -# undef bind_textdomain_codeset -# define bind_textdomain_codeset(Domainname, Codeset) \ - ((void) (Domainname), (const char *) (Codeset)) - -#endif - -/* A pseudo function call that serves as a marker for the automated - extraction of messages, but does not call gettext(). The run-time - translation is done at a different place in the code. - The argument, String, should be a literal string. Concatenated strings - and other string expressions won't work. - The macro's expansion is not parenthesized, so that it is suitable as - initializer for static 'char[]' or 'const char[]' variables. */ -#define gettext_noop(String) String - -/* The separator between msgctxt and msgid in a .mo file. */ -#define GETTEXT_CONTEXT_GLUE "\004" - -/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a - MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be - short and rarely need to change. - The letter 'p' stands for 'particular' or 'special'. */ -#ifdef DEFAULT_TEXT_DOMAIN -# define pgettext(Msgctxt, Msgid) \ - pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) -#else -# define pgettext(Msgctxt, Msgid) \ - pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) -#endif -#define dpgettext(Domainname, Msgctxt, Msgid) \ - pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) -#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \ - pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category) -#ifdef DEFAULT_TEXT_DOMAIN -# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ - npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) -#else -# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ - npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) -#endif -#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ - npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) -#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \ - npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category) - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static const char * -pgettext_aux (const char *domain, - const char *msg_ctxt_id, const char *msgid, - int category) -{ - const char *translation = dcgettext (domain, msg_ctxt_id, category); - if (translation == msg_ctxt_id) - return msgid; - else - return translation; -} - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static const char * -npgettext_aux (const char *domain, - const char *msg_ctxt_id, const char *msgid, - const char *msgid_plural, unsigned long int n, - int category) -{ - const char *translation = - dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); - if (translation == msg_ctxt_id || translation == msgid_plural) - return (n == 1 ? msgid : msgid_plural); - else - return translation; -} - -/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID - can be arbitrary expressions. But for string literals these macros are - less efficient than those above. */ - -#include - -#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \ - (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \ - /* || __STDC_VERSION__ >= 199901L */ ) - -#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS -#include -#endif - -#define pgettext_expr(Msgctxt, Msgid) \ - dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) -#define dpgettext_expr(Domainname, Msgctxt, Msgid) \ - dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static const char * -dcpgettext_expr (const char *domain, - const char *msgctxt, const char *msgid, - int category) -{ - size_t msgctxt_len = strlen (msgctxt) + 1; - size_t msgid_len = strlen (msgid) + 1; - const char *translation; -#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - char msg_ctxt_id[msgctxt_len + msgid_len]; -#else - char buf[1024]; - char *msg_ctxt_id = - (msgctxt_len + msgid_len <= sizeof (buf) - ? buf - : (char *) malloc (msgctxt_len + msgid_len)); - if (msg_ctxt_id != NULL) -#endif - { - memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); - msg_ctxt_id[msgctxt_len - 1] = '\004'; - memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); - translation = dcgettext (domain, msg_ctxt_id, category); -#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - if (msg_ctxt_id != buf) - free (msg_ctxt_id); -#endif - if (translation != msg_ctxt_id) - return translation; - } - return msgid; -} - -#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ - dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) -#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ - dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static const char * -dcnpgettext_expr (const char *domain, - const char *msgctxt, const char *msgid, - const char *msgid_plural, unsigned long int n, - int category) -{ - size_t msgctxt_len = strlen (msgctxt) + 1; - size_t msgid_len = strlen (msgid) + 1; - const char *translation; -#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - char msg_ctxt_id[msgctxt_len + msgid_len]; -#else - char buf[1024]; - char *msg_ctxt_id = - (msgctxt_len + msgid_len <= sizeof (buf) - ? buf - : (char *) malloc (msgctxt_len + msgid_len)); - if (msg_ctxt_id != NULL) -#endif - { - memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); - msg_ctxt_id[msgctxt_len - 1] = '\004'; - memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); - translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); -#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - if (msg_ctxt_id != buf) - free (msg_ctxt_id); -#endif - if (!(translation == msg_ctxt_id || translation == msgid_plural)) - return translation; - } - return (n == 1 ? msgid : msgid_plural); -} - -#endif /* _LIBGETTEXT_H */ diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/lib/Makefile.am index 932696aa34..5b927f0a63 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/lib/Makefile.am @@ -1,5 +1,12 @@ MAINTAINERCLEANFILES = Makefile.in +CLEANFILES= + +EOLIAN_FLAGS = @DEPS_EOLIAN_FLAGS@ \ + -I$(top_srcdir)/elm_code/lib + +include $(top_srcdir)/Makefile_Eolian_Helper.am + AM_CPPFLAGS = \ -I$(top_srcdir)/elm_code/lib \ -DEFL_BETA_API_SUPPORT \ @@ -10,9 +17,11 @@ AM_CPPFLAGS = \ lib_LTLIBRARIES = libelm_code.la includes_HEADERS = \ +elm_code_common.h \ elm_code_file.h \ elm_code_parse.h \ elm_code_widget.eo.h \ +elm_code_widget_text.h \ elm_code_diff_widget.h \ Elm_Code.h includesdir = $(includedir)/edi-@VMAJ@ @@ -28,3 +37,17 @@ elm_code_private.h libelm_code_la_LIBADD = @EFL_LIBS@ -lm libelm_code_la_LDFLAGS = -no-undefined @EFL_LTLIBRARY_FLAGS@ + +elm_code_eolian_files = \ +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) + +BUILT_SOURCES = \ + $(elm_code_eolian_c) \ + $(elm_code_eolian_h) + +elmcodeeolianfilesdir = $(datadir)/eolian/include/elm_code-@VMAJ@ +elmcodeeolianfiles_DATA = $(elm_code_eolian_files) +EXTRA_DIST = ${elmcodeeolianfiles_DATA} diff --git a/legacy/elm_code/lib/regen.sh b/legacy/elm_code/lib/regen.sh deleted file mode 100755 index b3c682e66a..0000000000 --- a/legacy/elm_code/lib/regen.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -cd `dirname $0` - -INCLUDE="-I /usr/local/share/eolian/include/eo-1 -I /usr/local/share/eolian/include/elementary-1 -I /usr/local/share/eolian/include/evas-1 -I /usr/local/share/eolian/include/efl-1" - -eolian_gen $INCLUDE --gh --eo -o elm_code_widget.eo.h elm_code_widget.eo -eolian_gen $INCLUDE --gc --eo -o elm_code_widget.eo.c elm_code_widget.eo -eolian_gen $INCLUDE --gi --eo -o elm_code_widget.c elm_code_widget.eo diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/tests/Makefile.am index 712c389029..dbcec9ab8f 100644 --- a/legacy/elm_code/tests/Makefile.am +++ b/legacy/elm_code/tests/Makefile.am @@ -14,8 +14,10 @@ elm_code_suite.c elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/lib/ \ -DEFL_BETA_API_SUPPORT \ -DEFL_EO_API_SUPPORT \ +-I$(top_srcdir)/elm_code/lib \ -DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/tests/\" \ -DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/tests/\" \ +-DTESTS_DIR=\"$(abspath $(srcdir))/\" \ -DEFL_BETA_API_SUPPORT \ @EFL_CFLAGS@ \ @CHECK_CFLAGS@ @@ -23,9 +25,12 @@ elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/lib/ \ elm_code_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la elm_code_suite_DEPENDENCIES = $(top_builddir)/elm_code/lib/libelm_code.la -endif - -testdir = $(datadir)/$(PACKAGE)/data -test_DATA = testdiff.diff +testdir = $(PACKAGE_TESTS_DIR) +test_DATA = \ +testfile.txt \ +testfile-withblanks.txt \ +testdiff.diff EXTRA_DIST = elm_code_suite.h $(test_DATA) + +endif diff --git a/legacy/elm_code/tests/elm_code_file_test_load.c b/legacy/elm_code/tests/elm_code_file_test_load.c index 474981d254..108f087c20 100644 --- a/legacy/elm_code/tests/elm_code_file_test_load.c +++ b/legacy/elm_code/tests/elm_code_file_test_load.c @@ -6,7 +6,7 @@ START_TEST (elm_code_file_load) { - char *path = "elm_code/tests/testfile.txt"; + char *path = TESTS_DIR "testfile.txt"; char real[EINA_PATH_MAX]; Elm_Code_File *file; Elm_Code *code; @@ -24,7 +24,7 @@ END_TEST START_TEST (elm_code_file_load_lines) { - char *path = "elm_code/tests/testfile.txt"; + char *path = TESTS_DIR "testfile.txt"; Elm_Code_File *file; Elm_Code *code; @@ -39,7 +39,7 @@ END_TEST START_TEST (elm_code_file_load_blank_lines) { - char *path = "elm_code/tests/testfile-withblanks.txt"; + char *path = TESTS_DIR "testfile-withblanks.txt"; Elm_Code_File *file; Elm_Code *code; @@ -66,7 +66,7 @@ static void _assert_line_content_eq(const char *content, Elm_Code_Line *line) START_TEST (elm_code_file_load_content) { - char *path = "elm_code/tests/testfile.txt"; + char *path = TESTS_DIR "testfile.txt"; Elm_Code_File *file; Elm_Code *code; diff --git a/legacy/elm_code/tests/elm_code_test_parse.c b/legacy/elm_code/tests/elm_code_test_parse.c index aed0a12e06..d1d32cfc1b 100644 --- a/legacy/elm_code/tests/elm_code_test_parse.c +++ b/legacy/elm_code/tests/elm_code_test_parse.c @@ -42,7 +42,7 @@ START_TEST (elm_code_parse_hook_file_test) { Elm_Code *code; Elm_Code_File *file; - char *path = "elm_code/tests/testfile.txt"; + char *path = TESTS_DIR "testfile.txt"; line_calls = 0; file_calls = 0; From d8bdb6b8925aef62106ed74233166b3e6f0a6e49 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 7 Feb 2015 16:05:42 +0000 Subject: [PATCH 077/254] Finally fix make distcheck - clean up Makefiles properly --- legacy/elm_code/tests/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/tests/Makefile.am index dbcec9ab8f..750d1a3e93 100644 --- a/legacy/elm_code/tests/Makefile.am +++ b/legacy/elm_code/tests/Makefile.am @@ -1,3 +1,5 @@ +MAINTAINERCLEANFILES = Makefile.in +CLEANFILES = check-results.xml if EFL_HAVE_TESTS From 9f6f9a52ff6189a2eb506f17f4ae63b15fce36f5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 8 Feb 2015 00:55:51 +0000 Subject: [PATCH 078/254] Fix a few warnings and possible build issues --- legacy/elm_code/tests/Makefile.am | 2 +- legacy/elm_code/tests/elm_code_test_basic.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/tests/Makefile.am index 750d1a3e93..af4ae1a307 100644 --- a/legacy/elm_code/tests/Makefile.am +++ b/legacy/elm_code/tests/Makefile.am @@ -24,7 +24,7 @@ elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/lib/ \ @EFL_CFLAGS@ \ @CHECK_CFLAGS@ -elm_code_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la +elm_code_suite_LDADD = @EFL_LIBS@ @CHECK_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la elm_code_suite_DEPENDENCIES = $(top_builddir)/elm_code/lib/libelm_code.la testdir = $(PACKAGE_TESTS_DIR) diff --git a/legacy/elm_code/tests/elm_code_test_basic.c b/legacy/elm_code/tests/elm_code_test_basic.c index 81a34bbe60..aabff68640 100644 --- a/legacy/elm_code/tests/elm_code_test_basic.c +++ b/legacy/elm_code/tests/elm_code_test_basic.c @@ -12,7 +12,7 @@ START_TEST (elm_code_create_test) code = elm_code_create(); elm_code_file_open(code, path); - ck_assert(code); + ck_assert(!!code); elm_code_free(code); } END_TEST From 2c3c4f504d7f16500a465a41a01999eb5ad0283d Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 10 Feb 2015 23:02:45 +0000 Subject: [PATCH 079/254] elm_code: Tidy up some unused code and fix up some focus management --- legacy/elm_code/lib/elm_code_widget.c | 33 ++++++++++++++---------- legacy/elm_code/lib/elm_code_widget.eo | 6 ++--- legacy/elm_code/lib/elm_code_widget.eo.c | 10 ++++--- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 609d62cdf2..00ca5fec39 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -489,12 +489,6 @@ _elm_code_widget_event_veto_cb(void *data, Evas_Object *obj EINA_UNUSED, widget = (Elm_Code_Widget *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (!pd->editable) - return EINA_FALSE; - - widget = (Elm_Code_Widget *)data; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (!pd->editable) return EINA_FALSE; @@ -511,9 +505,15 @@ _elm_code_widget_event_veto_cb(void *data, Evas_Object *obj EINA_UNUSED, EOLIAN static Eina_Bool _elm_code_widget_elm_widget_on_focus(Eo *obj, Elm_Code_Widget_Data *pd) { - Eina_Bool int_ret = EINA_FALSE; + Eina_Bool int_ret; + + if (!pd->editable) + return EINA_FALSE; + eo_do_super(obj, ELM_CODE_WIDGET_CLASS, int_ret = elm_obj_widget_on_focus()); - if (!int_ret) return EINA_TRUE; + + if (!int_ret) + return EINA_TRUE; pd->focussed = elm_widget_focus_get(obj); @@ -521,13 +521,18 @@ _elm_code_widget_elm_widget_on_focus(Eo *obj, Elm_Code_Widget_Data *pd) return EINA_TRUE; } -EOLIAN static void -_elm_code_widget_elm_interface_scrollable_content_pos_set(Eo *obj EINA_UNUSED, - Elm_Code_Widget_Data *pd EINA_UNUSED, - Evas_Coord x, Evas_Coord y, - Eina_Bool sig EINA_UNUSED) +EOLIAN static Eina_Bool +_elm_code_widget_elm_widget_focus_next_manager_is(Elm_Widget *obj EINA_UNUSED, + Elm_Code_Widget_Data *pd EINA_UNUSED) { - printf("scroll to %d, %d\n", x, y); + return EINA_FALSE; +} + +EOLIAN static Eina_Bool +_elm_code_widget_elm_widget_focus_direction_manager_is(Elm_Widget *obj EINA_UNUSED, + Elm_Code_Widget_Data *pd EINA_UNUSED) +{ + return EINA_FALSE; } EOLIAN static void diff --git a/legacy/elm_code/lib/elm_code_widget.eo b/legacy/elm_code/lib/elm_code_widget.eo index 2d92386697..1b29f39e85 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo +++ b/legacy/elm_code/lib/elm_code_widget.eo @@ -1,5 +1,4 @@ -class Elm_Code_Widget (Elm_Box, Elm_Interface_Scrollable, - Elm_Interface_Atspi_Text) +class Elm_Code_Widget (Elm_Box, Elm_Interface_Atspi_Text) { eo_prefix: elm_code_widget; properties { @@ -112,7 +111,8 @@ class Elm_Code_Widget (Elm_Box, Elm_Interface_Scrollable, Eo.Base.constructor; Evas.Object_Smart.add; Elm_Widget.on_focus; - Elm_Interface_Scrollable.content_pos_set; + Elm_Widget.focus_next_manager_is; + Elm_Widget.focus_direction_manager_is; } events { line,clicked; diff --git a/legacy/elm_code/lib/elm_code_widget.eo.c b/legacy/elm_code/lib/elm_code_widget.eo.c index 0affce2bdc..7364d59e85 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo.c +++ b/legacy/elm_code/lib/elm_code_widget.eo.c @@ -50,14 +50,18 @@ void _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd); Eina_Bool _elm_code_widget_elm_widget_on_focus(Eo *obj, Elm_Code_Widget_Data *pd); -void _elm_code_widget_elm_interface_scrollable_content_pos_set(Eo *obj, Elm_Code_Widget_Data *pd, Evas_Coord x, Evas_Coord y, Eina_Bool sig); +Eina_Bool _elm_code_widget_elm_widget_focus_next_manager_is(Eo *obj, Elm_Code_Widget_Data *pd); + + +Eina_Bool _elm_code_widget_elm_widget_focus_direction_manager_is(Eo *obj, Elm_Code_Widget_Data *pd); static Eo_Op_Description _elm_code_widget_op_desc[] = { EO_OP_FUNC_OVERRIDE(eo_constructor, _elm_code_widget_eo_base_constructor), EO_OP_FUNC_OVERRIDE(evas_obj_smart_add, _elm_code_widget_evas_object_smart_add), EO_OP_FUNC_OVERRIDE(elm_obj_widget_on_focus, _elm_code_widget_elm_widget_on_focus), - EO_OP_FUNC_OVERRIDE(elm_interface_scrollable_content_pos_set, _elm_code_widget_elm_interface_scrollable_content_pos_set), + EO_OP_FUNC_OVERRIDE(elm_obj_widget_focus_next_manager_is, _elm_code_widget_elm_widget_focus_next_manager_is), + EO_OP_FUNC_OVERRIDE(elm_obj_widget_focus_direction_manager_is, _elm_code_widget_elm_widget_focus_direction_manager_is), EO_OP_FUNC(elm_code_widget_code_set, _elm_code_widget_code_set, "Set the underlying code object that this widget renders"), EO_OP_FUNC(elm_code_widget_code_get, _elm_code_widget_code_get, "Get the underlying code object we are rendering"), EO_OP_FUNC(elm_code_widget_font_size_set, _elm_code_widget_font_size_set, "Set the font size that this widget uses, the font will always be a system monospaced font"), @@ -87,4 +91,4 @@ static const Eo_Class_Description _elm_code_widget_class_desc = { NULL }; -EO_DEFINE_CLASS(elm_code_widget_class_get, &_elm_code_widget_class_desc, ELM_BOX_CLASS, ELM_INTERFACE_SCROLLABLE_MIXIN, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); \ No newline at end of file +EO_DEFINE_CLASS(elm_code_widget_class_get, &_elm_code_widget_class_desc, ELM_BOX_CLASS, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); \ No newline at end of file From 486a50986c8108c1bbc173606c52f41c03b2057f Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 10 Feb 2015 23:03:18 +0000 Subject: [PATCH 080/254] elm_code: Update demo to split various functions. Adding more pages as use cases emerge --- legacy/elm_code/bin/elm_code_test_main.c | 102 ++++++++++++++++++++--- 1 file changed, 92 insertions(+), 10 deletions(-) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 5f33ffdcb8..6baba4053d 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -52,9 +52,7 @@ _elm_code_test_welcome_setup(Evas_Object *parent) widget = eo_add(ELM_CODE_WIDGET_CLASS, parent); eo_do(widget, elm_code_widget_code_set(code), - elm_code_widget_font_size_set(14), - elm_code_widget_editable_set(EINA_TRUE), - elm_code_widget_line_numbers_set(EINA_TRUE), + elm_code_widget_font_size_set(12), eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_cb, code)); _append_line(code->file, "Hello World, Elm Code!"); @@ -71,6 +69,32 @@ _elm_code_test_welcome_setup(Evas_Object *parent) return widget; } +static Evas_Object * +_elm_code_test_editor_setup(Evas_Object *parent) +{ + Elm_Code *code; + Elm_Code_Widget *widget; + + code = elm_code_create(); + widget = eo_add(ELM_CODE_WIDGET_CLASS, parent); + eo_do(widget, + elm_code_widget_code_set(code), + elm_code_widget_font_size_set(14), + elm_code_widget_editable_set(EINA_TRUE), + elm_code_widget_line_numbers_set(EINA_TRUE)); + + _append_line(code->file, "Edit me :)"); + _append_line(code->file, ""); + _append_line(code->file, ""); + _append_line(code->file, "...Please?"); + + 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_setup(Evas_Object *parent) { @@ -87,26 +111,84 @@ _elm_code_test_diff_setup(Evas_Object *parent) return diff; } +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)); + evas_object_show(screen); + + elm_naviframe_item_push(naviframe, "Editor", + 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; + Evas_Object *win, *vbox, *text, *button, *naviframe; + Elm_Object_Item *item; - win = elm_win_util_standard_add("main", "Elm_Code Test"); + 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); - elm_box_homogeneous_set(vbox, EINA_TRUE); evas_object_show(vbox); - elm_box_pack_end(vbox, _elm_code_test_welcome_setup(vbox)); - elm_box_pack_end(vbox, _elm_code_test_diff_setup(vbox)); - elm_win_resize_object_add(win, 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, 0.9); + 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, "Diff (comparison)"); + evas_object_size_hint_weight_set(button, 0.5, 0.25); + evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 0.1); + 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, 380 * elm_config_scale_get(), 240 * elm_config_scale_get()); + evas_object_resize(win, 400 * elm_config_scale_get(), 320 * elm_config_scale_get()); evas_object_show(win); return win; From 32e73da189a065f4727cd5ba17f9651d8c6310ea Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 11 Feb 2015 19:13:48 +0000 Subject: [PATCH 081/254] Use public types as far as possible --- legacy/elm_code/lib/elm_code_widget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 00ca5fec39..9b3771e4fa 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -522,14 +522,14 @@ _elm_code_widget_elm_widget_on_focus(Eo *obj, Elm_Code_Widget_Data *pd) } EOLIAN static Eina_Bool -_elm_code_widget_elm_widget_focus_next_manager_is(Elm_Widget *obj EINA_UNUSED, +_elm_code_widget_elm_widget_focus_next_manager_is(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd EINA_UNUSED) { return EINA_FALSE; } EOLIAN static Eina_Bool -_elm_code_widget_elm_widget_focus_direction_manager_is(Elm_Widget *obj EINA_UNUSED, +_elm_code_widget_elm_widget_focus_direction_manager_is(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd EINA_UNUSED) { return EINA_FALSE; From aa741e4898c3c4f58c0512dacac291fdef2816fa Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 11 Feb 2015 21:25:09 +0000 Subject: [PATCH 082/254] Fixing some warnings on Windows. Thanks, Vincent Torri --- legacy/elm_code/bin/elm_code_test_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/bin/elm_code_test_main.c index 6baba4053d..7f9311bdc7 100644 --- a/legacy/elm_code/bin/elm_code_test_main.c +++ b/legacy/elm_code/bin/elm_code_test_main.c @@ -6,6 +6,10 @@ * Always put system first, then EFL, then your public header, * and finally your private one. */ +#if ENABLE_NLS +# include +#endif + #include #include From a1d9eae33c7df2be35c1394d3b24429889778132 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 11 Feb 2015 22:01:37 +0000 Subject: [PATCH 083/254] Improving focus control a little --- legacy/elm_code/lib/elm_code_widget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/lib/elm_code_widget.c index 9b3771e4fa..bc98b03e07 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/lib/elm_code_widget.c @@ -518,7 +518,7 @@ _elm_code_widget_elm_widget_on_focus(Eo *obj, Elm_Code_Widget_Data *pd) pd->focussed = elm_widget_focus_get(obj); _elm_code_widget_fill(obj); - return EINA_TRUE; + return pd->focussed; } EOLIAN static Eina_Bool @@ -532,7 +532,7 @@ EOLIAN static Eina_Bool _elm_code_widget_elm_widget_focus_direction_manager_is(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd EINA_UNUSED) { - return EINA_FALSE; + return EINA_TRUE; } EOLIAN static void From 4f49e230bd3eb96ebe9f8accb27cfd4e2cc1d00f Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 14 Feb 2015 18:49:51 +0000 Subject: [PATCH 084/254] elm_code: focus: block focus leaving text area when editable. As well as setting when we should not have focus leave us a theme has been added. This allows us to extend from elm_entry which is better suited to us. --- legacy/elm_code/Makefile.am | 2 +- legacy/elm_code/data/Makefile.am | 4 + legacy/elm_code/data/themes/Makefile.am | 4 + .../elm_code/data/themes/default/Makefile.am | 20 +++ .../elm_code/data/themes/default/default.edc | 19 +++ legacy/elm_code/src/Makefile.am | 4 + legacy/elm_code/{ => src}/bin/Makefile.am | 4 +- .../{ => src}/bin/elm_code_test_main.c | 0 .../{ => src}/bin/elm_code_test_private.h | 0 legacy/elm_code/{ => src}/lib/Elm_Code.h | 0 legacy/elm_code/{ => src}/lib/Makefile.am | 5 +- legacy/elm_code/{ => src}/lib/elm_code.c | 0 .../elm_code/{ => src}/lib/elm_code_common.h | 0 .../{ => src}/lib/elm_code_diff_widget.c | 0 .../{ => src}/lib/elm_code_diff_widget.h | 0 legacy/elm_code/{ => src}/lib/elm_code_file.c | 0 legacy/elm_code/{ => src}/lib/elm_code_file.h | 0 .../elm_code/{ => src}/lib/elm_code_parse.c | 0 .../elm_code/{ => src}/lib/elm_code_parse.h | 0 .../elm_code/{ => src}/lib/elm_code_private.h | 1 - .../elm_code/{ => src}/lib/elm_code_widget.c | 148 +++++++++--------- .../elm_code/{ => src}/lib/elm_code_widget.eo | 3 +- .../{ => src}/lib/elm_code_widget.eo.c | 6 +- .../{ => src}/lib/elm_code_widget.eo.h | 0 .../{ => src}/lib/elm_code_widget_text.c | 0 .../{ => src}/lib/elm_code_widget_text.h | 0 legacy/elm_code/{ => src}/tests/Makefile.am | 12 +- .../{ => src}/tests/elm_code_file_test_load.c | 0 .../tests/elm_code_file_test_memory.c | 0 .../elm_code/{ => src}/tests/elm_code_suite.c | 0 .../elm_code/{ => src}/tests/elm_code_suite.h | 0 .../{ => src}/tests/elm_code_test_basic.c | 0 .../{ => src}/tests/elm_code_test_parse.c | 0 .../{ => src}/tests/elm_code_test_widget.c | 0 legacy/elm_code/{ => src}/tests/testdiff.diff | 0 .../{ => src}/tests/testfile-withblanks.txt | 0 legacy/elm_code/{ => src}/tests/testfile.txt | 0 37 files changed, 139 insertions(+), 93 deletions(-) create mode 100644 legacy/elm_code/data/Makefile.am create mode 100644 legacy/elm_code/data/themes/Makefile.am create mode 100644 legacy/elm_code/data/themes/default/Makefile.am create mode 100644 legacy/elm_code/data/themes/default/default.edc create mode 100644 legacy/elm_code/src/Makefile.am rename legacy/elm_code/{ => src}/bin/Makefile.am (77%) rename legacy/elm_code/{ => src}/bin/elm_code_test_main.c (100%) rename legacy/elm_code/{ => src}/bin/elm_code_test_private.h (100%) rename legacy/elm_code/{ => src}/lib/Elm_Code.h (100%) rename legacy/elm_code/{ => src}/lib/Makefile.am (89%) rename legacy/elm_code/{ => src}/lib/elm_code.c (100%) rename legacy/elm_code/{ => src}/lib/elm_code_common.h (100%) rename legacy/elm_code/{ => src}/lib/elm_code_diff_widget.c (100%) rename legacy/elm_code/{ => src}/lib/elm_code_diff_widget.h (100%) rename legacy/elm_code/{ => src}/lib/elm_code_file.c (100%) rename legacy/elm_code/{ => src}/lib/elm_code_file.h (100%) rename legacy/elm_code/{ => src}/lib/elm_code_parse.c (100%) rename legacy/elm_code/{ => src}/lib/elm_code_parse.h (100%) rename legacy/elm_code/{ => src}/lib/elm_code_private.h (96%) rename legacy/elm_code/{ => src}/lib/elm_code_widget.c (88%) rename legacy/elm_code/{ => src}/lib/elm_code_widget.eo (97%) rename legacy/elm_code/{ => src}/lib/elm_code_widget.eo.c (95%) rename legacy/elm_code/{ => src}/lib/elm_code_widget.eo.h (100%) rename legacy/elm_code/{ => src}/lib/elm_code_widget_text.c (100%) rename legacy/elm_code/{ => src}/lib/elm_code_widget_text.h (100%) rename legacy/elm_code/{ => src}/tests/Makefile.am (66%) rename legacy/elm_code/{ => src}/tests/elm_code_file_test_load.c (100%) rename legacy/elm_code/{ => src}/tests/elm_code_file_test_memory.c (100%) rename legacy/elm_code/{ => src}/tests/elm_code_suite.c (100%) rename legacy/elm_code/{ => src}/tests/elm_code_suite.h (100%) rename legacy/elm_code/{ => src}/tests/elm_code_test_basic.c (100%) rename legacy/elm_code/{ => src}/tests/elm_code_test_parse.c (100%) rename legacy/elm_code/{ => src}/tests/elm_code_test_widget.c (100%) rename legacy/elm_code/{ => src}/tests/testdiff.diff (100%) rename legacy/elm_code/{ => src}/tests/testfile-withblanks.txt (100%) rename legacy/elm_code/{ => src}/tests/testfile.txt (100%) diff --git a/legacy/elm_code/Makefile.am b/legacy/elm_code/Makefile.am index 15871c99eb..b10ba50bda 100644 --- a/legacy/elm_code/Makefile.am +++ b/legacy/elm_code/Makefile.am @@ -1,4 +1,4 @@ MAINTAINERCLEANFILES = Makefile.in -SUBDIRS = lib bin tests +SUBDIRS = src data diff --git a/legacy/elm_code/data/Makefile.am b/legacy/elm_code/data/Makefile.am new file mode 100644 index 0000000000..f67d4f3e7b --- /dev/null +++ b/legacy/elm_code/data/Makefile.am @@ -0,0 +1,4 @@ +MAINTAINERCLEANFILES = Makefile.in + +SUBDIRS = themes + diff --git a/legacy/elm_code/data/themes/Makefile.am b/legacy/elm_code/data/themes/Makefile.am new file mode 100644 index 0000000000..31a2b40dd3 --- /dev/null +++ b/legacy/elm_code/data/themes/Makefile.am @@ -0,0 +1,4 @@ +MAINTAINERCLEANFILES = Makefile.in + +SUBDIRS = default + diff --git a/legacy/elm_code/data/themes/default/Makefile.am b/legacy/elm_code/data/themes/default/Makefile.am new file mode 100644 index 0000000000..46593bf159 --- /dev/null +++ b/legacy/elm_code/data/themes/default/Makefile.am @@ -0,0 +1,20 @@ +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 diff --git a/legacy/elm_code/data/themes/default/default.edc b/legacy/elm_code/data/themes/default/default.edc new file mode 100644 index 0000000000..dea7a81adb --- /dev/null +++ b/legacy/elm_code/data/themes/default/default.edc @@ -0,0 +1,19 @@ +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; + } + } + } + } + } +} + diff --git a/legacy/elm_code/src/Makefile.am b/legacy/elm_code/src/Makefile.am new file mode 100644 index 0000000000..15871c99eb --- /dev/null +++ b/legacy/elm_code/src/Makefile.am @@ -0,0 +1,4 @@ +MAINTAINERCLEANFILES = Makefile.in + +SUBDIRS = lib bin tests + diff --git a/legacy/elm_code/bin/Makefile.am b/legacy/elm_code/src/bin/Makefile.am similarity index 77% rename from legacy/elm_code/bin/Makefile.am rename to legacy/elm_code/src/bin/Makefile.am index 0e6d5ba047..74d06a849a 100644 --- a/legacy/elm_code/bin/Makefile.am +++ b/legacy/elm_code/src/bin/Makefile.am @@ -6,7 +6,7 @@ AM_CPPFLAGS = \ -DPACKAGE_BIN_DIR=\"$(bindir)\" \ -DPACKAGE_LIB_DIR=\"$(libdir)\" \ -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ --I$(top_srcdir)/elm_code/lib/ \ +-I$(top_srcdir)/elm_code/src/lib/ \ -DLOCALEDIR=\"$(datadir)/locale\" \ -DEFL_BETA_API_SUPPORT \ @EFL_CFLAGS@ @@ -15,7 +15,7 @@ elm_code_test_SOURCES = \ elm_code_test_main.c \ elm_code_test_private.h -elm_code_test_LDADD = @EFL_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la +elm_code_test_LDADD = @EFL_LIBS@ $(top_builddir)/elm_code/src/lib/libelm_code.la elm_code_test_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ diff --git a/legacy/elm_code/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c similarity index 100% rename from legacy/elm_code/bin/elm_code_test_main.c rename to legacy/elm_code/src/bin/elm_code_test_main.c diff --git a/legacy/elm_code/bin/elm_code_test_private.h b/legacy/elm_code/src/bin/elm_code_test_private.h similarity index 100% rename from legacy/elm_code/bin/elm_code_test_private.h rename to legacy/elm_code/src/bin/elm_code_test_private.h diff --git a/legacy/elm_code/lib/Elm_Code.h b/legacy/elm_code/src/lib/Elm_Code.h similarity index 100% rename from legacy/elm_code/lib/Elm_Code.h rename to legacy/elm_code/src/lib/Elm_Code.h diff --git a/legacy/elm_code/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am similarity index 89% rename from legacy/elm_code/lib/Makefile.am rename to legacy/elm_code/src/lib/Makefile.am index 5b927f0a63..3e8a4c837a 100644 --- a/legacy/elm_code/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -3,12 +3,13 @@ MAINTAINERCLEANFILES = Makefile.in CLEANFILES= EOLIAN_FLAGS = @DEPS_EOLIAN_FLAGS@ \ - -I$(top_srcdir)/elm_code/lib + -I$(top_srcdir)/elm_code/src/lib include $(top_srcdir)/Makefile_Eolian_Helper.am AM_CPPFLAGS = \ --I$(top_srcdir)/elm_code/lib \ +-I$(top_srcdir)/elm_code/src/lib \ +-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ -DEFL_BETA_API_SUPPORT \ -DEFL_EO_API_SUPPORT \ @EFL_CFLAGS@ \ diff --git a/legacy/elm_code/lib/elm_code.c b/legacy/elm_code/src/lib/elm_code.c similarity index 100% rename from legacy/elm_code/lib/elm_code.c rename to legacy/elm_code/src/lib/elm_code.c diff --git a/legacy/elm_code/lib/elm_code_common.h b/legacy/elm_code/src/lib/elm_code_common.h similarity index 100% rename from legacy/elm_code/lib/elm_code_common.h rename to legacy/elm_code/src/lib/elm_code_common.h diff --git a/legacy/elm_code/lib/elm_code_diff_widget.c b/legacy/elm_code/src/lib/elm_code_diff_widget.c similarity index 100% rename from legacy/elm_code/lib/elm_code_diff_widget.c rename to legacy/elm_code/src/lib/elm_code_diff_widget.c diff --git a/legacy/elm_code/lib/elm_code_diff_widget.h b/legacy/elm_code/src/lib/elm_code_diff_widget.h similarity index 100% rename from legacy/elm_code/lib/elm_code_diff_widget.h rename to legacy/elm_code/src/lib/elm_code_diff_widget.h diff --git a/legacy/elm_code/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c similarity index 100% rename from legacy/elm_code/lib/elm_code_file.c rename to legacy/elm_code/src/lib/elm_code_file.c diff --git a/legacy/elm_code/lib/elm_code_file.h b/legacy/elm_code/src/lib/elm_code_file.h similarity index 100% rename from legacy/elm_code/lib/elm_code_file.h rename to legacy/elm_code/src/lib/elm_code_file.h diff --git a/legacy/elm_code/lib/elm_code_parse.c b/legacy/elm_code/src/lib/elm_code_parse.c similarity index 100% rename from legacy/elm_code/lib/elm_code_parse.c rename to legacy/elm_code/src/lib/elm_code_parse.c diff --git a/legacy/elm_code/lib/elm_code_parse.h b/legacy/elm_code/src/lib/elm_code_parse.h similarity index 100% rename from legacy/elm_code/lib/elm_code_parse.h rename to legacy/elm_code/src/lib/elm_code_parse.h diff --git a/legacy/elm_code/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h similarity index 96% rename from legacy/elm_code/lib/elm_code_private.h rename to legacy/elm_code/src/lib/elm_code_private.h index c464d95013..854d4b6826 100644 --- a/legacy/elm_code/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -35,7 +35,6 @@ typedef struct double gravity_x, gravity_y; unsigned int cursor_line, cursor_col; - Eina_Bool cursor_move_vetoed; Eina_Bool editable, focussed; Eina_Bool show_line_numbers; } Elm_Code_Widget_Data; diff --git a/legacy/elm_code/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c similarity index 88% rename from legacy/elm_code/lib/elm_code_widget.c rename to legacy/elm_code/src/lib/elm_code_widget.c index bc98b03e07..a12fac1867 100644 --- a/legacy/elm_code/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -35,7 +35,6 @@ _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUS pd->cursor_line = 1; pd->cursor_col = 1; - pd->cursor_move_vetoed = EINA_TRUE; } EOLIAN static void @@ -271,6 +270,57 @@ _elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EIN _elm_code_widget_fill(widget); } +static Eina_Bool +_elm_code_widget_cursor_key_will_move(Elm_Code_Widget *widget, const char *key) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + line = elm_code_file_line_get(pd->code->file, pd->cursor_line); + + if (!line) + return EINA_FALSE; + + if (!strcmp(key, "Up")) + return pd->cursor_line > 1; + else if (!strcmp(key, "Down")) + return pd->cursor_line < elm_code_file_lines_get(pd->code->file); + else if (!strcmp(key, "Left")) + return pd->cursor_col > 1; + else if (!strcmp(key, "Right")) + return pd->cursor_col < (unsigned int) line->length + 1; + else + return EINA_FALSE; +} + +static void +_elm_code_widget_update_focus_directions(Elm_Code_Widget *obj) +{ + if (_elm_code_widget_cursor_key_will_move(obj, "Up")) + elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_UP); + else + elm_widget_focus_next_object_set(obj, NULL, ELM_FOCUS_UP); + + if (_elm_code_widget_cursor_key_will_move(obj, "Down")) + elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_DOWN); + else + elm_widget_focus_next_object_set(obj, NULL, ELM_FOCUS_DOWN); + + if (_elm_code_widget_cursor_key_will_move(obj, "Left")) + elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_LEFT); + else + elm_widget_focus_next_object_set(obj, NULL, ELM_FOCUS_LEFT); + + if (_elm_code_widget_cursor_key_will_move(obj, "Right")) + elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_RIGHT); + else + elm_widget_focus_next_object_set(obj, NULL, ELM_FOCUS_RIGHT); + + elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_PREVIOUS); + elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_NEXT); +} + static void _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas_Coord y) { @@ -298,6 +348,7 @@ _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas if (pd->cursor_col == 0) pd->cursor_col = 1; + _elm_code_widget_update_focus_directions(widget); _elm_code_widget_fill(widget); } @@ -407,42 +458,6 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) _elm_code_widget_fill(widget); } -static Eina_Bool -_elm_code_widget_cursor_key_can_control(Evas_Event_Key_Down *event) -{ - if (!strcmp(event->key, "Up")) - return EINA_TRUE; - else if (!strcmp(event->key, "Down")) - return EINA_TRUE; - else if (!strcmp(event->key, "Left")) - return EINA_TRUE; - else if (!strcmp(event->key, "Right")) - return EINA_TRUE; - else - return EINA_FALSE; -} - -static Eina_Bool -_elm_code_widget_cursor_key_will_move(Elm_Code_Widget *widget, Evas_Event_Key_Down *event) -{ - Elm_Code_Widget_Data *pd; - Elm_Code_Line *line; - - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - line = elm_code_file_line_get(pd->code->file, pd->cursor_line); - - if (!strcmp(event->key, "Up")) - return pd->cursor_line > 1; - else if (!strcmp(event->key, "Down")) - return pd->cursor_line < elm_code_file_lines_get(pd->code->file); - else if (!strcmp(event->key, "Left")) - return pd->cursor_col > 1; - else if (!strcmp(event->key, "Right")) - return pd->cursor_col < (unsigned int) line->length + 1; - else - return EINA_FALSE; -} - static void _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) @@ -458,12 +473,7 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, if (!pd->editable) return; - pd->cursor_move_vetoed = EINA_TRUE; - if (_elm_code_widget_cursor_key_can_control(ev) && !_elm_code_widget_cursor_key_will_move(widget, ev)) - { - pd->cursor_move_vetoed = EINA_FALSE; - return; - } + _elm_code_widget_update_focus_directions(widget); if (!strcmp(ev->key, "Up")) _elm_code_widget_cursor_move_up(widget); @@ -477,48 +487,34 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, INF("Unhandled key %s", ev->key); } -static Eina_Bool -_elm_code_widget_event_veto_cb(void *data, Evas_Object *obj EINA_UNUSED, - Evas_Object *src EINA_UNUSED, Evas_Callback_Type type, - void *event_info EINA_UNUSED) +static void +_elm_code_widget_focused_event_cb(void *data, Evas_Object *obj, + void *event_info EINA_UNUSED) { Elm_Code_Widget *widget; Elm_Code_Widget_Data *pd; - Eina_Bool vetoed; widget = (Elm_Code_Widget *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (!pd->editable) - return EINA_FALSE; + pd->focussed = EINA_TRUE; - vetoed = EINA_TRUE; - if (type == EVAS_CALLBACK_KEY_DOWN) - { - vetoed = pd->cursor_move_vetoed; - pd->cursor_move_vetoed = EINA_TRUE; - } - - return vetoed; + _elm_code_widget_update_focus_directions(widget); + _elm_code_widget_fill(obj); } -EOLIAN static Eina_Bool -_elm_code_widget_elm_widget_on_focus(Eo *obj, Elm_Code_Widget_Data *pd) +static void +_elm_code_widget_unfocused_event_cb(void *data, Evas_Object *obj, + void *event_info EINA_UNUSED) { - Eina_Bool int_ret; + Elm_Code_Widget *widget; + Elm_Code_Widget_Data *pd; - if (!pd->editable) - return EINA_FALSE; - - eo_do_super(obj, ELM_CODE_WIDGET_CLASS, int_ret = elm_obj_widget_on_focus()); - - if (!int_ret) - return EINA_TRUE; - - pd->focussed = elm_widget_focus_get(obj); + widget = (Elm_Code_Widget *)data; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + pd->focussed = EINA_FALSE; _elm_code_widget_fill(obj); - return pd->focussed; } EOLIAN static Eina_Bool @@ -652,11 +648,14 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) eo_do_super(obj, ELM_CODE_WIDGET_CLASS, evas_obj_smart_add()); elm_object_focus_allow_set(obj, EINA_TRUE); + elm_layout_file_set(obj, PACKAGE_DATA_DIR "/themes/elm_code.edj", "elm_code/layout/default"); + scroller = elm_scroller_add(obj); evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(scroller); - elm_box_pack_end(obj, scroller); + elm_layout_content_set(obj, "elm.swallow.content", scroller); + elm_object_focus_allow_set(scroller, EINA_FALSE); pd->scroller = scroller; grid = evas_object_textgrid_add(obj); @@ -667,11 +666,12 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) pd->grid = grid; _elm_code_widget_setup_palette(grid); - evas_object_event_callback_add(grid, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, obj); + evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, obj); evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_clicked_cb, obj); evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget_key_down_cb, obj); - elm_object_event_callback_add(obj, _elm_code_widget_event_veto_cb, obj); + evas_object_smart_callback_add(obj, "focused", _elm_code_widget_focused_event_cb, obj); + evas_object_smart_callback_add(obj, "unfocused", _elm_code_widget_unfocused_event_cb, obj); eo_do(obj, eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, obj); diff --git a/legacy/elm_code/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/elm_code_widget.eo similarity index 97% rename from legacy/elm_code/lib/elm_code_widget.eo rename to legacy/elm_code/src/lib/elm_code_widget.eo index 1b29f39e85..3bc81b81ec 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/elm_code_widget.eo @@ -1,4 +1,4 @@ -class Elm_Code_Widget (Elm_Box, Elm_Interface_Atspi_Text) +class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) { eo_prefix: elm_code_widget; properties { @@ -110,7 +110,6 @@ class Elm_Code_Widget (Elm_Box, Elm_Interface_Atspi_Text) class.constructor; Eo.Base.constructor; Evas.Object_Smart.add; - Elm_Widget.on_focus; Elm_Widget.focus_next_manager_is; Elm_Widget.focus_direction_manager_is; } diff --git a/legacy/elm_code/lib/elm_code_widget.eo.c b/legacy/elm_code/src/lib/elm_code_widget.eo.c similarity index 95% rename from legacy/elm_code/lib/elm_code_widget.eo.c rename to legacy/elm_code/src/lib/elm_code_widget.eo.c index 7364d59e85..a61a1cba8f 100644 --- a/legacy/elm_code/lib/elm_code_widget.eo.c +++ b/legacy/elm_code/src/lib/elm_code_widget.eo.c @@ -47,9 +47,6 @@ void _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd); void _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd); -Eina_Bool _elm_code_widget_elm_widget_on_focus(Eo *obj, Elm_Code_Widget_Data *pd); - - Eina_Bool _elm_code_widget_elm_widget_focus_next_manager_is(Eo *obj, Elm_Code_Widget_Data *pd); @@ -59,7 +56,6 @@ Eina_Bool _elm_code_widget_elm_widget_focus_direction_manager_is(Eo *obj, Elm_Co static Eo_Op_Description _elm_code_widget_op_desc[] = { EO_OP_FUNC_OVERRIDE(eo_constructor, _elm_code_widget_eo_base_constructor), EO_OP_FUNC_OVERRIDE(evas_obj_smart_add, _elm_code_widget_evas_object_smart_add), - EO_OP_FUNC_OVERRIDE(elm_obj_widget_on_focus, _elm_code_widget_elm_widget_on_focus), EO_OP_FUNC_OVERRIDE(elm_obj_widget_focus_next_manager_is, _elm_code_widget_elm_widget_focus_next_manager_is), EO_OP_FUNC_OVERRIDE(elm_obj_widget_focus_direction_manager_is, _elm_code_widget_elm_widget_focus_direction_manager_is), EO_OP_FUNC(elm_code_widget_code_set, _elm_code_widget_code_set, "Set the underlying code object that this widget renders"), @@ -91,4 +87,4 @@ static const Eo_Class_Description _elm_code_widget_class_desc = { NULL }; -EO_DEFINE_CLASS(elm_code_widget_class_get, &_elm_code_widget_class_desc, ELM_BOX_CLASS, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); \ No newline at end of file +EO_DEFINE_CLASS(elm_code_widget_class_get, &_elm_code_widget_class_desc, ELM_LAYOUT_CLASS, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); \ No newline at end of file diff --git a/legacy/elm_code/lib/elm_code_widget.eo.h b/legacy/elm_code/src/lib/elm_code_widget.eo.h similarity index 100% rename from legacy/elm_code/lib/elm_code_widget.eo.h rename to legacy/elm_code/src/lib/elm_code_widget.eo.h diff --git a/legacy/elm_code/lib/elm_code_widget_text.c b/legacy/elm_code/src/lib/elm_code_widget_text.c similarity index 100% rename from legacy/elm_code/lib/elm_code_widget_text.c rename to legacy/elm_code/src/lib/elm_code_widget_text.c diff --git a/legacy/elm_code/lib/elm_code_widget_text.h b/legacy/elm_code/src/lib/elm_code_widget_text.h similarity index 100% rename from legacy/elm_code/lib/elm_code_widget_text.h rename to legacy/elm_code/src/lib/elm_code_widget_text.h diff --git a/legacy/elm_code/tests/Makefile.am b/legacy/elm_code/src/tests/Makefile.am similarity index 66% rename from legacy/elm_code/tests/Makefile.am rename to legacy/elm_code/src/tests/Makefile.am index af4ae1a307..168321d5fa 100644 --- a/legacy/elm_code/tests/Makefile.am +++ b/legacy/elm_code/src/tests/Makefile.am @@ -13,19 +13,19 @@ elm_code_test_parse.c \ elm_code_test_widget.c \ elm_code_suite.c -elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/lib/ \ +elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/src/lib/ \ -DEFL_BETA_API_SUPPORT \ -DEFL_EO_API_SUPPORT \ --I$(top_srcdir)/elm_code/lib \ --DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/tests/\" \ --DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/tests/\" \ +-I$(top_srcdir)/elm_code/src/lib \ +-DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/src/tests/\" \ +-DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/src/tests/\" \ -DTESTS_DIR=\"$(abspath $(srcdir))/\" \ -DEFL_BETA_API_SUPPORT \ @EFL_CFLAGS@ \ @CHECK_CFLAGS@ -elm_code_suite_LDADD = @EFL_LIBS@ @CHECK_LIBS@ $(top_builddir)/elm_code/lib/libelm_code.la -elm_code_suite_DEPENDENCIES = $(top_builddir)/elm_code/lib/libelm_code.la +elm_code_suite_LDADD = @EFL_LIBS@ @CHECK_LIBS@ $(top_builddir)/elm_code/src/lib/libelm_code.la +elm_code_suite_DEPENDENCIES = $(top_builddir)/elm_code/src/lib/libelm_code.la testdir = $(PACKAGE_TESTS_DIR) test_DATA = \ diff --git a/legacy/elm_code/tests/elm_code_file_test_load.c b/legacy/elm_code/src/tests/elm_code_file_test_load.c similarity index 100% rename from legacy/elm_code/tests/elm_code_file_test_load.c rename to legacy/elm_code/src/tests/elm_code_file_test_load.c diff --git a/legacy/elm_code/tests/elm_code_file_test_memory.c b/legacy/elm_code/src/tests/elm_code_file_test_memory.c similarity index 100% rename from legacy/elm_code/tests/elm_code_file_test_memory.c rename to legacy/elm_code/src/tests/elm_code_file_test_memory.c diff --git a/legacy/elm_code/tests/elm_code_suite.c b/legacy/elm_code/src/tests/elm_code_suite.c similarity index 100% rename from legacy/elm_code/tests/elm_code_suite.c rename to legacy/elm_code/src/tests/elm_code_suite.c diff --git a/legacy/elm_code/tests/elm_code_suite.h b/legacy/elm_code/src/tests/elm_code_suite.h similarity index 100% rename from legacy/elm_code/tests/elm_code_suite.h rename to legacy/elm_code/src/tests/elm_code_suite.h diff --git a/legacy/elm_code/tests/elm_code_test_basic.c b/legacy/elm_code/src/tests/elm_code_test_basic.c similarity index 100% rename from legacy/elm_code/tests/elm_code_test_basic.c rename to legacy/elm_code/src/tests/elm_code_test_basic.c diff --git a/legacy/elm_code/tests/elm_code_test_parse.c b/legacy/elm_code/src/tests/elm_code_test_parse.c similarity index 100% rename from legacy/elm_code/tests/elm_code_test_parse.c rename to legacy/elm_code/src/tests/elm_code_test_parse.c diff --git a/legacy/elm_code/tests/elm_code_test_widget.c b/legacy/elm_code/src/tests/elm_code_test_widget.c similarity index 100% rename from legacy/elm_code/tests/elm_code_test_widget.c rename to legacy/elm_code/src/tests/elm_code_test_widget.c diff --git a/legacy/elm_code/tests/testdiff.diff b/legacy/elm_code/src/tests/testdiff.diff similarity index 100% rename from legacy/elm_code/tests/testdiff.diff rename to legacy/elm_code/src/tests/testdiff.diff diff --git a/legacy/elm_code/tests/testfile-withblanks.txt b/legacy/elm_code/src/tests/testfile-withblanks.txt similarity index 100% rename from legacy/elm_code/tests/testfile-withblanks.txt rename to legacy/elm_code/src/tests/testfile-withblanks.txt diff --git a/legacy/elm_code/tests/testfile.txt b/legacy/elm_code/src/tests/testfile.txt similarity index 100% rename from legacy/elm_code/tests/testfile.txt rename to legacy/elm_code/src/tests/testfile.txt From 9a0f269e924e7dcb00faf6050efa28c47a7a8d70 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 14 Feb 2015 23:14:06 +0000 Subject: [PATCH 085/254] elm_code: Tidying our callbacks and line manipulation. Now the line_done callback allows styling to be set during the load process. --- legacy/elm_code/src/bin/elm_code_test_main.c | 27 +++-- legacy/elm_code/src/lib/Elm_Code.h | 1 + legacy/elm_code/src/lib/Makefile.am | 2 + legacy/elm_code/src/lib/elm_code.c | 6 +- legacy/elm_code/src/lib/elm_code_common.h | 6 +- .../elm_code/src/lib/elm_code_diff_widget.c | 102 ++++++++++-------- legacy/elm_code/src/lib/elm_code_file.c | 71 +++--------- legacy/elm_code/src/lib/elm_code_file.h | 30 +----- legacy/elm_code/src/lib/elm_code_line.c | 44 ++++++++ legacy/elm_code/src/lib/elm_code_line.h | 58 ++++++++++ legacy/elm_code/src/lib/elm_code_widget.c | 6 +- legacy/elm_code/src/tests/Makefile.am | 1 + .../src/tests/elm_code_file_test_memory.c | 6 +- .../elm_code/src/tests/elm_code_test_parse.c | 2 +- .../elm_code/src/tests/elm_code_test_widget.c | 6 +- 15 files changed, 218 insertions(+), 150 deletions(-) create mode 100644 legacy/elm_code/src/lib/elm_code_line.c create mode 100644 legacy/elm_code/src/lib/elm_code_line.h diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 7f9311bdc7..e6235fc68d 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -31,12 +31,12 @@ static void _append_line(Elm_Code_File *file, const char *line) int length; length = strlen(line); - elm_code_file_line_append(file, line, length); + elm_code_file_line_append(file, line, length, NULL); } static Eina_Bool -_elm_code_test_line_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, - const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +_elm_code_test_line_clicked_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, + const Eo_Event_Description *desc EINA_UNUSED, void *event_info) { Elm_Code_Line *line; @@ -46,6 +46,22 @@ _elm_code_test_line_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, return EINA_TRUE; } +static Eina_Bool +_elm_code_test_line_done_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, + const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +{ + Elm_Code_Line *line; + + line = (Elm_Code_Line *)event_info; + + if (line->number == 1) + elm_code_line_token_add(line, 14, 21, 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) { @@ -57,14 +73,13 @@ _elm_code_test_welcome_setup(Evas_Object *parent) eo_do(widget, elm_code_widget_code_set(code), elm_code_widget_font_size_set(12), - eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_cb, code)); + eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_test_line_done_cb, NULL); + eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code)); _append_line(code->file, "Hello World, Elm Code!"); - elm_code_file_line_token_add(code->file, 1, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); _append_line(code->file, ""); _append_line(code->file, "This is a demo of elm_code's capabilities."); _append_line(code->file, "*** Currently experimental ***"); - elm_code_file_line_status_set(code->file, 4, ELM_CODE_STATUS_TYPE_ERROR); 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); diff --git a/legacy/elm_code/src/lib/Elm_Code.h b/legacy/elm_code/src/lib/Elm_Code.h index d60f2f47ca..9cfefa4b21 100644 --- a/legacy/elm_code/src/lib/Elm_Code.h +++ b/legacy/elm_code/src/lib/Elm_Code.h @@ -34,6 +34,7 @@ #endif /* ! _WIN32 */ #include "elm_code_common.h" +#include "elm_code_line.h" #include "elm_code_file.h" #include "elm_code_parse.h" #include "elm_code_widget.eo.h" diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index 3e8a4c837a..274c845f12 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -19,6 +19,7 @@ lib_LTLIBRARIES = libelm_code.la includes_HEADERS = \ elm_code_common.h \ +elm_code_line.h \ elm_code_file.h \ elm_code_parse.h \ elm_code_widget.eo.h \ @@ -28,6 +29,7 @@ Elm_Code.h includesdir = $(includedir)/edi-@VMAJ@ libelm_code_la_SOURCES = \ +elm_code_line.c \ elm_code_file.c \ elm_code_parse.c \ elm_code_widget_text.c \ diff --git a/legacy/elm_code/src/lib/elm_code.c b/legacy/elm_code/src/lib/elm_code.c index 1f965120e7..105ab3be82 100644 --- a/legacy/elm_code/src/lib/elm_code.c +++ b/legacy/elm_code/src/lib/elm_code.c @@ -12,8 +12,10 @@ static int _elm_code_init = 0; int _elm_code_lib_log_dom = -1; -EAPI const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE = - EO_EVENT_DESCRIPTION("line,set,done", ""); +EAPI const Eo_Event_Description ELM_CODE_EVENT_LINE_STYLE_SET = + EO_EVENT_DESCRIPTION("line,style,set", ""); +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", ""); diff --git a/legacy/elm_code/src/lib/elm_code_common.h b/legacy/elm_code/src/lib/elm_code_common.h index 12ab5befa7..35c86512ba 100644 --- a/legacy/elm_code/src/lib/elm_code_common.h +++ b/legacy/elm_code/src/lib/elm_code_common.h @@ -4,7 +4,11 @@ typedef struct _Elm_Code Elm_Code; typedef struct _Elm_Code_File Elm_Code_File; -EAPI extern const Eo_Event_Description ELM_CODE_EVENT_LINE_SET_DONE; +/** Event used to notify that a line's style callbacks have completed */ +EAPI extern const Eo_Event_Description ELM_CODE_EVENT_LINE_STYLE_SET; +/** Event marking that a single line has loaded and ready to be styled */ +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 { diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.c b/legacy/elm_code/src/lib/elm_code_diff_widget.c index 2315d0a59e..21790e982e 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/src/lib/elm_code_diff_widget.c @@ -6,78 +6,89 @@ #include "elm_code_private.h" -#define ELM_CODE_DIFF_WIDGET_LEFT "diffwidgetleft" -#define ELM_CODE_DIFF_WIDGET_RIGHT "diffwidgetright" +#define _ELM_CODE_DIFF_WIDGET_LEFT "diffwidgetleft" +#define _ELM_CODE_DIFF_WIDGET_RIGHT "diffwidgetright" -static void _elm_code_diff_widget_parse_diff_line(Elm_Code_Line *line, int number, Elm_Code_File *left, Elm_Code_File *right) +#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) { if (line->length < 1) { - elm_code_file_line_append(left, "", 0); - elm_code_file_line_append(right, "", 0); + elm_code_file_line_append(left, "", 0, NULL); + elm_code_file_line_append(right, "", 0, NULL); } if (line->content[0] == '+') { - elm_code_file_line_append(left, "", 0); - elm_code_file_line_append(right, line->content+1, line->length-1); - elm_code_file_line_status_set(right, number, ELM_CODE_STATUS_TYPE_ADDED); + elm_code_file_line_append(left, "", 0, NULL); + elm_code_file_line_append(right, line->content+1, line->length-1, _ELM_CODE_DIFF_WIDGET_TYPE_ADDED); } else if (line->content[0] == '-') { - elm_code_file_line_append(left, line->content+1, line->length-1); - elm_code_file_line_append(right, "", 0); - elm_code_file_line_status_set(left, number, ELM_CODE_STATUS_TYPE_REMOVED); + elm_code_file_line_append(left, line->content+1, line->length-1, _ELM_CODE_DIFF_WIDGET_TYPE_REMOVED); + elm_code_file_line_append(right, "", 0, NULL); } else { - elm_code_file_line_append(left, line->content+1, line->length-1); - elm_code_file_line_append(right, line->content+1, line->length-1); + elm_code_file_line_append(left, line->content+1, line->length-1, NULL); + elm_code_file_line_append(right, line->content+1, line->length-1, NULL); } } -static void _elm_code_diff_widget_parse_diff(Elm_Code_File *diff, Elm_Code_File *left, Elm_Code_File *right) +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; - int number, offset; + int offset; - number = 0; offset = 0; EINA_LIST_FOREACH(diff->lines, item, line) { - - if (line->length > 0) + if (line->length > 0 && (line->content[0] == 'd' || line->content[0] == 'i' || line->content[0] == 'n')) { - if (line->content[0] == 'd' || line->content[0] == 'i' || line->content[0] == 'n') - { - offset = 0; - continue; - } + offset = 0; + continue; } - number++; if (offset == 0) - { - elm_code_file_line_append(left, line->content+4, line->length-4); - elm_code_file_line_status_set(left, number, ELM_CODE_STATUS_TYPE_CHANGED); - } + elm_code_file_line_append(left, line->content+4, line->length-4, _ELM_CODE_DIFF_WIDGET_TYPE_CHANGED); else if (offset == 1) - { - number--; - elm_code_file_line_append(right, line->content+4, line->length-4); - elm_code_file_line_status_set(right, number, ELM_CODE_STATUS_TYPE_CHANGED); - } + elm_code_file_line_append(right, line->content+4, line->length-4, _ELM_CODE_DIFF_WIDGET_TYPE_CHANGED); else - { - _elm_code_diff_widget_parse_diff_line(line, number, left, right); - } + _elm_code_diff_widget_parse_diff_line(line, left, right); offset++; } } -EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) +static Eina_Bool +_elm_code_diff_widget_line_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, + const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +{ + Elm_Code_Line *line; + + line = (Elm_Code_Line *)event_info; + + if (!line->data) + return EO_CALLBACK_CONTINUE; + + if (!strcmp(_ELM_CODE_DIFF_WIDGET_TYPE_ADDED, (char *)line->data)) + line->status = ELM_CODE_STATUS_TYPE_ADDED; + else if (!strcmp(_ELM_CODE_DIFF_WIDGET_TYPE_REMOVED, (char *)line->data)) + line->status = ELM_CODE_STATUS_TYPE_REMOVED; + else if (!strcmp(_ELM_CODE_DIFF_WIDGET_TYPE_CHANGED, (char *)line->data)) + line->status = ELM_CODE_STATUS_TYPE_CHANGED; + + return EO_CALLBACK_CONTINUE; +} + +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; @@ -93,37 +104,40 @@ EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) wcode1 = elm_code_create(); widget_left = eo_add(ELM_CODE_WIDGET_CLASS, parent); eo_do(widget_left, - elm_code_widget_code_set(wcode1)); + elm_code_widget_code_set(wcode1), + eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_diff_widget_line_cb, NULL)); 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); + 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(); widget_right = eo_add(ELM_CODE_WIDGET_CLASS, parent); eo_do(widget_right, - elm_code_widget_code_set(wcode2)); + elm_code_widget_code_set(wcode2), + eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_diff_widget_line_cb, NULL)); 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); + 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_size_set(Evas_Object *widget, int size) +EAPI void +elm_code_diff_widget_font_size_set(Evas_Object *widget, int size) { Elm_Code_Widget *child; - child = (Elm_Code_Widget *) evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_LEFT); + child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_LEFT); eo_do(child, elm_code_widget_font_size_set(size)); - child = (Elm_Code_Widget *) evas_object_data_get(widget, ELM_CODE_DIFF_WIDGET_RIGHT); + child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_RIGHT); eo_do(child, elm_code_widget_font_size_set(size)); } diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index b4d783339e..cc24dcd498 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -6,7 +6,7 @@ #include "elm_code_private.h" -static Elm_Code_Line *_elm_code_blank_create(int line) +static Elm_Code_Line *_elm_code_blank_create(int line, void *data) { Elm_Code_Line *ecl; @@ -15,14 +15,16 @@ static Elm_Code_Line *_elm_code_blank_create(int line) ecl->number = line; ecl->status = ELM_CODE_STATUS_TYPE_DEFAULT; + ecl->data = data; + return ecl; } -static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *content, int length, int row, Eina_Bool mapped) +static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *content, int length, int row, Eina_Bool mapped, void *data) { Elm_Code_Line *line; - line = _elm_code_blank_create(row); + line = _elm_code_blank_create(row, data); if (!line) return; if (mapped) @@ -43,7 +45,10 @@ static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *con if (file->parent) { elm_code_parse_line(file->parent, line); - elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_SET_DONE, line); + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); + + // this is called so we can refresh after any styling changes from LOAD_DONE + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_STYLE_SET, line); } } @@ -83,13 +88,13 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) /* Working around the issue that eina_file_map_lines does not trigger an item for empty lines */ while (lastindex < line->index - 1) { - ecl = _elm_code_blank_create(++lastindex); + ecl = _elm_code_blank_create(++lastindex, NULL); if (!ecl) continue; ret->lines = eina_list_append(ret->lines, ecl); } - _elm_code_file_line_append_data(ret, line->start, line->length, lastindex = line->index, EINA_TRUE); + _elm_code_file_line_append_data(ret, line->start, line->length, lastindex = line->index, EINA_TRUE, NULL); } eina_iterator_free(it); @@ -159,12 +164,12 @@ EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file) } -EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length) +EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length, void *data) { int row; row = elm_code_file_lines_get(file); - _elm_code_file_line_append_data(file, line, length, row+1, EINA_FALSE); + return _elm_code_file_line_append_data(file, line, length, row+1, EINA_FALSE, data); } EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int number) @@ -172,53 +177,3 @@ EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int num return eina_list_nth(file->lines, number - 1); } -EAPI const char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int number, int *length) -{ - Elm_Code_Line *line; - - line = elm_code_file_line_get(file, number); - - if (!line) - return NULL; - - *length = line->length; - - if (line->modified) - return line->modified; - return line->content; -} - -EAPI void elm_code_file_line_status_set(Elm_Code_File *file, unsigned int number, Elm_Code_Status_Type status) -{ - Elm_Code_Line *line; - - line = elm_code_file_line_get(file, number); - - if (!line) - return; - - line->status = status; - - if (file->parent) - elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_SET_DONE, line); -} - -EAPI void elm_code_file_line_token_add(Elm_Code_File *file, unsigned int number, int start, int end, - Elm_Code_Token_Type type) -{ - Elm_Code_Line *line; - Elm_Code_Token *tok; - - line = elm_code_file_line_get(file, number); - tok = calloc(1, sizeof(Elm_Code_Token)); - - tok->start = start; - tok->end = end; - tok->type = type; - - line->tokens = eina_list_append(line->tokens, tok); - - if (file->parent) - elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_SET_DONE, line); -} - diff --git a/legacy/elm_code/src/lib/elm_code_file.h b/legacy/elm_code/src/lib/elm_code_file.h index b37de52c5b..36f39a5e0c 100644 --- a/legacy/elm_code/src/lib/elm_code_file.h +++ b/legacy/elm_code/src/lib/elm_code_file.h @@ -10,27 +10,6 @@ extern "C" { * @brief These routines are used for interacting with files using Elm Code. */ -typedef struct _Elm_Code_Token -{ - int start, end; - - Elm_Code_Token_Type type; - -} Elm_Code_Token; - -typedef struct _Elm_Code_Line -{ - const char *content; - int length; - unsigned int number; - char *modified; - - Elm_Code_Status_Type status; - Eina_List *tokens; - - -} Elm_Code_Line; - struct _Elm_Code_File { void *parent; @@ -79,17 +58,10 @@ EAPI void elm_code_file_clear(Elm_Code_File *file); EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file); -EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length); +EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length, void *data); EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int line); -EAPI const char *elm_code_file_line_content_get(Elm_Code_File *file, unsigned int line, int *length); - -EAPI void elm_code_file_line_status_set(Elm_Code_File *file, unsigned int line, Elm_Code_Status_Type status); - -EAPI void elm_code_file_line_token_add(Elm_Code_File *file, unsigned int number, int start, int end, - Elm_Code_Token_Type type); - /** * @} */ diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c new file mode 100644 index 0000000000..6a7af560be --- /dev/null +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -0,0 +1,44 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include "Elm_Code.h" + +#include "elm_code_private.h" + +EAPI const char *elm_code_line_content_get(Elm_Code_Line *line, int *length) +{ + if (!line) + return NULL; + + *length = line->length; + + if (line->modified) + return line->modified; + return line->content; +} + +EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status) +{ + if (!line) + return; + + line->status = status; +} + +EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, Elm_Code_Token_Type type) +{ + Elm_Code_Token *tok; + + if (!line) + return; + + tok = calloc(1, sizeof(Elm_Code_Token)); + + tok->start = start; + tok->end = end; + tok->type = type; + + line->tokens = eina_list_append(line->tokens, tok); +} + diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h new file mode 100644 index 0000000000..339c96691d --- /dev/null +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -0,0 +1,58 @@ +#ifndef ELM_CODE_LINE_H_ +# define ELM_CODE_LINE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for interacting with lines of content using Elm Code. + */ + +typedef struct _Elm_Code_Token +{ + int start, end; + + Elm_Code_Token_Type type; + +} Elm_Code_Token; + +typedef struct _Elm_Code_Line +{ + const char *content; + int length; + unsigned int number; + char *modified; + + Elm_Code_Status_Type status; + Eina_List *tokens; + + void *data; +} Elm_Code_Line; + +/** + * @brief Line handling functions. + * @defgroup Line and content manipulation + * + * @{ + * + * Functions for handling content and styling of lines within elm code. + * + */ + +EAPI const char *elm_code_line_content_get(Elm_Code_Line *line, int *length); + +EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status); + +EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, Elm_Code_Token_Type type); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ELM_CODE_LINE_H_ */ diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index a12fac1867..477f93f5c0 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -243,7 +243,7 @@ _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); _elm_code_widget_fill_line(widget, cells, line); - return EINA_TRUE; + return EO_CALLBACK_CONTINUE; } @@ -256,7 +256,7 @@ _elm_code_widget_file_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descrip widget = (Elm_Code_Widget *)data; _elm_code_widget_fill(widget); - return EINA_TRUE; + return EO_CALLBACK_CONTINUE; } static void @@ -674,7 +674,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) evas_object_smart_callback_add(obj, "unfocused", _elm_code_widget_unfocused_event_cb, obj); eo_do(obj, - eo_event_callback_add(&ELM_CODE_EVENT_LINE_SET_DONE, _elm_code_widget_line_cb, obj); + eo_event_callback_add(&ELM_CODE_EVENT_LINE_STYLE_SET, _elm_code_widget_line_cb, obj); eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj)); _elm_code_widget_font_size_set(obj, pd, 10); diff --git a/legacy/elm_code/src/tests/Makefile.am b/legacy/elm_code/src/tests/Makefile.am index 168321d5fa..7a829d3f66 100644 --- a/legacy/elm_code/src/tests/Makefile.am +++ b/legacy/elm_code/src/tests/Makefile.am @@ -17,6 +17,7 @@ elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/src/lib/ \ -DEFL_BETA_API_SUPPORT \ -DEFL_EO_API_SUPPORT \ -I$(top_srcdir)/elm_code/src/lib \ +-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ -DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/src/tests/\" \ -DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/src/tests/\" \ -DTESTS_DIR=\"$(abspath $(srcdir))/\" \ diff --git a/legacy/elm_code/src/tests/elm_code_file_test_memory.c b/legacy/elm_code/src/tests/elm_code_file_test_memory.c index cf4de295a7..e4b3e3721f 100644 --- a/legacy/elm_code/src/tests/elm_code_file_test_memory.c +++ b/legacy/elm_code/src/tests/elm_code_file_test_memory.c @@ -11,7 +11,7 @@ START_TEST (elm_code_file_memory_lines) code = elm_code_create(); ck_assert_uint_eq(0, elm_code_file_lines_get(code->file)); - elm_code_file_line_append(code->file, "a line", 6); + elm_code_file_line_append(code->file, "a line", 6, NULL); ck_assert_uint_eq(1, elm_code_file_lines_get(code->file)); elm_code_free(code); @@ -26,10 +26,10 @@ START_TEST (elm_code_file_memory_tokens) code = elm_code_create(); file = code->file; - elm_code_file_line_append(file, "a line", 6); - elm_code_file_line_token_add(file, 1, 2, 5, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_file_line_append(file, "a line", 6, NULL); line = elm_code_file_line_get(file, 1); + elm_code_line_token_add(line, 2, 5, ELM_CODE_TOKEN_TYPE_COMMENT); ck_assert_uint_eq(1, eina_list_count(line->tokens)); elm_code_free(code); } diff --git a/legacy/elm_code/src/tests/elm_code_test_parse.c b/legacy/elm_code/src/tests/elm_code_test_parse.c index d1d32cfc1b..ebe8b34939 100644 --- a/legacy/elm_code/src/tests/elm_code_test_parse.c +++ b/legacy/elm_code/src/tests/elm_code_test_parse.c @@ -29,7 +29,7 @@ START_TEST (elm_code_parse_hook_memory_test) file = elm_code_file_new(code); elm_code_parser_add(code, _parser_line_callback, _parser_file_callback); - elm_code_file_line_append(file, "some \"test content\" for parsing", 31); + elm_code_file_line_append(file, "some \"test content\" for parsing", 31, NULL); ck_assert_int_eq(1, line_calls); ck_assert_int_eq(0, file_calls); diff --git a/legacy/elm_code/src/tests/elm_code_test_widget.c b/legacy/elm_code/src/tests/elm_code_test_widget.c index 22ab5b51f5..2836bb4c44 100644 --- a/legacy/elm_code/src/tests/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/elm_code_test_widget.c @@ -22,12 +22,12 @@ START_TEST (elm_code_widget_token_render_simple_test) code = elm_code_create(); file = code->file; - elm_code_file_line_append(file, "some \"test content\", 45", 23); + elm_code_file_line_append(file, "some \"test content\", 45", 23, NULL); line = elm_code_file_line_get(file, 1); length = line->length; - elm_code_file_line_token_add(file, 1, 6+1, 17+1, ELM_CODE_TOKEN_TYPE_COMMENT); - elm_code_file_line_token_add(file, 1, 21+1, 22+1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 6+1, 17+1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 21+1, 22+1, ELM_CODE_TOKEN_TYPE_COMMENT); _elm_code_widget_fill_line_tokens(NULL, cells, length+1, line); _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT, 1); From f9709f915c1198bc1bc0bd0b7052b3f453f462f8 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 15 Feb 2015 20:35:41 +0000 Subject: [PATCH 086/254] An update to get closer to make check passing for windows. Thanks (and credit) to Vincent Torri again --- legacy/elm_code/src/tests/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/legacy/elm_code/src/tests/Makefile.am b/legacy/elm_code/src/tests/Makefile.am index 7a829d3f66..3f85a3fa84 100644 --- a/legacy/elm_code/src/tests/Makefile.am +++ b/legacy/elm_code/src/tests/Makefile.am @@ -23,6 +23,7 @@ elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/src/lib/ \ -DTESTS_DIR=\"$(abspath $(srcdir))/\" \ -DEFL_BETA_API_SUPPORT \ @EFL_CFLAGS@ \ +-DEFL_ELM_CODE_BUILD \ @CHECK_CFLAGS@ elm_code_suite_LDADD = @EFL_LIBS@ @CHECK_LIBS@ $(top_builddir)/elm_code/src/lib/libelm_code.la From 384a12282eb9610d73e1ed1003f95d9e5f50f08e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 17 Feb 2015 23:56:13 +0000 Subject: [PATCH 087/254] Add a temporary fix for some scroll/append/refresh issue with layout --- legacy/elm_code/src/lib/elm_code_widget.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 477f93f5c0..37688b0b74 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -240,8 +240,10 @@ _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, if (!_elm_code_widget_resize(widget)) return EINA_TRUE; - cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); - _elm_code_widget_fill_line(widget, cells, line); +// FIXME refresh just the row - but this resulted in undrawn areas +// cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); +// _elm_code_widget_fill_line(widget, cells, line); + _elm_code_widget_fill(widget); return EO_CALLBACK_CONTINUE; } From 9dea8c488d4dc0586b2ee0f879fc0c9daa2555b6 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 19 Feb 2015 00:22:07 +0000 Subject: [PATCH 088/254] elm_code: Actually use it as our main editor window! Need to hook in the clang highlighting and undo stack to the elm_code_widget --- legacy/elm_code/src/bin/elm_code_test_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index e6235fc68d..d3fd2cbd0d 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -257,8 +257,8 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) args = ecore_getopt_parse(&optdesc, values, argc, argv); if (args < 0) { - EINA_LOG_CRIT("Could not parse arguments."); - goto end; + EINA_LOG_CRIT("Could not parse arguments."); + goto end; } else if (quit_option) { From 5d0224efa5a39e9444486dc9d02eacd517f122a6 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 19 Feb 2015 21:16:18 +0000 Subject: [PATCH 089/254] elm_code: get / set the cursor position When the cursor is updated make sure we have scrolled so it's visible. Also adjust focus next points too. --- legacy/elm_code/src/lib/elm_code_widget.c | 130 ++++++++++++++----- legacy/elm_code/src/lib/elm_code_widget.eo | 19 +++ legacy/elm_code/src/lib/elm_code_widget.eo.c | 13 ++ legacy/elm_code/src/lib/elm_code_widget.eo.h | 30 +++++ 4 files changed, 156 insertions(+), 36 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 37688b0b74..df95f25b05 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -137,11 +137,12 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c } static void -_elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) +_elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) { char *chr, *number; unsigned int length, x; int w, gutter, g; + Evas_Textgrid_Cell *cells; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); @@ -152,6 +153,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, E length = line->length; evas_object_textgrid_size_get(pd->grid, &w, NULL); + cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); cells[gutter-1].codepoint = status_icons[line->status]; cells[gutter-1].bold = 1; @@ -203,7 +205,6 @@ static void _elm_code_widget_fill(Elm_Code_Widget *widget) { Elm_Code_Line *line; - Evas_Textgrid_Cell *cells; int w, h; unsigned int y; Elm_Code_Widget_Data *pd; @@ -218,8 +219,7 @@ _elm_code_widget_fill(Elm_Code_Widget *widget) { line = elm_code_file_line_get(pd->code->file, y); - cells = evas_object_textgrid_cellrow_get(pd->grid, y - 1); - _elm_code_widget_fill_line(widget, cells, line); + _elm_code_widget_fill_line(widget, line); } } @@ -242,7 +242,7 @@ _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, // FIXME refresh just the row - but this resulted in undrawn areas // cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); -// _elm_code_widget_fill_line(widget, cells, line); +// _elm_code_widget_fill_line(widget, line); _elm_code_widget_fill(widget); return EO_CALLBACK_CONTINUE; @@ -323,6 +323,48 @@ _elm_code_widget_update_focus_directions(Elm_Code_Widget *obj) elm_widget_focus_next_object_set(obj, obj, ELM_FOCUS_NEXT); } +static void +_elm_code_widget_cursor_ensure_visible(Elm_Code_Widget *widget) +{ + Evas_Coord viewx, viewy, vieww, viewh, cellw, cellh; + Evas_Coord curx, cury; + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + elm_scroller_region_get(pd->scroller, &viewx, &viewy, &vieww, &viewh); + evas_object_textgrid_cell_size_get(pd->grid, &cellw, &cellh); + + curx = (pd->cursor_col + elm_code_widget_text_left_gutter_width_get(widget) - 1) * cellw; + cury = (pd->cursor_line - 1) * cellh; + + if (curx >= viewx && cury >= viewy && curx + cellw <= viewx + vieww && cury + cellh <= viewy + viewh) + return; + + elm_scroller_region_show(pd->scroller, curx, cury, cellw, cellh); +} + +static void +_elm_code_widget_cursor_move(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, unsigned int col, unsigned int line, + Eina_Bool was_key) +{ + unsigned int oldrow; + + oldrow = pd->cursor_line; + pd->cursor_col = col; + pd->cursor_line = line; + + if (!was_key) + _elm_code_widget_update_focus_directions(widget); + + eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CURSOR_CHANGED, widget)); + _elm_code_widget_cursor_ensure_visible(widget); + + if (oldrow != pd->cursor_line) + _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, oldrow)); + _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, pd->cursor_line)); +} + static void _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas_Coord y) { @@ -338,20 +380,15 @@ _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas row = ((double) y / ch) + 1; line = elm_code_file_line_get(pd->code->file, row); - if (line) - { - pd->cursor_line = row; + if (!line) + return; - if (col <= (unsigned int) line->length + 1) - pd->cursor_col = col; - else - pd->cursor_col = line->length + 1; - } - if (pd->cursor_col == 0) - pd->cursor_col = 1; + if (col > (unsigned int) line->length + 1) + col = line->length + 1; + else if (col == 0) + col = 1; - _elm_code_widget_update_focus_directions(widget); - _elm_code_widget_fill(widget); + _elm_code_widget_cursor_move(widget, pd, col, row, EINA_FALSE); } static void @@ -401,17 +438,21 @@ _elm_code_widget_cursor_move_up(Elm_Code_Widget *widget) { Elm_Code_Widget_Data *pd; Elm_Code_Line *line; + unsigned int row, col; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + row = pd->cursor_line; + col = pd->cursor_col; - if (pd->cursor_line > 1) - pd->cursor_line--; + if (pd->cursor_line <= 1) + return; - line = elm_code_file_line_get(pd->code->file, pd->cursor_line); - if (pd->cursor_col > (unsigned int) line->length + 1) - pd->cursor_col = line->length + 1; + row--; + line = elm_code_file_line_get(pd->code->file, row); + if (col > (unsigned int) line->length + 1) + col = line->length + 1; - _elm_code_widget_fill(widget); + _elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE); } static void @@ -419,17 +460,21 @@ _elm_code_widget_cursor_move_down(Elm_Code_Widget *widget) { Elm_Code_Widget_Data *pd; Elm_Code_Line *line; + unsigned int row, col; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + row = pd->cursor_line; + col = pd->cursor_col; - if (pd->cursor_line < elm_code_file_lines_get(pd->code->file)) - pd->cursor_line++; + if (pd->cursor_line >= elm_code_file_lines_get(pd->code->file)) + return; - line = elm_code_file_line_get(pd->code->file, pd->cursor_line); - if (pd->cursor_col > (unsigned int) line->length + 1) - pd->cursor_col = line->length + 1; + row++; + line = elm_code_file_line_get(pd->code->file, row); + if (col > (unsigned int) line->length + 1) + col = line->length + 1; - _elm_code_widget_fill(widget); + _elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE); } static void @@ -439,10 +484,10 @@ _elm_code_widget_cursor_move_left(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (pd->cursor_col > 1) - pd->cursor_col--; + if (pd->cursor_col <= 1) + return; - _elm_code_widget_fill(widget); + _elm_code_widget_cursor_move(widget, pd, pd->cursor_col-1, pd->cursor_line, EINA_TRUE); } static void @@ -454,10 +499,10 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); line = elm_code_file_line_get(pd->code->file, pd->cursor_line); - if (pd->cursor_col <= (unsigned int) line->length) - pd->cursor_col++; + if (pd->cursor_col > (unsigned int) line->length) + return; - _elm_code_widget_fill(widget); + _elm_code_widget_cursor_move(widget, pd, pd->cursor_col+1, pd->cursor_line, EINA_TRUE); } static void @@ -475,7 +520,7 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, if (!pd->editable) return; - _elm_code_widget_update_focus_directions(widget); + _elm_code_widget_update_focus_directions((Elm_Code_Widget *)obj); if (!strcmp(ev->key, "Up")) _elm_code_widget_cursor_move_up(widget); @@ -599,6 +644,19 @@ _elm_code_widget_line_numbers_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) return pd->show_line_numbers; } +EOLIAN static void +_elm_code_widget_cursor_position_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int col, unsigned int line) +{ + _elm_code_widget_cursor_move(obj, pd, col, line, EINA_FALSE); +} + +EOLIAN static void +_elm_code_widget_cursor_position_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, unsigned int *col, unsigned int *line) +{ + *col = pd->cursor_col; + *line = pd->cursor_line; +} + static void _elm_code_widget_setup_palette(Evas_Object *o) { diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/elm_code_widget.eo index 3bc81b81ec..8525f5e896 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/elm_code_widget.eo @@ -103,6 +103,24 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) Eina_Bool line_numbers; /*@ Whether or not line numbers (or their placeholder) should be shown */ } } + cursor_position { + set { + /*@ + Set the current location of the text cursor. + + @ingroup Editing */ + } + get { + /*@ + Get the current x and y position of the widget's cursor + + @ingroup Editing */ + } + values { + uint col; /*@ The horizontal position of the cursor, starting from column 1 */ + uint line; /*@ The vertical position of the cursor - the top row is 1 an */ + } + } } methods { } @@ -115,6 +133,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) } events { line,clicked; + cursor,changed; } } diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo.c b/legacy/elm_code/src/lib/elm_code_widget.eo.c index a61a1cba8f..5c4ca2fb94 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo.c +++ b/legacy/elm_code/src/lib/elm_code_widget.eo.c @@ -1,5 +1,7 @@ EOAPI const Eo_Event_Description _ELM_CODE_WIDGET_EVENT_LINE_CLICKED = EO_EVENT_DESCRIPTION("line,clicked", ""); +EOAPI const Eo_Event_Description _ELM_CODE_WIDGET_EVENT_CURSOR_CHANGED = + EO_EVENT_DESCRIPTION("cursor,changed", ""); void _elm_code_widget_code_set(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code *code); @@ -41,6 +43,14 @@ Eina_Bool _elm_code_widget_line_numbers_get(Eo *obj, Elm_Code_Widget_Data *pd); EOAPI EO_FUNC_BODY(elm_code_widget_line_numbers_get, Eina_Bool, 0); +void _elm_code_widget_cursor_position_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int col, unsigned int line); + +EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_cursor_position_set, EO_FUNC_CALL(col, line), unsigned int col, unsigned int line); + +void _elm_code_widget_cursor_position_get(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int *col, unsigned int *line); + +EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_cursor_position_get, EO_FUNC_CALL(col, line), unsigned int *col, unsigned int *line); + void _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd); @@ -68,11 +78,14 @@ static Eo_Op_Description _elm_code_widget_op_desc[] = { EO_OP_FUNC(elm_code_widget_editable_get, _elm_code_widget_editable_get, "Get the current editable state of this widget"), EO_OP_FUNC(elm_code_widget_line_numbers_set, _elm_code_widget_line_numbers_set, "Set whether line numbers should be displayed in the left gutter."), EO_OP_FUNC(elm_code_widget_line_numbers_get, _elm_code_widget_line_numbers_get, "Get the status of line number display for this widget."), + EO_OP_FUNC(elm_code_widget_cursor_position_set, _elm_code_widget_cursor_position_set, "Set the current location of the text cursor."), + EO_OP_FUNC(elm_code_widget_cursor_position_get, _elm_code_widget_cursor_position_get, "Get the current x and y position of the widget's cursor"), EO_OP_SENTINEL }; static const Eo_Event_Description *_elm_code_widget_event_desc[] = { ELM_CODE_WIDGET_EVENT_LINE_CLICKED, + ELM_CODE_WIDGET_EVENT_CURSOR_CHANGED, NULL }; diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo.h b/legacy/elm_code/src/lib/elm_code_widget.eo.h index 2730ddd396..138dced805 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo.h +++ b/legacy/elm_code/src/lib/elm_code_widget.eo.h @@ -140,11 +140,41 @@ EOAPI void elm_code_widget_line_numbers_set(Eina_Bool line_numbers); */ EOAPI Eina_Bool elm_code_widget_line_numbers_get(void); +/** + * + * Set the current location of the text cursor. + * + * @ingroup Editing + * + * @param[in] col The horizontal position of the cursor, starting from column 1 + * @param[in] line The vertical position of the cursor - the top row is 1 an + * + */ +EOAPI void elm_code_widget_cursor_position_set(unsigned int col, unsigned int line); + +/** + * + * Get the current x and y position of the widget's cursor + * + * @ingroup Editing + * + * @param[out] col The horizontal position of the cursor, starting from column 1 + * @param[out] line The vertical position of the cursor - the top row is 1 an + * + */ +EOAPI void elm_code_widget_cursor_position_get(unsigned int *col, unsigned int *line); + EOAPI extern const Eo_Event_Description _ELM_CODE_WIDGET_EVENT_LINE_CLICKED; +EOAPI extern const Eo_Event_Description _ELM_CODE_WIDGET_EVENT_CURSOR_CHANGED; /** * No description */ #define ELM_CODE_WIDGET_EVENT_LINE_CLICKED (&(_ELM_CODE_WIDGET_EVENT_LINE_CLICKED)) +/** + * No description + */ +#define ELM_CODE_WIDGET_EVENT_CURSOR_CHANGED (&(_ELM_CODE_WIDGET_EVENT_CURSOR_CHANGED)) + #endif From 4e1af4b488324076deb5f09d4b0622af6c6bcf5b Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 19 Feb 2015 21:52:41 +0000 Subject: [PATCH 090/254] elm_code: Update FIXME to be realisic - the textgrid size_set does not append --- legacy/elm_code/src/lib/elm_code_widget.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 37688b0b74..55d4fc0b7b 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -225,24 +225,16 @@ _elm_code_widget_fill(Elm_Code_Widget *widget) static Eina_Bool _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, - const Eo_Event_Description *desc EINA_UNUSED, void *event_info) + const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) { Elm_Code_Widget *widget; - Elm_Code_Line *line; - - Evas_Textgrid_Cell *cells; - Elm_Code_Widget_Data *pd; widget = (Elm_Code_Widget *)data; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - line = (Elm_Code_Line *)event_info; if (!_elm_code_widget_resize(widget)) return EINA_TRUE; -// FIXME refresh just the row - but this resulted in undrawn areas -// cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); -// _elm_code_widget_fill_line(widget, cells, line); + // FIXME refresh just the row unless we have resized (by being the result of a row append) _elm_code_widget_fill(widget); return EO_CALLBACK_CONTINUE; From d59ce760cafc1fdbf521a74c52a6dc4657855926 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 19 Feb 2015 22:35:01 +0000 Subject: [PATCH 091/254] eo: remove generated files from git --- legacy/elm_code/src/lib/elm_code_widget.eo.c | 90 ----------- legacy/elm_code/src/lib/elm_code_widget.eo.h | 150 ------------------- 2 files changed, 240 deletions(-) delete mode 100644 legacy/elm_code/src/lib/elm_code_widget.eo.c delete mode 100644 legacy/elm_code/src/lib/elm_code_widget.eo.h diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo.c b/legacy/elm_code/src/lib/elm_code_widget.eo.c deleted file mode 100644 index a61a1cba8f..0000000000 --- a/legacy/elm_code/src/lib/elm_code_widget.eo.c +++ /dev/null @@ -1,90 +0,0 @@ -EOAPI const Eo_Event_Description _ELM_CODE_WIDGET_EVENT_LINE_CLICKED = - EO_EVENT_DESCRIPTION("line,clicked", ""); - -void _elm_code_widget_code_set(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code *code); - -EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_code_set, EO_FUNC_CALL(code), Elm_Code *code); - -Elm_Code * _elm_code_widget_code_get(Eo *obj, Elm_Code_Widget_Data *pd); - -EOAPI EO_FUNC_BODY(elm_code_widget_code_get, Elm_Code *, 0); - -void _elm_code_widget_font_size_set(Eo *obj, Elm_Code_Widget_Data *pd, Evas_Font_Size font_size); - -EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_font_size_set, EO_FUNC_CALL(font_size), Evas_Font_Size font_size); - -Evas_Font_Size _elm_code_widget_font_size_get(Eo *obj, Elm_Code_Widget_Data *pd); - -EOAPI EO_FUNC_BODY(elm_code_widget_font_size_get, Evas_Font_Size, 0); - -void _elm_code_widget_gravity_set(Eo *obj, Elm_Code_Widget_Data *pd, double x, double y); - -EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_gravity_set, EO_FUNC_CALL(x, y), double x, double y); - -void _elm_code_widget_gravity_get(Eo *obj, Elm_Code_Widget_Data *pd, double *x, double *y); - -EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_gravity_get, EO_FUNC_CALL(x, y), double *x, double *y); - -void _elm_code_widget_editable_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool editable); - -EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_editable_set, EO_FUNC_CALL(editable), Eina_Bool editable); - -Eina_Bool _elm_code_widget_editable_get(Eo *obj, Elm_Code_Widget_Data *pd); - -EOAPI EO_FUNC_BODY(elm_code_widget_editable_get, Eina_Bool, 0); - -void _elm_code_widget_line_numbers_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool line_numbers); - -EOAPI EO_VOID_FUNC_BODYV(elm_code_widget_line_numbers_set, EO_FUNC_CALL(line_numbers), Eina_Bool line_numbers); - -Eina_Bool _elm_code_widget_line_numbers_get(Eo *obj, Elm_Code_Widget_Data *pd); - -EOAPI EO_FUNC_BODY(elm_code_widget_line_numbers_get, Eina_Bool, 0); - -void _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd); - - -void _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd); - - -Eina_Bool _elm_code_widget_elm_widget_focus_next_manager_is(Eo *obj, Elm_Code_Widget_Data *pd); - - -Eina_Bool _elm_code_widget_elm_widget_focus_direction_manager_is(Eo *obj, Elm_Code_Widget_Data *pd); - - -static Eo_Op_Description _elm_code_widget_op_desc[] = { - EO_OP_FUNC_OVERRIDE(eo_constructor, _elm_code_widget_eo_base_constructor), - EO_OP_FUNC_OVERRIDE(evas_obj_smart_add, _elm_code_widget_evas_object_smart_add), - EO_OP_FUNC_OVERRIDE(elm_obj_widget_focus_next_manager_is, _elm_code_widget_elm_widget_focus_next_manager_is), - EO_OP_FUNC_OVERRIDE(elm_obj_widget_focus_direction_manager_is, _elm_code_widget_elm_widget_focus_direction_manager_is), - EO_OP_FUNC(elm_code_widget_code_set, _elm_code_widget_code_set, "Set the underlying code object that this widget renders"), - EO_OP_FUNC(elm_code_widget_code_get, _elm_code_widget_code_get, "Get the underlying code object we are rendering"), - EO_OP_FUNC(elm_code_widget_font_size_set, _elm_code_widget_font_size_set, "Set the font size that this widget uses, the font will always be a system monospaced font"), - EO_OP_FUNC(elm_code_widget_font_size_get, _elm_code_widget_font_size_get, "Get the font size currently in use"), - EO_OP_FUNC(elm_code_widget_gravity_set, _elm_code_widget_gravity_set, "Set how this widget's scroller should respond to new lines being added."), - EO_OP_FUNC(elm_code_widget_gravity_get, _elm_code_widget_gravity_get, "Get the current x and y gravity of the widget's scroller"), - EO_OP_FUNC(elm_code_widget_editable_set, _elm_code_widget_editable_set, "Set whether this widget allows editing"), - EO_OP_FUNC(elm_code_widget_editable_get, _elm_code_widget_editable_get, "Get the current editable state of this widget"), - EO_OP_FUNC(elm_code_widget_line_numbers_set, _elm_code_widget_line_numbers_set, "Set whether line numbers should be displayed in the left gutter."), - EO_OP_FUNC(elm_code_widget_line_numbers_get, _elm_code_widget_line_numbers_get, "Get the status of line number display for this widget."), - EO_OP_SENTINEL -}; - -static const Eo_Event_Description *_elm_code_widget_event_desc[] = { - ELM_CODE_WIDGET_EVENT_LINE_CLICKED, - NULL -}; - -static const Eo_Class_Description _elm_code_widget_class_desc = { - EO_VERSION, - "Elm_Code_Widget", - EO_CLASS_TYPE_REGULAR, - EO_CLASS_DESCRIPTION_OPS(_elm_code_widget_op_desc), - _elm_code_widget_event_desc, - sizeof(Elm_Code_Widget_Data), - _elm_code_widget_class_constructor, - NULL -}; - -EO_DEFINE_CLASS(elm_code_widget_class_get, &_elm_code_widget_class_desc, ELM_LAYOUT_CLASS, ELM_INTERFACE_ATSPI_TEXT_INTERFACE, NULL); \ No newline at end of file diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo.h b/legacy/elm_code/src/lib/elm_code_widget.eo.h deleted file mode 100644 index 2730ddd396..0000000000 --- a/legacy/elm_code/src/lib/elm_code_widget.eo.h +++ /dev/null @@ -1,150 +0,0 @@ -#ifndef _ELM_CODE_WIDGET_EO_H_ -#define _ELM_CODE_WIDGET_EO_H_ - -#ifndef _ELM_CODE_WIDGET_EO_CLASS_TYPE -#define _ELM_CODE_WIDGET_EO_CLASS_TYPE - -typedef Eo Elm_Code_Widget; - -#endif - -#ifndef _ELM_CODE_WIDGET_EO_TYPES -#define _ELM_CODE_WIDGET_EO_TYPES - - -#endif -#define ELM_CODE_WIDGET_CLASS elm_code_widget_class_get() - -const Eo_Class *elm_code_widget_class_get(void) EINA_CONST; - -/** - * - * Set the underlying code object that this widget renders - * - * @ingroup Data - * - * @param[in] code Our underlying Elm_Code object - * - */ -EOAPI void elm_code_widget_code_set(Elm_Code *code); - -/** - * - * Get the underlying code object we are rendering - * - * @ingroup Data - * - * - */ -EOAPI Elm_Code * elm_code_widget_code_get(void); - -/** - * - * Set the font size that this widget uses, the font will always be a system monospaced font - * - * @ingroup Style - * - * @param[in] font_size The font size of the widgget - * - */ -EOAPI void elm_code_widget_font_size_set(Evas_Font_Size font_size); - -/** - * - * Get the font size currently in use - * - * @ingroup Style - * - * - */ -EOAPI Evas_Font_Size elm_code_widget_font_size_get(void); - -/** - * - * Set how this widget's scroller should respond to new lines being added. - * - * An x value of 0.0 will maintain the distance from the left edge, 1.0 will ensure the rightmost edge (of the longest line) is respected - * With 0.0 for y the view will keep it's position relative to the top whereas 1.0 will scroll downward as lines are added. - * - * @ingroup Layout - * - * @param[in] x The horizontal value of the scroller gravity - valid values are 0.0 and 1.0 - * @param[in] y The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 - * - */ -EOAPI void elm_code_widget_gravity_set(double x, double y); - -/** - * - * Get the current x and y gravity of the widget's scroller - * - * @ingroup Layout - * - * @param[out] x The horizontal value of the scroller gravity - valid values are 0.0 and 1.0 - * @param[out] y The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 - * - */ -EOAPI void elm_code_widget_gravity_get(double *x, double *y); - -/** - * - * Set whether this widget allows editing - * - * If @a editable then the widget will allow user input to manipulate - * the underlying Elm_Code_File of this Elm_Code instance. - * Any other Elm_Code_Widget's connected to this Elm_Code will - * update to reflect the changes. - * - * @ingroup Features - * - * @param[in] editable The editable state of the widget - * - */ -EOAPI void elm_code_widget_editable_set(Eina_Bool editable); - -/** - * - * Get the current editable state of this widget - * - * @return EINA_TRUE if the widget is editable, EINA_FALSE otherwise. - * If this widget is not editable the underlying Elm_Code_File could - * still be manipulated by a different widget or the filesystem. - * - * @ingroup Features - * - * - */ -EOAPI Eina_Bool elm_code_widget_editable_get(void); - -/** - * - * Set whether line numbers should be displayed in the left gutter. - * - * Passing EINA_TRUE will reserve a space for showing line numbers, - * EINA_FALSE will turn this off. - * - * @ingroup Features - * - * @param[in] line_numbers Whether or not line numbers (or their placeholder) should be shown - * - */ -EOAPI void elm_code_widget_line_numbers_set(Eina_Bool line_numbers); - -/** - * - * Get the status of line number display for this widget. - * - * @ingroup Features - * - * - */ -EOAPI Eina_Bool elm_code_widget_line_numbers_get(void); - -EOAPI extern const Eo_Event_Description _ELM_CODE_WIDGET_EVENT_LINE_CLICKED; - -/** - * No description - */ -#define ELM_CODE_WIDGET_EVENT_LINE_CLICKED (&(_ELM_CODE_WIDGET_EVENT_LINE_CLICKED)) - -#endif From 685abd7054c0e605e8cd8cc54474bd1b14177957 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 21 Feb 2015 17:30:17 +0000 Subject: [PATCH 092/254] syntax: Update clang to output elm_code tokens Addition of a refresh line command to say we're done. We no longer need an active window for highlighting as it's so much faster! --- legacy/elm_code/src/lib/elm_code_common.h | 13 ++++++++ legacy/elm_code/src/lib/elm_code_widget.c | 35 +++++++++++++++++++++- legacy/elm_code/src/lib/elm_code_widget.eo | 5 ++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_common.h b/legacy/elm_code/src/lib/elm_code_common.h index 35c86512ba..40efdaeded 100644 --- a/legacy/elm_code/src/lib/elm_code_common.h +++ b/legacy/elm_code/src/lib/elm_code_common.h @@ -13,7 +13,11 @@ EAPI extern const Eo_Event_Description ELM_CODE_EVENT_FILE_LOAD_DONE; typedef enum { ELM_CODE_STATUS_TYPE_DEFAULT = 0, + 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, @@ -29,6 +33,15 @@ typedef enum { 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, diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 3240e397ab..fd4b09a58b 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -570,6 +570,12 @@ _elm_code_widget_elm_widget_focus_direction_manager_is(Eo *obj EINA_UNUSED, return EINA_TRUE; } +EOAPI void +_elm_code_widget_line_refresh(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm_Code_Line *line) +{ + _elm_code_widget_fill_line(obj, line); +} + EOLIAN static void _elm_code_widget_font_size_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Evas_Font_Size font_size) { @@ -655,8 +661,16 @@ _elm_code_widget_setup_palette(Evas_Object *o) // setup status colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, 36, 36, 36, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_IGNORED, + 36, 36, 36, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_NOTE, + 255, 153, 0, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_WARNING, + 255, 153, 0, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ERROR, 205, 54, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FATAL, + 205, 54, 54, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ADDED, 36, 96, 36, 255); @@ -674,7 +688,26 @@ _elm_code_widget_setup_palette(Evas_Object *o) evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT, 205, 205, 205, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_COMMENT, - 54, 205, 255, 255); + 51, 153, 255, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_STRING, + 255, 90, 53, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_NUMBER, + 212, 212, 42, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_BRACE, + 101, 101, 101, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_TYPE, + 51, 153, 255, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CLASS, + 114, 170, 212, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_FUNCTION, + 114, 170, 212, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_PARAM, + 255, 255, 255, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_KEYWORD, + 255, 153, 0, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_PREPROCESSOR, + 0, 176, 0, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_ADDED, 54, 255, 54, 255); diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/elm_code_widget.eo index 8525f5e896..0608e81e41 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/elm_code_widget.eo @@ -123,6 +123,11 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) } } methods { + line_refresh { + params { + Elm_Code_Line *line; /*@ @in The line to refresh. */ + } + } } implements { class.constructor; From cb83e9e91278e9079affe0ec3a97f05dd69a43df Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 21 Feb 2015 18:24:17 +0000 Subject: [PATCH 093/254] elm_code: Support multi-line tokens Adding a new token to each line it covers. Each token references the end line so newline behaviour can be set --- legacy/elm_code/src/bin/elm_code_test_main.c | 2 +- legacy/elm_code/src/lib/elm_code_file.c | 7 ++++--- legacy/elm_code/src/lib/elm_code_line.c | 17 +++++++++++++++-- legacy/elm_code/src/lib/elm_code_line.h | 5 ++++- legacy/elm_code/src/lib/elm_code_widget.c | 13 ++++++++----- .../src/tests/elm_code_file_test_memory.c | 2 +- .../elm_code/src/tests/elm_code_test_widget.c | 4 ++-- 7 files changed, 35 insertions(+), 15 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index d3fd2cbd0d..97fbb09018 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -55,7 +55,7 @@ _elm_code_test_line_done_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, line = (Elm_Code_Line *)event_info; if (line->number == 1) - elm_code_line_token_add(line, 14, 21, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 14, 21, 1, ELM_CODE_TOKEN_TYPE_COMMENT); else if (line->number == 4) line->status = ELM_CODE_STATUS_TYPE_ERROR; diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index cc24dcd498..c73f71fc4c 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -6,13 +6,14 @@ #include "elm_code_private.h" -static Elm_Code_Line *_elm_code_blank_create(int line, void *data) +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; @@ -24,7 +25,7 @@ static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *con { Elm_Code_Line *line; - line = _elm_code_blank_create(row, data); + line = _elm_code_file_line_blank_create(file, row, data); if (!line) return; if (mapped) @@ -88,7 +89,7 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) /* Working around the issue that eina_file_map_lines does not trigger an item for empty lines */ while (lastindex < line->index - 1) { - ecl = _elm_code_blank_create(++lastindex, NULL); + ecl = _elm_code_file_line_blank_create(ret, ++lastindex, NULL); if (!ecl) continue; ret->lines = eina_list_append(ret->lines, ecl); diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index 6a7af560be..117227b22a 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -26,19 +26,32 @@ EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type sta line->status = status; } -EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, Elm_Code_Token_Type type) +EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int lines, + Elm_Code_Token_Type type) { Elm_Code_Token *tok; + unsigned int end_line; + Elm_Code_Line *next_line; if (!line) return; tok = calloc(1, sizeof(Elm_Code_Token)); + end_line = line->number; + if (lines > 1) + end_line += lines - 1; + tok->start = start; tok->end = end; + tok->end_line = end_line; tok->type = type; line->tokens = eina_list_append(line->tokens, tok); -} + if (end_line > line->number) + { + next_line = elm_code_file_line_get(line->file, line->number + 1); + elm_code_line_token_add(next_line, 1, end, lines - 1, type); + } +} diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index 339c96691d..5a66f73fe7 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -13,6 +13,7 @@ extern "C" { typedef struct _Elm_Code_Token { int start, end; + unsigned int end_line; Elm_Code_Token_Type type; @@ -20,6 +21,8 @@ typedef struct _Elm_Code_Token typedef struct _Elm_Code_Line { + Elm_Code_File *file; + const char *content; int length; unsigned int number; @@ -45,7 +48,7 @@ EAPI const char *elm_code_line_content_get(Elm_Code_Line *line, int *length); EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status); -EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, Elm_Code_Token_Type type); +EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int lines, Elm_Code_Token_Type type); /** * @} diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index fd4b09a58b..eb731e281e 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -116,7 +116,7 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c { Eina_List *item; Elm_Code_Token *token; - int start, length, offset; + int start, end, length, offset; offset = elm_code_widget_text_left_gutter_width_get(widget) - 1; start = offset + 1; @@ -124,13 +124,16 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c EINA_LIST_FOREACH(line->tokens, item, token) { - - _elm_code_widget_fill_line_token(cells, count, start, token->start + offset, ELM_CODE_TOKEN_TYPE_DEFAULT); + if (token->start > start) + _elm_code_widget_fill_line_token(cells, count, start, token->start + offset, ELM_CODE_TOKEN_TYPE_DEFAULT); // TODO handle a token starting before the previous finishes - _elm_code_widget_fill_line_token(cells, count, token->start + offset, token->end + offset, token->type); + end = token->end; + if (token->end_line > line->number) + end = count; + _elm_code_widget_fill_line_token(cells, count, token->start + offset, end + offset, token->type); - start = token->end + offset + 1; + start = end + offset + 1; } _elm_code_widget_fill_line_token(cells, count, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); diff --git a/legacy/elm_code/src/tests/elm_code_file_test_memory.c b/legacy/elm_code/src/tests/elm_code_file_test_memory.c index e4b3e3721f..b82ce2eda2 100644 --- a/legacy/elm_code/src/tests/elm_code_file_test_memory.c +++ b/legacy/elm_code/src/tests/elm_code_file_test_memory.c @@ -29,7 +29,7 @@ START_TEST (elm_code_file_memory_tokens) elm_code_file_line_append(file, "a line", 6, NULL); line = elm_code_file_line_get(file, 1); - elm_code_line_token_add(line, 2, 5, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 2, 5, 1, ELM_CODE_TOKEN_TYPE_COMMENT); ck_assert_uint_eq(1, eina_list_count(line->tokens)); elm_code_free(code); } diff --git a/legacy/elm_code/src/tests/elm_code_test_widget.c b/legacy/elm_code/src/tests/elm_code_test_widget.c index 2836bb4c44..e30c890b92 100644 --- a/legacy/elm_code/src/tests/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/elm_code_test_widget.c @@ -26,8 +26,8 @@ START_TEST (elm_code_widget_token_render_simple_test) line = elm_code_file_line_get(file, 1); length = line->length; - elm_code_line_token_add(line, 6+1, 17+1, ELM_CODE_TOKEN_TYPE_COMMENT); - elm_code_line_token_add(line, 21+1, 22+1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 6+1, 17+1, 1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 21+1, 22+1, 1, ELM_CODE_TOKEN_TYPE_COMMENT); _elm_code_widget_fill_line_tokens(NULL, cells, length+1, line); _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT, 1); From c3e08838083c7c4fc8356d54f287301c8f6ba49f Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 22 Feb 2015 20:07:08 +0000 Subject: [PATCH 094/254] elm_code: Support text insertion for simple edits. Hook into the widget for elm_code_test and edi editors. Only alphanumeric and space, but it's a start. --- legacy/elm_code/src/lib/Elm_Code.h | 1 + legacy/elm_code/src/lib/Makefile.am | 2 + legacy/elm_code/src/lib/elm_code_line.c | 12 ---- legacy/elm_code/src/lib/elm_code_line.h | 8 +-- legacy/elm_code/src/lib/elm_code_text.c | 59 +++++++++++++++++++ legacy/elm_code/src/lib/elm_code_text.h | 35 +++++++++++ legacy/elm_code/src/lib/elm_code_widget.c | 21 +++++++ legacy/elm_code/src/tests/Makefile.am | 1 + legacy/elm_code/src/tests/elm_code_suite.c | 1 + legacy/elm_code/src/tests/elm_code_suite.h | 1 + .../elm_code/src/tests/elm_code_test_text.c | 44 ++++++++++++++ 11 files changed, 168 insertions(+), 17 deletions(-) create mode 100644 legacy/elm_code/src/lib/elm_code_text.c create mode 100644 legacy/elm_code/src/lib/elm_code_text.h create mode 100644 legacy/elm_code/src/tests/elm_code_test_text.c diff --git a/legacy/elm_code/src/lib/Elm_Code.h b/legacy/elm_code/src/lib/Elm_Code.h index 9cfefa4b21..c435739bf5 100644 --- a/legacy/elm_code/src/lib/Elm_Code.h +++ b/legacy/elm_code/src/lib/Elm_Code.h @@ -35,6 +35,7 @@ #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 "elm_code_widget.eo.h" diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index 274c845f12..3691edbf86 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -20,6 +20,7 @@ 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 \ elm_code_widget.eo.h \ @@ -30,6 +31,7 @@ includesdir = $(includedir)/edi-@VMAJ@ libelm_code_la_SOURCES = \ elm_code_line.c \ +elm_code_text.c \ elm_code_file.c \ elm_code_parse.c \ elm_code_widget_text.c \ diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index 117227b22a..b1ab3080fa 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -6,18 +6,6 @@ #include "elm_code_private.h" -EAPI const char *elm_code_line_content_get(Elm_Code_Line *line, int *length) -{ - if (!line) - return NULL; - - *length = line->length; - - if (line->modified) - return line->modified; - return line->content; -} - EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status) { if (!line) diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index 5a66f73fe7..ea7cff5b56 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -35,17 +35,15 @@ typedef struct _Elm_Code_Line } Elm_Code_Line; /** - * @brief Line handling functions. - * @defgroup Line and content manipulation + * @brief Line markup functions. + * @defgroup Line highlighting and status manipulation * * @{ * - * Functions for handling content and styling of lines within elm code. + * Functions for handling styling and marking up lines within elm code. * */ -EAPI const char *elm_code_line_content_get(Elm_Code_Line *line, int *length); - EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status); EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int lines, Elm_Code_Token_Type type); diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c new file mode 100644 index 0000000000..690bb36484 --- /dev/null +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -0,0 +1,59 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include "Elm_Code.h" + +#include "elm_code_private.h" + +EAPI const char +*elm_code_line_text_get(Elm_Code_Line *line, int *length) +{ + if (!line) + return NULL; + + if (length) + *length = line->length; + + if (line->modified) + return line->modified; + return line->content; +} + +EAPI void +elm_code_line_text_insert(Elm_Code_Line *line, int position, const char *string, int length) +{ + Elm_Code_File *file; + char *inserted; + + if (!line) + return; + + inserted = malloc(sizeof(char) * line->length + length + 1); + position--; + if (position > line->length) + position = line->length; + if (position < 0) + position = 0; + + if (line->modified) + { + strncpy(inserted, line->modified, position); + strncpy(inserted + position, string, length); + strncpy(inserted + position + length, line->modified + position, line->length - position); + + free(line->modified); + } + else + { + strncpy(inserted, line->content, position); + strncpy(inserted + position, string, length); + strncpy(inserted + position + length, line->content + position, line->length - position); + } + + line->modified = inserted; + line->length = line->length + length; + + file = line->file; + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); +} diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h new file mode 100644 index 0000000000..05b56334ac --- /dev/null +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -0,0 +1,35 @@ +#ifndef ELM_CODE_TEXT_H_ +# define ELM_CODE_TEXT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for interacting with the textual content of files/lines in Elm Code. + */ + +/** + * @brief Text handling functions. + * @defgroup Text access and manipulation + * + * @{ + * + * Functions for handling content of lines within elm code. + * + */ + +EAPI const char *elm_code_line_text_get(Elm_Code_Line *line, int *length); + +EAPI void elm_code_line_text_insert(Elm_Code_Line *line, int position, const char *string, int length); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ELM_CODE_TEXT_H_ */ diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index eb731e281e..bdb79fd26d 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -500,6 +500,23 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) _elm_code_widget_cursor_move(widget, pd, pd->cursor_col+1, pd->cursor_line, EINA_TRUE); } +static void +_elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text, int length) +{ + Elm_Code *code; + Elm_Code_Line *line; + unsigned int row, col; + + eo_do(widget, + code = elm_code_widget_code_get(), + elm_code_widget_cursor_position_get(&col, &row)); + line = elm_code_file_line_get(code->file, row); + + elm_code_line_text_insert(line, col, text, length); + eo_do(widget, + elm_code_widget_cursor_position_set(col + length, row)); +} + static void _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) @@ -525,6 +542,10 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, _elm_code_widget_cursor_move_left(widget); else if (!strcmp(ev->key, "Right")) _elm_code_widget_cursor_move_right(widget); + else if (strlen(ev->key) == 1) + _elm_code_widget_text_at_cursor_insert(widget, ev->key, 1); + else if (!strcmp(ev->key, "space")) + _elm_code_widget_text_at_cursor_insert(widget, " ", 1); else INF("Unhandled key %s", ev->key); } diff --git a/legacy/elm_code/src/tests/Makefile.am b/legacy/elm_code/src/tests/Makefile.am index 3f85a3fa84..99ec87f35f 100644 --- a/legacy/elm_code/src/tests/Makefile.am +++ b/legacy/elm_code/src/tests/Makefile.am @@ -10,6 +10,7 @@ elm_code_file_test_load.c \ elm_code_file_test_memory.c \ elm_code_test_basic.c \ elm_code_test_parse.c \ +elm_code_test_text.c \ elm_code_test_widget.c \ elm_code_suite.c diff --git a/legacy/elm_code/src/tests/elm_code_suite.c b/legacy/elm_code/src/tests/elm_code_suite.c index e2250cd591..ec0f93c2bb 100644 --- a/legacy/elm_code/src/tests/elm_code_suite.c +++ b/legacy/elm_code/src/tests/elm_code_suite.c @@ -16,6 +16,7 @@ static const struct { { "file_load", elm_code_file_test_load }, { "file_memory", elm_code_file_test_memory }, { "parse", elm_code_test_parse }, + { "text", elm_code_test_text }, { "basic", elm_code_test_basic }, { "widget", elm_code_test_widget }, }; diff --git a/legacy/elm_code/src/tests/elm_code_suite.h b/legacy/elm_code/src/tests/elm_code_suite.h index 58d6317dcc..cd98285efa 100644 --- a/legacy/elm_code/src/tests/elm_code_suite.h +++ b/legacy/elm_code/src/tests/elm_code_suite.h @@ -9,6 +9,7 @@ void elm_code_file_test_load(TCase *tc); void elm_code_file_test_memory(TCase *tc); void elm_code_test_basic(TCase *tc); void elm_code_test_parse(TCase *tc); +void elm_code_test_text(TCase *tc); void elm_code_test_widget(TCase *tc); #endif /* _EDLM_CODE_SUITE_H */ diff --git a/legacy/elm_code/src/tests/elm_code_test_text.c b/legacy/elm_code/src/tests/elm_code_test_text.c new file mode 100644 index 0000000000..44c2fd3621 --- /dev/null +++ b/legacy/elm_code/src/tests/elm_code_test_text.c @@ -0,0 +1,44 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "elm_code_suite.h" +#include "elm_code_text.h" + +START_TEST (elm_code_text_get_test) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + + code = elm_code_create(); + file = elm_code_file_new(code); + + elm_code_file_line_append(file, "test", 4, NULL); + line = elm_code_file_line_get(file, 1); + ck_assert_str_eq("test", elm_code_line_text_get(line, NULL)); +} +END_TEST + +START_TEST (elm_code_text_insert_test) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + + code = elm_code_create(); + file = elm_code_file_new(code); + + elm_code_file_line_append(file, "test", 4, NULL); + line = elm_code_file_line_get(file, 1); + + elm_code_line_text_insert(line, 5, "ing", 3); + ck_assert_str_eq("testing", elm_code_line_text_get(line, NULL)); +} +END_TEST + +void elm_code_test_text(TCase *tc) +{ + tcase_add_test(tc, elm_code_text_get_test); + tcase_add_test(tc, elm_code_text_insert_test); +} From d9a94200cc1fc10368a5719ff435c3164d136d62 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 22 Feb 2015 21:50:34 +0000 Subject: [PATCH 095/254] elm_code: don't run resize code more than needed Our cells are now always the size of the widget so we can avoid the safety checks... --- legacy/elm_code/src/lib/elm_code_widget.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 55d4fc0b7b..d16d1891c2 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -57,7 +57,7 @@ _elm_code_widget_scroll_by(Elm_Code_Widget *widget, int by_x, int by_y) elm_scroller_region_show(pd->scroller, x, y, w, h); } -static Eina_Bool +static void _elm_code_widget_resize(Elm_Code_Widget *widget) { Elm_Code_Line *line; @@ -70,7 +70,7 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) gutter = elm_code_widget_text_left_gutter_width_get(widget); if (!pd->code) - return EINA_FALSE; + return; evas_object_geometry_get(widget, NULL, NULL, &ww, &wh); evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); @@ -95,8 +95,6 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) _elm_code_widget_scroll_by(widget, (pd->gravity_x == 1.0 && ww > old_width) ? ww - old_width : 0, (pd->gravity_y == 1.0 && wh > old_height) ? wh - old_height : 0); - - return h > 0 && w > 0; } static void @@ -147,9 +145,6 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, E pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); gutter = elm_code_widget_text_left_gutter_width_get(widget); - if (!_elm_code_widget_resize(widget)) - return; - length = line->length; evas_object_textgrid_size_get(pd->grid, &w, NULL); @@ -210,8 +205,7 @@ _elm_code_widget_fill(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (!_elm_code_widget_resize(widget)) - return; + _elm_code_widget_resize(widget); evas_object_textgrid_size_get(pd->grid, &w, &h); for (y = 1; y <= (unsigned int) h && y <= elm_code_file_lines_get(pd->code->file); y++) @@ -231,9 +225,6 @@ _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, widget = (Elm_Code_Widget *)data; - if (!_elm_code_widget_resize(widget)) - return EINA_TRUE; - // FIXME refresh just the row unless we have resized (by being the result of a row append) _elm_code_widget_fill(widget); From e329755283d8455f50baa6e21ecdb2e9b3781bf2 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 22 Feb 2015 22:13:33 +0000 Subject: [PATCH 096/254] elm_code: Fill the widget and gutter to the end This helps with refreshing too so we blank removed lines --- legacy/elm_code/src/lib/elm_code_widget.c | 92 ++++++++++++++++++----- 1 file changed, 72 insertions(+), 20 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index d16d1891c2..3d895079f1 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -134,12 +134,53 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c _elm_code_widget_fill_line_token(cells, count, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); } +static void +_elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, + Elm_Code_Status_Type status, int line) +{ + char *number = NULL; + int w, gutter, g; + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + gutter = elm_code_widget_text_left_gutter_width_get(widget); + + evas_object_textgrid_size_get(pd->grid, &w, NULL); + + cells[gutter-1].codepoint = status_icons[status]; + cells[gutter-1].bold = 1; + cells[gutter-1].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG; + cells[gutter-1].bg = (status == ELM_CODE_STATUS_TYPE_DEFAULT) ? ELM_CODE_WIDGET_COLOR_GUTTER_BG : status; + + if (pd->show_line_numbers) + { + if (line > 0) + { + number = malloc(sizeof(char) * gutter); + snprintf(number, gutter, "%*d", gutter - 1, line); + } + for (g = 0; g < gutter - 1; g++) + { + if (number) + cells[g].codepoint = *(number + g); + else + cells[g].codepoint = 0; + + cells[g].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG; + cells[g].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG; + } + + if (number) + free(number); + } +} + static void _elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, Elm_Code_Line *line) { - char *chr, *number; + char *chr; unsigned int length, x; - int w, gutter, g; + int w, gutter; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); @@ -148,24 +189,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, E length = line->length; evas_object_textgrid_size_get(pd->grid, &w, NULL); - cells[gutter-1].codepoint = status_icons[line->status]; - cells[gutter-1].bold = 1; - cells[gutter-1].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG; - cells[gutter-1].bg = (line->status == ELM_CODE_STATUS_TYPE_DEFAULT) ? ELM_CODE_WIDGET_COLOR_GUTTER_BG : line->status; - - if (pd->show_line_numbers) - { - number = malloc(sizeof(char) * gutter); - snprintf(number, gutter, "%*d", gutter - 1, line->number); - - for (g = 0; g < gutter - 1; g++) - { - cells[g].codepoint = *(number + g); - cells[g].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG; - cells[g].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG; - } - free(number); - } + _elm_code_widget_fill_gutter(widget, cells, line->status, line->number); if (line->modified) chr = line->modified; @@ -194,6 +218,28 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, E evas_object_textgrid_update_add(pd->grid, 0, line->number - 1, w, 1); } +static void +_elm_code_widget_empty_line(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, unsigned int number) +{ + unsigned int x; + int w, gutter; + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + gutter = elm_code_widget_text_left_gutter_width_get(widget); + + evas_object_textgrid_size_get(pd->grid, &w, NULL); + _elm_code_widget_fill_gutter(widget, cells, ELM_CODE_STATUS_TYPE_DEFAULT, 0); + + for (x = gutter; x < (unsigned int) w; x++) + { + cells[x].codepoint = 0; + cells[x].bg = ELM_CODE_STATUS_TYPE_DEFAULT; + } + + evas_object_textgrid_update_add(pd->grid, 0, number - 1, w, 1); +} + static void _elm_code_widget_fill(Elm_Code_Widget *widget) { @@ -215,6 +261,12 @@ _elm_code_widget_fill(Elm_Code_Widget *widget) cells = evas_object_textgrid_cellrow_get(pd->grid, y - 1); _elm_code_widget_fill_line(widget, cells, line); } + for (; y <= (unsigned int) h; y++) + { + cells = evas_object_textgrid_cellrow_get(pd->grid, y - 1); + + _elm_code_widget_empty_line(widget, cells, y); + } } static Eina_Bool From b08274d8b11ac4253459aae66bf2190fe3b9b44f Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 22 Feb 2015 23:38:54 +0000 Subject: [PATCH 097/254] Merge branch master conflicts in elm_code_widget.c resolved --- legacy/elm_code/src/lib/elm_code_widget.c | 107 +++++++++++++++------- 1 file changed, 75 insertions(+), 32 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index bdb79fd26d..9673c9a674 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -57,7 +57,7 @@ _elm_code_widget_scroll_by(Elm_Code_Widget *widget, int by_x, int by_y) elm_scroller_region_show(pd->scroller, x, y, w, h); } -static Eina_Bool +static void _elm_code_widget_resize(Elm_Code_Widget *widget) { Elm_Code_Line *line; @@ -70,7 +70,7 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) gutter = elm_code_widget_text_left_gutter_width_get(widget); if (!pd->code) - return EINA_FALSE; + return; evas_object_geometry_get(widget, NULL, NULL, &ww, &wh); evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); @@ -95,8 +95,6 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) _elm_code_widget_scroll_by(widget, (pd->gravity_x == 1.0 && ww > old_width) ? ww - old_width : 0, (pd->gravity_y == 1.0 && wh > old_height) ? wh - old_height : 0); - - return h > 0 && w > 0; } static void @@ -139,43 +137,64 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c _elm_code_widget_fill_line_token(cells, count, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); } +static void +_elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, + Elm_Code_Status_Type status, int line) +{ + char *number = NULL; + int w, gutter, g; + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + gutter = elm_code_widget_text_left_gutter_width_get(widget); + + evas_object_textgrid_size_get(pd->grid, &w, NULL); + + cells[gutter-1].codepoint = status_icons[status]; + cells[gutter-1].bold = 1; + cells[gutter-1].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG; + cells[gutter-1].bg = (status == ELM_CODE_STATUS_TYPE_DEFAULT) ? ELM_CODE_WIDGET_COLOR_GUTTER_BG : status; + + if (pd->show_line_numbers) + { + if (line > 0) + { + number = malloc(sizeof(char) * gutter); + snprintf(number, gutter, "%*d", gutter - 1, line); + } + for (g = 0; g < gutter - 1; g++) + { + if (number) + cells[g].codepoint = *(number + g); + else + cells[g].codepoint = 0; + + cells[g].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG; + cells[g].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG; + } + + if (number) + free(number); + } +} + static void _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) { - char *chr, *number; + char *chr; unsigned int length, x; - int w, gutter, g; + int w, gutter; Evas_Textgrid_Cell *cells; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); gutter = elm_code_widget_text_left_gutter_width_get(widget); - if (!_elm_code_widget_resize(widget)) - return; - length = line->length; evas_object_textgrid_size_get(pd->grid, &w, NULL); cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); - cells[gutter-1].codepoint = status_icons[line->status]; - cells[gutter-1].bold = 1; - cells[gutter-1].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG; - cells[gutter-1].bg = (line->status == ELM_CODE_STATUS_TYPE_DEFAULT) ? ELM_CODE_WIDGET_COLOR_GUTTER_BG : line->status; - - if (pd->show_line_numbers) - { - number = malloc(sizeof(char) * gutter); - snprintf(number, gutter, "%*d", gutter - 1, line->number); - - for (g = 0; g < gutter - 1; g++) - { - cells[g].codepoint = *(number + g); - cells[g].fg = ELM_CODE_WIDGET_COLOR_GUTTER_FG; - cells[g].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG; - } - free(number); - } + _elm_code_widget_fill_gutter(widget, cells, line->status, line->number); if (line->modified) chr = line->modified; @@ -204,6 +223,30 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) evas_object_textgrid_update_add(pd->grid, 0, line->number - 1, w, 1); } +static void +_elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number) +{ + unsigned int x; + int w, gutter; + Evas_Textgrid_Cell *cells; + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + gutter = elm_code_widget_text_left_gutter_width_get(widget); + + evas_object_textgrid_size_get(pd->grid, &w, NULL); + cells = evas_object_textgrid_cellrow_get(pd->grid, number - 1); + _elm_code_widget_fill_gutter(widget, cells, ELM_CODE_STATUS_TYPE_DEFAULT, 0); + + for (x = gutter; x < (unsigned int) w; x++) + { + cells[x].codepoint = 0; + cells[x].bg = ELM_CODE_STATUS_TYPE_DEFAULT; + } + + evas_object_textgrid_update_add(pd->grid, 0, number - 1, w, 1); +} + static void _elm_code_widget_fill(Elm_Code_Widget *widget) { @@ -214,8 +257,7 @@ _elm_code_widget_fill(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (!_elm_code_widget_resize(widget)) - return; + _elm_code_widget_resize(widget); evas_object_textgrid_size_get(pd->grid, &w, &h); for (y = 1; y <= (unsigned int) h && y <= elm_code_file_lines_get(pd->code->file); y++) @@ -224,6 +266,10 @@ _elm_code_widget_fill(Elm_Code_Widget *widget) _elm_code_widget_fill_line(widget, line); } + for (; y <= (unsigned int) h; y++) + { + _elm_code_widget_empty_line(widget, y); + } } static Eina_Bool @@ -234,9 +280,6 @@ _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, widget = (Elm_Code_Widget *)data; - if (!_elm_code_widget_resize(widget)) - return EINA_TRUE; - // FIXME refresh just the row unless we have resized (by being the result of a row append) _elm_code_widget_fill(widget); From ca9b64e3c8094cc96a793e38378133f8239cf054 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 23 Feb 2015 21:52:49 +0000 Subject: [PATCH 098/254] elm_code: display a line-width marker if requested --- legacy/elm_code/src/lib/elm_code_private.h | 1 + legacy/elm_code/src/lib/elm_code_widget.c | 35 ++++++++++++++++++++-- legacy/elm_code/src/lib/elm_code_widget.eo | 20 +++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h index 854d4b6826..e46a468c35 100644 --- a/legacy/elm_code/src/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -37,4 +37,5 @@ typedef struct unsigned int cursor_line, cursor_col; Eina_Bool editable, focussed; Eina_Bool show_line_numbers; + unsigned int line_width_marker; } Elm_Code_Widget_Data; diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 9673c9a674..134be964aa 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -108,6 +108,22 @@ _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start } } +static unsigned int +_elm_code_widget_status_type_get(Elm_Code_Widget *widget, Elm_Code_Status_Type set_type, unsigned int col) +{ + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (set_type != ELM_CODE_STATUS_TYPE_DEFAULT) + return set_type; + + if (pd->line_width_marker == col) + return ELM_CODE_WIDGET_COLOR_GUTTER_BG; + + return ELM_CODE_STATUS_TYPE_DEFAULT; +} + static void _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, unsigned int count, Elm_Code_Line *line) @@ -203,14 +219,14 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) for (x = gutter; x < (unsigned int) w && x < length + gutter; x++) { cells[x].codepoint = *chr; - cells[x].bg = line->status; + cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); chr++; } for (; x < (unsigned int) w; x++) { cells[x].codepoint = 0; - cells[x].bg = line->status; + cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); } _elm_code_widget_fill_line_tokens(widget, cells, w, line); @@ -241,7 +257,7 @@ _elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number) for (x = gutter; x < (unsigned int) w; x++) { cells[x].codepoint = 0; - cells[x].bg = ELM_CODE_STATUS_TYPE_DEFAULT; + cells[x].bg = _elm_code_widget_status_type_get(widget, ELM_CODE_STATUS_TYPE_DEFAULT, x - gutter + 1); } evas_object_textgrid_update_add(pd->grid, 0, number - 1, w, 1); @@ -709,6 +725,19 @@ _elm_code_widget_line_numbers_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) return pd->show_line_numbers; } +EOLIAN static void +_elm_code_widget_line_width_marker_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int col) +{ + pd->line_width_marker = col; + _elm_code_widget_fill(obj); +} + +EOLIAN static unsigned int +_elm_code_widget_line_width_marker_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) +{ + return pd->line_width_marker; +} + EOLIAN static void _elm_code_widget_cursor_position_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int col, unsigned int line) { diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/elm_code_widget.eo index 0608e81e41..9ee6aa41c5 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/elm_code_widget.eo @@ -103,6 +103,26 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) Eina_Bool line_numbers; /*@ Whether or not line numbers (or their placeholder) should be shown */ } } + line_width_marker { + set { + /*@ + Set where the line width market should be shown. + + Passing a non-zero value will set which line width to mark with a vertical line. + Passing 0 will hide this marker. + + @ingroup Features */ + } + get { + /*@ + Get the position of the line width marker, any positive return indicates where the marker appears. + + @ingroup Features */ + } + values { + uint line_width_marker; /*@ Where to display a line width marker, if at all */ + } + } cursor_position { set { /*@ From 67eb529aa36f7fda1ae5680e213b833537af7d15 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 24 Feb 2015 00:26:58 +0000 Subject: [PATCH 099/254] elm_code: Add missing status icons from new states --- legacy/elm_code/src/lib/elm_code_widget.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 134be964aa..53bf20ac08 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -15,6 +15,10 @@ typedef enum { Eina_Unicode status_icons[] = { ' ', + ' ', + ' ', + ' ', + '!', '!', '+', From b89e88accc1ad876e0de0e5204c87c09247c10f2 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 26 Feb 2015 13:54:46 +0000 Subject: [PATCH 100/254] elm_code: Move parser callbacks to private. Don't expose the internal callback mechanics, just the addition of parsers --- legacy/elm_code/src/lib/elm_code_file.c | 4 ++-- legacy/elm_code/src/lib/elm_code_parse.c | 13 ++++++++----- legacy/elm_code/src/lib/elm_code_parse.h | 4 ---- legacy/elm_code/src/lib/elm_code_private.h | 6 ++++++ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index cc24dcd498..e5a56ac37f 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -44,7 +44,7 @@ static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *con if (file->parent) { - elm_code_parse_line(file->parent, line); + _elm_code_parse_line(file->parent, line); elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); // this is called so we can refresh after any styling changes from LOAD_DONE @@ -100,7 +100,7 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) if (ret->parent) { - elm_code_parse_file(ret->parent, ret); + _elm_code_parse_file(ret->parent, ret); elm_code_callback_fire(ret->parent, &ELM_CODE_EVENT_FILE_LOAD_DONE, ret); } return ret; diff --git a/legacy/elm_code/src/lib/elm_code_parse.c b/legacy/elm_code/src/lib/elm_code_parse.c index 0503aa07dd..30ff948cc9 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.c +++ b/legacy/elm_code/src/lib/elm_code_parse.c @@ -6,7 +6,8 @@ #include "elm_code_private.h" -EAPI void elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line) +void +_elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line) { Elm_Code_Parser *parser; Eina_List *item; @@ -17,7 +18,8 @@ EAPI void elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line) } } -EAPI void elm_code_parse_file(Elm_Code *code, Elm_Code_File *file) +void +_elm_code_parse_file(Elm_Code *code, Elm_Code_File *file) { Elm_Code_Parser *parser; Eina_List *item; @@ -28,9 +30,10 @@ EAPI void elm_code_parse_file(Elm_Code *code, Elm_Code_File *file) } } -EAPI void elm_code_parser_add(Elm_Code *code, - void (*parse_line)(Elm_Code_Line *), - void (*parse_file)(Elm_Code_File *)) +EAPI void +elm_code_parser_add(Elm_Code *code, + void (*parse_line)(Elm_Code_Line *), + void (*parse_file)(Elm_Code_File *)) { Elm_Code_Parser *parser; diff --git a/legacy/elm_code/src/lib/elm_code_parse.h b/legacy/elm_code/src/lib/elm_code_parse.h index 1c58d27b74..d52c688e2e 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.h +++ b/legacy/elm_code/src/lib/elm_code_parse.h @@ -30,10 +30,6 @@ typedef struct _Elm_Code_Parser EAPI void elm_code_parser_add(Elm_Code *code, void (*parse_line)(Elm_Code_Line *), void (*parse_file)(Elm_Code_File *)); -EAPI void elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line); - -EAPI void elm_code_parse_file(Elm_Code *code, Elm_Code_File *file); - /** * @} */ diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h index 854d4b6826..af862dc4a0 100644 --- a/legacy/elm_code/src/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -38,3 +38,9 @@ typedef struct Eina_Bool editable, focussed; Eina_Bool show_line_numbers; } Elm_Code_Widget_Data; + +/* Private parser callbacks */ + +void _elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line); + +void _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file); From bc1cfc7b8728290cc2e02eccee5d05502c258c4d Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 26 Feb 2015 23:19:09 +0000 Subject: [PATCH 101/254] elm_code parse: Add standard parsers starting with diff. Allow code instances to have provided parsers added easily. These can be chained to have multiple passes. --- legacy/elm_code/src/bin/elm_code_test_main.c | 50 +++++++ legacy/elm_code/src/lib/elm_code.c | 2 +- .../elm_code/src/lib/elm_code_diff_widget.c | 60 ++++----- legacy/elm_code/src/lib/elm_code_parse.c | 123 +++++++++++++++++- legacy/elm_code/src/lib/elm_code_parse.h | 11 +- legacy/elm_code/src/lib/elm_code_private.h | 2 + legacy/elm_code/src/lib/elm_code_text.c | 4 +- 7 files changed, 205 insertions(+), 47 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 97fbb09018..db994e508b 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -114,6 +114,32 @@ _elm_code_test_editor_setup(Evas_Object *parent) return widget; } +static Evas_Object * +_elm_code_test_diff_inline_setup(Evas_Object *parent) +{ + char path[PATH_MAX]; + Evas_Object *diff; + Elm_Code *code; + + snprintf(path, sizeof(path), "%s/../edi/data/testdiff.diff", elm_app_data_dir_get()); + + code = elm_code_create(); + elm_code_file_open(code, path); + + diff = eo_add(ELM_CODE_WIDGET_CLASS, parent); + eo_do(diff, + elm_code_widget_code_set(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, path); + + return diff; +} + static Evas_Object * _elm_code_test_diff_setup(Evas_Object *parent) { @@ -145,6 +171,21 @@ _elm_code_test_welcome_editor_cb(void *data, Evas_Object *obj EINA_UNUSED, void 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) { @@ -192,6 +233,15 @@ elm_code_test_win_setup(void) 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); diff --git a/legacy/elm_code/src/lib/elm_code.c b/legacy/elm_code/src/lib/elm_code.c index cf735778ad..b951d2b1f8 100644 --- a/legacy/elm_code/src/lib/elm_code.c +++ b/legacy/elm_code/src/lib/elm_code.c @@ -33,7 +33,7 @@ elm_code_init(void) goto shutdown_eina; } - // Put here your initialization logic of your library + _elm_code_parse_setup(); eina_log_timing(_elm_code_lib_log_dom, EINA_LOG_STATE_STOP, EINA_LOG_STATE_INIT); diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.c b/legacy/elm_code/src/lib/elm_code_diff_widget.c index 21790e982e..275eb97c23 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/src/lib/elm_code_diff_widget.c @@ -16,26 +16,30 @@ static void _elm_code_diff_widget_parse_diff_line(Elm_Code_Line *line, Elm_Code_File *left, Elm_Code_File *right) { + const char *content; + int length; + if (line->length < 1) { elm_code_file_line_append(left, "", 0, NULL); elm_code_file_line_append(right, "", 0, NULL); } - if (line->content[0] == '+') + 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, line->content+1, line->length-1, _ELM_CODE_DIFF_WIDGET_TYPE_ADDED); + elm_code_file_line_append(right, content, length, NULL); } - else if (line->content[0] == '-') + else if (content[0] == '-') { - elm_code_file_line_append(left, line->content+1, line->length-1, _ELM_CODE_DIFF_WIDGET_TYPE_REMOVED); + elm_code_file_line_append(left, content, length, NULL); elm_code_file_line_append(right, "", 0, NULL); } else { - elm_code_file_line_append(left, line->content+1, line->length-1, NULL); - elm_code_file_line_append(right, line->content+1, line->length-1, NULL); + elm_code_file_line_append(left, content, length, NULL); + elm_code_file_line_append(right, content, length, NULL); } } @@ -44,47 +48,35 @@ _elm_code_diff_widget_parse_diff(Elm_Code_File *diff, Elm_Code_File *left, Elm_C { Eina_List *item; Elm_Code_Line *line; - int offset; + const char *content; + int offset, length; offset = 0; EINA_LIST_FOREACH(diff->lines, item, line) { - if (line->length > 0 && (line->content[0] == 'd' || line->content[0] == 'i' || line->content[0] == 'n')) + 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, line->content+4, line->length-4, _ELM_CODE_DIFF_WIDGET_TYPE_CHANGED); + elm_code_file_line_append(left, content, length, NULL); else if (offset == 1) - elm_code_file_line_append(right, line->content+4, line->length-4, _ELM_CODE_DIFF_WIDGET_TYPE_CHANGED); + elm_code_file_line_append(right, content, length, NULL); else _elm_code_diff_widget_parse_diff_line(line, left, right); offset++; } -} -static Eina_Bool -_elm_code_diff_widget_line_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, - const Eo_Event_Description *desc EINA_UNUSED, void *event_info) -{ - Elm_Code_Line *line; - - line = (Elm_Code_Line *)event_info; - - if (!line->data) - return EO_CALLBACK_CONTINUE; - - if (!strcmp(_ELM_CODE_DIFF_WIDGET_TYPE_ADDED, (char *)line->data)) - line->status = ELM_CODE_STATUS_TYPE_ADDED; - else if (!strcmp(_ELM_CODE_DIFF_WIDGET_TYPE_REMOVED, (char *)line->data)) - line->status = ELM_CODE_STATUS_TYPE_REMOVED; - else if (!strcmp(_ELM_CODE_DIFF_WIDGET_TYPE_CHANGED, (char *)line->data)) - line->status = ELM_CODE_STATUS_TYPE_CHANGED; - - return EO_CALLBACK_CONTINUE; + _elm_code_parse_file(left->parent, left); + _elm_code_parse_file(right->parent, right); } EAPI Evas_Object * @@ -104,8 +96,8 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) wcode1 = elm_code_create(); widget_left = eo_add(ELM_CODE_WIDGET_CLASS, parent); eo_do(widget_left, - elm_code_widget_code_set(wcode1), - eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_diff_widget_line_cb, NULL)); + elm_code_widget_code_set(wcode1)); + elm_code_parser_standard_add(wcode1, ELM_CODE_PARSER_STANDARD_DIFF); 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); @@ -117,8 +109,8 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) wcode2 = elm_code_create(); widget_right = eo_add(ELM_CODE_WIDGET_CLASS, parent); eo_do(widget_right, - elm_code_widget_code_set(wcode2), - eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_diff_widget_line_cb, NULL)); + elm_code_widget_code_set(wcode2)); + elm_code_parser_standard_add(wcode2, ELM_CODE_PARSER_STANDARD_DIFF); 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); diff --git a/legacy/elm_code/src/lib/elm_code_parse.c b/legacy/elm_code/src/lib/elm_code_parse.c index bea1b30e21..f722ac40f0 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.c +++ b/legacy/elm_code/src/lib/elm_code_parse.c @@ -6,6 +6,16 @@ #include "elm_code_private.h" +struct _Elm_Code_Parser +{ + void (*parse_line)(Elm_Code_Line *, void *); + + void (*parse_file)(Elm_Code_File *, void *); + + void *data; +}; + + void _elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line) { @@ -32,6 +42,22 @@ _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file) } } +static Elm_Code_Parser * +_elm_code_parser_new(void (*parse_line)(Elm_Code_Line *, void *), + void (*parse_file)(Elm_Code_File *, void *)) +{ + Elm_Code_Parser *parser; + + parser = calloc(1, sizeof(Elm_Code_Parser)); + if (!parser) + return NULL; + + parser->parse_line = parse_line; + parser->parse_file = parse_file; + + return parser; +} + EAPI void elm_code_parser_add(Elm_Code *code, void (*parse_line)(Elm_Code_Line *, void *), @@ -39,14 +65,105 @@ elm_code_parser_add(Elm_Code *code, { Elm_Code_Parser *parser; - parser = calloc(1, sizeof(Elm_Code_Parser)); + parser = _elm_code_parser_new(parse_line, parse_file); if (!parser) return; - parser->parse_line = parse_line; - parser->parse_file = parse_file; parser->data = data; code->parsers = eina_list_append(code->parsers, parser); } +EAPI void +elm_code_parser_standard_add(Elm_Code *code, Elm_Code_Parser *parser) +{ + if (!parser || !code) + return; + + code->parsers = eina_list_append(code->parsers, parser); +} + +EAPI Elm_Code_Parser * +ELM_CODE_PARSER_STANDARD_DIFF; + +static void +_elm_code_parser_diff_trim_leading(Elm_Code_Line *line, unsigned int count) +{ + char *replace, *old = NULL; + + if (line->modified) + { + old = line->modified; + replace = malloc(sizeof(char) * (line->length - count)); + + strncpy(replace, old + count, line->length - count); + line->modified = replace; + free(old); + } + else + { + line->content += count; + } + + line->length -= count; +} + +static void +_elm_code_parser_diff_parse_line(Elm_Code_Line *line, void *data EINA_UNUSED) +{ + const char *content; + int length; + + content = elm_code_line_text_get(line, &length); + if (length < 1) + return; + + if (content[0] == 'd' || content[0] == 'i' || content[0] == 'n') + { + elm_code_line_status_set(line, ELM_CODE_STATUS_TYPE_CHANGED); + return; + } + + if (content[0] == '+') + elm_code_line_status_set(line, ELM_CODE_STATUS_TYPE_ADDED); + else if (content[0] == '-') + elm_code_line_status_set(line, ELM_CODE_STATUS_TYPE_REMOVED); + + _elm_code_parser_diff_trim_leading(line, 1); +} + +static void +_elm_code_parser_diff_parse_file(Elm_Code_File *file, void *data EINA_UNUSED) +{ + Eina_List *item; + Elm_Code_Line *line; + const char *content; + int length, offset; + + offset = 0; + EINA_LIST_FOREACH(file->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; + continue; + } + + if (offset <= 1 && (content[0] == '+' || content[0] == '-')) + { + elm_code_line_status_set(line, ELM_CODE_STATUS_TYPE_CHANGED); + _elm_code_parser_diff_trim_leading(line, 3); + } + + offset++; + } +} + +void +_elm_code_parse_setup() +{ + ELM_CODE_PARSER_STANDARD_DIFF = _elm_code_parser_new(_elm_code_parser_diff_parse_line, + _elm_code_parser_diff_parse_file); +} diff --git a/legacy/elm_code/src/lib/elm_code_parse.h b/legacy/elm_code/src/lib/elm_code_parse.h index 7d53f4d289..d991345b5a 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.h +++ b/legacy/elm_code/src/lib/elm_code_parse.h @@ -10,14 +10,9 @@ extern "C" { * @brief These routines are used for handling the parsing of Elm Code content. */ -typedef struct _Elm_Code_Parser -{ - void (*parse_line)(Elm_Code_Line *, void *); +typedef struct _Elm_Code_Parser Elm_Code_Parser; - void (*parse_file)(Elm_Code_File *, void *); - - void *data; -} Elm_Code_Parser; +EAPI Elm_Code_Parser *ELM_CODE_PARSER_STANDARD_DIFF; /**< A provided parser that will mark up diff text */ /** * @brief Parser helper functions. @@ -32,6 +27,8 @@ typedef struct _Elm_Code_Parser EAPI void elm_code_parser_add(Elm_Code *code, void (*parse_line)(Elm_Code_Line *, void *), void (*parse_file)(Elm_Code_File *, void *), void *data); +EAPI void elm_code_parser_standard_add(Elm_Code *code, Elm_Code_Parser *parser); + /** * @} */ diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h index 1183c2a6fd..68de837372 100644 --- a/legacy/elm_code/src/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -42,6 +42,8 @@ typedef struct /* Private parser callbacks */ +void _elm_code_parse_setup(); + void _elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line); void _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file); diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 690bb36484..5ba5fa85b9 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -6,8 +6,8 @@ #include "elm_code_private.h" -EAPI const char -*elm_code_line_text_get(Elm_Code_Line *line, int *length) +EAPI const char * +elm_code_line_text_get(Elm_Code_Line *line, int *length) { if (!line) return NULL; From a7adf4f1f6138f4c387d891499065ad27d7dc222 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 26 Feb 2015 23:56:10 +0000 Subject: [PATCH 102/254] elm_code edit: Support insert of any single char. broadens from alphanumeric to include punctionation and various symbols. --- legacy/elm_code/src/lib/elm_code_widget.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index ec296f8b4e..680dd504c3 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -605,12 +605,10 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, _elm_code_widget_cursor_move_left(widget); else if (!strcmp(ev->key, "Right")) _elm_code_widget_cursor_move_right(widget); - else if (strlen(ev->key) == 1) - _elm_code_widget_text_at_cursor_insert(widget, ev->key, 1); - else if (!strcmp(ev->key, "space")) - _elm_code_widget_text_at_cursor_insert(widget, " ", 1); + else if (ev->string && strlen(ev->string) == 1) + _elm_code_widget_text_at_cursor_insert(widget, ev->string, 1); else - INF("Unhandled key %s", ev->key); + INF("Unhandled key %s (%s) (%s)", ev->key, ev->keyname, ev->string); } static void From df310e14f43d4911597bfb4441077d7e319b3154 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 27 Feb 2015 15:07:38 +0000 Subject: [PATCH 103/254] elm_code: Fix finalized check macro --- legacy/elm_code/src/lib/elm_code_widget.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 8f9b4686e0..310db71e17 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -27,12 +27,14 @@ Eina_Unicode status_icons[] = { 0 }; -#define EO_CONSTRUCTOR_CHECK_RETURN(obj) \ - if (eo_do(obj, eo_finalized_get())) \ +#define EO_CONSTRUCTOR_CHECK_RETURN(obj) do { \ + Eina_Bool finalized; \ + if (eo_do_ret(obj, finalized, eo_finalized_get())) \ { \ ERR("This function is only allowed during construction."); \ return; \ - } + } \ +} while (0) EOLIAN static void _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd) From 20c108ea320b69989a286c9e8e665f793e57d9cf Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 28 Feb 2015 13:14:18 +0000 Subject: [PATCH 104/254] elm_code tests: fix test path --- legacy/elm_code/src/tests/elm_code_test_basic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/tests/elm_code_test_basic.c b/legacy/elm_code/src/tests/elm_code_test_basic.c index aabff68640..b968e90523 100644 --- a/legacy/elm_code/src/tests/elm_code_test_basic.c +++ b/legacy/elm_code/src/tests/elm_code_test_basic.c @@ -6,7 +6,7 @@ START_TEST (elm_code_create_test) { - char *path = "elm_code/tests/testfile.txt"; + char *path = "elm_code/src/tests/testfile.txt"; Elm_Code *code; code = elm_code_create(); From f4a760f4a5b7dc74f13e52f99b107c04415005f1 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 28 Feb 2015 13:22:38 +0000 Subject: [PATCH 105/254] elm_code: require an elm_code for each widget In our finalizer we ensure that an elm_code is set. No longer allow code_set to be called after construction. --- legacy/elm_code/src/bin/elm_code_test_main.c | 8 ++--- .../elm_code/src/lib/elm_code_diff_widget.c | 8 ++--- legacy/elm_code/src/lib/elm_code_widget.c | 24 +++++++++++-- legacy/elm_code/src/lib/elm_code_widget.eo | 5 ++- .../elm_code/src/tests/elm_code_test_widget.c | 34 +++++++++++++++++++ 5 files changed, 68 insertions(+), 11 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index e6235fc68d..336459b162 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -69,9 +69,9 @@ _elm_code_test_welcome_setup(Evas_Object *parent) Elm_Code_Widget *widget; code = elm_code_create(); - widget = eo_add(ELM_CODE_WIDGET_CLASS, parent); + widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, + elm_code_widget_code_set(code)); eo_do(widget, - elm_code_widget_code_set(code), elm_code_widget_font_size_set(12), eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_test_line_done_cb, NULL); eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code)); @@ -95,9 +95,9 @@ _elm_code_test_editor_setup(Evas_Object *parent) Elm_Code_Widget *widget; code = elm_code_create(); - widget = eo_add(ELM_CODE_WIDGET_CLASS, parent); + widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, + elm_code_widget_code_set(code)); eo_do(widget, - elm_code_widget_code_set(code), elm_code_widget_font_size_set(14), elm_code_widget_editable_set(EINA_TRUE), elm_code_widget_line_numbers_set(EINA_TRUE)); diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.c b/legacy/elm_code/src/lib/elm_code_diff_widget.c index 21790e982e..6148f6a170 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/src/lib/elm_code_diff_widget.c @@ -102,9 +102,9 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // left side of diff wcode1 = elm_code_create(); - widget_left = eo_add(ELM_CODE_WIDGET_CLASS, parent); + widget_left = eo_add(ELM_CODE_WIDGET_CLASS, parent, + elm_code_widget_code_set(wcode1)); eo_do(widget_left, - elm_code_widget_code_set(wcode1), eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_diff_widget_line_cb, NULL)); evas_object_size_hint_weight_set(widget_left, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -115,9 +115,9 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // right side of diff wcode2 = elm_code_create(); - widget_right = eo_add(ELM_CODE_WIDGET_CLASS, parent); + widget_right = eo_add(ELM_CODE_WIDGET_CLASS, parent, + elm_code_widget_code_set(wcode2)); eo_do(widget_right, - elm_code_widget_code_set(wcode2), eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_diff_widget_line_cb, NULL)); evas_object_size_hint_weight_set(widget_right, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 3d895079f1..8f9b4686e0 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -27,9 +27,15 @@ Eina_Unicode status_icons[] = { 0 }; +#define EO_CONSTRUCTOR_CHECK_RETURN(obj) \ + if (eo_do(obj, eo_finalized_get())) \ + { \ + ERR("This function is only allowed during construction."); \ + return; \ + } EOLIAN static void -_elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED) +_elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd) { eo_do_super(obj, ELM_CODE_WIDGET_CLASS, eo_constructor()); @@ -37,6 +43,18 @@ _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUS pd->cursor_col = 1; } +EOLIAN static Eo * +_elm_code_widget_eo_base_finalize(Eo *obj, Elm_Code_Widget_Data *pd) +{ + eo_do_super(obj, ELM_CODE_WIDGET_CLASS, eo_finalize()); + + if (pd->code) + return obj; + + ERR("Elm_Code_Widget cannot finalize without calling elm_code_widget_code_set."); + return NULL; +} + EOLIAN static void _elm_code_widget_class_constructor(Eo_Class *klass EINA_UNUSED) { @@ -582,8 +600,10 @@ _elm_code_widget_font_size_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) } EOLIAN static void -_elm_code_widget_code_set(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm_Code *code) +_elm_code_widget_code_set(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code *code) { + EO_CONSTRUCTOR_CHECK_RETURN(obj); + pd->code = code; code->widgets = eina_list_append(code->widgets, obj); diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/elm_code_widget.eo index 3bc81b81ec..36c6c98f77 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/elm_code_widget.eo @@ -5,7 +5,9 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) code { set { /*@ - Set the underlying code object that this widget renders + Set the underlying code object that this widget renders. + This can only be set during construction, once the widget is created the + backing code object cannot be changed. @ingroup Data */ } @@ -109,6 +111,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) implements { class.constructor; Eo.Base.constructor; + Eo.Base.finalize; Evas.Object_Smart.add; Elm_Widget.focus_next_manager_is; Elm_Widget.focus_direction_manager_is; diff --git a/legacy/elm_code/src/tests/elm_code_test_widget.c b/legacy/elm_code/src/tests/elm_code_test_widget.c index 2836bb4c44..ed5e91be84 100644 --- a/legacy/elm_code/src/tests/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/elm_code_test_widget.c @@ -41,8 +41,42 @@ START_TEST (elm_code_widget_token_render_simple_test) } END_TEST +START_TEST (elm_code_widget_construct) +{ + Elm_Code *code; + Elm_Code_Widget *widget, *win; + + elm_init(1, NULL); + code = elm_code_create(); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = eo_add(ELM_CODE_WIDGET_CLASS, win, + elm_code_widget_code_set(code)); + + ck_assert(!!widget); + elm_code_free(code); + elm_shutdown(); +} +END_TEST + +START_TEST (elm_code_widget_construct_nocode) +{ + Elm_Code_Widget *widget, *win; + + elm_init(1, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = eo_add(ELM_CODE_WIDGET_CLASS, win); + ck_assert(!widget); + + elm_shutdown(); +} +END_TEST + void elm_code_test_widget(TCase *tc) { tcase_add_test(tc, elm_code_widget_token_render_simple_test); + tcase_add_test(tc, elm_code_widget_construct); + tcase_add_test(tc, elm_code_widget_construct_nocode); } From c4f97f2f3ea0f8080ded94f638daa92efc4d077e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 28 Feb 2015 14:20:32 +0000 Subject: [PATCH 106/254] elm_code: support line insertion in our widget call a line insertion on enter pressed --- legacy/elm_code/src/lib/elm_code_file.c | 42 +++++++++++++++++++---- legacy/elm_code/src/lib/elm_code_file.h | 2 ++ legacy/elm_code/src/lib/elm_code_widget.c | 22 ++++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index b51b3f10e9..3ce6c94952 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -21,9 +21,10 @@ static Elm_Code_Line *_elm_code_file_line_blank_create(Elm_Code_File *file, int return ecl; } -static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *content, int length, int row, Eina_Bool mapped, void *data) +static void _elm_code_file_line_insert_data(Elm_Code_File *file, const char *content, int length, + unsigned int row, Eina_Bool mapped, void *data) { - Elm_Code_Line *line; + Elm_Code_Line *line, *after; line = _elm_code_file_line_blank_create(file, row, data); if (!line) return; @@ -41,7 +42,15 @@ static void _elm_code_file_line_append_data(Elm_Code_File *file, const char *con line->length = length; } - file->lines = eina_list_append(file->lines, line); + 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) { @@ -92,7 +101,7 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) ret->lines = eina_list_append(ret->lines, ecl); } - _elm_code_file_line_append_data(ret, line->start, line->length, lastindex = line->index, EINA_TRUE, NULL); + _elm_code_file_line_insert_data(ret, line->start, line->length, lastindex = line->index, EINA_TRUE, NULL); } eina_iterator_free(it); @@ -166,8 +175,29 @@ EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int l { int row; - row = elm_code_file_lines_get(file); - return _elm_code_file_line_append_data(file, line, length, row+1, EINA_FALSE, data); + row = elm_code_file_lines_get(file) + 1; + _elm_code_file_line_insert_data(file, line, length, row, EINA_FALSE, data); +} + +EAPI void elm_code_file_line_insert(Elm_Code_File *file, unsigned int row, const char *line, int length, void *data) +{ + Eina_List *item; + Elm_Code_Line *line_item; + unsigned int r; + + _elm_code_file_line_insert_data(file, line, length, row, EINA_FALSE, data); + + r = row; + EINA_LIST_FOREACH(file->lines, item, line_item) + { + if (line_item->number < row) + continue; + + line_item->number = r++; + + if (file->parent) + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line_item); + } } EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int number) diff --git a/legacy/elm_code/src/lib/elm_code_file.h b/legacy/elm_code/src/lib/elm_code_file.h index 36f39a5e0c..24286f60ed 100644 --- a/legacy/elm_code/src/lib/elm_code_file.h +++ b/legacy/elm_code/src/lib/elm_code_file.h @@ -60,6 +60,8 @@ EAPI unsigned int elm_code_file_lines_get(Elm_Code_File *file); EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int length, void *data); +EAPI void elm_code_file_line_insert(Elm_Code_File *file, unsigned int row, const char *line, int length, void *data); + EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int line); /** diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 680dd504c3..a2acf527a0 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -580,6 +580,24 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text elm_code_widget_cursor_position_set(col + length, row)); } +static void +_elm_code_widget_newline(Elm_Code_Widget *widget) +{ + Elm_Code *code; + Elm_Code_Line *line; + unsigned int row, col; + + eo_do(widget, + code = elm_code_widget_code_get(), + elm_code_widget_cursor_position_get(&col, &row)); + line = elm_code_file_line_get(code->file, row); + + elm_code_file_line_insert(code->file, line->number + 1, "", 0, NULL); + + eo_do(widget, + elm_code_widget_cursor_position_set(1, row + 1)); +} + static void _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) @@ -605,6 +623,10 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, _elm_code_widget_cursor_move_left(widget); else if (!strcmp(ev->key, "Right")) _elm_code_widget_cursor_move_right(widget); + + else if (!strcmp(ev->key, "KP_Enter") || !strcmp(ev->key, "Return")) + _elm_code_widget_newline(widget); + else if (ev->string && strlen(ev->string) == 1) _elm_code_widget_text_at_cursor_insert(widget, ev->string, 1); else From dec03ca188a9d083662fa963996b153f194f76cc Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 28 Feb 2015 14:59:42 +0000 Subject: [PATCH 107/254] elm_code widget: add show_whitespace option display items for space, tab and newline if requested --- legacy/elm_code/src/bin/elm_code_test_main.c | 1 + legacy/elm_code/src/lib/elm_code_private.h | 1 + legacy/elm_code/src/lib/elm_code_widget.c | 43 +++++++++++++++++++- legacy/elm_code/src/lib/elm_code_widget.eo | 17 ++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index db994e508b..b8a8ffc8d9 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -100,6 +100,7 @@ _elm_code_test_editor_setup(Evas_Object *parent) elm_code_widget_code_set(code), elm_code_widget_font_size_set(14), elm_code_widget_editable_set(EINA_TRUE), + elm_code_widget_show_whitespace_set(EINA_TRUE), elm_code_widget_line_numbers_set(EINA_TRUE)); _append_line(code->file, "Edit me :)"); diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h index 68de837372..74232f5ddb 100644 --- a/legacy/elm_code/src/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -38,6 +38,7 @@ typedef struct Eina_Bool editable, focussed; Eina_Bool show_line_numbers; unsigned int line_width_marker; + Eina_Bool show_whitespace; } Elm_Code_Widget_Data; /* Private parser callbacks */ diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index a2acf527a0..261f950223 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -8,6 +8,7 @@ typedef enum { ELM_CODE_WIDGET_COLOR_GUTTER_BG = ELM_CODE_TOKEN_TYPE_COUNT, ELM_CODE_WIDGET_COLOR_GUTTER_FG, + ELM_CODE_WIDGET_COLOR_WHITESPACE, ELM_CODE_WIDGET_COLOR_CURSOR, ELM_CODE_WIDGET_COLOR_COUNT @@ -198,6 +199,27 @@ _elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, } } +static void +_elm_code_widget_fill_whitespace(Elm_Code_Widget *widget EINA_UNUSED, char character, Evas_Textgrid_Cell *cell) +{ + switch (character) + { + case ' ': + cell->codepoint = 0x00b7; + break; + case '\t': + cell->codepoint = 0x2192; + break; + case '\n': + cell->codepoint = 0x23ce; + break; + default: + return; + } + + cell->fg = ELM_CODE_WIDGET_COLOR_WHITESPACE; +} + static void _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) { @@ -215,6 +237,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); _elm_code_widget_fill_gutter(widget, cells, line->status, line->number); + _elm_code_widget_fill_line_tokens(widget, cells, w, line); if (line->modified) chr = line->modified; @@ -225,6 +248,8 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) cells[x].codepoint = *chr; cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); + if (pd->show_whitespace) + _elm_code_widget_fill_whitespace(widget, *chr, &cells[x]); chr++; } for (; x < (unsigned int) w; x++) @@ -233,12 +258,13 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); } - _elm_code_widget_fill_line_tokens(widget, cells, w, line); if (pd->editable && pd->focussed && pd->cursor_line == line->number) { if (pd->cursor_col + gutter - 1 < (unsigned int) w) cells[pd->cursor_col + gutter - 1].bg = ELM_CODE_WIDGET_COLOR_CURSOR; } + if (pd->show_whitespace) + _elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]); evas_object_textgrid_update_add(pd->grid, 0, line->number - 1, w, 1); } @@ -762,6 +788,19 @@ _elm_code_widget_line_width_marker_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data return pd->line_width_marker; } +EOLIAN static void +_elm_code_widget_show_whitespace_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool show) +{ + pd->show_whitespace = show; + _elm_code_widget_fill(obj); +} + +EOLIAN static Eina_Bool +_elm_code_widget_show_whitespace_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) +{ + return pd->show_whitespace; +} + EOLIAN static void _elm_code_widget_cursor_position_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int col, unsigned int line) { @@ -843,6 +882,8 @@ _elm_code_widget_setup_palette(Evas_Object *o) 75, 75, 75, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_FG, 139, 139, 139, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_WHITESPACE, + 101, 101, 101, 125); } EOLIAN static void diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/elm_code_widget.eo index 9ee6aa41c5..fe7bd9d4af 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/elm_code_widget.eo @@ -123,6 +123,23 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) uint line_width_marker; /*@ Where to display a line width marker, if at all */ } } + show_whitespace { + set { + /*@ + Set where white space should be shown. + + @ingroup Features */ + } + get { + /*@ + Get whether or not white space will be visible. + + @ingroup Features */ + } + values { + Eina_Bool show_whitespace; /*@ Whether or not we show whitespace characters */ + } + } cursor_position { set { /*@ From ec9c327ce10e8ad30565a232e75ebc58021c679e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 28 Feb 2015 16:28:22 +0000 Subject: [PATCH 108/254] editor: update to latest elm_code and show whitespace --- legacy/elm_code/src/lib/elm_code_widget.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index c3b1443f1b..79c6eae812 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -837,6 +837,8 @@ _elm_code_widget_cursor_position_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data * static void _elm_code_widget_setup_palette(Evas_Object *o) { + double feint = 0.5; + // setup status colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, 36, 36, 36, 255); @@ -903,7 +905,7 @@ _elm_code_widget_setup_palette(Evas_Object *o) evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_FG, 139, 139, 139, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_WHITESPACE, - 101, 101, 101, 125); + 101 * feint, 101 * feint, 101 * feint, 255 * feint); } EOLIAN static void From 9e184f62704dd8865bba077072383c05ea092fab Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 27 Feb 2015 15:33:06 +0000 Subject: [PATCH 109/254] elm_code demo: Show multiple widgets for one code. Illustrates that we can display a single elm_code in many widgets --- legacy/elm_code/src/bin/elm_code_test_main.c | 55 +++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 87d3ed43ef..6a0148d3ec 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -115,6 +115,24 @@ _elm_code_test_editor_setup(Evas_Object *parent) return widget; } +static Evas_Object * +_elm_code_test_mirror_setup(Elm_Code *code, Evas_Object *parent) +{ + Elm_Code_Widget *widget; + + widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, + elm_code_widget_code_set(code)); + eo_do(widget, + elm_code_widget_font_size_set(11), + elm_code_widget_line_numbers_set(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) { @@ -171,6 +189,30 @@ _elm_code_test_welcome_editor_cb(void *data, Evas_Object *obj EINA_UNUSED, void 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); + eo_do(widget, + code = elm_code_widget_code_get()); + elm_box_pack_end(screen, widget); + + elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, screen)); + elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, 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) { @@ -227,12 +269,21 @@ elm_code_test_win_setup(void) 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, 0.9); + 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, "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); @@ -245,7 +296,7 @@ elm_code_test_win_setup(void) 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.1); + 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); From 2e5d0e7e021d61709281f2b4ada339f0d5f8f4dd Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 28 Feb 2015 22:50:18 +0000 Subject: [PATCH 110/254] elm_code editor: adjust tokens when we insert text --- legacy/elm_code/src/bin/elm_code_test_main.c | 5 +++++ legacy/elm_code/src/lib/elm_code_text.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 6a0148d3ec..be679d222e 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -92,6 +92,7 @@ static Evas_Object * _elm_code_test_editor_setup(Evas_Object *parent) { Elm_Code *code; + Elm_Code_Line *line; Elm_Code_Widget *widget; code = elm_code_create(); @@ -108,6 +109,10 @@ _elm_code_test_editor_setup(Evas_Object *parent) _append_line(code->file, ""); _append_line(code->file, "...Please?"); + line = elm_code_file_line_get(code->file, 1); + elm_code_line_token_add(line, 6, 7, 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); diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 5ba5fa85b9..62ca36c12c 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -20,6 +20,22 @@ elm_code_line_text_get(Elm_Code_Line *line, int *length) return line->content; } +static void +_elm_code_line_tokens_move_right(Elm_Code_Line *line, int position, int move) +{ + Eina_List *item; + Elm_Code_Token *token; + + EINA_LIST_FOREACH(line->tokens, item, token) + { + if (token->end >= position) + token->end += move; + + if (token->start > position) + token->start += move; + } +} + EAPI void elm_code_line_text_insert(Elm_Code_Line *line, int position, const char *string, int length) { @@ -36,6 +52,8 @@ elm_code_line_text_insert(Elm_Code_Line *line, int position, const char *string, if (position < 0) position = 0; + _elm_code_line_tokens_move_right(line, position + 1, length); + if (line->modified) { strncpy(inserted, line->modified, position); From a2026576a2ea869cc65cf1687f63c385b364695a Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 7 Mar 2015 20:48:02 +0100 Subject: [PATCH 111/254] Add initial unicode support for elm_code Note the number of utf8 characters when we load the data. Make sure the widget is referencing unicode_length for all our metrics. --- legacy/elm_code/src/bin/elm_code_test_main.c | 4 +-- legacy/elm_code/src/lib/elm_code_file.c | 19 +++++++++- legacy/elm_code/src/lib/elm_code_line.c | 6 ++++ legacy/elm_code/src/lib/elm_code_line.h | 4 ++- legacy/elm_code/src/lib/elm_code_parse.c | 1 + legacy/elm_code/src/lib/elm_code_text.c | 7 ++-- legacy/elm_code/src/lib/elm_code_text.h | 2 +- legacy/elm_code/src/lib/elm_code_widget.c | 38 +++++++++++--------- 8 files changed, 55 insertions(+), 26 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index be679d222e..fd96f20e4a 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -76,10 +76,10 @@ _elm_code_test_welcome_setup(Evas_Object *parent) eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_test_line_done_cb, NULL); eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code)); - _append_line(code->file, "Hello World, Elm 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 ***"); + _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); diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index 3ce6c94952..d25bdd2895 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -21,7 +21,23 @@ static Elm_Code_Line *_elm_code_file_line_blank_create(Elm_Code_File *file, int return ecl; } -static void _elm_code_file_line_insert_data(Elm_Code_File *file, const char *content, int length, +static unsigned int +_elm_code_file_line_unicode_strlen(const char *chars, unsigned int length) +{ + unsigned int count = 0; + int index = 0; + + while ((unsigned int) index < length) + { + eina_unicode_utf8_next_get(chars, &index); + + count++; + } + + return count; +} + +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; @@ -41,6 +57,7 @@ static void _elm_code_file_line_insert_data(Elm_Code_File *file, const char *con line->modified[length] = 0; line->length = length; } + line->unicode_length = _elm_code_file_line_unicode_strlen(content, length); if (row == 1) file->lines = eina_list_prepend(file->lines, line); diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index b1ab3080fa..e4fcfa41eb 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -6,6 +6,12 @@ #include "elm_code_private.h" +EAPI unsigned int +elm_code_line_utf8_length_get(Elm_Code_Line *line) +{ + return line->unicode_length; +} + EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status) { if (!line) diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index ea7cff5b56..b057c64809 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -24,7 +24,7 @@ typedef struct _Elm_Code_Line Elm_Code_File *file; const char *content; - int length; + unsigned int length, unicode_length; unsigned int number; char *modified; @@ -34,6 +34,8 @@ typedef struct _Elm_Code_Line void *data; } Elm_Code_Line; +EAPI unsigned int elm_code_line_utf8_length_get(Elm_Code_Line *line); + /** * @brief Line markup functions. * @defgroup Line highlighting and status manipulation diff --git a/legacy/elm_code/src/lib/elm_code_parse.c b/legacy/elm_code/src/lib/elm_code_parse.c index f722ac40f0..c57e877716 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.c +++ b/legacy/elm_code/src/lib/elm_code_parse.c @@ -106,6 +106,7 @@ _elm_code_parser_diff_trim_leading(Elm_Code_Line *line, unsigned int count) } line->length -= count; + line->unicode_length -= count; } static void diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 62ca36c12c..5241b66320 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -37,7 +37,7 @@ _elm_code_line_tokens_move_right(Elm_Code_Line *line, int position, int move) } EAPI void -elm_code_line_text_insert(Elm_Code_Line *line, int position, const char *string, int length) +elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char *string, int length) { Elm_Code_File *file; char *inserted; @@ -46,11 +46,10 @@ elm_code_line_text_insert(Elm_Code_Line *line, int position, const char *string, return; inserted = malloc(sizeof(char) * line->length + length + 1); - position--; + if (position > 0) + position--; if (position > line->length) position = line->length; - if (position < 0) - position = 0; _elm_code_line_tokens_move_right(line, position + 1, length); diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 05b56334ac..73c845da5b 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -22,7 +22,7 @@ extern "C" { EAPI const char *elm_code_line_text_get(Elm_Code_Line *line, int *length); -EAPI void elm_code_line_text_insert(Elm_Code_Line *line, int position, const char *string, int length); +EAPI void elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char *string, int length); /** * @} diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index e14cce6611..e5fb2dcd22 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -105,8 +105,8 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) w = 0; h = elm_code_file_lines_get(pd->code->file); EINA_LIST_FOREACH(pd->code->file->lines, item, line) - if (line->length + gutter + 1 > w) - w = line->length + gutter + 1; + if ((int) line->unicode_length + gutter + 1 > w) + w = (int) line->unicode_length + gutter + 1; if (w*cw > ww) ww = w*cw; @@ -159,7 +159,7 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c offset = elm_code_widget_text_left_gutter_width_get(widget) - 1; start = offset + 1; - length = line->length + offset; + length = line->unicode_length + offset; EINA_LIST_FOREACH(line->tokens, item, token) { @@ -220,7 +220,7 @@ _elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, } static void -_elm_code_widget_fill_whitespace(Elm_Code_Widget *widget EINA_UNUSED, char character, Evas_Textgrid_Cell *cell) +_elm_code_widget_fill_whitespace(Elm_Code_Widget *widget EINA_UNUSED, Eina_Unicode character, Evas_Textgrid_Cell *cell) { switch (character) { @@ -244,33 +244,37 @@ static void _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) { char *chr; + Eina_Unicode unichr; unsigned int length, x; - int w, gutter; + int w, chrpos, gutter; Evas_Textgrid_Cell *cells; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); gutter = elm_code_widget_text_left_gutter_width_get(widget); - length = line->length; evas_object_textgrid_size_get(pd->grid, &w, NULL); cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); _elm_code_widget_fill_gutter(widget, cells, line->status, line->number); _elm_code_widget_fill_line_tokens(widget, cells, w, line); + length = elm_code_line_utf8_length_get(line); + chrpos = 0; if (line->modified) chr = line->modified; else chr = (char *)line->content; + for (x = gutter; x < (unsigned int) w && x < length + gutter; x++) { - cells[x].codepoint = *chr; + unichr = eina_unicode_utf8_next_get(chr, &chrpos); + + cells[x].codepoint = unichr; cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); if (pd->show_whitespace) - _elm_code_widget_fill_whitespace(widget, *chr, &cells[x]); - chr++; + _elm_code_widget_fill_whitespace(widget, unichr, &cells[x]); } for (; x < (unsigned int) w; x++) { @@ -395,7 +399,7 @@ _elm_code_widget_cursor_key_will_move(Elm_Code_Widget *widget, const char *key) else if (!strcmp(key, "Left")) return pd->cursor_col > 1; else if (!strcmp(key, "Right")) - return pd->cursor_col < (unsigned int) line->length + 1; + return pd->cursor_col < (unsigned int) line->unicode_length + 1; else return EINA_FALSE; } @@ -487,8 +491,8 @@ _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas if (!line) return; - if (col > (unsigned int) line->length + 1) - col = line->length + 1; + if (col > (unsigned int) line->unicode_length + 1) + col = line->unicode_length + 1; else if (col == 0) col = 1; @@ -553,8 +557,8 @@ _elm_code_widget_cursor_move_up(Elm_Code_Widget *widget) row--; line = elm_code_file_line_get(pd->code->file, row); - if (col > (unsigned int) line->length + 1) - col = line->length + 1; + if (col > (unsigned int) line->unicode_length + 1) + col = line->unicode_length + 1; _elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE); } @@ -575,8 +579,8 @@ _elm_code_widget_cursor_move_down(Elm_Code_Widget *widget) row++; line = elm_code_file_line_get(pd->code->file, row); - if (col > (unsigned int) line->length + 1) - col = line->length + 1; + if (col > (unsigned int) line->unicode_length + 1) + col = line->unicode_length + 1; _elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE); } @@ -603,7 +607,7 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); line = elm_code_file_line_get(pd->code->file, pd->cursor_line); - if (pd->cursor_col > (unsigned int) line->length) + if (pd->cursor_col > (unsigned int) line->unicode_length) return; _elm_code_widget_cursor_move(widget, pd, pd->cursor_col+1, pd->cursor_line, EINA_TRUE); From 4e14c1a06994e38280c7866a82c2106e1cb3dc9c Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 7 Mar 2015 22:35:59 +0100 Subject: [PATCH 112/254] elm_code unicode: update when editing issues here with inserting unicode which I need to get to --- legacy/elm_code/src/lib/elm_code_text.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 5241b66320..e29bd6ed36 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -69,7 +69,10 @@ elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char } line->modified = inserted; - line->length = line->length + length; + line->length += length; + +// TODO update calculation + line->unicode_length += length; file = line->file; elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); From f96c0345ff642c9cc2e89d997f0afd126ca6a91f Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 8 Mar 2015 09:44:26 +0100 Subject: [PATCH 113/254] elm_code edit: support backspace and delete. don't propogate backspace as other widgets use it to navigate adjust tokens left when we remove content and remove if 0 width token. --- legacy/elm_code/src/lib/elm_code_text.c | 59 +++++++++++++++++++++ legacy/elm_code/src/lib/elm_code_text.h | 2 + legacy/elm_code/src/lib/elm_code_widget.c | 60 ++++++++++++++++++++++ legacy/elm_code/src/lib/elm_code_widget.eo | 1 + 4 files changed, 122 insertions(+) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index e29bd6ed36..08b3155c56 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -36,6 +36,25 @@ _elm_code_line_tokens_move_right(Elm_Code_Line *line, int position, int move) } } +static void +_elm_code_line_tokens_move_left(Elm_Code_Line *line, int position, int move) +{ + Eina_List *item, *next; + Elm_Code_Token *token; + + EINA_LIST_FOREACH_SAFE(line->tokens, item, next, token) + { + if (token->end >= position) + token->end -= move; + + if (token->start > position) + token->start -= move; + + if (token->end < token->start) + line->tokens = eina_list_remove_list(line->tokens, item); + } +} + EAPI void elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char *string, int length) { @@ -77,3 +96,43 @@ elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char file = line->file; elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); } + +EAPI void +elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length) +{ + Elm_Code_File *file; + char *removed; + + if (!line) + return; + + removed = malloc(sizeof(char) * line->length - length + 1); + if (position > 0) + position--; + if (position > line->length) + position = line->length; + + _elm_code_line_tokens_move_left(line, position + 1, length); + + if (line->modified) + { + strncpy(removed, line->modified, position); + strncpy(removed + position, line->modified + position + length, line->length - position - length); + + free(line->modified); + } + else + { + strncpy(removed, line->content, position); + strncpy(removed + position, line->content + position + length, line->length - position - length); + } + + line->modified = removed; + line->length -= length; + +// TODO update calculation + line->unicode_length -= length; + + file = line->file; + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); +} diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 73c845da5b..0f7b38ece9 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -24,6 +24,8 @@ EAPI const char *elm_code_line_text_get(Elm_Code_Line *line, int *length); EAPI void elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char *string, int length); +EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length); + /** * @} */ diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index e5fb2dcd22..5b34c5d69c 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -648,6 +648,45 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) elm_code_widget_cursor_position_set(1, row + 1)); } +static void +_elm_code_widget_backspace(Elm_Code_Widget *widget) +{ + Elm_Code *code; + Elm_Code_Line *line; + unsigned int row, col; + + eo_do(widget, + code = elm_code_widget_code_get(), + elm_code_widget_cursor_position_get(&col, &row)); + + if (col <= 1) + return; + line = elm_code_file_line_get(code->file, row); + + elm_code_line_text_remove(line, col - 1, 1); + eo_do(widget, + elm_code_widget_cursor_position_set(col - 1, row)); +} + +static void +_elm_code_widget_delete(Elm_Code_Widget *widget) +{ + Elm_Code *code; + Elm_Code_Line *line; + unsigned int row, col; + + eo_do(widget, + code = elm_code_widget_code_get(), + elm_code_widget_cursor_position_get(&col, &row)); + line = elm_code_file_line_get(code->file, row); + if (col > line->unicode_length) + return; + + elm_code_line_text_remove(line, col, 1); + eo_do(widget, + elm_code_widget_cursor_position_set(col, row)); +} + static void _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) @@ -676,6 +715,10 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, else if (!strcmp(ev->key, "KP_Enter") || !strcmp(ev->key, "Return")) _elm_code_widget_newline(widget); + else if (!strcmp(ev->key, "BackSpace")) + _elm_code_widget_backspace(widget); + else if (!strcmp(ev->key, "Delete")) + _elm_code_widget_delete(widget); else if (ev->string && strlen(ev->string) == 1) _elm_code_widget_text_at_cursor_insert(widget, ev->string, 1); @@ -713,6 +756,23 @@ _elm_code_widget_unfocused_event_cb(void *data, Evas_Object *obj, _elm_code_widget_fill(obj); } +EOLIAN static Eina_Bool +_elm_code_widget_elm_widget_event(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd EINA_UNUSED, + Evas_Object *src EINA_UNUSED, Evas_Callback_Type type, void *event_info) +{ + Evas_Event_Key_Down *ev = event_info; + + if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE; + + if (!strcmp(ev->key, "BackSpace")) + { + ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; + return EINA_TRUE; + } + + return EINA_FALSE; +} + EOLIAN static Eina_Bool _elm_code_widget_elm_widget_focus_next_manager_is(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd EINA_UNUSED) diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/elm_code_widget.eo index 898eb05672..f3eef61f0b 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/elm_code_widget.eo @@ -173,6 +173,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) Eo.Base.constructor; Eo.Base.finalize; Evas.Object_Smart.add; + Elm_Widget.event; Elm_Widget.focus_next_manager_is; Elm_Widget.focus_direction_manager_is; } From ed521af168c484bf61519f1424e1f6d7869e8ca5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 8 Mar 2015 11:14:02 +0100 Subject: [PATCH 114/254] elm_code line: unsigned int for length --- legacy/elm_code/src/lib/elm_code_diff_widget.c | 4 ++-- legacy/elm_code/src/lib/elm_code_parse.c | 4 ++-- legacy/elm_code/src/lib/elm_code_text.c | 2 +- legacy/elm_code/src/lib/elm_code_text.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.c b/legacy/elm_code/src/lib/elm_code_diff_widget.c index 7c562aecaa..368872414c 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/src/lib/elm_code_diff_widget.c @@ -17,7 +17,7 @@ static void _elm_code_diff_widget_parse_diff_line(Elm_Code_Line *line, Elm_Code_File *left, Elm_Code_File *right) { const char *content; - int length; + unsigned int length; if (line->length < 1) { @@ -49,7 +49,7 @@ _elm_code_diff_widget_parse_diff(Elm_Code_File *diff, Elm_Code_File *left, Elm_C Eina_List *item; Elm_Code_Line *line; const char *content; - int offset, length; + unsigned int offset, length; offset = 0; EINA_LIST_FOREACH(diff->lines, item, line) diff --git a/legacy/elm_code/src/lib/elm_code_parse.c b/legacy/elm_code/src/lib/elm_code_parse.c index c57e877716..912cbaac2c 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.c +++ b/legacy/elm_code/src/lib/elm_code_parse.c @@ -113,7 +113,7 @@ static void _elm_code_parser_diff_parse_line(Elm_Code_Line *line, void *data EINA_UNUSED) { const char *content; - int length; + unsigned int length; content = elm_code_line_text_get(line, &length); if (length < 1) @@ -139,7 +139,7 @@ _elm_code_parser_diff_parse_file(Elm_Code_File *file, void *data EINA_UNUSED) Eina_List *item; Elm_Code_Line *line; const char *content; - int length, offset; + unsigned int length, offset; offset = 0; EINA_LIST_FOREACH(file->lines, item, line) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 08b3155c56..e7a6e6997d 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -7,7 +7,7 @@ #include "elm_code_private.h" EAPI const char * -elm_code_line_text_get(Elm_Code_Line *line, int *length) +elm_code_line_text_get(Elm_Code_Line *line, unsigned int *length) { if (!line) return NULL; diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 0f7b38ece9..0b14378f97 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -20,7 +20,7 @@ extern "C" { * */ -EAPI const char *elm_code_line_text_get(Elm_Code_Line *line, int *length); +EAPI const char *elm_code_line_text_get(Elm_Code_Line *line, unsigned int *length); EAPI void elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char *string, int length); From e951c13e9172f5e3411d194f720c3b178147901a Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 8 Mar 2015 11:15:31 +0100 Subject: [PATCH 115/254] elm_code line: move freeing to the line file --- legacy/elm_code/src/lib/elm_code_file.c | 9 ++------- legacy/elm_code/src/lib/elm_code_line.c | 12 ++++++++++++ legacy/elm_code/src/lib/elm_code_line.h | 2 ++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index d25bdd2895..269eddc4c6 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -136,9 +136,7 @@ EAPI void elm_code_file_free(Elm_Code_File *file) EINA_LIST_FREE(file->lines, l) { - if (l->modified) - free(l->modified); - free(l); + elm_code_line_free(l); } if (file->file) @@ -172,10 +170,7 @@ EAPI void elm_code_file_clear(Elm_Code_File *file) EINA_LIST_FREE(file->lines, l) { - if (l->modified) - free(l->modified); - - free(l); + elm_code_line_free(l); } if (file->parent) diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index e4fcfa41eb..bb8121c02c 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -6,6 +6,18 @@ #include "elm_code_private.h" +EAPI void +elm_code_line_free(Elm_Code_Line *line) +{ + if (!line) + return; + + if (line->modified) + free(line->modified); + + free(line); +} + EAPI unsigned int elm_code_line_utf8_length_get(Elm_Code_Line *line) { diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index b057c64809..af9663ba65 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -34,6 +34,8 @@ typedef struct _Elm_Code_Line void *data; } Elm_Code_Line; +EAPI void elm_code_line_free(Elm_Code_Line *line); + EAPI unsigned int elm_code_line_utf8_length_get(Elm_Code_Line *line); /** From 7f787e8cae71b2262620cb408121c41aa41b8c93 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 8 Mar 2015 11:33:07 +0100 Subject: [PATCH 116/254] elm_code widget: backspace or delete merges lines This is text only for now but serves as editor foundation. --- legacy/elm_code/src/lib/elm_code_file.c | 28 ++++++++++ legacy/elm_code/src/lib/elm_code_file.h | 2 + legacy/elm_code/src/lib/elm_code_text.c | 23 +++++++++ legacy/elm_code/src/lib/elm_code_text.h | 2 + legacy/elm_code/src/lib/elm_code_widget.c | 62 ++++++++++++++++++++++- 5 files changed, 115 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index 269eddc4c6..c2849230e8 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -212,6 +212,34 @@ EAPI void elm_code_file_line_insert(Elm_Code_File *file, unsigned int row, const } } +EAPI void elm_code_file_line_remove(Elm_Code_File *file, unsigned int row) +{ + Eina_List *item, *next; + Elm_Code_Line *line_item, *tofree = NULL; + unsigned int r; + + r = row; + EINA_LIST_FOREACH_SAFE(file->lines, item, next, line_item) + { + if (line_item->number < row) + continue; + else if (line_item->number == row) + { + tofree = line_item; + file->lines = eina_list_remove_list(file->lines, item); + continue; + } + + line_item->number = r++; + + if (file->parent) + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line_item); + } + + if (tofree) + elm_code_line_free(tofree); +} + EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int number) { return eina_list_nth(file->lines, number - 1); diff --git a/legacy/elm_code/src/lib/elm_code_file.h b/legacy/elm_code/src/lib/elm_code_file.h index 24286f60ed..aac206a4ee 100644 --- a/legacy/elm_code/src/lib/elm_code_file.h +++ b/legacy/elm_code/src/lib/elm_code_file.h @@ -62,6 +62,8 @@ EAPI void elm_code_file_line_append(Elm_Code_File *file, const char *line, int l EAPI void elm_code_file_line_insert(Elm_Code_File *file, unsigned int row, const char *line, int length, void *data); +EAPI void elm_code_file_line_remove(Elm_Code_File *file, unsigned int row); + EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int line); /** diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index e7a6e6997d..b71ef5ad32 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -20,6 +20,29 @@ elm_code_line_text_get(Elm_Code_Line *line, unsigned int *length) return line->content; } +EAPI void +elm_code_line_text_set(Elm_Code_Line *line, const char *chars, unsigned int length) +{ + Elm_Code_File *file; + char *newtext; + + if (!line) + return; + + if (line->modified) + free(line->modified); + + newtext = malloc(sizeof(char) * length + 1); + strncpy(newtext, chars, length); + line->modified = newtext; + line->length = length; +// TODO update calculation + line->unicode_length = length; + + file = line->file; + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); +} + static void _elm_code_line_tokens_move_right(Elm_Code_Line *line, int position, int move) { diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 0b14378f97..edd6225932 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -22,6 +22,8 @@ extern "C" { EAPI const char *elm_code_line_text_get(Elm_Code_Line *line, unsigned int *length); +EAPI void elm_code_line_text_set(Elm_Code_Line *line, const char *chars, unsigned int length); + EAPI void elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char *string, int length); EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length); diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 5b34c5d69c..04cc2e85a7 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -648,6 +648,49 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) elm_code_widget_cursor_position_set(1, row + 1)); } +static void +_elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) +{ + Elm_Code *code; + Elm_Code_Line *line, *otherline; + unsigned int row, col; + + const char *text1, *text2; + char *newtext; + unsigned int length1, length2; + + eo_do(widget, + code = elm_code_widget_code_get(), + elm_code_widget_cursor_position_get(&col, &row)); + line = elm_code_file_line_get(code->file, row); + + if (nextline) + { + otherline = elm_code_file_line_get(code->file, row + 1); + text1 = elm_code_line_text_get(line, &length1); + text2 = elm_code_line_text_get(otherline, &length2); + } + else + { + otherline = elm_code_file_line_get(code->file, row - 1); + text1 = elm_code_line_text_get(otherline, &length1); + text2 = elm_code_line_text_get(line, &length2); + } + + newtext = malloc(sizeof(char) * (length1 + length2 + 1)); + snprintf(newtext, length1 + 1, "%s", text1); + snprintf(newtext + length1, length2 + 1, "%s", text2); + +// TODO we need to merge tokens from these lines (move this to elm_code_text) + elm_code_file_line_remove(code->file, otherline->number); + elm_code_line_text_set(line, newtext, length1 + length2); + + free(newtext); + if (!nextline) + eo_do(widget, + elm_code_widget_cursor_position_set(length1 + 1, row - 1)); +} + static void _elm_code_widget_backspace(Elm_Code_Widget *widget) { @@ -660,7 +703,16 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) elm_code_widget_cursor_position_get(&col, &row)); if (col <= 1) - return; + { + if (row == 1) + return; + + _elm_code_widget_backspaceline(widget, EINA_FALSE); + line = elm_code_file_line_get(code->file, row - 1); + + return; + } + line = elm_code_file_line_get(code->file, row); elm_code_line_text_remove(line, col - 1, 1); @@ -680,7 +732,13 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) elm_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); if (col > line->unicode_length) - return; + { + if (row == elm_code_file_lines_get(code->file)) + return; + + _elm_code_widget_backspaceline(widget, EINA_TRUE); + return; + } elm_code_line_text_remove(line, col, 1); eo_do(widget, From 6457da64828a0f2fefc48dfc54d61dcd0690ef46 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 8 Mar 2015 11:52:12 +0100 Subject: [PATCH 117/254] elm_code edit: split content on newline. Tokens also need to be split so this is text only for now --- legacy/elm_code/src/lib/elm_code_widget.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 04cc2e85a7..c76f7f7a9b 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -634,16 +634,24 @@ static void _elm_code_widget_newline(Elm_Code_Widget *widget) { Elm_Code *code; - Elm_Code_Line *line; - unsigned int row, col; + Elm_Code_Line *line, *newline; + unsigned int row, col, length; + char *content; eo_do(widget, code = elm_code_widget_code_get(), elm_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); + content = (char *) elm_code_line_text_get(line, &length); + content = strndup(content, length); elm_code_file_line_insert(code->file, line->number + 1, "", 0, NULL); + newline = elm_code_file_line_get(code->file, line->number + 1); +// TODO we need to split tokens from these lines (move this to elm_code_line?) + elm_code_line_text_set(newline, content + col - 1, length - col + 1); + elm_code_line_text_set(line, content, col - 1); + free(content); eo_do(widget, elm_code_widget_cursor_position_set(1, row + 1)); } @@ -681,7 +689,7 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) snprintf(newtext, length1 + 1, "%s", text1); snprintf(newtext + length1, length2 + 1, "%s", text2); -// TODO we need to merge tokens from these lines (move this to elm_code_text) +// TODO we need to merge tokens from these lines (move this to elm_code_line?) elm_code_file_line_remove(code->file, otherline->number); elm_code_line_text_set(line, newtext, length1 + length2); From ec58b84e3e2277defbacde47012d80d00a26c47d Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 8 Mar 2015 12:07:29 +0100 Subject: [PATCH 118/254] elm_code editor: fix crash backspacing last line fill an empty line if we're deleting the last line --- legacy/elm_code/src/lib/elm_code_widget.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index c76f7f7a9b..38815ba840 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -456,6 +456,7 @@ static void _elm_code_widget_cursor_move(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, unsigned int col, unsigned int line, Eina_Bool was_key) { + Elm_Code *code; unsigned int oldrow; oldrow = pd->cursor_line; @@ -469,7 +470,13 @@ _elm_code_widget_cursor_move(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, _elm_code_widget_cursor_ensure_visible(widget); if (oldrow != pd->cursor_line) - _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, oldrow)); + { + code = pd->code; + if (oldrow <= elm_code_file_lines_get(code->file)) + _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, oldrow)); + else + _elm_code_widget_empty_line(widget, oldrow); + } _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, pd->cursor_line)); } From 7c5d0e38732041465c27b79e0832893a2a8a6f48 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 14 Mar 2015 16:42:56 +0000 Subject: [PATCH 119/254] elm_code unicode: highlight tokens correctly When encountering unicode characters make sure we highlight in the correct columns rather than at the byte locations. --- legacy/elm_code/src/bin/elm_code_test_main.c | 4 +-- legacy/elm_code/src/lib/elm_code_file.c | 18 +--------- legacy/elm_code/src/lib/elm_code_text.c | 35 +++++++++++++++----- legacy/elm_code/src/lib/elm_code_text.h | 18 ++++++++-- legacy/elm_code/src/lib/elm_code_widget.c | 29 ++++++++-------- 5 files changed, 62 insertions(+), 42 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index fd96f20e4a..67f03d0012 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -55,7 +55,7 @@ _elm_code_test_line_done_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, line = (Elm_Code_Line *)event_info; if (line->number == 1) - elm_code_line_token_add(line, 14, 21, 1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 18, 25, 1, ELM_CODE_TOKEN_TYPE_COMMENT); else if (line->number == 4) line->status = ELM_CODE_STATUS_TYPE_ERROR; @@ -76,7 +76,7 @@ _elm_code_test_welcome_setup(Evas_Object *parent) eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_test_line_done_cb, NULL); eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code)); - _append_line(code->file, "Hello World, Elm 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 ***"); diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index c2849230e8..3c4d63fed6 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -21,22 +21,6 @@ static Elm_Code_Line *_elm_code_file_line_blank_create(Elm_Code_File *file, int return ecl; } -static unsigned int -_elm_code_file_line_unicode_strlen(const char *chars, unsigned int length) -{ - unsigned int count = 0; - int index = 0; - - while ((unsigned int) index < length) - { - eina_unicode_utf8_next_get(chars, &index); - - count++; - } - - return count; -} - 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) { @@ -57,7 +41,7 @@ static void _elm_code_file_line_insert_data(Elm_Code_File *file, const char *con line->modified[length] = 0; line->length = length; } - line->unicode_length = _elm_code_file_line_unicode_strlen(content, length); + line->unicode_length = elm_code_text_unicode_strlen(content, length); if (row == 1) file->lines = eina_list_prepend(file->lines, line); diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index b71ef5ad32..ff885d9fba 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -36,8 +36,7 @@ elm_code_line_text_set(Elm_Code_Line *line, const char *chars, unsigned int leng strncpy(newtext, chars, length); line->modified = newtext; line->length = length; -// TODO update calculation - line->unicode_length = length; + line->unicode_length = elm_code_text_unicode_strlen(line->modified, line->length); file = line->file; elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); @@ -112,9 +111,7 @@ elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char line->modified = inserted; line->length += length; - -// TODO update calculation - line->unicode_length += length; + line->unicode_length = elm_code_text_unicode_strlen(line->modified, line->length); file = line->file; elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); @@ -152,10 +149,32 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length line->modified = removed; line->length -= length; - -// TODO update calculation - line->unicode_length -= length; + line->unicode_length = elm_code_text_unicode_strlen(line->modified, line->length); file = line->file; elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); } + +/* generic text functions */ + +EAPI unsigned int +elm_code_text_unicode_strlen(const char *chars, unsigned int length) +{ + Eina_Unicode unicode; + unsigned int count = 0; + int index = 0; + + if (chars == NULL) + return 0; + + while ((unsigned int) index < length) + { + unicode = eina_unicode_utf8_next_get(chars, &index); + if (unicode == 0) + break; + + count++; + } + + return count; +} diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index edd6225932..8049253515 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -11,8 +11,8 @@ extern "C" { */ /** - * @brief Text handling functions. - * @defgroup Text access and manipulation + * @brief Line text handling functions. + * @defgroup Text access and manipulation within lines * * @{ * @@ -28,6 +28,20 @@ EAPI void elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length); +/** + * @} + * + * @brief Generic text handling functions. + * @defgroup Text helper functions + * + * @{ + * + * Functions for managing unicode text. + * + */ + +EAPI unsigned int elm_code_text_unicode_strlen(const char *chars, unsigned int length); + /** * @} */ diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 38815ba840..c17d13ac4d 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -155,24 +155,30 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c { Eina_List *item; Elm_Code_Token *token; - int start, end, length, offset; + const char *content; + unsigned int start, end, length, offset; + unsigned int token_start_col, token_end_col; - offset = elm_code_widget_text_left_gutter_width_get(widget) - 1; - start = offset + 1; + offset = elm_code_widget_text_left_gutter_width_get(widget); + start = offset; + content = elm_code_line_text_get(line, NULL); length = line->unicode_length + offset; EINA_LIST_FOREACH(line->tokens, item, token) { - if (token->start > start) - _elm_code_widget_fill_line_token(cells, count, start, token->start + offset, ELM_CODE_TOKEN_TYPE_DEFAULT); + token_start_col = elm_code_text_unicode_strlen(content, token->start - 1) + offset; + token_end_col = elm_code_text_unicode_strlen(content, token->end - 1) + offset; + + if (token_start_col > start) + _elm_code_widget_fill_line_token(cells, count, start, token_start_col, ELM_CODE_TOKEN_TYPE_DEFAULT); // TODO handle a token starting before the previous finishes - end = token->end; + end = token_end_col; if (token->end_line > line->number) - end = count; - _elm_code_widget_fill_line_token(cells, count, token->start + offset, end + offset, token->type); + end = length + offset; + _elm_code_widget_fill_line_token(cells, count, token_start_col, end, token->type); - start = end + offset + 1; + start = end + 1; } _elm_code_widget_fill_line_token(cells, count, start, length, ELM_CODE_TOKEN_TYPE_DEFAULT); @@ -261,10 +267,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) length = elm_code_line_utf8_length_get(line); chrpos = 0; - if (line->modified) - chr = line->modified; - else - chr = (char *)line->content; + chr = (char *)elm_code_line_text_get(line, NULL); for (x = gutter; x < (unsigned int) w && x < length + gutter; x++) { From 433bac2c1bad953eb9c4c994aed4d2ce73a0cb84 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 15 Mar 2015 23:07:31 +0000 Subject: [PATCH 120/254] elm_code file: detect line endings Check for Windows otherwise default to unix for now. --- legacy/elm_code/src/lib/elm_code_file.c | 19 +++++++++++ legacy/elm_code/src/lib/elm_code_file.h | 8 +++++ .../src/tests/elm_code_file_test_load.c | 34 +++++++++++++++++++ .../elm_code/src/tests/testfile-windows.txt | 4 +++ 4 files changed, 65 insertions(+) create mode 100644 legacy/elm_code/src/tests/testfile-windows.txt diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index 3c4d63fed6..e83a425a5b 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -21,6 +21,17 @@ static Elm_Code_Line *_elm_code_file_line_blank_create(Elm_Code_File *file, int 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) { @@ -93,6 +104,9 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) { 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 */ while (lastindex < line->index - 1) { @@ -148,6 +162,11 @@ EAPI const char *elm_code_file_path_get(Elm_Code_File *file) return eina_file_filename_get(file->file); } +EAPI Elm_Code_File_Line_Ending elm_code_file_line_ending_get(Elm_Code_File *file) +{ + return file->line_ending; +} + EAPI void elm_code_file_clear(Elm_Code_File *file) { Elm_Code_Line *l; diff --git a/legacy/elm_code/src/lib/elm_code_file.h b/legacy/elm_code/src/lib/elm_code_file.h index aac206a4ee..78bca4d1a5 100644 --- a/legacy/elm_code/src/lib/elm_code_file.h +++ b/legacy/elm_code/src/lib/elm_code_file.h @@ -10,6 +10,11 @@ extern "C" { * @brief These routines are used for interacting with files using Elm Code. */ +typedef enum { + ELM_CODE_FILE_LINE_ENDING_UNIX = 0, + ELM_CODE_FILE_LINE_ENDING_WINDOWS +} Elm_Code_File_Line_Ending; + struct _Elm_Code_File { void *parent; @@ -18,6 +23,7 @@ struct _Elm_Code_File Eina_File *file; void *map; + Elm_Code_File_Line_Ending line_ending; }; /** @@ -42,6 +48,8 @@ EAPI const char *elm_code_file_filename_get(Elm_Code_File *file); EAPI const char *elm_code_file_path_get(Elm_Code_File *file); +EAPI Elm_Code_File_Line_Ending elm_code_file_line_ending_get(Elm_Code_File *file); + /** * @} * diff --git a/legacy/elm_code/src/tests/elm_code_file_test_load.c b/legacy/elm_code/src/tests/elm_code_file_test_load.c index 108f087c20..27813fb656 100644 --- a/legacy/elm_code/src/tests/elm_code_file_test_load.c +++ b/legacy/elm_code/src/tests/elm_code_file_test_load.c @@ -80,11 +80,45 @@ START_TEST (elm_code_file_load_content) } END_TEST +START_TEST (elm_code_file_line_ending_unix) +{ + char *path = TESTS_DIR "testfile.txt"; + Elm_Code_File *file; + Elm_Code *code; + + code = elm_code_create(); + file = elm_code_file_open(code, path); + + ck_assert_int_eq(ELM_CODE_FILE_LINE_ENDING_UNIX, elm_code_file_line_ending_get(file)); + + elm_code_file_close(file); + elm_code_free(code); +} +END_TEST + +START_TEST (elm_code_file_line_ending_windows) +{ + char *path = TESTS_DIR "testfile-windows.txt"; + Elm_Code_File *file; + Elm_Code *code; + + code = elm_code_create(); + file = elm_code_file_open(code, path); + + ck_assert_int_eq(ELM_CODE_FILE_LINE_ENDING_WINDOWS, elm_code_file_line_ending_get(file)); + + elm_code_file_close(file); + elm_code_free(code); +} +END_TEST + void elm_code_file_test_load(TCase *tc) { tcase_add_test(tc, elm_code_file_load); tcase_add_test(tc, elm_code_file_load_lines); tcase_add_test(tc, elm_code_file_load_blank_lines); tcase_add_test(tc, elm_code_file_load_content); + tcase_add_test(tc, elm_code_file_line_ending_unix); + tcase_add_test(tc, elm_code_file_line_ending_windows); } diff --git a/legacy/elm_code/src/tests/testfile-windows.txt b/legacy/elm_code/src/tests/testfile-windows.txt new file mode 100644 index 0000000000..c397f82dcb --- /dev/null +++ b/legacy/elm_code/src/tests/testfile-windows.txt @@ -0,0 +1,4 @@ +line 1 +line2 +a third +another line From e4cf9ed41af3ea9d949a5c535943555baeced936 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 17 Mar 2015 22:42:03 +0000 Subject: [PATCH 121/254] elm_code: selection highlighting Adding initial support for displaying selection within the widget --- legacy/elm_code/src/bin/elm_code_test_main.c | 3 + legacy/elm_code/src/lib/Elm_Code.h | 1 + legacy/elm_code/src/lib/Makefile.am | 2 + legacy/elm_code/src/lib/elm_code_private.h | 11 +++ legacy/elm_code/src/lib/elm_code_widget.c | 65 +++++++++++--- .../src/lib/elm_code_widget_selection.c | 89 +++++++++++++++++++ .../src/lib/elm_code_widget_selection.h | 34 +++++++ 7 files changed, 195 insertions(+), 10 deletions(-) create mode 100644 legacy/elm_code/src/lib/elm_code_widget_selection.c create mode 100644 legacy/elm_code/src/lib/elm_code_widget_selection.h diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 67f03d0012..f5f2605855 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -85,6 +85,9 @@ _elm_code_test_welcome_setup(Evas_Object *parent) 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; } diff --git a/legacy/elm_code/src/lib/Elm_Code.h b/legacy/elm_code/src/lib/Elm_Code.h index c435739bf5..332cb95893 100644 --- a/legacy/elm_code/src/lib/Elm_Code.h +++ b/legacy/elm_code/src/lib/Elm_Code.h @@ -40,6 +40,7 @@ #include "elm_code_parse.h" #include "elm_code_widget.eo.h" #include "elm_code_widget_text.h" +#include "elm_code_widget_selection.h" #include "elm_code_diff_widget.h" #ifdef __cplusplus diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index 3691edbf86..9885cbda58 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -25,6 +25,7 @@ elm_code_file.h \ elm_code_parse.h \ elm_code_widget.eo.h \ elm_code_widget_text.h \ +elm_code_widget_selection.h \ elm_code_diff_widget.h \ Elm_Code.h includesdir = $(includedir)/edi-@VMAJ@ @@ -35,6 +36,7 @@ elm_code_text.c \ elm_code_file.c \ elm_code_parse.c \ elm_code_widget_text.c \ +elm_code_widget_selection.c \ elm_code_widget.c \ elm_code_diff_widget.c \ elm_code.c \ diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h index 74232f5ddb..b37a3fffe0 100644 --- a/legacy/elm_code/src/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -26,6 +26,15 @@ extern int _elm_code_lib_log_dom; #endif +/** + * Structure holding the info about a selected region. + */ +typedef struct +{ + unsigned int start_line, end_line; + unsigned int start_col, end_col; +} Elm_Code_Widget_Selection_Data; + typedef struct { Elm_Code *code; @@ -39,6 +48,8 @@ typedef struct Eina_Bool show_line_numbers; unsigned int line_width_marker; Eina_Bool show_whitespace; + + Elm_Code_Widget_Selection_Data *selection; } Elm_Code_Widget_Data; /* Private parser callbacks */ diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index c17d13ac4d..6a070a566c 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -10,6 +10,7 @@ typedef enum { ELM_CODE_WIDGET_COLOR_GUTTER_FG, ELM_CODE_WIDGET_COLOR_WHITESPACE, ELM_CODE_WIDGET_COLOR_CURSOR, + ELM_CODE_WIDGET_COLOR_SELECTION, ELM_CODE_WIDGET_COLOR_COUNT } Elm_Code_Widget_Colors; @@ -226,8 +227,14 @@ _elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, } static void -_elm_code_widget_fill_whitespace(Elm_Code_Widget *widget EINA_UNUSED, Eina_Unicode character, Evas_Textgrid_Cell *cell) +_elm_code_widget_fill_whitespace(Elm_Code_Widget *widget, Eina_Unicode character, Evas_Textgrid_Cell *cell) { + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + if (!pd->show_whitespace) + return; + switch (character) { case ' ': @@ -246,6 +253,47 @@ _elm_code_widget_fill_whitespace(Elm_Code_Widget *widget EINA_UNUSED, Eina_Unico cell->fg = ELM_CODE_WIDGET_COLOR_WHITESPACE; } +static void +_elm_code_widget_fill_cursor(Elm_Code_Widget *widget, Elm_Code_Line *line, Evas_Textgrid_Cell *cells, + int gutter, int w) +{ + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (pd->editable && pd->focussed && pd->cursor_line == line->number) + { + if (pd->cursor_col + gutter - 1 < (unsigned int) w) + cells[pd->cursor_col + gutter - 1].bg = ELM_CODE_WIDGET_COLOR_CURSOR; + } +} + +static void +_elm_code_widget_fill_selection(Elm_Code_Widget *widget, Elm_Code_Line *line, Evas_Textgrid_Cell *cells, + int gutter, int w) +{ + Elm_Code_Widget_Data *pd; + unsigned int x, start, end; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (!pd->selection) + return; + + if (pd->selection->start_line > line->number || pd->selection->end_line < line->number) + return; + + start = pd->selection->start_col; + if (pd->selection->start_line < line->number) + start = 1; + end = pd->selection->end_col; + if (pd->selection->end_line > line->number) + end = w; + + for (x = gutter + start - 1; x < gutter + end && x < (unsigned int) w; x++) + cells[x].bg = ELM_CODE_WIDGET_COLOR_SELECTION; +} + static void _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) { @@ -276,8 +324,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) cells[x].codepoint = unichr; cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); - if (pd->show_whitespace) - _elm_code_widget_fill_whitespace(widget, unichr, &cells[x]); + _elm_code_widget_fill_whitespace(widget, unichr, &cells[x]); } for (; x < (unsigned int) w; x++) { @@ -285,13 +332,9 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); } - if (pd->editable && pd->focussed && pd->cursor_line == line->number) - { - if (pd->cursor_col + gutter - 1 < (unsigned int) w) - cells[pd->cursor_col + gutter - 1].bg = ELM_CODE_WIDGET_COLOR_CURSOR; - } - if (pd->show_whitespace) - _elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]); + _elm_code_widget_fill_cursor(widget, line, cells, gutter, w); + _elm_code_widget_fill_selection(widget, line, cells, gutter, w); + _elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]); evas_object_textgrid_update_add(pd->grid, 0, line->number - 1, w, 1); } @@ -1042,6 +1085,8 @@ _elm_code_widget_setup_palette(Evas_Object *o) // other styles that the widget uses evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_CURSOR, 205, 205, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_SELECTION, + 51, 153, 255, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_BG, 75, 75, 75, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_FG, diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.c b/legacy/elm_code/src/lib/elm_code_widget_selection.c new file mode 100644 index 0000000000..88639fc075 --- /dev/null +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.c @@ -0,0 +1,89 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include "Elm_Code.h" + +#include "elm_code_private.h" + +static Elm_Code_Widget_Selection_Data * +_elm_code_widget_selection_new() +{ + Elm_Code_Widget_Selection_Data *data; + + data = calloc(1, sizeof(Elm_Code_Widget_Selection_Data)); + + return data; +} + +EAPI void +elm_code_widget_selection_start(Evas_Object *widget, + unsigned int line, unsigned int col) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Widget_Selection_Data *selection; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (!pd->selection) + { + selection = _elm_code_widget_selection_new(); + + selection->end_line = line; + selection->end_col = col; + + pd->selection = selection; + } + + pd->selection->start_line = line; + pd->selection->start_col = col; +} + +EAPI void +elm_code_widget_selection_end(Evas_Object *widget, + unsigned int line, unsigned int col) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Widget_Selection_Data *selection; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (!pd->selection) + { + selection = _elm_code_widget_selection_new(); + + selection->start_line = line; + selection->start_col = col; + + pd->selection = selection; + } + + pd->selection->end_line = line; + pd->selection->end_col = col; +} + +EAPI void +elm_code_widget_selection_clear(Evas_Object *widget) +{ + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (pd->selection) + free(pd->selection); + + pd->selection = NULL; +} + +EAPI const char * +elm_code_widget_selection_text_get(Evas_Object *widget) +{ + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (!pd->selection) + return ""; + + return "TODO"; +} diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.h b/legacy/elm_code/src/lib/elm_code_widget_selection.h new file mode 100644 index 0000000000..73e18227a1 --- /dev/null +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.h @@ -0,0 +1,34 @@ +#ifndef ELM_CODE_WIDGET_SELECTION_H_ +# define ELM_CODE_WIDGET_SELECTION_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Selection handling functions. + * @defgroup Managing the complexities of selecting text across seperate lines. + * + * @{ + * + * Functions for selection handling + * + */ + +EAPI void elm_code_widget_selection_start(Evas_Object *widget, unsigned int line, unsigned int col); + +EAPI void elm_code_widget_selection_end(Evas_Object *widget, unsigned int line, unsigned int col); + +EAPI void elm_code_widget_selection_clear(Evas_Object *widget); + +EAPI const char *elm_code_widget_selection_text_get(Evas_Object *widget); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ELM_CODE_WIDGET_SELECTION_H_ */ From 4398dd38f8ef267bee5dd3bc0980965baaed8774 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 18 Mar 2015 22:18:34 +0000 Subject: [PATCH 122/254] elm_code whitespace: only display actual newlines No newlines at the end of a file if there is no other line --- legacy/elm_code/src/lib/elm_code_widget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 6a070a566c..4da9d63854 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -334,7 +334,8 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) _elm_code_widget_fill_cursor(widget, line, cells, gutter, w); _elm_code_widget_fill_selection(widget, line, cells, gutter, w); - _elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]); + if (line->number < elm_code_file_lines_get(line->file)) + _elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]); evas_object_textgrid_update_add(pd->grid, 0, line->number - 1, w, 1); } @@ -402,7 +403,6 @@ _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, return EO_CALLBACK_CONTINUE; } - static Eina_Bool _elm_code_widget_file_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) From 6509d5c1d64a9f4e9f52c3f18f4018d3476a39d5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 18 Mar 2015 22:24:56 +0000 Subject: [PATCH 123/254] elm_code selection: Input selecttion from mouse When editable allow dragging the cursor with a mouse button down then set up a selecttion. --- legacy/elm_code/src/lib/elm_code_widget.c | 131 +++++++++++++++--- legacy/elm_code/src/lib/elm_code_widget.eo | 2 + .../src/lib/elm_code_widget_selection.c | 25 ++++ 3 files changed, 135 insertions(+), 23 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 4da9d63854..923fc9df45 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -415,6 +415,18 @@ _elm_code_widget_file_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descrip return EO_CALLBACK_CONTINUE; } +static Eina_Bool +_elm_code_widget_selection_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + Elm_Code_Widget *widget; + + widget = (Elm_Code_Widget *)data; + + _elm_code_widget_fill(widget); + return EO_CALLBACK_CONTINUE; +} + static void _elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) @@ -526,24 +538,45 @@ _elm_code_widget_cursor_move(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, pd->cursor_line)); } +static Eina_Bool +_elm_code_widget_position_at_coordinates_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, + Evas_Coord x, Evas_Coord y, + unsigned int *row, unsigned int *col) +{ + Elm_Code_Line *line; + Evas_Coord ox, oy, sx, sy; + int cw, ch; + + evas_object_geometry_get(widget, &ox, &oy, NULL, NULL); + elm_scroller_region_get(pd->scroller, &sx, &sy, NULL, NULL); + x = x + sx - ox; + y = y + sy - oy; + + evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); + if (col) + *col = ((double) x / cw) - elm_code_widget_text_left_gutter_width_get(widget) + 1; + if (row) + *row = ((double) y / ch) + 1; + + line = elm_code_file_line_get(pd->code->file, *row); + return !!line; +} + static void _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas_Coord y) { Elm_Code_Widget_Data *pd; Elm_Code_Line *line; - int cw, ch; unsigned int row, col; + Eina_Bool hasline; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); - col = ((double) x / cw) - elm_code_widget_text_left_gutter_width_get(widget) + 1; - row = ((double) y / ch) + 1; - - line = elm_code_file_line_get(pd->code->file, row); - if (!line) + hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, x, y, &row, &col); + if (!hasline) return; + line = elm_code_file_line_get(pd->code->file, row); if (col > (unsigned int) line->unicode_length + 1) col = line->unicode_length + 1; else if (col == 0) @@ -553,45 +586,93 @@ _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas } static void -_elm_code_widget_clicked_readonly_cb(Elm_Code_Widget *widget, Evas_Coord y) +_elm_code_widget_clicked_readonly_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas_Coord y) { Elm_Code_Widget_Data *pd; Elm_Code_Line *line; - int ch; unsigned int row; + Eina_Bool hasline; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - evas_object_textgrid_cell_size_get(pd->grid, NULL, &ch); - row = ((double) y / ch) + 1; + hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, x, y, &row, NULL); + if (!hasline) + return; line = elm_code_file_line_get(pd->code->file, row); - if (line) - eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, line)); + eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, line)); } static void -_elm_code_widget_clicked_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, +_elm_code_widget_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, + void *event_info) +{ + Elm_Code_Widget *widget; + Elm_Code_Widget_Data *pd; + Evas_Event_Mouse_Down *event; + unsigned int row, col; + + widget = (Elm_Code_Widget *)data; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + event = (Evas_Event_Mouse_Down *)event_info; + + elm_code_widget_selection_clear(widget); + if (!pd->editable) + return; + + _elm_code_widget_position_at_coordinates_get(widget, pd, event->canvas.x, event->canvas.y, &row, &col); + elm_code_widget_selection_start(widget, row, col); +} + +static void +_elm_code_widget_mouse_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, + void *event_info) +{ + Elm_Code_Widget *widget; + Elm_Code_Widget_Data *pd; + Evas_Event_Mouse_Move *event; + unsigned int row, col; + + widget = (Elm_Code_Widget *)data; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + event = (Evas_Event_Mouse_Move *)event_info; + + if (!pd->editable || !pd->selection || !event->buttons) + return; + + _elm_code_widget_position_at_coordinates_get(widget, pd, event->cur.canvas.x, event->cur.canvas.y, &row, &col); + + elm_code_widget_selection_end(widget, row, col); +} + +static void +_elm_code_widget_mouse_up_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) { Elm_Code_Widget *widget; Elm_Code_Widget_Data *pd; Evas_Event_Mouse_Up *event; - Evas_Coord x, y, ox, oy, sx, sy; + Evas_Coord x, y; widget = (Elm_Code_Widget *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); event = (Evas_Event_Mouse_Up *)event_info; - evas_object_geometry_get(widget, &ox, &oy, NULL, NULL); - elm_scroller_region_get(pd->scroller, &sx, &sy, NULL, NULL); - x = event->canvas.x + sx - ox; - y = event->canvas.y + sy - oy; + if (pd->selection) + { + if (pd->selection->start_line == pd->selection->end_line && + pd->selection->start_col == pd->selection->end_col) + elm_code_widget_selection_clear(widget); + else + return; + } + x = event->canvas.x; + y = event->canvas.y; if (pd->editable) _elm_code_widget_clicked_editable_cb(widget, x, y); else - _elm_code_widget_clicked_readonly_cb(widget, y); + _elm_code_widget_clicked_readonly_cb(widget, x, y); } static void @@ -1122,15 +1203,19 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) _elm_code_widget_setup_palette(grid); evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, obj); - evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_clicked_cb, obj); + evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_DOWN, _elm_code_widget_mouse_down_cb, obj); + evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_MOVE, _elm_code_widget_mouse_move_cb, obj); + evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_mouse_up_cb, obj); evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget_key_down_cb, obj); evas_object_smart_callback_add(obj, "focused", _elm_code_widget_focused_event_cb, obj); evas_object_smart_callback_add(obj, "unfocused", _elm_code_widget_unfocused_event_cb, obj); eo_do(obj, - eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_widget_line_cb, obj); - eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj)); + eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_widget_line_cb, obj), + eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj), + eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, _elm_code_widget_selection_cb, obj), + eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_cb, obj)); _elm_code_widget_font_size_set(obj, pd, 10); } diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/elm_code_widget.eo index f3eef61f0b..7b6fabe9ba 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/elm_code_widget.eo @@ -180,6 +180,8 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) events { line,clicked; cursor,changed; + selection,changed; + selection,cleared; } } diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.c b/legacy/elm_code/src/lib/elm_code_widget_selection.c index 88639fc075..2a98cda1bf 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.c @@ -16,6 +16,26 @@ _elm_code_widget_selection_new() return data; } +static void +_elm_code_widget_selection_limit(Evas_Object *widget EINA_UNUSED, Elm_Code_Widget_Data *pd, + unsigned int *row, unsigned int *col) +{ + Elm_Code_Line *line; + Elm_Code_File *file; + + file = pd->code->file; + + if (*row > elm_code_file_lines_get(file)) + *row = elm_code_file_lines_get(file); + + line = elm_code_file_line_get(file, *row); + + if (*col > line->unicode_length + 1) + *col = line->unicode_length + 1; + if (*col < 1) + *col = 1; +} + EAPI void elm_code_widget_selection_start(Evas_Object *widget, unsigned int line, unsigned int col) @@ -25,6 +45,7 @@ elm_code_widget_selection_start(Evas_Object *widget, pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + _elm_code_widget_selection_limit(widget, pd, &line, &col); if (!pd->selection) { selection = _elm_code_widget_selection_new(); @@ -37,6 +58,7 @@ elm_code_widget_selection_start(Evas_Object *widget, pd->selection->start_line = line; pd->selection->start_col = col; + eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget)); } EAPI void @@ -48,6 +70,7 @@ elm_code_widget_selection_end(Evas_Object *widget, pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + _elm_code_widget_selection_limit(widget, pd, &line, &col); if (!pd->selection) { selection = _elm_code_widget_selection_new(); @@ -60,6 +83,7 @@ elm_code_widget_selection_end(Evas_Object *widget, pd->selection->end_line = line; pd->selection->end_col = col; + eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget)); } EAPI void @@ -73,6 +97,7 @@ elm_code_widget_selection_clear(Evas_Object *widget) free(pd->selection); pd->selection = NULL; + eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget)); } EAPI const char * From c335a5b921135081392837287c4fc9b785221b22 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 21 Mar 2015 13:58:30 +0000 Subject: [PATCH 124/254] elm_code file: get line ending chars Quickly add support for the line end character sequence. Just windows and Unix now, as per the enum defined. --- legacy/elm_code/src/lib/elm_code_file.c | 15 +++++++++++++++ legacy/elm_code/src/lib/elm_code_file.h | 2 ++ .../elm_code/src/tests/elm_code_file_test_load.c | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index e83a425a5b..292c478cd4 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -167,6 +167,21 @@ EAPI Elm_Code_File_Line_Ending elm_code_file_line_ending_get(Elm_Code_File *file return file->line_ending; } +EAPI const char *elm_code_file_line_ending_chars_get(Elm_Code_File *file, short *length) +{ + if (length) + { + if (elm_code_file_line_ending_get(file) == ELM_CODE_FILE_LINE_ENDING_WINDOWS) + *length = 2; + else + *length = 1; + } + + if (elm_code_file_line_ending_get(file) == ELM_CODE_FILE_LINE_ENDING_WINDOWS) + return "\r\n"; + return "\n"; +} + EAPI void elm_code_file_clear(Elm_Code_File *file) { Elm_Code_Line *l; diff --git a/legacy/elm_code/src/lib/elm_code_file.h b/legacy/elm_code/src/lib/elm_code_file.h index 78bca4d1a5..e0e3e687b3 100644 --- a/legacy/elm_code/src/lib/elm_code_file.h +++ b/legacy/elm_code/src/lib/elm_code_file.h @@ -50,6 +50,8 @@ EAPI const char *elm_code_file_path_get(Elm_Code_File *file); EAPI Elm_Code_File_Line_Ending elm_code_file_line_ending_get(Elm_Code_File *file); +EAPI const char *elm_code_file_line_ending_chars_get(Elm_Code_File *file, short *length); + /** * @} * diff --git a/legacy/elm_code/src/tests/elm_code_file_test_load.c b/legacy/elm_code/src/tests/elm_code_file_test_load.c index 27813fb656..838eadc9b6 100644 --- a/legacy/elm_code/src/tests/elm_code_file_test_load.c +++ b/legacy/elm_code/src/tests/elm_code_file_test_load.c @@ -85,11 +85,14 @@ START_TEST (elm_code_file_line_ending_unix) char *path = TESTS_DIR "testfile.txt"; Elm_Code_File *file; Elm_Code *code; + short len; code = elm_code_create(); file = elm_code_file_open(code, path); ck_assert_int_eq(ELM_CODE_FILE_LINE_ENDING_UNIX, elm_code_file_line_ending_get(file)); + ck_assert_str_eq("\n", elm_code_file_line_ending_chars_get(file, &len)); + ck_assert_int_eq(1, len); elm_code_file_close(file); elm_code_free(code); @@ -101,11 +104,14 @@ START_TEST (elm_code_file_line_ending_windows) char *path = TESTS_DIR "testfile-windows.txt"; Elm_Code_File *file; Elm_Code *code; + short len; code = elm_code_create(); file = elm_code_file_open(code, path); ck_assert_int_eq(ELM_CODE_FILE_LINE_ENDING_WINDOWS, elm_code_file_line_ending_get(file)); + ck_assert_str_eq("\r\n", elm_code_file_line_ending_chars_get(file, &len)); + ck_assert_int_eq(2, len); elm_code_file_close(file); elm_code_free(code); From 015b2cfa9798bbce70892b16ad4cc38b101d5d53 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 21 Mar 2015 19:25:25 +0000 Subject: [PATCH 125/254] elm_code file: add save method to write out lines use a temporary file as we may have mapped the data directly. --- legacy/elm_code/src/lib/elm_code_file.c | 70 +++++++++++++++++++++---- legacy/elm_code/src/lib/elm_code_file.h | 2 + 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index 292c478cd4..ec3b4ad33b 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -71,6 +71,33 @@ static void _elm_code_file_line_insert_data(Elm_Code_File *file, const char *con } } +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; @@ -128,6 +155,39 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) return ret; } +EAPI void elm_code_file_save(Elm_Code_File *file) +{ + Eina_List *item; + Elm_Code_Line *line_item; + const char *path, *content, *crchars; + char *tmp; + unsigned int length; + short crlength; + FILE *out; + + path = elm_code_file_path_get(file); + tmp = _elm_code_file_tmp_path_get(file); + crchars = elm_code_file_line_ending_chars_get(file, &crlength); + + out = fopen(tmp, "w"); + if (out == NULL) + { + free(tmp); + return; + } + + EINA_LIST_FOREACH(file->lines, item, line_item) + { + content = elm_code_line_text_get(line_item, &length); + fwrite(content, sizeof(char), length, out); + fwrite(crchars, sizeof(char), crlength, out); + } + fclose(out); + + ecore_file_mv(tmp, path); + free(tmp); +} + EAPI void elm_code_file_free(Elm_Code_File *file) { Elm_Code_Line *l; @@ -152,16 +212,6 @@ EAPI void elm_code_file_close(Elm_Code_File *file) eina_file_close(file->file); } -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 Elm_Code_File_Line_Ending elm_code_file_line_ending_get(Elm_Code_File *file) { return file->line_ending; diff --git a/legacy/elm_code/src/lib/elm_code_file.h b/legacy/elm_code/src/lib/elm_code_file.h index e0e3e687b3..3c3d4bd339 100644 --- a/legacy/elm_code/src/lib/elm_code_file.h +++ b/legacy/elm_code/src/lib/elm_code_file.h @@ -40,6 +40,8 @@ EAPI Elm_Code_File *elm_code_file_new(Elm_Code *code); EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path); +EAPI void elm_code_file_save(Elm_Code_File *file); + EAPI void elm_code_file_free(Elm_Code_File *file); EAPI void elm_code_file_close(Elm_Code_File *file); From 036622efd21921c57d759ab5de546e2479c2dd2e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 21 Mar 2015 20:04:12 +0000 Subject: [PATCH 126/254] elm_code widget: fire user change events This does not yet have a "change" attached so does not support undo/redo yet --- legacy/elm_code/src/lib/elm_code_widget.c | 19 ++++++++++++++----- legacy/elm_code/src/lib/elm_code_widget.eo | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 923fc9df45..79b0c3b5b9 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -761,7 +761,9 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text elm_code_line_text_insert(line, col, text, length); eo_do(widget, - elm_code_widget_cursor_position_set(col + length, row)); + elm_code_widget_cursor_position_set(col + length, row), +// TODO construct and pass a change object + eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } static void @@ -787,7 +789,9 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) free(content); eo_do(widget, - elm_code_widget_cursor_position_set(1, row + 1)); + elm_code_widget_cursor_position_set(1, row + 1), +// TODO construct and pass a change object + eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } static void @@ -831,6 +835,8 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) if (!nextline) eo_do(widget, elm_code_widget_cursor_position_set(length1 + 1, row - 1)); +// TODO construct and pass a change object + eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } static void @@ -850,8 +856,6 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) return; _elm_code_widget_backspaceline(widget, EINA_FALSE); - line = elm_code_file_line_get(code->file, row - 1); - return; } @@ -860,6 +864,9 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) elm_code_line_text_remove(line, col - 1, 1); eo_do(widget, elm_code_widget_cursor_position_set(col - 1, row)); + +// TODO construct and pass a change object + eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } static void @@ -884,7 +891,9 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) elm_code_line_text_remove(line, col, 1); eo_do(widget, - elm_code_widget_cursor_position_set(col, row)); + elm_code_widget_cursor_position_set(col, row), +// TODO construct and pass a change object + eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } static void diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/elm_code_widget.eo index 7b6fabe9ba..9ef2aa649b 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/elm_code_widget.eo @@ -180,6 +180,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) events { line,clicked; cursor,changed; + changed,user; selection,changed; selection,cleared; } From ef4e5ee6861fc32a1443955fd44620ba603c73a6 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 22 Mar 2015 22:28:07 +0000 Subject: [PATCH 127/254] elm_code selection: move cursor to selection --- legacy/elm_code/src/lib/elm_code_widget_selection.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.c b/legacy/elm_code/src/lib/elm_code_widget_selection.c index 2a98cda1bf..3a50c394c7 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.c @@ -58,7 +58,9 @@ elm_code_widget_selection_start(Evas_Object *widget, pd->selection->start_line = line; pd->selection->start_col = col; - eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget)); + eo_do(widget, + eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget), + elm_code_widget_cursor_position_set(col, line)); } EAPI void From e2718aac979fc22fbefd0eabf7e93af2983a1138 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 22 Mar 2015 22:36:04 +0000 Subject: [PATCH 128/254] elm_code: add text search functions. Update the search and replace UI to work with the new elm_ode UI. --- legacy/elm_code/src/lib/elm_code_text.c | 32 +++++++++++++ legacy/elm_code/src/lib/elm_code_text.h | 6 +++ .../elm_code/src/tests/elm_code_test_text.c | 45 +++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index ff885d9fba..34397fd396 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -42,6 +42,38 @@ elm_code_line_text_set(Elm_Code_Line *line, const char *chars, unsigned int leng elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); } +EAPI int +elm_code_line_text_strpos(Elm_Code_Line *line, const char *search, int offset) +{ + unsigned int length, searchlen, c; + const char *content; + char *ptr; + + searchlen = strlen(search); + content = elm_code_line_text_get(line, &length); + ptr = (char *) content; + + if (searchlen > length) + return ELM_CODE_TEXT_NOT_FOUND; + + ptr += offset; + for (c = offset; c < length - strlen(search); c++) + { + if (!strncmp(ptr, search, searchlen)) + return c; + + ptr++; + } + + return ELM_CODE_TEXT_NOT_FOUND; +} + +EAPI Eina_Bool +elm_code_line_text_contains(Elm_Code_Line *line, const char *search) +{ + return elm_code_line_text_strpos(line, search, 0) != ELM_CODE_TEXT_NOT_FOUND; +} + static void _elm_code_line_tokens_move_right(Elm_Code_Line *line, int position, int move) { diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 8049253515..a051706734 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -1,6 +1,8 @@ #ifndef ELM_CODE_TEXT_H_ # define ELM_CODE_TEXT_H_ +#define ELM_CODE_TEXT_NOT_FOUND -1 + #ifdef __cplusplus extern "C" { #endif @@ -24,6 +26,10 @@ EAPI const char *elm_code_line_text_get(Elm_Code_Line *line, unsigned int *lengt EAPI void elm_code_line_text_set(Elm_Code_Line *line, const char *chars, unsigned int length); +EAPI int elm_code_line_text_strpos(Elm_Code_Line *line, const char *search, int offset); + +EAPI Eina_Bool elm_code_line_text_contains(Elm_Code_Line *line, const char *search); + EAPI void elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char *string, int length); EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length); diff --git a/legacy/elm_code/src/tests/elm_code_test_text.c b/legacy/elm_code/src/tests/elm_code_test_text.c index 44c2fd3621..3aad59e2f1 100644 --- a/legacy/elm_code/src/tests/elm_code_test_text.c +++ b/legacy/elm_code/src/tests/elm_code_test_text.c @@ -37,8 +37,53 @@ START_TEST (elm_code_text_insert_test) } END_TEST +START_TEST (elm_code_text_contains_test) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + + code = elm_code_create(); + file = elm_code_file_new(code); + + elm_code_file_line_append(file, "a test string...", 17, NULL); + line = elm_code_file_line_get(file, 1); + + ck_assert_int_eq(EINA_TRUE, elm_code_line_text_contains(line, "test")); + ck_assert_int_eq(EINA_FALSE, elm_code_line_text_contains(line, "text")); + + ck_assert_int_eq(EINA_TRUE, elm_code_line_text_contains(line, "a t")); + ck_assert_int_eq(EINA_TRUE, elm_code_line_text_contains(line, "...")); +} +END_TEST + +START_TEST (elm_code_text_strpos_test) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + + code = elm_code_create(); + file = elm_code_file_new(code); + + elm_code_file_line_append(file, "a test string...", 17, NULL); + line = elm_code_file_line_get(file, 1); + + ck_assert_int_eq(2, elm_code_line_text_strpos(line, "test", 0)); + ck_assert_int_eq(2, elm_code_line_text_strpos(line, "test", 1)); + ck_assert_int_eq(2, elm_code_line_text_strpos(line, "test", 2)); + ck_assert_int_eq(ELM_CODE_TEXT_NOT_FOUND, elm_code_line_text_strpos(line, "test", 5)); + ck_assert_int_eq(ELM_CODE_TEXT_NOT_FOUND, elm_code_line_text_strpos(line, "text", 0)); + + ck_assert_int_eq(0, elm_code_line_text_strpos(line, "a t", 0)); + ck_assert_int_eq(13, elm_code_line_text_strpos(line, "...", 0)); +} +END_TEST + void elm_code_test_text(TCase *tc) { tcase_add_test(tc, elm_code_text_get_test); tcase_add_test(tc, elm_code_text_insert_test); + tcase_add_test(tc, elm_code_text_contains_test); + tcase_add_test(tc, elm_code_text_strpos_test); } From 7eede66db66d35c4389bd60ca6fc3ce1f33f7c18 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 17 Mar 2015 08:45:04 +0000 Subject: [PATCH 129/254] elm_code: Remove accidental dep on efl-git --- legacy/elm_code/src/lib/elm_code_widget.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 310db71e17..958b7e5e05 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -29,7 +29,9 @@ Eina_Unicode status_icons[] = { #define EO_CONSTRUCTOR_CHECK_RETURN(obj) do { \ Eina_Bool finalized; \ - if (eo_do_ret(obj, finalized, eo_finalized_get())) \ + \ + eo_do(obj, finalized = eo_finalized_get()); \ + if (finalized) \ { \ ERR("This function is only allowed during construction."); \ return; \ From 35866daf6a7fc45a3641f5c32403443d771ba365 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 25 Mar 2015 21:55:00 +0000 Subject: [PATCH 130/254] elm_code selection: test and implement single line Multi line selection still to come --- legacy/elm_code/src/lib/elm_code_text.c | 15 ++++ legacy/elm_code/src/lib/elm_code_text.h | 2 + .../src/lib/elm_code_widget_selection.c | 15 +++- .../src/lib/elm_code_widget_selection.h | 2 +- legacy/elm_code/src/tests/Makefile.am | 1 + legacy/elm_code/src/tests/elm_code_suite.c | 1 + legacy/elm_code/src/tests/elm_code_suite.h | 1 + .../tests/elm_code_test_widget_selection.c | 73 +++++++++++++++++++ 8 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 legacy/elm_code/src/tests/elm_code_test_widget_selection.c diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 34397fd396..a9e86be57a 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -74,6 +74,21 @@ elm_code_line_text_contains(Elm_Code_Line *line, const char *search) return elm_code_line_text_strpos(line, search, 0) != ELM_CODE_TEXT_NOT_FOUND; } +EAPI char * +elm_code_line_text_substr(Elm_Code_Line *line, unsigned int position, int length) +{ + const char *content; + + if (!line || length < 1) + return strdup(""); + + if (position + length > line->length) + length = line->length - position; + + content = elm_code_line_text_get(line, NULL); + return strndup(content + position, length); +} + static void _elm_code_line_tokens_move_right(Elm_Code_Line *line, int position, int move) { diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index a051706734..3df2ff6774 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -30,6 +30,8 @@ EAPI int elm_code_line_text_strpos(Elm_Code_Line *line, const char *search, int EAPI Eina_Bool elm_code_line_text_contains(Elm_Code_Line *line, const char *search); +EAPI char *elm_code_line_text_substr(Elm_Code_Line *line, unsigned int position, int length); + EAPI void elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char *string, int length); EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length); diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.c b/legacy/elm_code/src/lib/elm_code_widget_selection.c index 3a50c394c7..671ccd383b 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.c @@ -102,15 +102,24 @@ elm_code_widget_selection_clear(Evas_Object *widget) eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget)); } -EAPI const char * +EAPI char * elm_code_widget_selection_text_get(Evas_Object *widget) { Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (!pd->selection) - return ""; + return strdup(""); - return "TODO"; + if (pd->selection->start_line == pd->selection->end_line) + { + line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); + + return elm_code_line_text_substr(line, pd->selection->start_col - 1, + pd->selection->end_col - pd->selection->start_col + 1); + } + + return strdup("TODO"); } diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.h b/legacy/elm_code/src/lib/elm_code_widget_selection.h index 73e18227a1..0484414934 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.h +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.h @@ -21,7 +21,7 @@ EAPI void elm_code_widget_selection_end(Evas_Object *widget, unsigned int line, EAPI void elm_code_widget_selection_clear(Evas_Object *widget); -EAPI const char *elm_code_widget_selection_text_get(Evas_Object *widget); +EAPI char *elm_code_widget_selection_text_get(Evas_Object *widget); /** * @} diff --git a/legacy/elm_code/src/tests/Makefile.am b/legacy/elm_code/src/tests/Makefile.am index 99ec87f35f..131aa1e448 100644 --- a/legacy/elm_code/src/tests/Makefile.am +++ b/legacy/elm_code/src/tests/Makefile.am @@ -12,6 +12,7 @@ elm_code_test_basic.c \ elm_code_test_parse.c \ elm_code_test_text.c \ elm_code_test_widget.c \ +elm_code_test_widget_selection.c \ elm_code_suite.c elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/src/lib/ \ diff --git a/legacy/elm_code/src/tests/elm_code_suite.c b/legacy/elm_code/src/tests/elm_code_suite.c index ec0f93c2bb..d45976869f 100644 --- a/legacy/elm_code/src/tests/elm_code_suite.c +++ b/legacy/elm_code/src/tests/elm_code_suite.c @@ -19,6 +19,7 @@ static const struct { { "text", elm_code_test_text }, { "basic", elm_code_test_basic }, { "widget", elm_code_test_widget }, + { "widget_selection", elm_code_test_widget_selection }, }; START_TEST(elm_code_initialization) diff --git a/legacy/elm_code/src/tests/elm_code_suite.h b/legacy/elm_code/src/tests/elm_code_suite.h index cd98285efa..d03e11b565 100644 --- a/legacy/elm_code/src/tests/elm_code_suite.h +++ b/legacy/elm_code/src/tests/elm_code_suite.h @@ -11,5 +11,6 @@ void elm_code_test_basic(TCase *tc); void elm_code_test_parse(TCase *tc); void elm_code_test_text(TCase *tc); void elm_code_test_widget(TCase *tc); +void elm_code_test_widget_selection(TCase *tc); #endif /* _EDLM_CODE_SUITE_H */ diff --git a/legacy/elm_code/src/tests/elm_code_test_widget_selection.c b/legacy/elm_code/src/tests/elm_code_test_widget_selection.c new file mode 100644 index 0000000000..512cb3c114 --- /dev/null +++ b/legacy/elm_code/src/tests/elm_code_test_widget_selection.c @@ -0,0 +1,73 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "elm_code_suite.h" + +#include "elm_code_widget_selection.h" + +START_TEST (elm_code_test_widget_selection_set) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Widget *widget; + Evas_Object *win; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "test", 4, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = eo_add(ELM_CODE_WIDGET_CLASS, win, + elm_code_widget_code_set(code)); + + elm_code_widget_selection_start(widget, 1, 2); + elm_code_widget_selection_end(widget, 1, 3); + elm_code_widget_selection_clear(widget); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + +START_TEST (elm_code_test_widget_selection_text_get) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Widget *widget; + Evas_Object *win; + char *selection; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "test", 4, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = eo_add(ELM_CODE_WIDGET_CLASS, win, + elm_code_widget_code_set(code)); + + ck_assert_str_eq("", elm_code_widget_selection_text_get(widget)); + + elm_code_widget_selection_start(widget, 1, 2); + elm_code_widget_selection_end(widget, 1, 3); + + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("es", selection); + free(selection); + + elm_code_widget_selection_clear(widget); + ck_assert_str_eq("", elm_code_widget_selection_text_get(widget)); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + +void elm_code_test_widget_selection(TCase *tc) +{ + tcase_add_test(tc, elm_code_test_widget_selection_set); + tcase_add_test(tc, elm_code_test_widget_selection_text_get); +} + From fabfa95d06311651c20909d79775595256515382 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 25 Mar 2015 22:17:41 +0000 Subject: [PATCH 131/254] elm_code selection: support two line selection --- .../src/lib/elm_code_widget_selection.c | 50 ++++++++++++++++--- .../tests/elm_code_test_widget_selection.c | 31 ++++++++++++ 2 files changed, 73 insertions(+), 8 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.c b/legacy/elm_code/src/lib/elm_code_widget_selection.c index 671ccd383b..4a3bd2ca49 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.c @@ -102,24 +102,58 @@ elm_code_widget_selection_clear(Evas_Object *widget) eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget)); } +static char * +_elm_code_widget_selection_text_single_get(Elm_Code_Widget_Data *pd) +{ + Elm_Code_Line *line; + + line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); + + return elm_code_line_text_substr(line, pd->selection->start_col - 1, + pd->selection->end_col - pd->selection->start_col + 1); +} + +static char * +_elm_code_widget_selection_text_multi_get(Elm_Code_Widget_Data *pd) +{ + Elm_Code_Line *line; + char *first, *last, *ret; + const char *newline; + short newline_len; + int ret_len; + + newline = elm_code_file_line_ending_chars_get(pd->code->file, &newline_len); + + line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); + first = elm_code_line_text_substr(line, pd->selection->start_col - 1, + line->length - pd->selection->start_col + 1); + + line = elm_code_file_line_get(pd->code->file, pd->selection->end_line); + last = elm_code_line_text_substr(line, 0, pd->selection->end_col + 1); + + ret_len = strlen(first) + strlen(last) + newline_len; + ret = malloc(sizeof(char) * (ret_len + 1)); + snprintf(ret, ret_len, "%s%s%s", first, newline, last); + + free(first); + free(last); + return ret; +} + EAPI char * elm_code_widget_selection_text_get(Evas_Object *widget) { Elm_Code_Widget_Data *pd; - Elm_Code_Line *line; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (!pd->selection) + if (!pd->selection || pd->selection->end_line < pd->selection->start_line) return strdup(""); if (pd->selection->start_line == pd->selection->end_line) - { - line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); - - return elm_code_line_text_substr(line, pd->selection->start_col - 1, - pd->selection->end_col - pd->selection->start_col + 1); - } + return _elm_code_widget_selection_text_single_get(pd); + else + return _elm_code_widget_selection_text_multi_get(pd); return strdup("TODO"); } diff --git a/legacy/elm_code/src/tests/elm_code_test_widget_selection.c b/legacy/elm_code/src/tests/elm_code_test_widget_selection.c index 512cb3c114..a475344cce 100644 --- a/legacy/elm_code/src/tests/elm_code_test_widget_selection.c +++ b/legacy/elm_code/src/tests/elm_code_test_widget_selection.c @@ -65,9 +65,40 @@ START_TEST (elm_code_test_widget_selection_text_get) } END_TEST +START_TEST (elm_code_test_widget_selection_text_get_multiline) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Widget *widget; + Evas_Object *win; + char *selection; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "test", 4, NULL); + elm_code_file_line_append(file, "test", 4, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = eo_add(ELM_CODE_WIDGET_CLASS, win, + elm_code_widget_code_set(code)); + + elm_code_widget_selection_start(widget, 1, 3); + elm_code_widget_selection_end(widget, 2, 2); + + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("st\nte", selection); + free(selection); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + void elm_code_test_widget_selection(TCase *tc) { tcase_add_test(tc, elm_code_test_widget_selection_set); tcase_add_test(tc, elm_code_test_widget_selection_text_get); + tcase_add_test(tc, elm_code_test_widget_selection_text_get_multiline); } From 71b80a15475504503990a174749ac0534770cd15 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 25 Mar 2015 22:55:32 +0000 Subject: [PATCH 132/254] elm_code selection: complete multiline text get ready for copy and cut functions --- .../src/lib/elm_code_widget_selection.c | 30 ++++++++++++++-- .../tests/elm_code_test_widget_selection.c | 34 ++++++++++++++++++- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.c b/legacy/elm_code/src/lib/elm_code_widget_selection.c index 4a3bd2ca49..ce0f937832 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.c @@ -117,10 +117,11 @@ static char * _elm_code_widget_selection_text_multi_get(Elm_Code_Widget_Data *pd) { Elm_Code_Line *line; - char *first, *last, *ret; + char *first, *last, *ret, *ptr; const char *newline; short newline_len; int ret_len; + unsigned int row; newline = elm_code_file_line_ending_chars_get(pd->code->file, &newline_len); @@ -129,11 +130,34 @@ _elm_code_widget_selection_text_multi_get(Elm_Code_Widget_Data *pd) line->length - pd->selection->start_col + 1); line = elm_code_file_line_get(pd->code->file, pd->selection->end_line); - last = elm_code_line_text_substr(line, 0, pd->selection->end_col + 1); + last = elm_code_line_text_substr(line, 0, pd->selection->end_col); ret_len = strlen(first) + strlen(last) + newline_len; + + for (row = pd->selection->start_line + 1; row < pd->selection->end_line; row++) + { + line = elm_code_file_line_get(pd->code->file, row); + ret_len += line->length + newline_len; + } + ret = malloc(sizeof(char) * (ret_len + 1)); - snprintf(ret, ret_len, "%s%s%s", first, newline, last); + snprintf(ret, strlen(first) + newline_len + 1, "%s%s", first, newline); + + ptr = ret; + ptr += strlen(first) + newline_len; + + for (row = pd->selection->start_line + 1; row < pd->selection->end_line; row++) + { + line = elm_code_file_line_get(pd->code->file, row); + if (line->modified) + snprintf(ptr, line->length + 1, "%s", line->modified); + else + snprintf(ptr, line->length + 1, "%s", line->content); + + snprintf(ptr + line->length, newline_len + 1, "%s", newline); + ptr += line->length + newline_len; + } + snprintf(ptr, strlen(last) + 1, "%s", last); free(first); free(last); diff --git a/legacy/elm_code/src/tests/elm_code_test_widget_selection.c b/legacy/elm_code/src/tests/elm_code_test_widget_selection.c index a475344cce..0e829bceb7 100644 --- a/legacy/elm_code/src/tests/elm_code_test_widget_selection.c +++ b/legacy/elm_code/src/tests/elm_code_test_widget_selection.c @@ -65,7 +65,7 @@ START_TEST (elm_code_test_widget_selection_text_get) } END_TEST -START_TEST (elm_code_test_widget_selection_text_get_multiline) +START_TEST (elm_code_test_widget_selection_text_get_twoline) { Elm_Code *code; Elm_Code_File *file; @@ -95,10 +95,42 @@ START_TEST (elm_code_test_widget_selection_text_get_multiline) } END_TEST +START_TEST (elm_code_test_widget_selection_text_get_multiline) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Widget *widget; + Evas_Object *win; + char *selection; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "test", 4, NULL); + elm_code_file_line_append(file, "test", 4, NULL); + elm_code_file_line_append(file, "test", 4, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = eo_add(ELM_CODE_WIDGET_CLASS, win, + elm_code_widget_code_set(code)); + + elm_code_widget_selection_start(widget, 1, 3); + elm_code_widget_selection_end(widget, 3, 2); + + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("st\ntest\nte", selection); + free(selection); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + void elm_code_test_widget_selection(TCase *tc) { tcase_add_test(tc, elm_code_test_widget_selection_set); tcase_add_test(tc, elm_code_test_widget_selection_text_get); + tcase_add_test(tc, elm_code_test_widget_selection_text_get_twoline); tcase_add_test(tc, elm_code_test_widget_selection_text_get_multiline); } From 903d9a9875f1a472a0b6e479960eec85306b20b9 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 25 Mar 2015 22:59:42 +0000 Subject: [PATCH 133/254] fix wrong types / names --- legacy/elm_code/src/bin/elm_code_test_main.c | 2 +- legacy/elm_code/src/tests/elm_code_test_widget.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index f5f2605855..416ae79303 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -43,7 +43,7 @@ _elm_code_test_line_clicked_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, line = (Elm_Code_Line *)event_info; printf("CLICKED line %d\n", line->number); - return EINA_TRUE; + return EO_CALLBACK_CONTINUE; } static Eina_Bool diff --git a/legacy/elm_code/src/tests/elm_code_test_widget.c b/legacy/elm_code/src/tests/elm_code_test_widget.c index a16d270be3..3f53fe36b6 100644 --- a/legacy/elm_code/src/tests/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/elm_code_test_widget.c @@ -44,7 +44,8 @@ END_TEST START_TEST (elm_code_widget_construct) { Elm_Code *code; - Elm_Code_Widget *widget, *win; + Elm_Code_Widget *widget; + Evas_Object *win; elm_init(1, NULL); code = elm_code_create(); @@ -61,7 +62,8 @@ END_TEST START_TEST (elm_code_widget_construct_nocode) { - Elm_Code_Widget *widget, *win; + Elm_Code_Widget *widget; + Evas_Object *win; elm_init(1, NULL); From b72fdea48895bf4b5f53e877e62025ec6c68c834 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 27 Mar 2015 21:45:43 +0000 Subject: [PATCH 134/254] elm_code file: test windows with new eina fixes Should pass from eina 1.13.99 --- .../elm_code/src/tests/elm_code_file_test_load.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/legacy/elm_code/src/tests/elm_code_file_test_load.c b/legacy/elm_code/src/tests/elm_code_file_test_load.c index 838eadc9b6..02a6f7ee74 100644 --- a/legacy/elm_code/src/tests/elm_code_file_test_load.c +++ b/legacy/elm_code/src/tests/elm_code_file_test_load.c @@ -52,6 +52,21 @@ START_TEST (elm_code_file_load_blank_lines) } END_TEST +START_TEST (elm_code_file_load_windows) +{ + char *path = TESTS_DIR "testfile-windows.txt"; + Elm_Code_File *file; + Elm_Code *code; + + code = elm_code_create(); + file = elm_code_file_open(code, path); + + ck_assert_uint_eq(4, elm_code_file_lines_get(file)); + elm_code_file_close(file); + elm_code_free(code); +} +END_TEST + static void _assert_line_content_eq(const char *content, Elm_Code_Line *line) { int length; @@ -123,6 +138,7 @@ void elm_code_file_test_load(TCase *tc) tcase_add_test(tc, elm_code_file_load); tcase_add_test(tc, elm_code_file_load_lines); tcase_add_test(tc, elm_code_file_load_blank_lines); + tcase_add_test(tc, elm_code_file_load_windows); tcase_add_test(tc, elm_code_file_load_content); tcase_add_test(tc, elm_code_file_line_ending_unix); tcase_add_test(tc, elm_code_file_line_ending_windows); From c509a2ba98e7ee69bd8524f2ab6ca980b4431890 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 27 Mar 2015 23:45:23 +0000 Subject: [PATCH 135/254] Note that a fix is now temporary --- legacy/elm_code/src/lib/elm_code_file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index ec3b4ad33b..41a7e8f1c7 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -135,6 +135,7 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) 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); From 71233e8a3030b2a8bc8388785c7f02567fc48d36 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 27 Mar 2015 23:54:28 +0000 Subject: [PATCH 136/254] clang: save errors and display if clicked Using a gutter click in elm_code to print to console for now --- legacy/elm_code/src/lib/elm_code_line.c | 2 + legacy/elm_code/src/lib/elm_code_line.h | 1 + legacy/elm_code/src/lib/elm_code_widget.c | 70 ++++++++++++++-------- legacy/elm_code/src/lib/elm_code_widget.eo | 1 + 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index bb8121c02c..d7d9ee6b2e 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -12,6 +12,8 @@ elm_code_line_free(Elm_Code_Line *line) if (!line) return; + if (line->status_text) + free((char *)line->status_text); if (line->modified) free(line->modified); diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index af9663ba65..3cb1baf7e0 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -32,6 +32,7 @@ typedef struct _Elm_Code_Line Eina_List *tokens; void *data; + const char *status_text; } Elm_Code_Line; EAPI void elm_code_line_free(Elm_Code_Line *line); diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 6eec759d3d..68dc4aec31 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -2,7 +2,7 @@ # include "config.h" #endif -#include +#include "Elm_Code.h" #include "elm_code_private.h" typedef enum { @@ -543,11 +543,12 @@ _elm_code_widget_cursor_move(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, static Eina_Bool _elm_code_widget_position_at_coordinates_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Evas_Coord x, Evas_Coord y, - unsigned int *row, unsigned int *col) + unsigned int *row, int *col) { Elm_Code_Line *line; Evas_Coord ox, oy, sx, sy; int cw, ch; + unsigned int number; evas_object_geometry_get(widget, &ox, &oy, NULL, NULL); elm_scroller_region_get(pd->scroller, &sx, &sy, NULL, NULL); @@ -555,53 +556,62 @@ _elm_code_widget_position_at_coordinates_get(Elm_Code_Widget *widget, Elm_Code_W y = y + sy - oy; evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); + number = ((double) y / ch) + 1; if (col) *col = ((double) x / cw) - elm_code_widget_text_left_gutter_width_get(widget) + 1; if (row) - *row = ((double) y / ch) + 1; + *row = number; - line = elm_code_file_line_get(pd->code->file, *row); + line = elm_code_file_line_get(pd->code->file, number); return !!line; } static void -_elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas_Coord y) +_elm_code_widget_clicked_gutter_cb(Elm_Code_Widget *widget, unsigned int row) { Elm_Code_Widget_Data *pd; Elm_Code_Line *line; - unsigned int row, col; - Eina_Bool hasline; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, x, y, &row, &col); - if (!hasline) + line = elm_code_file_line_get(pd->code->file, row); + if (!line) return; + eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_LINE_GUTTER_CLICKED, line)); +} + +static void +_elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, unsigned int row, unsigned int col) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + line = elm_code_file_line_get(pd->code->file, row); - if (col > (unsigned int) line->unicode_length + 1) + if (!line) + return; + + if (col > line->unicode_length + 1) col = line->unicode_length + 1; - else if (col == 0) + else if (col <= 0) col = 1; _elm_code_widget_cursor_move(widget, pd, col, row, EINA_FALSE); } static void -_elm_code_widget_clicked_readonly_cb(Elm_Code_Widget *widget, Evas_Coord x, Evas_Coord y) +_elm_code_widget_clicked_readonly_cb(Elm_Code_Widget *widget, unsigned int row) { Elm_Code_Widget_Data *pd; Elm_Code_Line *line; - unsigned int row; - Eina_Bool hasline; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - - hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, x, y, &row, NULL); - if (!hasline) + line = elm_code_file_line_get(pd->code->file, row); + if (!line) return; - line = elm_code_file_line_get(pd->code->file, row); eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, line)); } @@ -612,7 +622,8 @@ _elm_code_widget_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj Elm_Code_Widget *widget; Elm_Code_Widget_Data *pd; Evas_Event_Mouse_Down *event; - unsigned int row, col; + unsigned int row; + int col; widget = (Elm_Code_Widget *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); @@ -623,7 +634,8 @@ _elm_code_widget_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj return; _elm_code_widget_position_at_coordinates_get(widget, pd, event->canvas.x, event->canvas.y, &row, &col); - elm_code_widget_selection_start(widget, row, col); + if (col > 0) + elm_code_widget_selection_start(widget, row, col); } static void @@ -633,7 +645,8 @@ _elm_code_widget_mouse_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj Elm_Code_Widget *widget; Elm_Code_Widget_Data *pd; Evas_Event_Mouse_Move *event; - unsigned int row, col; + unsigned int row; + int col; widget = (Elm_Code_Widget *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); @@ -655,6 +668,9 @@ _elm_code_widget_mouse_up_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj E Elm_Code_Widget_Data *pd; Evas_Event_Mouse_Up *event; Evas_Coord x, y; + unsigned int row; + int col; + Eina_Bool hasline; widget = (Elm_Code_Widget *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); @@ -671,10 +687,16 @@ _elm_code_widget_mouse_up_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj E x = event->canvas.x; y = event->canvas.y; - if (pd->editable) - _elm_code_widget_clicked_editable_cb(widget, x, y); + hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, x, y, &row, &col); + if (!hasline) + return; + + if (col <= 0) + _elm_code_widget_clicked_gutter_cb(widget, row); + else if (pd->editable) + _elm_code_widget_clicked_editable_cb(widget, row, (unsigned int) col); else - _elm_code_widget_clicked_readonly_cb(widget, x, y); + _elm_code_widget_clicked_readonly_cb(widget, row); } static void diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/elm_code_widget.eo index 9ef2aa649b..98b35cc012 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/elm_code_widget.eo @@ -179,6 +179,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) } events { line,clicked; + line,gutter,clicked; cursor,changed; changed,user; selection,changed; From 94642cac2dd4dc52bdd23b65deba0e7cd899d74e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 28 Mar 2015 15:17:08 +0000 Subject: [PATCH 137/254] elm_code selection: Support selection deletion In the widget we always delete the selection if typing begins. If delete or backspace was pressed don't execute the keystroke after. --- legacy/elm_code/src/lib/elm_code_widget.c | 22 ++++ .../src/lib/elm_code_widget_selection.c | 73 +++++++++++- .../src/lib/elm_code_widget_selection.h | 2 + .../tests/elm_code_test_widget_selection.c | 112 ++++++++++++++++++ 4 files changed, 207 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 68dc4aec31..f180b7f2f4 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -771,6 +771,20 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) _elm_code_widget_cursor_move(widget, pd, pd->cursor_col+1, pd->cursor_line, EINA_TRUE); } +static Eina_Bool +_elm_code_widget_delete_selection(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (!pd->selection) + return EINA_FALSE; + + elm_code_widget_selection_delete(widget); + return EINA_TRUE; +} + static void _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text, int length) { @@ -778,6 +792,7 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text Elm_Code_Line *line; unsigned int row, col; + _elm_code_widget_delete_selection(widget); eo_do(widget, code = elm_code_widget_code_get(), elm_code_widget_cursor_position_get(&col, &row)); @@ -798,6 +813,7 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) unsigned int row, col, length; char *content; + _elm_code_widget_delete_selection(widget); eo_do(widget, code = elm_code_widget_code_get(), elm_code_widget_cursor_position_get(&col, &row)); @@ -870,6 +886,9 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) Elm_Code_Line *line; unsigned int row, col; + if (_elm_code_widget_delete_selection(widget)) + return; + eo_do(widget, code = elm_code_widget_code_get(), elm_code_widget_cursor_position_get(&col, &row)); @@ -900,6 +919,9 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) Elm_Code_Line *line; unsigned int row, col; + if (_elm_code_widget_delete_selection(widget)) + return; + eo_do(widget, code = elm_code_widget_code_get(), elm_code_widget_cursor_position_get(&col, &row)); diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.c b/legacy/elm_code/src/lib/elm_code_widget_selection.c index ce0f937832..d9faaaa1ae 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.c @@ -102,6 +102,77 @@ elm_code_widget_selection_clear(Evas_Object *widget) eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget)); } +static void +_elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd) +{ + Elm_Code_Line *line; + const char *old; + unsigned int old_length, length; + char *content; + + if (pd->selection->end_col <= pd->selection->start_col) + return; + + line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); + old = elm_code_line_text_get(line, &old_length); + length = line->length - (pd->selection->end_col - pd->selection->start_col); + content = malloc(sizeof(char) * (length + 1)); + snprintf(content, pd->selection->start_col, old); + snprintf(content + pd->selection->start_col - 1, old_length - pd->selection->end_col + 1, + old + pd->selection->end_col); + elm_code_line_text_set(line, content, length); + free(content); +} + +static void +_elm_code_widget_selection_delete_multi(Elm_Code_Widget_Data *pd) +{ + Elm_Code_Line *line; + const char *first, *last; + unsigned int last_length, length, i; + char *content; + + if (pd->selection->end_line <= pd->selection->start_line) + return; + + line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); + first = elm_code_line_text_get(line, NULL); + line = elm_code_file_line_get(pd->code->file, pd->selection->end_line); + last = elm_code_line_text_get(line, &last_length); + length = pd->selection->start_col + last_length - pd->selection->end_col + 1; + content = malloc(sizeof(char) * (length + 1)); + snprintf(content, pd->selection->start_col, first); + snprintf(content + pd->selection->start_col - 1, last_length - pd->selection->end_col + 1, + last + pd->selection->end_col); + + for (i = line->number; i > pd->selection->start_line; i--) + elm_code_file_line_remove(pd->code->file, i); + + line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); + elm_code_line_text_set(line, content, length); + free(content); +} + +EAPI void +elm_code_widget_selection_delete(Evas_Object *widget) +{ + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (!pd->selection) + return; + + if (pd->selection->start_line == pd->selection->end_line) + _elm_code_widget_selection_delete_single(pd); + else + _elm_code_widget_selection_delete_multi(pd); + + free(pd->selection); + pd->selection = NULL; + eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget)); +} + static char * _elm_code_widget_selection_text_single_get(Elm_Code_Widget_Data *pd) { @@ -178,6 +249,4 @@ elm_code_widget_selection_text_get(Evas_Object *widget) return _elm_code_widget_selection_text_single_get(pd); else return _elm_code_widget_selection_text_multi_get(pd); - - return strdup("TODO"); } diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.h b/legacy/elm_code/src/lib/elm_code_widget_selection.h index 0484414934..e0e39c2ce9 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.h +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.h @@ -21,6 +21,8 @@ EAPI void elm_code_widget_selection_end(Evas_Object *widget, unsigned int line, EAPI void elm_code_widget_selection_clear(Evas_Object *widget); +EAPI void elm_code_widget_selection_delete(Evas_Object *widget); + EAPI char *elm_code_widget_selection_text_get(Evas_Object *widget); /** diff --git a/legacy/elm_code/src/tests/elm_code_test_widget_selection.c b/legacy/elm_code/src/tests/elm_code_test_widget_selection.c index 0e829bceb7..db0a60fa4e 100644 --- a/legacy/elm_code/src/tests/elm_code_test_widget_selection.c +++ b/legacy/elm_code/src/tests/elm_code_test_widget_selection.c @@ -126,11 +126,123 @@ START_TEST (elm_code_test_widget_selection_text_get_multiline) } END_TEST +START_TEST (elm_code_test_widget_selection_delete) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + Elm_Code_Widget *widget; + Evas_Object *win; + const char *text; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "text", 4, NULL); + + win = elm_win_add(NULL, "code", ELM_WIN_BASIC); + widget = eo_add(ELM_CODE_WIDGET_CLASS, win, + elm_code_widget_code_set(code)); + line = elm_code_file_line_get(file, 1); + text = elm_code_line_text_get(line, NULL); + ck_assert_str_eq("text", text); + + elm_code_widget_selection_start(widget, 1, 2); + elm_code_widget_selection_end(widget, 1, 3); + elm_code_widget_selection_delete(widget); + + line = elm_code_file_line_get(file, 1); + text = elm_code_line_text_get(line, NULL); + ck_assert_str_eq("tt", text); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + +START_TEST (elm_code_test_widget_selection_delete_twoline) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + Elm_Code_Widget *widget; + Evas_Object *win; + const char *text; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "text", 4, NULL); + elm_code_file_line_append(file, "TEXT", 4, NULL); + + win = elm_win_add(NULL, "code", ELM_WIN_BASIC); + widget = eo_add(ELM_CODE_WIDGET_CLASS, win, + elm_code_widget_code_set(code)); + line = elm_code_file_line_get(file, 1); + text = elm_code_line_text_get(line, NULL); + ck_assert_str_eq("text", text); + ck_assert_int_eq(2, elm_code_file_lines_get(file)); + + elm_code_widget_selection_start(widget, 1, 3); + elm_code_widget_selection_end(widget, 2, 2); + elm_code_widget_selection_delete(widget); + + line = elm_code_file_line_get(file, 1); + text = elm_code_line_text_get(line, NULL); + ck_assert_str_eq("teXT", text); + ck_assert_int_eq(1, elm_code_file_lines_get(file)); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + +START_TEST (elm_code_test_widget_selection_delete_multiline) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + Elm_Code_Widget *widget; + Evas_Object *win; + const char *text; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "text", 4, NULL); + elm_code_file_line_append(file, "remove", 6, NULL); + elm_code_file_line_append(file, "TEXT", 4, NULL); + + win = elm_win_add(NULL, "code", ELM_WIN_BASIC); + widget = eo_add(ELM_CODE_WIDGET_CLASS, win, + elm_code_widget_code_set(code)); + line = elm_code_file_line_get(file, 1); + text = elm_code_line_text_get(line, NULL); + ck_assert_str_eq("text", text); + ck_assert_int_eq(3, elm_code_file_lines_get(file)); + + elm_code_widget_selection_start(widget, 1, 3); + elm_code_widget_selection_end(widget, 3, 2); + elm_code_widget_selection_delete(widget); + + line = elm_code_file_line_get(file, 1); + text = elm_code_line_text_get(line, NULL); + ck_assert_str_eq("teXT", text); + ck_assert_int_eq(1, elm_code_file_lines_get(file)); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + void elm_code_test_widget_selection(TCase *tc) { tcase_add_test(tc, elm_code_test_widget_selection_set); tcase_add_test(tc, elm_code_test_widget_selection_text_get); tcase_add_test(tc, elm_code_test_widget_selection_text_get_twoline); tcase_add_test(tc, elm_code_test_widget_selection_text_get_multiline); + tcase_add_test(tc, elm_code_test_widget_selection_delete); + tcase_add_test(tc, elm_code_test_widget_selection_delete_twoline); + tcase_add_test(tc, elm_code_test_widget_selection_delete_multiline); } From eee6e3c41143f5bd5b4b284d780f12e93345ee8c Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 28 Mar 2015 16:05:36 +0000 Subject: [PATCH 138/254] search: Update replace for elm_code selection code That should be search and replace completely ported now --- legacy/elm_code/src/lib/elm_code_widget_selection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.c b/legacy/elm_code/src/lib/elm_code_widget_selection.c index d9faaaa1ae..ee3cd9a9f7 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.c @@ -110,7 +110,7 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd) unsigned int old_length, length; char *content; - if (pd->selection->end_col <= pd->selection->start_col) + if (pd->selection->end_col < pd->selection->start_col) return; line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); From 08daaed1f58b8e501de7c71a0627464d99e4e954 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 28 Mar 2015 17:57:47 +0000 Subject: [PATCH 139/254] elm_code: Cut, copy and paste working Current limitations that paste is into a single line --- legacy/elm_code/src/lib/elm_code_widget.c | 20 ++++++ .../src/lib/elm_code_widget_selection.c | 69 +++++++++++++++++++ .../src/lib/elm_code_widget_selection.h | 4 ++ 3 files changed, 93 insertions(+) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index f180b7f2f4..6911f95519 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -942,6 +942,20 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } +static void +_elm_code_widget_control_key_down_cb(Elm_Code_Widget *widget, const char *key) +{ + if (!key) + return; + + if (!strcmp("c", key)) + elm_code_widget_selection_copy(widget); + else if (!strcmp("v", key)) + elm_code_widget_selection_paste(widget); + else if (!strcmp("x", key)) + elm_code_widget_selection_cut(widget); +} + static void _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) @@ -959,6 +973,12 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, _elm_code_widget_update_focus_directions((Elm_Code_Widget *)obj); + if (evas_key_modifier_is_set(ev->modifiers, "Control")) + { + _elm_code_widget_control_key_down_cb(widget, ev->key); + return; + } + if (!strcmp(ev->key, "Up")) _elm_code_widget_cursor_move_up(widget); else if (!strcmp(ev->key, "Down")) diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.c b/legacy/elm_code/src/lib/elm_code_widget_selection.c index ee3cd9a9f7..115a7a051c 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.c @@ -250,3 +250,72 @@ elm_code_widget_selection_text_get(Evas_Object *widget) else return _elm_code_widget_selection_text_multi_get(pd); } + +static void +_selection_loss_cb(void *data, Elm_Sel_Type selection EINA_UNUSED) +{ + Elm_Code_Widget *widget; + + widget = (Elm_Code_Widget *)data; +// TODO we need to know whih selection we are clearing! +// elm_code_widget_selection_clear(widget); +} + +EAPI void +elm_code_widget_selection_cut(Evas_Object *widget) +{ + char *text; + + text = elm_code_widget_selection_text_get(widget); + elm_cnp_selection_set(widget, ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT, text, strlen(text)); + elm_cnp_selection_loss_callback_set(widget, ELM_SEL_TYPE_CLIPBOARD, _selection_loss_cb, widget); + free(text); + + elm_code_widget_selection_delete(widget); +} + +EAPI void +elm_code_widget_selection_copy(Evas_Object *widget) +{ + char *text; + + text = elm_code_widget_selection_text_get(widget); + elm_cnp_selection_set(widget, ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT, text, strlen(text)); + elm_cnp_selection_loss_callback_set(widget, ELM_SEL_TYPE_CLIPBOARD, _selection_loss_cb, widget); + free(text); +} + +static Eina_Bool +_selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data *ev) +{ + Elm_Code *code; + Elm_Code_Widget *widget; + Elm_Code_Line *line; + unsigned int row, col; + + widget = (Elm_Code_Widget *)data; + if (ev->format != ELM_SEL_FORMAT_TEXT) + return EINA_TRUE; + + if (ev->len <= 0) + return EINA_TRUE; + + eo_do(widget, + code = elm_code_widget_code_get(), + elm_code_widget_cursor_position_get(&col, &row)); + line = elm_code_file_line_get(code->file, row); + + elm_code_line_text_insert(line, col, ev->data, ev->len - 1); + + eo_do(widget, + elm_code_widget_cursor_position_set(col + ev->len - 1, row)); + return EINA_TRUE; +} + +EAPI void +elm_code_widget_selection_paste(Evas_Object *widget) +{ + elm_code_widget_selection_delete(widget); + + elm_cnp_selection_get(widget, ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT, _selection_paste_cb, widget); +} diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.h b/legacy/elm_code/src/lib/elm_code_widget_selection.h index e0e39c2ce9..0e476a20b5 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.h +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.h @@ -25,6 +25,10 @@ EAPI void elm_code_widget_selection_delete(Evas_Object *widget); EAPI char *elm_code_widget_selection_text_get(Evas_Object *widget); +EAPI void elm_code_widget_selection_cut(Evas_Object *widget); +EAPI void elm_code_widget_selection_copy(Evas_Object *widget); +EAPI void elm_code_widget_selection_paste(Evas_Object *widget); + /** * @} */ From e0e0eaa32c96bc8205b62877a9600dae6b8562cb Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 29 Mar 2015 20:12:28 +0100 Subject: [PATCH 140/254] elm_code: Support rendering tabs Add a tabstop configurable value so the view can be adjusted. shuffle all content and tokens along when a tab is encountered. --- legacy/elm_code/src/lib/elm_code_file.c | 1 - legacy/elm_code/src/lib/elm_code_line.c | 6 -- legacy/elm_code/src/lib/elm_code_line.h | 4 +- legacy/elm_code/src/lib/elm_code_parse.c | 1 - legacy/elm_code/src/lib/elm_code_private.h | 2 +- legacy/elm_code/src/lib/elm_code_text.c | 34 ++++++-- legacy/elm_code/src/lib/elm_code_text.h | 6 +- legacy/elm_code/src/lib/elm_code_widget.c | 83 ++++++++++++++----- legacy/elm_code/src/lib/elm_code_widget.eo | 20 +++++ .../src/lib/elm_code_widget_selection.c | 6 +- 10 files changed, 119 insertions(+), 44 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index 41a7e8f1c7..8848b95a70 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -52,7 +52,6 @@ static void _elm_code_file_line_insert_data(Elm_Code_File *file, const char *con line->modified[length] = 0; line->length = length; } - line->unicode_length = elm_code_text_unicode_strlen(content, length); if (row == 1) file->lines = eina_list_prepend(file->lines, line); diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index d7d9ee6b2e..dfddb67231 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -20,12 +20,6 @@ elm_code_line_free(Elm_Code_Line *line) free(line); } -EAPI unsigned int -elm_code_line_utf8_length_get(Elm_Code_Line *line) -{ - return line->unicode_length; -} - EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status) { if (!line) diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index 3cb1baf7e0..d2f7968e89 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -24,7 +24,7 @@ typedef struct _Elm_Code_Line Elm_Code_File *file; const char *content; - unsigned int length, unicode_length; + unsigned int length; unsigned int number; char *modified; @@ -37,8 +37,6 @@ typedef struct _Elm_Code_Line EAPI void elm_code_line_free(Elm_Code_Line *line); -EAPI unsigned int elm_code_line_utf8_length_get(Elm_Code_Line *line); - /** * @brief Line markup functions. * @defgroup Line highlighting and status manipulation diff --git a/legacy/elm_code/src/lib/elm_code_parse.c b/legacy/elm_code/src/lib/elm_code_parse.c index 912cbaac2c..9146e46f6d 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.c +++ b/legacy/elm_code/src/lib/elm_code_parse.c @@ -106,7 +106,6 @@ _elm_code_parser_diff_trim_leading(Elm_Code_Line *line, unsigned int count) } line->length -= count; - line->unicode_length -= count; } static void diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h index b37a3fffe0..260d3ffc2d 100644 --- a/legacy/elm_code/src/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -46,7 +46,7 @@ typedef struct unsigned int cursor_line, cursor_col; Eina_Bool editable, focussed; Eina_Bool show_line_numbers; - unsigned int line_width_marker; + unsigned int line_width_marker, tabstop; Eina_Bool show_whitespace; Elm_Code_Widget_Selection_Data *selection; diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index a9e86be57a..8460f90f0d 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -36,7 +36,6 @@ elm_code_line_text_set(Elm_Code_Line *line, const char *chars, unsigned int leng strncpy(newtext, chars, length); line->modified = newtext; line->length = length; - line->unicode_length = elm_code_text_unicode_strlen(line->modified, line->length); file = line->file; elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); @@ -158,7 +157,6 @@ elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char line->modified = inserted; line->length += length; - line->unicode_length = elm_code_text_unicode_strlen(line->modified, line->length); file = line->file; elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); @@ -196,7 +194,6 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length line->modified = removed; line->length -= length; - line->unicode_length = elm_code_text_unicode_strlen(line->modified, line->length); file = line->file; elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); @@ -204,24 +201,47 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length /* generic text functions */ +unsigned int +elm_code_text_tabwidth_at_position(unsigned int position, unsigned int tabstop) +{ + return tabstop - (position % tabstop); +} + EAPI unsigned int -elm_code_text_unicode_strlen(const char *chars, unsigned int length) +elm_code_line_text_column_width_to_position(Elm_Code_Line *line, unsigned int position, unsigned int tabstop) { Eina_Unicode unicode; unsigned int count = 0; int index = 0; + const char *chars; - if (chars == NULL) + if (line->length == 0) return 0; - while ((unsigned int) index < length) + if (line->modified) + chars = line->modified; + else + chars = line->content; + if (position > line->length) + position = line->length; + + while ((unsigned int) index < position) { unicode = eina_unicode_utf8_next_get(chars, &index); if (unicode == 0) break; - count++; + if (unicode == '\t') + count += elm_code_text_tabwidth_at_position(count, tabstop); + else + count++; } return count; } + +EAPI unsigned int +elm_code_line_text_column_width(Elm_Code_Line *line, unsigned int tabstop) +{ + return elm_code_line_text_column_width_to_position(line, line->length, tabstop); +} diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 3df2ff6774..1deb1ab5b0 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -48,7 +48,11 @@ EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, * */ -EAPI unsigned int elm_code_text_unicode_strlen(const char *chars, unsigned int length); +EAPI unsigned int elm_code_text_tabwidth_at_position(unsigned int position, unsigned int tabstop); + +EAPI unsigned int elm_code_line_text_column_width_to_position(Elm_Code_Line *line, unsigned int length, unsigned int tabstop); + +EAPI unsigned int elm_code_line_text_column_width(Elm_Code_Line *line, unsigned int tabstop); /** * @} diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 6911f95519..caf6af9311 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -51,6 +51,8 @@ _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd) pd->cursor_line = 1; pd->cursor_col = 1; + + pd->tabstop = 8; } EOLIAN static Eo * @@ -92,6 +94,7 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) Eina_List *item; Evas_Coord ww, wh, old_width, old_height; int w, h, cw, ch, gutter; + unsigned int line_width; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); @@ -108,8 +111,11 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) w = 0; h = elm_code_file_lines_get(pd->code->file); EINA_LIST_FOREACH(pd->code->file->lines, item, line) - if ((int) line->unicode_length + gutter + 1 > w) - w = (int) line->unicode_length + gutter + 1; + { + line_width = elm_code_line_text_column_width(line, pd->tabstop); + if ((int) column_length + gutter + 1 > w) + w = (int) column_length + gutter + 1; + } if (w*cw > ww) ww = w*cw; @@ -156,21 +162,21 @@ static void _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, unsigned int count, Elm_Code_Line *line) { + Elm_Code_Widget_Data *pd; Eina_List *item; Elm_Code_Token *token; - const char *content; unsigned int start, end, length, offset; unsigned int token_start_col, token_end_col; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); offset = elm_code_widget_text_left_gutter_width_get(widget); start = offset; - content = elm_code_line_text_get(line, NULL); - length = line->unicode_length + offset; + length = elm_code_line_text_column_width(line, pd->tabstop) + offset; EINA_LIST_FOREACH(line->tokens, item, token) { - token_start_col = elm_code_text_unicode_strlen(content, token->start - 1) + offset; - token_end_col = elm_code_text_unicode_strlen(content, token->end - 1) + offset; + token_start_col = elm_code_line_text_column_width_to_position(line, token->start - 1, pd->tabstop) + offset; + token_end_col = elm_code_line_text_column_width_to_position(line, token->end - 1, pd->tabstop) + offset; if (token_start_col > start) _elm_code_widget_fill_line_token(cells, count, start, token_start_col, ELM_CODE_TOKEN_TYPE_DEFAULT); @@ -235,7 +241,11 @@ _elm_code_widget_fill_whitespace(Elm_Code_Widget *widget, Eina_Unicode character pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (!pd->show_whitespace) - return; + { + if (character== '\t') + cell->codepoint = 0; + return; + } switch (character) { @@ -301,7 +311,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) { char *chr; Eina_Unicode unichr; - unsigned int length, x; + unsigned int length, x, charwidth, i; int w, chrpos, gutter; Evas_Textgrid_Cell *cells; Elm_Code_Widget_Data *pd; @@ -315,17 +325,26 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) _elm_code_widget_fill_gutter(widget, cells, line->status, line->number); _elm_code_widget_fill_line_tokens(widget, cells, w, line); - length = elm_code_line_utf8_length_get(line); + length = elm_code_line_text_column_width(line, pd->tabstop); chrpos = 0; chr = (char *)elm_code_line_text_get(line, NULL); - for (x = gutter; x < (unsigned int) w && x < length + gutter; x++) + for (x = gutter; x < (unsigned int) w && x < length + gutter; x+=charwidth) { unichr = eina_unicode_utf8_next_get(chr, &chrpos); cells[x].codepoint = unichr; cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); + charwidth = 1; + if (unichr == '\t') + charwidth = elm_code_text_tabwidth_at_position(x - gutter, pd->tabstop); + for (i = x + 1; i < x + charwidth; i++) + { + cells[i].codepoint = 0; + cells[i].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); + } + _elm_code_widget_fill_whitespace(widget, unichr, &cells[x]); } for (; x < (unsigned int) w; x++) @@ -459,7 +478,7 @@ _elm_code_widget_cursor_key_will_move(Elm_Code_Widget *widget, const char *key) else if (!strcmp(key, "Left")) return pd->cursor_col > 1; else if (!strcmp(key, "Right")) - return pd->cursor_col < (unsigned int) line->unicode_length + 1; + return pd->cursor_col < elm_code_line_text_column_width(line, pd->tabstop) + 1; else return EINA_FALSE; } @@ -586,15 +605,17 @@ _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, unsigned int row, { Elm_Code_Widget_Data *pd; Elm_Code_Line *line; + unsigned int column_width; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); line = elm_code_file_line_get(pd->code->file, row); if (!line) return; + column_width = elm_code_line_text_column_width(line, pd->tabstop); - if (col > line->unicode_length + 1) - col = line->unicode_length + 1; + if (col > column_width + 1) + col = column_width + 1; else if (col <= 0) col = 1; @@ -704,7 +725,7 @@ _elm_code_widget_cursor_move_up(Elm_Code_Widget *widget) { Elm_Code_Widget_Data *pd; Elm_Code_Line *line; - unsigned int row, col; + unsigned int row, col, column_width; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); row = pd->cursor_line; @@ -715,8 +736,9 @@ _elm_code_widget_cursor_move_up(Elm_Code_Widget *widget) row--; line = elm_code_file_line_get(pd->code->file, row); - if (col > (unsigned int) line->unicode_length + 1) - col = line->unicode_length + 1; + column_width = elm_code_line_text_column_width(line, pd->tabstop); + if (col > column_width + 1) + col = column_width + 1; _elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE); } @@ -726,7 +748,7 @@ _elm_code_widget_cursor_move_down(Elm_Code_Widget *widget) { Elm_Code_Widget_Data *pd; Elm_Code_Line *line; - unsigned int row, col; + unsigned int row, col, column_width; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); row = pd->cursor_line; @@ -737,8 +759,9 @@ _elm_code_widget_cursor_move_down(Elm_Code_Widget *widget) row++; line = elm_code_file_line_get(pd->code->file, row); - if (col > (unsigned int) line->unicode_length + 1) - col = line->unicode_length + 1; + column_width = elm_code_line_text_column_width(line, pd->tabstop); + if (col > column_width + 1) + col = column_width + 1; _elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE); } @@ -765,7 +788,7 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); line = elm_code_file_line_get(pd->code->file, pd->cursor_line); - if (pd->cursor_col > (unsigned int) line->unicode_length) + if (pd->cursor_col > elm_code_line_text_column_width(line, pd->tabstop)) return; _elm_code_widget_cursor_move(widget, pd, pd->cursor_col+1, pd->cursor_line, EINA_TRUE); @@ -918,6 +941,9 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) Elm_Code *code; Elm_Code_Line *line; unsigned int row, col; + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (_elm_code_widget_delete_selection(widget)) return; @@ -926,7 +952,7 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) code = elm_code_widget_code_get(), elm_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); - if (col > line->unicode_length) + if (col > elm_code_line_text_column_width(line, pd->tabstop)) { if (row == elm_code_file_lines_get(code->file)) return; @@ -1111,6 +1137,19 @@ _elm_code_widget_gravity_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, doub *y = pd->gravity_y; } +EOLIAN static void +_elm_code_widget_tabstop_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, unsigned int tabstop) +{ + pd->tabstop = tabstop; + _elm_code_widget_fill(obj); +} + +EOLIAN static unsigned int +_elm_code_widget_tabstop_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) +{ + return pd->tabstop; +} + EOLIAN static void _elm_code_widget_editable_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool editable) { diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/elm_code_widget.eo index 98b35cc012..f8b8c6cda3 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/elm_code_widget.eo @@ -59,6 +59,26 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) double y; /*@ The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 */ } } + tabstop { + set { + /*@ + Set the width of a tab stop, used purely for visual layout of tab characters. + + Recommended value is between 2 and 8. + + @ingroup Layout */ + } + get { + /*@ + Get the current width of a tab stop. + This is used to determine where characters after a tab should appear in the line.. + + @ingroup Layout */ + } + values { + uint tabstop; /*@ Maximum width of a tab character */ + } + } editable { set { /*@ diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.c b/legacy/elm_code/src/lib/elm_code_widget_selection.c index 115a7a051c..e1b388fb40 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.c @@ -22,6 +22,7 @@ _elm_code_widget_selection_limit(Evas_Object *widget EINA_UNUSED, Elm_Code_Widge { Elm_Code_Line *line; Elm_Code_File *file; + unsigned int width; file = pd->code->file; @@ -29,9 +30,10 @@ _elm_code_widget_selection_limit(Evas_Object *widget EINA_UNUSED, Elm_Code_Widge *row = elm_code_file_lines_get(file); line = elm_code_file_line_get(file, *row); + width = elm_code_line_text_column_width(line, pd->tabstop); - if (*col > line->unicode_length + 1) - *col = line->unicode_length + 1; + if (*col > width + 1) + *col = width + 1; if (*col < 1) *col = 1; } From ba44ecf1faecfdd99b73518237e2d33649a781af Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 29 Mar 2015 20:13:30 +0100 Subject: [PATCH 141/254] elm_code editor: display cursor over selection If they overlap it's good to know where text will appear --- legacy/elm_code/src/lib/elm_code_widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index caf6af9311..5f0d1162c5 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -353,8 +353,8 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); } - _elm_code_widget_fill_cursor(widget, line, cells, gutter, w); _elm_code_widget_fill_selection(widget, line, cells, gutter, w); + _elm_code_widget_fill_cursor(widget, line, cells, gutter, w); if (line->number < elm_code_file_lines_get(line->file)) _elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]); From a5fbc90b1450d50e4a34c825acb4f50d4d0ad6aa Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 29 Mar 2015 20:39:26 +0100 Subject: [PATCH 142/254] elm_code: Fix minor mistakes with tab commit --- legacy/elm_code/src/lib/elm_code_widget.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 5f0d1162c5..0bdefc4017 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -113,8 +113,8 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) EINA_LIST_FOREACH(pd->code->file->lines, item, line) { line_width = elm_code_line_text_column_width(line, pd->tabstop); - if ((int) column_length + gutter + 1 > w) - w = (int) column_length + gutter + 1; + if ((int) line_width + gutter + 1 > w) + w = (int) line_width + gutter + 1; } if (w*cw > ww) @@ -342,7 +342,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) for (i = x + 1; i < x + charwidth; i++) { cells[i].codepoint = 0; - cells[i].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); + cells[i].bg = _elm_code_widget_status_type_get(widget, line->status, i - gutter + 1); } _elm_code_widget_fill_whitespace(widget, unichr, &cells[x]); From 73b612a3408697ad464badf6852df01ca6aa02d2 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 29 Mar 2015 20:52:38 +0100 Subject: [PATCH 143/254] elm_code: fix tests to provide elm_code widget Required by new tab rendering changes --- legacy/elm_code/src/tests/elm_code_test_widget.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/tests/elm_code_test_widget.c b/legacy/elm_code/src/tests/elm_code_test_widget.c index 3f53fe36b6..6311dc23c7 100644 --- a/legacy/elm_code/src/tests/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/elm_code_test_widget.c @@ -16,11 +16,20 @@ START_TEST (elm_code_widget_token_render_simple_test) Elm_Code_File *file; Elm_Code_Line *line; Elm_Code *code; + Elm_Code_Widget *widget; + Evas_Object *win; + int length; Evas_Textgrid_Cell cells[25]; + elm_init(1, NULL); code = elm_code_create(); + + win = elm_win_add(NULL, "code", ELM_WIN_BASIC); + widget = eo_add(ELM_CODE_WIDGET_CLASS, win, + elm_code_widget_code_set(code)); + file = code->file; elm_code_file_line_append(file, "some \"test content\", 45", 23, NULL); line = elm_code_file_line_get(file, 1); @@ -29,7 +38,7 @@ START_TEST (elm_code_widget_token_render_simple_test) elm_code_line_token_add(line, 6+1, 17+1, 1, ELM_CODE_TOKEN_TYPE_COMMENT); elm_code_line_token_add(line, 21+1, 22+1, 1, ELM_CODE_TOKEN_TYPE_COMMENT); - _elm_code_widget_fill_line_tokens(NULL, cells, length+1, line); + _elm_code_widget_fill_line_tokens(widget, cells, length+1, line); _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT, 1); _assert_cell_type(cells[4], ELM_CODE_TOKEN_TYPE_DEFAULT, 4); _assert_cell_type(cells[6], ELM_CODE_TOKEN_TYPE_DEFAULT, 6); @@ -38,6 +47,7 @@ START_TEST (elm_code_widget_token_render_simple_test) _assert_cell_type(cells[23], ELM_CODE_TOKEN_TYPE_COMMENT, 23); elm_code_free(code); + elm_shutdown(); } END_TEST From 3ce607322b8f9e95b9a9bc2e04dadbd05a2110aa Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 30 Mar 2015 20:07:45 +0100 Subject: [PATCH 144/254] elm_code editor: handle tabs when deleting Make sure we're at the right position when we delete, backspace or split lines with tabs in them --- legacy/elm_code/src/lib/elm_code_text.c | 31 +++++++++++ legacy/elm_code/src/lib/elm_code_text.h | 2 + legacy/elm_code/src/lib/elm_code_widget.c | 55 ++++++++++++++----- .../src/lib/elm_code_widget_selection.c | 12 +++- 4 files changed, 83 insertions(+), 17 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 8460f90f0d..9b7d8f36b2 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -245,3 +245,34 @@ elm_code_line_text_column_width(Elm_Code_Line *line, unsigned int tabstop) { return elm_code_line_text_column_width_to_position(line, line->length, tabstop); } + +EAPI unsigned int +elm_code_line_text_position_for_column_get(Elm_Code_Line *line, unsigned int column, unsigned int tabstop) +{ + Eina_Unicode unicode; + unsigned int count = 0; + int index = 0; + const char *chars; + + if (line->length == 0) + return 0; + + if (line->modified) + chars = line->modified; + else + chars = line->content; + + while ((unsigned int) count < column && index <= line->length) + { + unicode = eina_unicode_utf8_next_get(chars, &index); + if (unicode == 0) + break; + + if (unicode == '\t') + count += elm_code_text_tabwidth_at_position(count, tabstop); + else + count++; + } + + return (unsigned int) index; +} diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 1deb1ab5b0..17a47ebc2f 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -54,6 +54,8 @@ EAPI unsigned int elm_code_line_text_column_width_to_position(Elm_Code_Line *lin EAPI unsigned int elm_code_line_text_column_width(Elm_Code_Line *line, unsigned int tabstop); +EAPI unsigned int elm_code_line_text_position_for_column_get(Elm_Code_Line *line, unsigned int column, unsigned int tabstop); + /** * @} */ diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 0bdefc4017..ba46ce4061 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -813,7 +813,10 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text { Elm_Code *code; Elm_Code_Line *line; - unsigned int row, col; + Elm_Code_Widget_Data *pd; + unsigned int row, col, position, col_width; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); _elm_code_widget_delete_selection(widget); eo_do(widget, @@ -821,9 +824,13 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text elm_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); - elm_code_line_text_insert(line, col, text, length); + position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); + elm_code_line_text_insert(line, position + 1, text, length); + col_width = elm_code_line_text_column_width_to_position(line, position + length, pd->tabstop) - + elm_code_line_text_column_width_to_position(line, position, pd->tabstop); + eo_do(widget, - elm_code_widget_cursor_position_set(col + length, row), + elm_code_widget_cursor_position_set(col + col_width, row), // TODO construct and pass a change object eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } @@ -833,9 +840,11 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) { Elm_Code *code; Elm_Code_Line *line, *newline; - unsigned int row, col, length; + Elm_Code_Widget_Data *pd; + unsigned int row, col, length, position; char *content; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); _elm_code_widget_delete_selection(widget); eo_do(widget, code = elm_code_widget_code_get(), @@ -847,8 +856,10 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) elm_code_file_line_insert(code->file, line->number + 1, "", 0, NULL); newline = elm_code_file_line_get(code->file, line->number + 1); // TODO we need to split tokens from these lines (move this to elm_code_line?) - elm_code_line_text_set(newline, content + col - 1, length - col + 1); - elm_code_line_text_set(line, content, col - 1); + + position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); + elm_code_line_text_set(newline, content + position, length - position + 2); + elm_code_line_text_set(line, content, position); free(content); eo_do(widget, @@ -862,7 +873,8 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) { Elm_Code *code; Elm_Code_Line *line, *otherline; - unsigned int row, col; + Elm_Code_Widget_Data *pd; + unsigned int row, col, position; const char *text1, *text2; char *newtext; @@ -896,8 +908,13 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) free(newtext); if (!nextline) - eo_do(widget, - elm_code_widget_cursor_position_set(length1 + 1, row - 1)); + { + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + position = elm_code_line_text_column_width_to_position(line, length1, pd->tabstop); + + eo_do(widget, + elm_code_widget_cursor_position_set(position + 1, row - 1)); + } // TODO construct and pass a change object eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } @@ -907,7 +924,8 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) { Elm_Code *code; Elm_Code_Line *line; - unsigned int row, col; + Elm_Code_Widget_Data *pd; + unsigned int row, col, position, col_width, char_width; if (_elm_code_widget_delete_selection(widget)) return; @@ -915,6 +933,7 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) eo_do(widget, code = elm_code_widget_code_get(), elm_code_widget_cursor_position_get(&col, &row)); + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (col <= 1) { @@ -927,9 +946,14 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) line = elm_code_file_line_get(code->file, row); - elm_code_line_text_remove(line, col - 1, 1); + position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); + char_width = elm_code_line_text_position_for_column_get(line, col, pd->tabstop) - + elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); + col_width = elm_code_line_text_column_width_to_position(line, position, pd->tabstop) - + elm_code_line_text_column_width_to_position(line, position - 1, pd->tabstop); + elm_code_line_text_remove(line, position, char_width); eo_do(widget, - elm_code_widget_cursor_position_set(col - 1, row)); + elm_code_widget_cursor_position_set(col - col_width, row)); // TODO construct and pass a change object eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); @@ -940,7 +964,7 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) { Elm_Code *code; Elm_Code_Line *line; - unsigned int row, col; + unsigned int row, col, position, char_width; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); @@ -961,7 +985,10 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) return; } - elm_code_line_text_remove(line, col, 1); + position = elm_code_line_text_position_for_column_get(line, col, pd->tabstop); + char_width = elm_code_line_text_position_for_column_get(line, col, pd->tabstop) - + elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); + elm_code_line_text_remove(line, position, char_width); eo_do(widget, elm_code_widget_cursor_position_set(col, row), // TODO construct and pass a change object diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.c b/legacy/elm_code/src/lib/elm_code_widget_selection.c index e1b388fb40..0b5d9dae0f 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/elm_code_widget_selection.c @@ -293,9 +293,12 @@ _selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data Elm_Code *code; Elm_Code_Widget *widget; Elm_Code_Line *line; - unsigned int row, col; + Elm_Code_Widget_Data *pd; + unsigned int row, col, col_width, position; widget = (Elm_Code_Widget *)data; + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + if (ev->format != ELM_SEL_FORMAT_TEXT) return EINA_TRUE; @@ -307,10 +310,13 @@ _selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data elm_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); - elm_code_line_text_insert(line, col, ev->data, ev->len - 1); + position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); + elm_code_line_text_insert(line, position + 1, ev->data, ev->len - 1); + col_width = elm_code_line_text_column_width_to_position(line, position + ev->len - 1, pd->tabstop) - + elm_code_line_text_column_width_to_position(line, position, pd->tabstop); eo_do(widget, - elm_code_widget_cursor_position_set(col + ev->len - 1, row)); + elm_code_widget_cursor_position_set(col + col_width, row)); return EINA_TRUE; } From 7942fa8710771f127ca21ae2b00e8de16783fb64 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 30 Mar 2015 23:36:28 +0100 Subject: [PATCH 145/254] elm_code editor: Fix bug with newlines Badness introduced with the tab work was padding lines with NULL --- legacy/elm_code/src/lib/elm_code_widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index ba46ce4061..c0fc9ea0a4 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -858,7 +858,7 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) // TODO we need to split tokens from these lines (move this to elm_code_line?) position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); - elm_code_line_text_set(newline, content + position, length - position + 2); + elm_code_line_text_set(newline, content + position, length - position); elm_code_line_text_set(line, content, position); free(content); From 5a1629e7a4d594bbe5774c99498edd1a558fa0b9 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 2 Apr 2015 00:32:16 +0100 Subject: [PATCH 146/254] editor: Fix performance of adding deleting lines removed the numerous callbacks that were not needed --- legacy/elm_code/src/lib/elm_code_file.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index 8848b95a70..1a729113f9 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -274,9 +274,6 @@ EAPI void elm_code_file_line_insert(Elm_Code_File *file, unsigned int row, const continue; line_item->number = r++; - - if (file->parent) - elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line_item); } } @@ -299,9 +296,6 @@ EAPI void elm_code_file_line_remove(Elm_Code_File *file, unsigned int row) } line_item->number = r++; - - if (file->parent) - elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line_item); } if (tofree) From 151956ea93ead5eea920a1dc8d40fe0b5851da34 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 2 Apr 2015 22:48:23 +0100 Subject: [PATCH 147/254] editor: Fix performance of loading large files --- legacy/elm_code/src/lib/elm_code_widget.c | 21 +++++++++++++++++++++ legacy/elm_code/src/lib/elm_code_widget.eo | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index c0fc9ea0a4..0d131e53ae 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -414,10 +414,17 @@ static Eina_Bool _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) { + Elm_Code_Line *line; Elm_Code_Widget *widget; + Eina_Bool visible; + line = (Elm_Code_Line *)event_info; widget = (Elm_Code_Widget *)data; + eo_do(widget, visible = elm_code_widget_line_visible_get(line)); + if (!visible) + return EO_CALLBACK_CONTINUE; + // FIXME refresh just the row unless we have resized (by being the result of a row append) _elm_code_widget_fill(widget); @@ -1121,6 +1128,20 @@ _elm_code_widget_line_refresh(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm _elm_code_widget_fill_line(obj, line); } +EOAPI Eina_Bool +_elm_code_widget_line_visible_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Code_Line *line) +{ + Evas_Coord cellh, viewy, viewh; + + elm_scroller_region_get(pd->scroller, NULL, &viewy, NULL, &viewh); + evas_object_textgrid_cell_size_get(pd->grid, NULL, &cellh); + + if (((int)line->number - 1) * cellh > viewy + viewh || (int)line->number * cellh < viewy) + return EINA_FALSE; + + return EINA_TRUE;; +} + EOLIAN static void _elm_code_widget_font_size_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Evas_Font_Size font_size) { diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/elm_code_widget.eo index f8b8c6cda3..ae7fdcfa40 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/elm_code_widget.eo @@ -187,6 +187,12 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) Elm_Code_Line *line; /*@ @in The line to refresh. */ } } + line_visible_get { + params { + Elm_Code_Line *line; /*@ @in The line to test for visibility. */ + } + return: bool (visible); /*@ true if the line specified is currently visible within the scroll region. */ + } } implements { class.constructor; From f50bff8e99ef64b37d9a353d1cfce2773e1f0a74 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 4 Apr 2015 17:51:39 +0100 Subject: [PATCH 148/254] editor: Add a tooltip popup if you hover over a line with a warning attached --- legacy/elm_code/src/lib/Makefile.am | 1 + legacy/elm_code/src/lib/elm_code_private.h | 7 +++ legacy/elm_code/src/lib/elm_code_widget.c | 14 +++++- .../src/lib/elm_code_widget_tooltip.c | 44 +++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 legacy/elm_code/src/lib/elm_code_widget_tooltip.c diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index 9885cbda58..0bd1a4ebf8 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -36,6 +36,7 @@ elm_code_text.c \ elm_code_file.c \ elm_code_parse.c \ elm_code_widget_text.c \ +elm_code_widget_tooltip.c \ elm_code_widget_selection.c \ elm_code_widget.c \ elm_code_diff_widget.c \ diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h index 260d3ffc2d..57dae7c746 100644 --- a/legacy/elm_code/src/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -50,6 +50,7 @@ typedef struct Eina_Bool show_whitespace; Elm_Code_Widget_Selection_Data *selection; + Evas_Object *tooltip; } Elm_Code_Widget_Data; /* Private parser callbacks */ @@ -59,3 +60,9 @@ void _elm_code_parse_setup(); void _elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line); void _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file); + +/* Private widget methods */ + +void _elm_code_widget_tooltip_text_set(Evas_Object *widget, const char *text); + +void _elm_code_widget_tooltip_add(Evas_Object *widget); diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 0d131e53ae..a7c6a00691 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -672,19 +672,28 @@ _elm_code_widget_mouse_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj { Elm_Code_Widget *widget; Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; Evas_Event_Mouse_Move *event; unsigned int row; int col; + Eina_Bool hasline; widget = (Elm_Code_Widget *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); event = (Evas_Event_Mouse_Move *)event_info; + hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, event->cur.canvas.x, event->cur.canvas.y, &row, &col); + if (!hasline) + _elm_code_widget_tooltip_text_set(widget, NULL); + else + { + line = elm_code_file_line_get(pd->code->file, row); + _elm_code_widget_tooltip_text_set(widget, line->status_text); + } + if (!pd->editable || !pd->selection || !event->buttons) return; - _elm_code_widget_position_at_coordinates_get(widget, pd, event->cur.canvas.x, event->cur.canvas.y, &row, &col); - elm_code_widget_selection_end(widget, row, col); } @@ -1360,6 +1369,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(grid); + _elm_code_widget_tooltip_add(obj); elm_object_content_set(scroller, grid); pd->grid = grid; _elm_code_widget_setup_palette(grid); diff --git a/legacy/elm_code/src/lib/elm_code_widget_tooltip.c b/legacy/elm_code/src/lib/elm_code_widget_tooltip.c new file mode 100644 index 0000000000..18bee520e1 --- /dev/null +++ b/legacy/elm_code/src/lib/elm_code_widget_tooltip.c @@ -0,0 +1,44 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include "Elm_Code.h" + +#include "elm_code_private.h" + +void +_elm_code_widget_tooltip_text_set(Evas_Object *widget, const char *text) +{ + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (!text) + elm_object_tooltip_hide(widget); + else + elm_object_tooltip_show(widget); + + if (pd->tooltip) // will have been created by the callback below... + elm_object_text_set(pd->tooltip, text); +} + +static Evas_Object * +_elm_code_widget_tooltip_cb(void *data EINA_UNUSED, Evas_Object *obj, Evas_Object *tooltip) +{ + Elm_Code_Widget_Data *pd; + Evas_Object *label; + + pd = eo_data_scope_get(obj, ELM_CODE_WIDGET_CLASS); + + label = elm_label_add(tooltip); + pd->tooltip = label; + + return label; +} + +void +_elm_code_widget_tooltip_add(Evas_Object *widget) +{ + elm_object_tooltip_content_cb_set(widget, _elm_code_widget_tooltip_cb, NULL, NULL); +} + From 4cf18aed40f425257463ed2066affbaf8d407027 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 4 Apr 2015 18:17:01 +0100 Subject: [PATCH 149/254] elm_code: refactor widget to seperate space. Keeping the private files for elm_code cleaner --- legacy/elm_code/src/bin/elm_code_test_main.c | 1 - legacy/elm_code/src/lib/Elm_Code.h | 6 +-- legacy/elm_code/src/lib/Makefile.am | 19 ++++----- legacy/elm_code/src/lib/elm_code_private.h | 34 +--------------- .../src/lib/{ => widget}/elm_code_widget.c | 1 + .../src/lib/{ => widget}/elm_code_widget.eo | 0 .../src/lib/widget/elm_code_widget_private.h | 39 +++++++++++++++++++ .../{ => widget}/elm_code_widget_selection.c | 2 +- .../{ => widget}/elm_code_widget_selection.h | 0 .../lib/{ => widget}/elm_code_widget_text.c | 2 +- .../lib/{ => widget}/elm_code_widget_text.h | 0 .../{ => widget}/elm_code_widget_tooltip.c | 2 +- legacy/elm_code/src/tests/Makefile.am | 4 +- .../tests/{ => widget}/elm_code_test_widget.c | 2 +- .../elm_code_test_widget_selection.c | 2 +- 15 files changed, 61 insertions(+), 53 deletions(-) rename legacy/elm_code/src/lib/{ => widget}/elm_code_widget.c (99%) rename legacy/elm_code/src/lib/{ => widget}/elm_code_widget.eo (100%) create mode 100644 legacy/elm_code/src/lib/widget/elm_code_widget_private.h rename legacy/elm_code/src/lib/{ => widget}/elm_code_widget_selection.c (99%) rename legacy/elm_code/src/lib/{ => widget}/elm_code_widget_selection.h (100%) rename legacy/elm_code/src/lib/{ => widget}/elm_code_widget_text.c (95%) rename legacy/elm_code/src/lib/{ => widget}/elm_code_widget_text.h (100%) rename legacy/elm_code/src/lib/{ => widget}/elm_code_widget_tooltip.c (96%) rename legacy/elm_code/src/tests/{ => widget}/elm_code_test_widget.c (98%) rename legacy/elm_code/src/tests/{ => widget}/elm_code_test_widget_selection.c (99%) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 416ae79303..1522cbcf76 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -14,7 +14,6 @@ #include #include -#include "elm_code_widget.eo.h" #include "elm_code_test_private.h" diff --git a/legacy/elm_code/src/lib/Elm_Code.h b/legacy/elm_code/src/lib/Elm_Code.h index 332cb95893..0df6bfff77 100644 --- a/legacy/elm_code/src/lib/Elm_Code.h +++ b/legacy/elm_code/src/lib/Elm_Code.h @@ -38,9 +38,9 @@ #include "elm_code_text.h" #include "elm_code_file.h" #include "elm_code_parse.h" -#include "elm_code_widget.eo.h" -#include "elm_code_widget_text.h" -#include "elm_code_widget_selection.h" +#include "widget/elm_code_widget.eo.h" +#include "widget/elm_code_widget_text.h" +#include "widget/elm_code_widget_selection.h" #include "elm_code_diff_widget.h" #ifdef __cplusplus diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index 0bd1a4ebf8..e849f65bec 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -23,9 +23,9 @@ elm_code_line.h \ elm_code_text.h \ elm_code_file.h \ elm_code_parse.h \ -elm_code_widget.eo.h \ -elm_code_widget_text.h \ -elm_code_widget_selection.h \ +widget/elm_code_widget.eo.h \ +widget/elm_code_widget_text.h \ +widget/elm_code_widget_selection.h \ elm_code_diff_widget.h \ Elm_Code.h includesdir = $(includedir)/edi-@VMAJ@ @@ -35,19 +35,20 @@ elm_code_line.c \ elm_code_text.c \ elm_code_file.c \ elm_code_parse.c \ -elm_code_widget_text.c \ -elm_code_widget_tooltip.c \ -elm_code_widget_selection.c \ -elm_code_widget.c \ +widget/elm_code_widget_text.c \ +widget/elm_code_widget_tooltip.c \ +widget/elm_code_widget_selection.c \ +widget/elm_code_widget.c \ elm_code_diff_widget.c \ elm_code.c \ -elm_code_private.h +elm_code_private.h \ +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 = \ -elm_code_widget.eo +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) diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h index 57dae7c746..fed2ff4134 100644 --- a/legacy/elm_code/src/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -24,35 +24,6 @@ extern int _elm_code_lib_log_dom; #endif #define DBG(...) EINA_LOG_DOM_DBG(_elm_code_lib_log_dom, __VA_ARGS__) -#endif - -/** - * Structure holding the info about a selected region. - */ -typedef struct -{ - unsigned int start_line, end_line; - unsigned int start_col, end_col; -} Elm_Code_Widget_Selection_Data; - -typedef struct -{ - Elm_Code *code; - Evas_Object *grid, *scroller; - - Evas_Font_Size font_size; - double gravity_x, gravity_y; - - unsigned int cursor_line, cursor_col; - Eina_Bool editable, focussed; - Eina_Bool show_line_numbers; - unsigned int line_width_marker, tabstop; - Eina_Bool show_whitespace; - - Elm_Code_Widget_Selection_Data *selection; - Evas_Object *tooltip; -} Elm_Code_Widget_Data; - /* Private parser callbacks */ void _elm_code_parse_setup(); @@ -61,8 +32,5 @@ void _elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line); void _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file); -/* Private widget methods */ -void _elm_code_widget_tooltip_text_set(Evas_Object *widget, const char *text); - -void _elm_code_widget_tooltip_add(Evas_Object *widget); +#endif diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c similarity index 99% rename from legacy/elm_code/src/lib/elm_code_widget.c rename to legacy/elm_code/src/lib/widget/elm_code_widget.c index a7c6a00691..b664516a88 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -4,6 +4,7 @@ #include "Elm_Code.h" #include "elm_code_private.h" +#include "elm_code_widget_private.h" typedef enum { ELM_CODE_WIDGET_COLOR_GUTTER_BG = ELM_CODE_TOKEN_TYPE_COUNT, diff --git a/legacy/elm_code/src/lib/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo similarity index 100% rename from legacy/elm_code/src/lib/elm_code_widget.eo rename to legacy/elm_code/src/lib/widget/elm_code_widget.eo diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h new file mode 100644 index 0000000000..0f758c7409 --- /dev/null +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h @@ -0,0 +1,39 @@ +#ifndef ELM_CODE_WIDGET_PRIVATE_H +# define ELM_CODE_WIDGET_PRIVATE_H + +/** + * Structure holding the info about a selected region. + */ +typedef struct +{ + unsigned int start_line, end_line; + unsigned int start_col, end_col; +} Elm_Code_Widget_Selection_Data; + +typedef struct +{ + Elm_Code *code; + Evas_Object *grid, *scroller; + + Evas_Font_Size font_size; + double gravity_x, gravity_y; + + unsigned int cursor_line, cursor_col; + Eina_Bool editable, focussed; + Eina_Bool show_line_numbers; + unsigned int line_width_marker, tabstop; + Eina_Bool show_whitespace; + + Elm_Code_Widget_Selection_Data *selection; + Evas_Object *tooltip; +} Elm_Code_Widget_Data; + +/* Private widget methods */ + +void _elm_code_widget_tooltip_text_set(Evas_Object *widget, const char *text); + +void _elm_code_widget_tooltip_add(Evas_Object *widget); + + + +#endif diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c similarity index 99% rename from legacy/elm_code/src/lib/elm_code_widget_selection.c rename to legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 0b5d9dae0f..a7a5c018c5 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -4,7 +4,7 @@ #include "Elm_Code.h" -#include "elm_code_private.h" +#include "elm_code_widget_private.h" static Elm_Code_Widget_Selection_Data * _elm_code_widget_selection_new() diff --git a/legacy/elm_code/src/lib/elm_code_widget_selection.h b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.h similarity index 100% rename from legacy/elm_code/src/lib/elm_code_widget_selection.h rename to legacy/elm_code/src/lib/widget/elm_code_widget_selection.h diff --git a/legacy/elm_code/src/lib/elm_code_widget_text.c b/legacy/elm_code/src/lib/widget/elm_code_widget_text.c similarity index 95% rename from legacy/elm_code/src/lib/elm_code_widget_text.c rename to legacy/elm_code/src/lib/widget/elm_code_widget_text.c index e96b5d1cbe..c50ebce51c 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_text.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_text.c @@ -4,7 +4,7 @@ #include "Elm_Code.h" -#include "elm_code_private.h" +#include "elm_code_widget_private.h" EAPI int elm_code_widget_text_line_number_width_get(Elm_Code_Widget *widget) diff --git a/legacy/elm_code/src/lib/elm_code_widget_text.h b/legacy/elm_code/src/lib/widget/elm_code_widget_text.h similarity index 100% rename from legacy/elm_code/src/lib/elm_code_widget_text.h rename to legacy/elm_code/src/lib/widget/elm_code_widget_text.h diff --git a/legacy/elm_code/src/lib/elm_code_widget_tooltip.c b/legacy/elm_code/src/lib/widget/elm_code_widget_tooltip.c similarity index 96% rename from legacy/elm_code/src/lib/elm_code_widget_tooltip.c rename to legacy/elm_code/src/lib/widget/elm_code_widget_tooltip.c index 18bee520e1..f08c18ec7f 100644 --- a/legacy/elm_code/src/lib/elm_code_widget_tooltip.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_tooltip.c @@ -4,7 +4,7 @@ #include "Elm_Code.h" -#include "elm_code_private.h" +#include "elm_code_widget_private.h" void _elm_code_widget_tooltip_text_set(Evas_Object *widget, const char *text) diff --git a/legacy/elm_code/src/tests/Makefile.am b/legacy/elm_code/src/tests/Makefile.am index 131aa1e448..8e74bc0b8b 100644 --- a/legacy/elm_code/src/tests/Makefile.am +++ b/legacy/elm_code/src/tests/Makefile.am @@ -11,8 +11,8 @@ elm_code_file_test_memory.c \ elm_code_test_basic.c \ elm_code_test_parse.c \ elm_code_test_text.c \ -elm_code_test_widget.c \ -elm_code_test_widget_selection.c \ +widget/elm_code_test_widget.c \ +widget/elm_code_test_widget_selection.c \ elm_code_suite.c elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/src/lib/ \ diff --git a/legacy/elm_code/src/tests/elm_code_test_widget.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c similarity index 98% rename from legacy/elm_code/src/tests/elm_code_test_widget.c rename to legacy/elm_code/src/tests/widget/elm_code_test_widget.c index 6311dc23c7..54c102c397 100644 --- a/legacy/elm_code/src/tests/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c @@ -4,7 +4,7 @@ #include "elm_code_suite.h" -#include "elm_code_widget.c" +#include "widget/elm_code_widget.c" static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type, int id) { diff --git a/legacy/elm_code/src/tests/elm_code_test_widget_selection.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c similarity index 99% rename from legacy/elm_code/src/tests/elm_code_test_widget_selection.c rename to legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c index db0a60fa4e..3463c455a7 100644 --- a/legacy/elm_code/src/tests/elm_code_test_widget_selection.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c @@ -4,7 +4,7 @@ #include "elm_code_suite.h" -#include "elm_code_widget_selection.h" +#include "widget/elm_code_widget_selection.h" START_TEST (elm_code_test_widget_selection_set) { From b6d0ced5ec6ca3b3feefa196312e0e2ce18c812d Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 4 Apr 2015 19:01:05 +0100 Subject: [PATCH 150/254] elm_code: bring widget_text into widget object --- legacy/elm_code/src/lib/Elm_Code.h | 1 - legacy/elm_code/src/lib/Makefile.am | 2 -- .../elm_code/src/lib/widget/elm_code_widget.c | 20 ++++++++----- .../src/lib/widget/elm_code_widget.eo | 10 ++++++- .../src/lib/widget/elm_code_widget_text.c | 17 +++++------ .../src/lib/widget/elm_code_widget_text.h | 30 ------------------- 6 files changed, 28 insertions(+), 52 deletions(-) delete mode 100644 legacy/elm_code/src/lib/widget/elm_code_widget_text.h diff --git a/legacy/elm_code/src/lib/Elm_Code.h b/legacy/elm_code/src/lib/Elm_Code.h index 0df6bfff77..83d8d27687 100644 --- a/legacy/elm_code/src/lib/Elm_Code.h +++ b/legacy/elm_code/src/lib/Elm_Code.h @@ -39,7 +39,6 @@ #include "elm_code_file.h" #include "elm_code_parse.h" #include "widget/elm_code_widget.eo.h" -#include "widget/elm_code_widget_text.h" #include "widget/elm_code_widget_selection.h" #include "elm_code_diff_widget.h" diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index e849f65bec..8d674f00e8 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -24,7 +24,6 @@ elm_code_text.h \ elm_code_file.h \ elm_code_parse.h \ widget/elm_code_widget.eo.h \ -widget/elm_code_widget_text.h \ widget/elm_code_widget_selection.h \ elm_code_diff_widget.h \ Elm_Code.h @@ -35,7 +34,6 @@ elm_code_line.c \ elm_code_text.c \ elm_code_file.c \ elm_code_parse.c \ -widget/elm_code_widget_text.c \ widget/elm_code_widget_tooltip.c \ widget/elm_code_widget_selection.c \ widget/elm_code_widget.c \ diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index b664516a88..fef9729833 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -99,7 +99,7 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - gutter = elm_code_widget_text_left_gutter_width_get(widget); + eo_do(widget, gutter = elm_code_widget_text_left_gutter_width_get()); if (!pd->code) return; @@ -170,7 +170,7 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c unsigned int token_start_col, token_end_col; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - offset = elm_code_widget_text_left_gutter_width_get(widget); + eo_do(widget, offset = elm_code_widget_text_left_gutter_width_get()); start = offset; length = elm_code_line_text_column_width(line, pd->tabstop) + offset; @@ -203,7 +203,7 @@ _elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - gutter = elm_code_widget_text_left_gutter_width_get(widget); + eo_do(widget, gutter = elm_code_widget_text_left_gutter_width_get()); evas_object_textgrid_size_get(pd->grid, &w, NULL); @@ -318,7 +318,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - gutter = elm_code_widget_text_left_gutter_width_get(widget); + eo_do(widget, gutter = elm_code_widget_text_left_gutter_width_get()); evas_object_textgrid_size_get(pd->grid, &w, NULL); cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); @@ -371,7 +371,7 @@ _elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number) Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - gutter = elm_code_widget_text_left_gutter_width_get(widget); + eo_do(widget, gutter = elm_code_widget_text_left_gutter_width_get()); evas_object_textgrid_size_get(pd->grid, &w, NULL); cells = evas_object_textgrid_cellrow_get(pd->grid, number - 1); @@ -524,13 +524,15 @@ _elm_code_widget_cursor_ensure_visible(Elm_Code_Widget *widget) Evas_Coord viewx, viewy, vieww, viewh, cellw, cellh; Evas_Coord curx, cury; Elm_Code_Widget_Data *pd; + int gutter; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); elm_scroller_region_get(pd->scroller, &viewx, &viewy, &vieww, &viewh); evas_object_textgrid_cell_size_get(pd->grid, &cellw, &cellh); - curx = (pd->cursor_col + elm_code_widget_text_left_gutter_width_get(widget) - 1) * cellw; + eo_do(widget, gutter = elm_code_widget_text_left_gutter_width_get()); + curx = (pd->cursor_col + gutter - 1) * cellw; cury = (pd->cursor_line - 1) * cellh; if (curx >= viewx && cury >= viewy && curx + cellw <= viewx + vieww && cury + cellh <= viewy + viewh) @@ -574,7 +576,7 @@ _elm_code_widget_position_at_coordinates_get(Elm_Code_Widget *widget, Elm_Code_W { Elm_Code_Line *line; Evas_Coord ox, oy, sx, sy; - int cw, ch; + int cw, ch, gutter; unsigned int number; evas_object_geometry_get(widget, &ox, &oy, NULL, NULL); @@ -583,9 +585,10 @@ _elm_code_widget_position_at_coordinates_get(Elm_Code_Widget *widget, Elm_Code_W y = y + sy - oy; evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); + eo_do(widget, gutter = elm_code_widget_text_left_gutter_width_get()); number = ((double) y / ch) + 1; if (col) - *col = ((double) x / cw) - elm_code_widget_text_left_gutter_width_get(widget) + 1; + *col = ((double) x / cw) - gutter + 1; if (row) *row = number; @@ -1393,4 +1396,5 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) _elm_code_widget_font_size_set(obj, pd, 10); } +#include "elm_code_widget_text.c" #include "elm_code_widget.eo.c" diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index ae7fdcfa40..38f1dbef4b 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -191,7 +191,15 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) params { Elm_Code_Line *line; /*@ @in The line to test for visibility. */ } - return: bool (visible); /*@ true if the line specified is currently visible within the scroll region. */ + return: bool; /*@ true if the line specified is currently visible within the scroll region. */ + } + + /* text functions */ + text_left_gutter_width_get { + return: int; /*@ the current column width of the gutter for the widget. */ + } + text_line_number_width_get { + return: int; /*@ the column width required to represent the number of lines in the widget. */ } } implements { diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_text.c b/legacy/elm_code/src/lib/widget/elm_code_widget_text.c index c50ebce51c..696fc30801 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_text.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_text.c @@ -6,13 +6,11 @@ #include "elm_code_widget_private.h" -EAPI int -elm_code_widget_text_line_number_width_get(Elm_Code_Widget *widget) +static int +_elm_code_widget_text_line_number_width_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) { - Elm_Code_Widget_Data *pd; int max; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); max = elm_code_file_lines_get(pd->code->file); if (max < 1) max = 1; @@ -20,19 +18,18 @@ elm_code_widget_text_line_number_width_get(Elm_Code_Widget *widget) return floor(log10(max)) + 1; } -EAPI int -elm_code_widget_text_left_gutter_width_get(Elm_Code_Widget *widget) +static int +_elm_code_widget_text_left_gutter_width_get(Eo *obj, Elm_Code_Widget_Data *pd) { - Elm_Code_Widget_Data *pd; + Elm_Code_Widget *widget; int width = 1; // the status icon, for now + widget = obj; if (!widget) return width; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (pd->show_line_numbers) - width += elm_code_widget_text_line_number_width_get(widget); + width += _elm_code_widget_text_line_number_width_get(widget, pd); return width; } diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_text.h b/legacy/elm_code/src/lib/widget/elm_code_widget_text.h deleted file mode 100644 index 5ac983e610..0000000000 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_text.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef ELM_CODE_WIDGET_TEXT_H_ -# define ELM_CODE_WIDGET_TEXT_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Text layout handling functions. - * @defgroup Managing the complexities of layout out text in an Elm_Code_Widget - * - * @{ - * - * Functions for text layout handling - * - */ - -EAPI int elm_code_widget_text_left_gutter_width_get(Elm_Code_Widget *widget); - -EAPI int elm_code_widget_text_line_number_width_get(Elm_Code_Widget *widget); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* ELM_CODE_WIDGET_TEXT_H_ */ From 58c1e5bc820d641c26a898008d0bb85d3c09542a Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 7 Apr 2015 23:05:47 +0100 Subject: [PATCH 151/254] elm_code: Fix position calculations at line end Addresses random NULLs in content after newline --- legacy/elm_code/src/lib/elm_code_text.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 9b7d8f36b2..2a68413bc5 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -262,13 +262,13 @@ elm_code_line_text_position_for_column_get(Elm_Code_Line *line, unsigned int col else chars = line->content; - while ((unsigned int) count < column && index <= line->length) + while ((unsigned int) count < column && index <= (int) line->length) { unicode = eina_unicode_utf8_next_get(chars, &index); - if (unicode == 0) - break; - if (unicode == '\t') + if (unicode == 0) + return line->length + 1; + else if (unicode == '\t') count += elm_code_text_tabwidth_at_position(count, tabstop); else count++; From 5e72e7e71eac5f3a45403475de181e4b5f48b939 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 7 Apr 2015 23:09:16 +0100 Subject: [PATCH 152/254] elm_code: Correctly delete tabs when mid-tab Delete at least 1 char and move cursor to the beginning of the tab --- .../elm_code/src/lib/widget/elm_code_widget.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index fef9729833..f641906253 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -945,7 +945,7 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) Elm_Code *code; Elm_Code_Line *line; Elm_Code_Widget_Data *pd; - unsigned int row, col, position, col_width, char_width; + unsigned int row, col, position, start_col, char_width; if (_elm_code_widget_delete_selection(widget)) return; @@ -969,11 +969,11 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); char_width = elm_code_line_text_position_for_column_get(line, col, pd->tabstop) - elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); - col_width = elm_code_line_text_column_width_to_position(line, position, pd->tabstop) - - elm_code_line_text_column_width_to_position(line, position - 1, pd->tabstop); - elm_code_line_text_remove(line, position, char_width); + start_col = elm_code_line_text_column_width_to_position(line, position - 1, pd->tabstop); + + elm_code_line_text_remove(line, position, char_width?char_width:1); eo_do(widget, - elm_code_widget_cursor_position_set(col - col_width, row)); + elm_code_widget_cursor_position_set(start_col + 1, row)); // TODO construct and pass a change object eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); @@ -984,7 +984,7 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) { Elm_Code *code; Elm_Code_Line *line; - unsigned int row, col, position, char_width; + unsigned int row, col, position, char_width, start_col; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); @@ -1008,9 +1008,11 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) position = elm_code_line_text_position_for_column_get(line, col, pd->tabstop); char_width = elm_code_line_text_position_for_column_get(line, col, pd->tabstop) - elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); - elm_code_line_text_remove(line, position, char_width); + start_col = elm_code_line_text_column_width_to_position(line, position - 1, pd->tabstop); + + elm_code_line_text_remove(line, position, char_width?char_width:1); eo_do(widget, - elm_code_widget_cursor_position_set(col, row), + elm_code_widget_cursor_position_set(start_col + 1, row), // TODO construct and pass a change object eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } From 8c0f74628b8df14440f2b7f1568648ecf1579721 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 12 Apr 2015 16:56:17 +0100 Subject: [PATCH 153/254] search: Fix issue when text is at end of line Tests were wrong, fix and add more --- legacy/elm_code/src/lib/elm_code_text.c | 2 +- legacy/elm_code/src/tests/elm_code_test_text.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 2a68413bc5..206a6cf34a 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -56,7 +56,7 @@ elm_code_line_text_strpos(Elm_Code_Line *line, const char *search, int offset) return ELM_CODE_TEXT_NOT_FOUND; ptr += offset; - for (c = offset; c < length - strlen(search); c++) + for (c = offset; c <= length - searchlen; c++) { if (!strncmp(ptr, search, searchlen)) return c; diff --git a/legacy/elm_code/src/tests/elm_code_test_text.c b/legacy/elm_code/src/tests/elm_code_test_text.c index 3aad59e2f1..f017835aff 100644 --- a/legacy/elm_code/src/tests/elm_code_test_text.c +++ b/legacy/elm_code/src/tests/elm_code_test_text.c @@ -46,7 +46,7 @@ START_TEST (elm_code_text_contains_test) code = elm_code_create(); file = elm_code_file_new(code); - elm_code_file_line_append(file, "a test string...", 17, NULL); + elm_code_file_line_append(file, "a test string...", 16, NULL); line = elm_code_file_line_get(file, 1); ck_assert_int_eq(EINA_TRUE, elm_code_line_text_contains(line, "test")); @@ -66,7 +66,7 @@ START_TEST (elm_code_text_strpos_test) code = elm_code_create(); file = elm_code_file_new(code); - elm_code_file_line_append(file, "a test string...", 17, NULL); + elm_code_file_line_append(file, "a test string...", 16, NULL); line = elm_code_file_line_get(file, 1); ck_assert_int_eq(2, elm_code_line_text_strpos(line, "test", 0)); @@ -76,6 +76,7 @@ START_TEST (elm_code_text_strpos_test) ck_assert_int_eq(ELM_CODE_TEXT_NOT_FOUND, elm_code_line_text_strpos(line, "text", 0)); ck_assert_int_eq(0, elm_code_line_text_strpos(line, "a t", 0)); + ck_assert_int_eq(ELM_CODE_TEXT_NOT_FOUND, elm_code_line_text_strpos(line, "a t", 2)); ck_assert_int_eq(13, elm_code_line_text_strpos(line, "...", 0)); } END_TEST From 462a60d85da591e04e4a2e1a04ad6f0b4db63cdd Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 12 Apr 2015 17:25:20 +0100 Subject: [PATCH 154/254] syntax: don't slow down by repeating tokens Clear out the token list before each parse callback loops --- legacy/elm_code/src/lib/elm_code_line.c | 10 ++++ legacy/elm_code/src/lib/elm_code_line.h | 2 + legacy/elm_code/src/lib/elm_code_parse.c | 8 +++ legacy/elm_code/src/tests/Makefile.am | 1 + legacy/elm_code/src/tests/elm_code_suite.h | 1 + .../elm_code/src/tests/elm_code_test_line.c | 52 +++++++++++++++++++ 6 files changed, 74 insertions(+) create mode 100644 legacy/elm_code/src/tests/elm_code_test_line.c diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index dfddb67231..852ed361f1 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -57,3 +57,13 @@ EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int l elm_code_line_token_add(next_line, 1, end, lines - 1, type); } } + +EAPI void elm_code_line_tokens_clear(Elm_Code_Line *line) +{ + Elm_Code_Token *token; + + EINA_LIST_FREE(line->tokens, token) + free(token); + line->tokens = NULL; +} + diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index d2f7968e89..64e3e350b1 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -51,6 +51,8 @@ EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type sta EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int lines, Elm_Code_Token_Type type); +EAPI void elm_code_line_tokens_clear(Elm_Code_Line *line); + /** * @} */ diff --git a/legacy/elm_code/src/lib/elm_code_parse.c b/legacy/elm_code/src/lib/elm_code_parse.c index 9146e46f6d..9a70ca485e 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.c +++ b/legacy/elm_code/src/lib/elm_code_parse.c @@ -22,6 +22,8 @@ _elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line) Elm_Code_Parser *parser; Eina_List *item; + elm_code_line_tokens_clear(line); + EINA_LIST_FOREACH(code->parsers, item, parser) { if (parser->parse_line) @@ -34,6 +36,12 @@ _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file) { Elm_Code_Parser *parser; Eina_List *item; + Elm_Code_Line *line; + + EINA_LIST_FOREACH(file->lines, item, line) + { + elm_code_line_tokens_clear(line); + } EINA_LIST_FOREACH(code->parsers, item, parser) { diff --git a/legacy/elm_code/src/tests/Makefile.am b/legacy/elm_code/src/tests/Makefile.am index 8e74bc0b8b..45476e5960 100644 --- a/legacy/elm_code/src/tests/Makefile.am +++ b/legacy/elm_code/src/tests/Makefile.am @@ -9,6 +9,7 @@ elm_code_suite_SOURCES = \ elm_code_file_test_load.c \ elm_code_file_test_memory.c \ elm_code_test_basic.c \ +elm_code_test_line.c \ elm_code_test_parse.c \ elm_code_test_text.c \ widget/elm_code_test_widget.c \ diff --git a/legacy/elm_code/src/tests/elm_code_suite.h b/legacy/elm_code/src/tests/elm_code_suite.h index d03e11b565..5a7f4e3662 100644 --- a/legacy/elm_code/src/tests/elm_code_suite.h +++ b/legacy/elm_code/src/tests/elm_code_suite.h @@ -8,6 +8,7 @@ void elm_code_file_test_load(TCase *tc); void elm_code_file_test_memory(TCase *tc); void elm_code_test_basic(TCase *tc); +void elm_code_test_line(TCase *tc); void elm_code_test_parse(TCase *tc); void elm_code_test_text(TCase *tc); void elm_code_test_widget(TCase *tc); diff --git a/legacy/elm_code/src/tests/elm_code_test_line.c b/legacy/elm_code/src/tests/elm_code_test_line.c new file mode 100644 index 0000000000..5d2689701e --- /dev/null +++ b/legacy/elm_code/src/tests/elm_code_test_line.c @@ -0,0 +1,52 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "elm_code_suite.h" + +START_TEST (elm_code_line_create_test) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + + code = elm_code_create(); + file = elm_code_file_new(code); + + elm_code_file_line_append(file, "a test string...", 16, NULL); + line = elm_code_file_line_get(file, 1); + + ck_assert(!!line); + + elm_code_free(code); +} +END_TEST + +START_TEST (elm_code_line_token_count_test) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + + code = elm_code_create(); + file = elm_code_file_new(code); + + elm_code_file_line_append(file, "a test string...", 16, NULL); + line = elm_code_file_line_get(file, 1); + + ck_assert_int_eq(0, eina_list_count(line->tokens)); + elm_code_line_token_add(line, 2, 5, 1, ELM_CODE_TOKEN_TYPE_COMMENT); + ck_assert_int_eq(1, eina_list_count(line->tokens)); + elm_code_line_tokens_clear(line); + ck_assert_int_eq(0, eina_list_count(line->tokens)); + + elm_code_free(code); +} +END_TEST + +void elm_code_test_line(TCase *tc) +{ + tcase_add_test(tc, elm_code_line_create_test); + tcase_add_test(tc, elm_code_line_token_count_test); +} + From 9cfe41ee003d636cbe100c01c419efe32ae63eab Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 12 Apr 2015 23:04:46 +0100 Subject: [PATCH 155/254] syntax: reset status and hints when we reset token re-use elm_code methods when we do this in edi --- legacy/elm_code/src/lib/elm_code_line.c | 21 +++++++++++++++++++++ legacy/elm_code/src/lib/elm_code_line.h | 6 +++++- legacy/elm_code/src/lib/elm_code_parse.c | 2 ++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index 852ed361f1..5195972be9 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -28,6 +28,17 @@ EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type sta line->status = status; } +EAPI void elm_code_line_status_text_set(Elm_Code_Line *line, const char *text) +{ + if (line->status_text) + free(line->status_text); + + if (text) + line->status_text = strdup(text); + else + line->status_text = NULL; +} + EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int lines, Elm_Code_Token_Type type) { @@ -67,3 +78,13 @@ EAPI void elm_code_line_tokens_clear(Elm_Code_Line *line) line->tokens = NULL; } +EAPI void elm_code_line_status_clear(Elm_Code_Line *line) +{ + line->status = ELM_CODE_STATUS_TYPE_DEFAULT; + if (line->status_text) + { + free((char *)line->status_text); + line->status_text = NULL; + } +} + diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index 64e3e350b1..e3ad1286b2 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -32,7 +32,7 @@ typedef struct _Elm_Code_Line Eina_List *tokens; void *data; - const char *status_text; + char *status_text; } Elm_Code_Line; EAPI void elm_code_line_free(Elm_Code_Line *line); @@ -49,6 +49,10 @@ EAPI void elm_code_line_free(Elm_Code_Line *line); EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status); +EAPI void elm_code_line_status_text_set(Elm_Code_Line *line, const char *text); + +EAPI void elm_code_line_status_clear(Elm_Code_Line *line); + EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int lines, Elm_Code_Token_Type type); EAPI void elm_code_line_tokens_clear(Elm_Code_Line *line); diff --git a/legacy/elm_code/src/lib/elm_code_parse.c b/legacy/elm_code/src/lib/elm_code_parse.c index 9a70ca485e..02c878adf5 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.c +++ b/legacy/elm_code/src/lib/elm_code_parse.c @@ -23,6 +23,7 @@ _elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line) Eina_List *item; elm_code_line_tokens_clear(line); + elm_code_line_status_clear(line); EINA_LIST_FOREACH(code->parsers, item, parser) { @@ -41,6 +42,7 @@ _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file) EINA_LIST_FOREACH(file->lines, item, line) { elm_code_line_tokens_clear(line); + elm_code_line_status_clear(line); } EINA_LIST_FOREACH(code->parsers, item, parser) From 137dbed20b43103d9a6513a7de68bfad9bf6e51b Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 13 Apr 2015 00:15:21 +0100 Subject: [PATCH 156/254] elm_code: retain line formatting on file callback We don't need to reset all the lines in file load - just clear --- legacy/elm_code/src/lib/elm_code_parse.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_parse.c b/legacy/elm_code/src/lib/elm_code_parse.c index 02c878adf5..408fd4846b 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.c +++ b/legacy/elm_code/src/lib/elm_code_parse.c @@ -37,13 +37,6 @@ _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file) { Elm_Code_Parser *parser; Eina_List *item; - Elm_Code_Line *line; - - EINA_LIST_FOREACH(file->lines, item, line) - { - elm_code_line_tokens_clear(line); - elm_code_line_status_clear(line); - } EINA_LIST_FOREACH(code->parsers, item, parser) { From 4e7cae76dc2357cbe283eb5e0a82619662e79bfc Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 19 Apr 2015 15:00:10 +0100 Subject: [PATCH 157/254] elm_code: add multiline paste support. Creating and breaking out a few helper text methods at the same time. Test all that we can for this reasonably complex operation --- legacy/elm_code/src/lib/elm_code_line.c | 18 ++++++ legacy/elm_code/src/lib/elm_code_line.h | 14 ++++- legacy/elm_code/src/lib/elm_code_text.c | 42 +++++++++++-- legacy/elm_code/src/lib/elm_code_text.h | 4 ++ .../elm_code/src/lib/widget/elm_code_widget.c | 15 +---- .../lib/widget/elm_code_widget_selection.c | 59 ++++++++++++++++--- .../elm_code/src/tests/elm_code_test_line.c | 23 ++++++++ .../elm_code/src/tests/elm_code_test_text.c | 11 ++++ 8 files changed, 159 insertions(+), 27 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index 5195972be9..f9d3b0856f 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -20,6 +20,24 @@ elm_code_line_free(Elm_Code_Line *line) free(line); } +EAPI void elm_code_line_split_at(Elm_Code_Line *line, unsigned int position) +{ + Elm_Code_Line *newline; + char *content; + unsigned int length; + + content = (char *) elm_code_line_text_get(line, &length); + content = strndup(content, length); + elm_code_file_line_insert(line->file, line->number + 1, "", 0, NULL); + newline = elm_code_file_line_get(line->file, line->number + 1); +// TODO we need to split tokens from these lines + + elm_code_line_text_set(newline, content + position, length - position); + elm_code_line_text_set(line, content, position); + + free(content); +} + EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status) { if (!line) diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index e3ad1286b2..6a0f767d6f 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -38,8 +38,20 @@ typedef struct _Elm_Code_Line EAPI void elm_code_line_free(Elm_Code_Line *line); /** + * @brief Line manipulation functions. + * @defgroup Content + * @{ + * + * Functions for changing the content of lines in an Elm_Code_File + */ + +EAPI void elm_code_line_split_at(Elm_Code_Line *line, unsigned int position); + +/** + * @} + * * @brief Line markup functions. - * @defgroup Line highlighting and status manipulation + * @defgroup Highlighting * * @{ * diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 206a6cf34a..8b22f3a19a 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -42,14 +42,12 @@ elm_code_line_text_set(Elm_Code_Line *line, const char *chars, unsigned int leng } EAPI int -elm_code_line_text_strpos(Elm_Code_Line *line, const char *search, int offset) +elm_code_text_strnpos(const char *content, unsigned int length, const char *search, int offset) { - unsigned int length, searchlen, c; - const char *content; + unsigned int searchlen, c; char *ptr; searchlen = strlen(search); - content = elm_code_line_text_get(line, &length); ptr = (char *) content; if (searchlen > length) @@ -67,6 +65,16 @@ elm_code_line_text_strpos(Elm_Code_Line *line, const char *search, int offset) return ELM_CODE_TEXT_NOT_FOUND; } +EAPI int +elm_code_line_text_strpos(Elm_Code_Line *line, const char *search, int offset) +{ + unsigned int length; + const char *content; + + content = elm_code_line_text_get(line, &length); + return elm_code_text_strnpos(content, length, search, offset); +} + EAPI Eina_Bool elm_code_line_text_contains(Elm_Code_Line *line, const char *search) { @@ -201,12 +209,36 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length /* generic text functions */ -unsigned int +EAPI unsigned int elm_code_text_tabwidth_at_position(unsigned int position, unsigned int tabstop) { return tabstop - (position % tabstop); } +EAPI int +elm_code_text_newlinenpos(const char *text, unsigned int length) +{ + int lfpos, crpos; + int check; + + lfpos = elm_code_text_strnpos(text, length, "\n", 0); + check = length; + if (lfpos != ELM_CODE_TEXT_NOT_FOUND) + check = lfpos; + crpos = elm_code_text_strnpos(text, check, "\r", 0); + + if (lfpos == ELM_CODE_TEXT_NOT_FOUND && crpos == ELM_CODE_TEXT_NOT_FOUND) + return ELM_CODE_TEXT_NOT_FOUND; + + if (crpos == ELM_CODE_TEXT_NOT_FOUND) + return lfpos; + if (lfpos == ELM_CODE_TEXT_NOT_FOUND) + return crpos; + if (lfpos < crpos) + return lfpos; + return crpos; +} + EAPI unsigned int elm_code_line_text_column_width_to_position(Elm_Code_Line *line, unsigned int position, unsigned int tabstop) { diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 17a47ebc2f..15b236e3f5 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -50,6 +50,10 @@ EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, EAPI unsigned int elm_code_text_tabwidth_at_position(unsigned int position, unsigned int tabstop); +EAPI int elm_code_text_strnpos(const char *text, unsigned int length, const char *search, int offset); + +EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length); + EAPI unsigned int elm_code_line_text_column_width_to_position(Elm_Code_Line *line, unsigned int length, unsigned int tabstop); EAPI unsigned int elm_code_line_text_column_width(Elm_Code_Line *line, unsigned int tabstop); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index f641906253..4c1edc4d29 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -859,10 +859,9 @@ static void _elm_code_widget_newline(Elm_Code_Widget *widget) { Elm_Code *code; - Elm_Code_Line *line, *newline; + Elm_Code_Line *line; Elm_Code_Widget_Data *pd; - unsigned int row, col, length, position; - char *content; + unsigned int row, col, position; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); _elm_code_widget_delete_selection(widget); @@ -871,17 +870,9 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) elm_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); - content = (char *) elm_code_line_text_get(line, &length); - content = strndup(content, length); - elm_code_file_line_insert(code->file, line->number + 1, "", 0, NULL); - newline = elm_code_file_line_get(code->file, line->number + 1); -// TODO we need to split tokens from these lines (move this to elm_code_line?) - position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); - elm_code_line_text_set(newline, content + position, length - position); - elm_code_line_text_set(line, content, position); + elm_code_line_split_at(line, position); - free(content); eo_do(widget, elm_code_widget_cursor_position_set(1, row + 1), // TODO construct and pass a change object diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index a7a5c018c5..473d999cff 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -287,14 +287,58 @@ elm_code_widget_selection_copy(Evas_Object *widget) free(text); } +static void +_selection_paste_single(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Code *code, + unsigned int col, unsigned int row, const char *text, unsigned int len) +{ + Elm_Code_Line *line; + unsigned int position, newcol; + + line = elm_code_file_line_get(code->file, row); + position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); + elm_code_line_text_insert(line, position + 1, text, len); + + newcol = elm_code_line_text_column_width_to_position(line, position + len, pd->tabstop); + eo_do(widget, + elm_code_widget_cursor_position_set(newcol + 1, row)); +} + +static void +_selection_paste_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Code *code, + unsigned int col, unsigned int row, const char *text, unsigned int len) +{ + Elm_Code_Line *line; + unsigned int position, newrow; + int nlpos; + char *ptr; + + line = elm_code_file_line_get(code->file, row); + position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); + elm_code_line_split_at(line, position); + + newrow = row; + ptr = (char *)text; + while ((nlpos = elm_code_text_newlinenpos(ptr, len)) != ELM_CODE_TEXT_NOT_FOUND) + { + if (newrow == row) + _selection_paste_single(widget, pd, code, col, row, text, nlpos); + else + elm_code_file_line_insert(code->file, newrow, ptr, nlpos, NULL); + + ptr += nlpos + 1; // TODO make this adapt to windows lengths (length param to newlinenpos) + newrow++; + } + + _selection_paste_single(widget, pd, code, 1, newrow, ptr, len - (ptr - text)); +} + static Eina_Bool _selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data *ev) { Elm_Code *code; Elm_Code_Widget *widget; - Elm_Code_Line *line; Elm_Code_Widget_Data *pd; - unsigned int row, col, col_width, position; + unsigned int row, col; widget = (Elm_Code_Widget *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); @@ -308,15 +352,12 @@ _selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data eo_do(widget, code = elm_code_widget_code_get(), elm_code_widget_cursor_position_get(&col, &row)); - line = elm_code_file_line_get(code->file, row); - position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); - elm_code_line_text_insert(line, position + 1, ev->data, ev->len - 1); + if (elm_code_text_newlinenpos(ev->data, ev->len) == ELM_CODE_TEXT_NOT_FOUND) + _selection_paste_single(widget, pd, code, col, row, ev->data, ev->len - 1); + else + _selection_paste_multi(widget, pd, code, col, row, ev->data, ev->len - 1); - col_width = elm_code_line_text_column_width_to_position(line, position + ev->len - 1, pd->tabstop) - - elm_code_line_text_column_width_to_position(line, position, pd->tabstop); - eo_do(widget, - elm_code_widget_cursor_position_set(col + col_width, row)); return EINA_TRUE; } diff --git a/legacy/elm_code/src/tests/elm_code_test_line.c b/legacy/elm_code/src/tests/elm_code_test_line.c index 5d2689701e..b19bf615c3 100644 --- a/legacy/elm_code/src/tests/elm_code_test_line.c +++ b/legacy/elm_code/src/tests/elm_code_test_line.c @@ -44,9 +44,32 @@ START_TEST (elm_code_line_token_count_test) } END_TEST +START_TEST (elm_code_line_split_test) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line, *newline; + + code = elm_code_create(); + file = elm_code_file_new(code); + + elm_code_file_line_append(file, "line1line2", 10, NULL); + line = elm_code_file_line_get(file, 1); + ck_assert_int_eq(1, elm_code_file_lines_get(file)); + ck_assert_int_eq(10, line->length); + + elm_code_line_split_at(line, 5); + ck_assert_int_eq(2, elm_code_file_lines_get(file)); + newline = elm_code_file_line_get(file, 2); + ck_assert_int_eq(5, line->length); + ck_assert_int_eq(5, newline->length); +} +END_TEST + void elm_code_test_line(TCase *tc) { tcase_add_test(tc, elm_code_line_create_test); tcase_add_test(tc, elm_code_line_token_count_test); + tcase_add_test(tc, elm_code_line_split_test); } diff --git a/legacy/elm_code/src/tests/elm_code_test_text.c b/legacy/elm_code/src/tests/elm_code_test_text.c index f017835aff..1798433203 100644 --- a/legacy/elm_code/src/tests/elm_code_test_text.c +++ b/legacy/elm_code/src/tests/elm_code_test_text.c @@ -81,10 +81,21 @@ START_TEST (elm_code_text_strpos_test) } END_TEST +START_TEST (elm_code_text_newline_position_test) +{ + const char *unixtext = "a test\nwith newline"; + const char *wintext = "a windows\r\nnewline"; + + ck_assert_int_eq(6, elm_code_text_newlinenpos(unixtext, strlen(unixtext))); + ck_assert_int_eq(9, elm_code_text_newlinenpos(wintext, strlen(wintext))); +} +END_TEST + void elm_code_test_text(TCase *tc) { tcase_add_test(tc, elm_code_text_get_test); tcase_add_test(tc, elm_code_text_insert_test); tcase_add_test(tc, elm_code_text_contains_test); tcase_add_test(tc, elm_code_text_strpos_test); + tcase_add_test(tc, elm_code_text_newline_position_test); } From d2f14a82b7e0a8fbd8e9cfca10a05f4593d8f23b Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 20 Apr 2015 01:21:03 +0100 Subject: [PATCH 158/254] elm_code: add a TODO/FIXME standard parser Corret some callback code and re-parse each time the file is saved. Use this to clean up save/parse code in EDI too --- legacy/elm_code/src/lib/elm_code_common.h | 2 ++ legacy/elm_code/src/lib/elm_code_file.c | 7 +++++ legacy/elm_code/src/lib/elm_code_parse.c | 22 ++++++++++++++++ legacy/elm_code/src/lib/elm_code_parse.h | 1 + legacy/elm_code/src/lib/elm_code_private.h | 2 ++ legacy/elm_code/src/lib/elm_code_text.c | 6 ++++- .../elm_code/src/lib/widget/elm_code_widget.c | 3 +++ .../elm_code/src/tests/elm_code_test_parse.c | 26 +++++++++++++++++++ 8 files changed, 68 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_common.h b/legacy/elm_code/src/lib/elm_code_common.h index 2174f49230..9c8ec5ab2e 100644 --- a/legacy/elm_code/src/lib/elm_code_common.h +++ b/legacy/elm_code/src/lib/elm_code_common.h @@ -24,6 +24,8 @@ typedef enum { ELM_CODE_STATUS_TYPE_PASSED, ELM_CODE_STATUS_TYPE_FAILED, + ELM_CODE_STATUS_TYPE_TODO, + ELM_CODE_STATUS_TYPE_COUNT } Elm_Code_Status_Type; diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index 1a729113f9..0b164bba53 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -186,6 +186,13 @@ EAPI void elm_code_file_save(Elm_Code_File *file) ecore_file_mv(tmp, path); free(tmp); + + if (file->parent) + { + _elm_code_parse_reset_file(file->parent, file); + _elm_code_parse_file(file->parent, file); + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_FILE_LOAD_DONE, file); + } } EAPI void elm_code_file_free(Elm_Code_File *file) diff --git a/legacy/elm_code/src/lib/elm_code_parse.c b/legacy/elm_code/src/lib/elm_code_parse.c index 408fd4846b..87627f75ef 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.c +++ b/legacy/elm_code/src/lib/elm_code_parse.c @@ -45,6 +45,18 @@ _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file) } } +void +_elm_code_parse_reset_file(Elm_Code *code, Elm_Code_File *file) +{ + Elm_Code_Line *line; + Eina_List *item; + + EINA_LIST_FOREACH(file->lines, item, line) + { + _elm_code_parse_line(code, line); + } +} + static Elm_Code_Parser * _elm_code_parser_new(void (*parse_line)(Elm_Code_Line *, void *), void (*parse_file)(Elm_Code_File *, void *)) @@ -164,9 +176,19 @@ _elm_code_parser_diff_parse_file(Elm_Code_File *file, void *data EINA_UNUSED) } } +static void +_elm_code_parser_todo_parse_line(Elm_Code_Line *line, void *data EINA_UNUSED) +{ + if (elm_code_line_text_strpos(line, "TODO", 0) != ELM_CODE_TEXT_NOT_FOUND) + elm_code_line_status_set(line, ELM_CODE_STATUS_TYPE_TODO); + else if (elm_code_line_text_strpos(line, "FIXME", 0) != ELM_CODE_TEXT_NOT_FOUND) + elm_code_line_status_set(line, ELM_CODE_STATUS_TYPE_TODO); +} + void _elm_code_parse_setup() { ELM_CODE_PARSER_STANDARD_DIFF = _elm_code_parser_new(_elm_code_parser_diff_parse_line, _elm_code_parser_diff_parse_file); + ELM_CODE_PARSER_STANDARD_TODO = _elm_code_parser_new(_elm_code_parser_todo_parse_line, NULL); } diff --git a/legacy/elm_code/src/lib/elm_code_parse.h b/legacy/elm_code/src/lib/elm_code_parse.h index d991345b5a..bc674f8b41 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.h +++ b/legacy/elm_code/src/lib/elm_code_parse.h @@ -13,6 +13,7 @@ extern "C" { typedef struct _Elm_Code_Parser Elm_Code_Parser; EAPI Elm_Code_Parser *ELM_CODE_PARSER_STANDARD_DIFF; /**< A provided parser that will mark up diff text */ +EAPI Elm_Code_Parser *ELM_CODE_PARSER_STANDARD_TODO; /**< A provided parser that will highlight TODO and FIXME lines */ /** * @brief Parser helper functions. diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h index fed2ff4134..1f16c8f4f3 100644 --- a/legacy/elm_code/src/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -32,5 +32,7 @@ void _elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line); void _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file); +void _elm_code_parse_reset_file(Elm_Code *code, Elm_Code_File *file); + #endif diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 8b22f3a19a..f51569ce0a 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -38,7 +38,11 @@ elm_code_line_text_set(Elm_Code_Line *line, const char *chars, unsigned int leng line->length = length; file = line->file; - elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); + if (file->parent) + { + _elm_code_parse_line(file->parent, line); + elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); + } } EAPI int diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 4c1edc4d29..e9c0344657 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1299,6 +1299,9 @@ _elm_code_widget_setup_palette(Evas_Object *o) evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FAILED, 96, 54, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_TODO, + 54, 54, 96, 255); + // setup token colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT, 205, 205, 205, 255); diff --git a/legacy/elm_code/src/tests/elm_code_test_parse.c b/legacy/elm_code/src/tests/elm_code_test_parse.c index a5349a5cb0..e91845c3b5 100644 --- a/legacy/elm_code/src/tests/elm_code_test_parse.c +++ b/legacy/elm_code/src/tests/elm_code_test_parse.c @@ -60,9 +60,35 @@ START_TEST (elm_code_parse_hook_file_test) } END_TEST +START_TEST (elm_code_parse_todo_test) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + + elm_code_init(); + + code = elm_code_create(); + elm_code_parser_standard_add(code, ELM_CODE_PARSER_STANDARD_TODO); + file = elm_code_file_new(code); + + elm_code_file_line_append(file, "xxx TODO line", 13, NULL); + line = elm_code_file_line_get(file, 1); + ck_assert_int_eq(ELM_CODE_STATUS_TYPE_TODO, line->status); + + elm_code_line_text_set(line, "FIXME too", 9); + ck_assert_int_eq(ELM_CODE_STATUS_TYPE_TODO, line->status); + + elm_code_line_text_set(line, "TOFIX", 5); + ck_assert_int_eq(ELM_CODE_STATUS_TYPE_DEFAULT, line->status); + elm_code_shutdown(); +} +END_TEST + void elm_code_test_parse(TCase *tc) { tcase_add_test(tc, elm_code_parse_hook_memory_test); tcase_add_test(tc, elm_code_parse_hook_file_test); + tcase_add_test(tc, elm_code_parse_todo_test); } From ee9cec7ddda0a40685bf3721d2ff6824bd812813 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 5 May 2015 21:40:22 +0100 Subject: [PATCH 159/254] editor: Fix crash when pasting multi line Not tracking length correctly so depending on what else is in memory we could overrun the buffer --- .../elm_code/src/lib/widget/elm_code_widget_selection.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 473d999cff..440833c192 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -308,7 +308,7 @@ _selection_paste_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Co unsigned int col, unsigned int row, const char *text, unsigned int len) { Elm_Code_Line *line; - unsigned int position, newrow; + unsigned int position, newrow, remain; int nlpos; char *ptr; @@ -318,14 +318,16 @@ _selection_paste_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Co newrow = row; ptr = (char *)text; - while ((nlpos = elm_code_text_newlinenpos(ptr, len)) != ELM_CODE_TEXT_NOT_FOUND) + remain = len; + while ((nlpos = elm_code_text_newlinenpos(ptr, remain)) != ELM_CODE_TEXT_NOT_FOUND) { if (newrow == row) _selection_paste_single(widget, pd, code, col, row, text, nlpos); else elm_code_file_line_insert(code->file, newrow, ptr, nlpos, NULL); - ptr += nlpos + 1; // TODO make this adapt to windows lengths (length param to newlinenpos) + remain -= nlpos + 1; // TODO make this adapt to windows lengths (length param to newlinenpos) + ptr += nlpos + 1; newrow++; } From a5e1f8238206aadf5fd45eca7861244abbfd14e4 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 5 May 2015 21:41:29 +0100 Subject: [PATCH 160/254] editor: correctly paste multiline windows text --- legacy/elm_code/src/lib/elm_code_text.c | 9 +++++++-- legacy/elm_code/src/lib/elm_code_text.h | 2 +- .../elm_code/src/lib/widget/elm_code_widget_selection.c | 9 +++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index f51569ce0a..2ae3432849 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -220,15 +220,17 @@ elm_code_text_tabwidth_at_position(unsigned int position, unsigned int tabstop) } EAPI int -elm_code_text_newlinenpos(const char *text, unsigned int length) +elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen) { int lfpos, crpos; int check; + if (nllen) + *nllen = 1; lfpos = elm_code_text_strnpos(text, length, "\n", 0); check = length; if (lfpos != ELM_CODE_TEXT_NOT_FOUND) - check = lfpos; + check = lfpos + 1; crpos = elm_code_text_strnpos(text, check, "\r", 0); if (lfpos == ELM_CODE_TEXT_NOT_FOUND && crpos == ELM_CODE_TEXT_NOT_FOUND) @@ -238,6 +240,9 @@ elm_code_text_newlinenpos(const char *text, unsigned int length) return lfpos; if (lfpos == ELM_CODE_TEXT_NOT_FOUND) return crpos; + + if (nllen) + *nllen = 2; if (lfpos < crpos) return lfpos; return crpos; diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 15b236e3f5..07eced913a 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -52,7 +52,7 @@ EAPI unsigned int elm_code_text_tabwidth_at_position(unsigned int position, unsi EAPI int elm_code_text_strnpos(const char *text, unsigned int length, const char *search, int offset); -EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length); +EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen); EAPI unsigned int elm_code_line_text_column_width_to_position(Elm_Code_Line *line, unsigned int length, unsigned int tabstop); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 440833c192..3838c107bb 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -310,6 +310,7 @@ _selection_paste_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Co Elm_Code_Line *line; unsigned int position, newrow, remain; int nlpos; + short nllen; char *ptr; line = elm_code_file_line_get(code->file, row); @@ -319,15 +320,15 @@ _selection_paste_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Co newrow = row; ptr = (char *)text; remain = len; - while ((nlpos = elm_code_text_newlinenpos(ptr, remain)) != ELM_CODE_TEXT_NOT_FOUND) + while ((nlpos = elm_code_text_newlinenpos(ptr, remain, &nllen)) != ELM_CODE_TEXT_NOT_FOUND) { if (newrow == row) _selection_paste_single(widget, pd, code, col, row, text, nlpos); else elm_code_file_line_insert(code->file, newrow, ptr, nlpos, NULL); - remain -= nlpos + 1; // TODO make this adapt to windows lengths (length param to newlinenpos) - ptr += nlpos + 1; + remain -= nlpos + nllen; + ptr += nlpos + nllen; newrow++; } @@ -355,7 +356,7 @@ _selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data code = elm_code_widget_code_get(), elm_code_widget_cursor_position_get(&col, &row)); - if (elm_code_text_newlinenpos(ev->data, ev->len) == ELM_CODE_TEXT_NOT_FOUND) + if (elm_code_text_newlinenpos(ev->data, ev->len, NULL) == ELM_CODE_TEXT_NOT_FOUND) _selection_paste_single(widget, pd, code, col, row, ev->data, ev->len - 1); else _selection_paste_multi(widget, pd, code, col, row, ev->data, ev->len - 1); From 246132b4eadb617be8826569488fb0b7dd345c51 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 5 May 2015 21:49:21 +0100 Subject: [PATCH 161/254] editor: bind home and end keys --- .../elm_code/src/lib/widget/elm_code_widget.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index e9c0344657..20e9eacbdd 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -814,6 +814,37 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) _elm_code_widget_cursor_move(widget, pd, pd->cursor_col+1, pd->cursor_line, EINA_TRUE); } + +static void +_elm_code_widget_cursor_move_home(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (pd->cursor_col <= 1) + return; + + _elm_code_widget_cursor_move(widget, pd, 1, pd->cursor_line, EINA_TRUE); +} + +static void +_elm_code_widget_cursor_move_end(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; + unsigned int lastcol; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + line = elm_code_file_line_get(pd->code->file, pd->cursor_line); + lastcol = elm_code_line_text_column_width(line, pd->tabstop); + if (pd->cursor_col > lastcol + 1) + return; + + _elm_code_widget_cursor_move(widget, pd, lastcol + 1, pd->cursor_line, EINA_TRUE); +} + static Eina_Bool _elm_code_widget_delete_selection(Elm_Code_Widget *widget) { @@ -1053,6 +1084,10 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, _elm_code_widget_cursor_move_left(widget); else if (!strcmp(ev->key, "Right")) _elm_code_widget_cursor_move_right(widget); + else if (!strcmp(ev->key, "Home")) + _elm_code_widget_cursor_move_home(widget); + else if (!strcmp(ev->key, "End")) + _elm_code_widget_cursor_move_end(widget); else if (!strcmp(ev->key, "KP_Enter") || !strcmp(ev->key, "Return")) _elm_code_widget_newline(widget); From c8d23dc7200d34745f65bd7734bf2ce3e45f754b Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 5 May 2015 22:38:02 +0100 Subject: [PATCH 162/254] editor: wrap left and right cursor moves around when there is a line to move to we should wrap cursor movements --- .../elm_code/src/lib/widget/elm_code_widget.c | 84 +++++++++++-------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 20e9eacbdd..4b1ce9db92 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -484,9 +484,10 @@ _elm_code_widget_cursor_key_will_move(Elm_Code_Widget *widget, const char *key) else if (!strcmp(key, "Down")) return pd->cursor_line < elm_code_file_lines_get(pd->code->file); else if (!strcmp(key, "Left")) - return pd->cursor_col > 1; + return pd->cursor_col > 1 || pd->cursor_line > 1; else if (!strcmp(key, "Right")) - return pd->cursor_col < elm_code_line_text_column_width(line, pd->tabstop) + 1; + return pd->cursor_col < elm_code_line_text_column_width(line, pd->tabstop) + 1 || + pd->cursor_line < elm_code_file_lines_get(pd->code->file); else return EINA_FALSE; } @@ -740,6 +741,36 @@ _elm_code_widget_mouse_up_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj E _elm_code_widget_clicked_readonly_cb(widget, row); } +static void +_elm_code_widget_cursor_move_home(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (pd->cursor_col <= 1) + return; + + _elm_code_widget_cursor_move(widget, pd, 1, pd->cursor_line, EINA_TRUE); +} + +static void +_elm_code_widget_cursor_move_end(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; + unsigned int lastcol; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + line = elm_code_file_line_get(pd->code->file, pd->cursor_line); + lastcol = elm_code_line_text_column_width(line, pd->tabstop); + if (pd->cursor_col > lastcol + 1) + return; + + _elm_code_widget_cursor_move(widget, pd, lastcol + 1, pd->cursor_line, EINA_TRUE); +} + static void _elm_code_widget_cursor_move_up(Elm_Code_Widget *widget) { @@ -794,7 +825,14 @@ _elm_code_widget_cursor_move_left(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (pd->cursor_col <= 1) - return; + { + if (pd->cursor_line > 1) + { + _elm_code_widget_cursor_move_up(widget); + _elm_code_widget_cursor_move_end(widget); + } + return; + } _elm_code_widget_cursor_move(widget, pd, pd->cursor_col-1, pd->cursor_line, EINA_TRUE); } @@ -809,42 +847,18 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) line = elm_code_file_line_get(pd->code->file, pd->cursor_line); if (pd->cursor_col > elm_code_line_text_column_width(line, pd->tabstop)) - return; + { + if (pd->cursor_line < elm_code_file_lines_get(pd->code->file)) + { + _elm_code_widget_cursor_move_down(widget); + _elm_code_widget_cursor_move_home(widget); + } + return; + } _elm_code_widget_cursor_move(widget, pd, pd->cursor_col+1, pd->cursor_line, EINA_TRUE); } - -static void -_elm_code_widget_cursor_move_home(Elm_Code_Widget *widget) -{ - Elm_Code_Widget_Data *pd; - - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - - if (pd->cursor_col <= 1) - return; - - _elm_code_widget_cursor_move(widget, pd, 1, pd->cursor_line, EINA_TRUE); -} - -static void -_elm_code_widget_cursor_move_end(Elm_Code_Widget *widget) -{ - Elm_Code_Widget_Data *pd; - Elm_Code_Line *line; - unsigned int lastcol; - - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - - line = elm_code_file_line_get(pd->code->file, pd->cursor_line); - lastcol = elm_code_line_text_column_width(line, pd->tabstop); - if (pd->cursor_col > lastcol + 1) - return; - - _elm_code_widget_cursor_move(widget, pd, lastcol + 1, pd->cursor_line, EINA_TRUE); -} - static Eina_Bool _elm_code_widget_delete_selection(Elm_Code_Widget *widget) { From a44f55cf6902415b73140f4d717c5bd51b714b07 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 11 May 2015 23:11:28 +0100 Subject: [PATCH 163/254] Update elm_code widget .eo doc for EFL master --- .../src/lib/widget/elm_code_widget.eo | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index 38f1dbef4b..7e82fce26d 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -1,8 +1,8 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) { eo_prefix: elm_code_widget; - properties { - code { + methods { + @property code { set { /*@ Set the underlying code object that this widget renders. @@ -21,7 +21,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) Elm_Code *code; /*@ Our underlying Elm_Code object */ } } - font_size { + @property font_size { set { /*@ Set the font size that this widget uses, the font will always be a system monospaced font @@ -38,7 +38,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) Evas_Font_Size font_size; /*@ The font size of the widgget */ } } - gravity { + @property gravity { set { /*@ Set how this widget's scroller should respond to new lines being added. @@ -59,7 +59,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) double y; /*@ The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 */ } } - tabstop { + @property tabstop { set { /*@ Set the width of a tab stop, used purely for visual layout of tab characters. @@ -79,7 +79,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) uint tabstop; /*@ Maximum width of a tab character */ } } - editable { + @property editable { set { /*@ Set whether this widget allows editing @@ -105,7 +105,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) Eina_Bool editable; /*@ The editable state of the widget */ } } - line_numbers { + @property line_numbers { set { /*@ Set whether line numbers should be displayed in the left gutter. @@ -125,7 +125,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) Eina_Bool line_numbers; /*@ Whether or not line numbers (or their placeholder) should be shown */ } } - line_width_marker { + @property line_width_marker { set { /*@ Set where the line width market should be shown. @@ -145,7 +145,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) uint line_width_marker; /*@ Where to display a line width marker, if at all */ } } - show_whitespace { + @property show_whitespace { set { /*@ Set where white space should be shown. @@ -162,7 +162,7 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) Eina_Bool show_whitespace; /*@ Whether or not we show whitespace characters */ } } - cursor_position { + @property cursor_position { set { /*@ Set the current location of the text cursor. @@ -180,8 +180,6 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) uint line; /*@ The vertical position of the cursor - the top row is 1 an */ } } - } - methods { line_refresh { params { Elm_Code_Line *line; /*@ @in The line to refresh. */ @@ -207,9 +205,9 @@ class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) Eo.Base.constructor; Eo.Base.finalize; Evas.Object_Smart.add; - Elm_Widget.event; - Elm_Widget.focus_next_manager_is; - Elm_Widget.focus_direction_manager_is; + Elm.Widget.event; + Elm.Widget.focus_next_manager_is; + Elm.Widget.focus_direction_manager_is; } events { line,clicked; From 703c63f426c89f65a7cc2bfe1c1008c855806f25 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 11 May 2015 23:17:44 +0100 Subject: [PATCH 164/254] eolian_gen fixes to inheritance --- legacy/elm_code/src/lib/widget/elm_code_widget.eo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index 7e82fce26d..8ea95d7b3a 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -1,4 +1,4 @@ -class Elm_Code_Widget (Elm_Layout, Elm_Interface_Atspi_Text) +class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) { eo_prefix: elm_code_widget; methods { From 7a8b0c8b937fa1bc9947b32e455e1a34e5ed2b8e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 12 May 2015 23:15:25 +0100 Subject: [PATCH 165/254] editor: add pageup/down support Page up or down by 85% of the visible window height --- .../elm_code/src/lib/widget/elm_code_widget.c | 77 +++++++++++++++++++ .../src/lib/widget/elm_code_widget.eo | 3 + 2 files changed, 80 insertions(+) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 4b1ce9db92..48a32a222b 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -859,6 +859,68 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) _elm_code_widget_cursor_move(widget, pd, pd->cursor_col+1, pd->cursor_line, EINA_TRUE); } +static unsigned int +_elm_code_widget_cursor_move_page_height_get(Elm_Code_Widget *widget) +{ + unsigned int lines; + + eo_do(widget, lines = elm_code_widget_lines_visible_get()); + return lines * 0.85; +} + +static void +_elm_code_widget_cursor_move_pageup(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; + unsigned int row, col, column_width; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + row = pd->cursor_line; + col = pd->cursor_col; + + if (pd->cursor_line <= 1) + return; + + if (row > _elm_code_widget_cursor_move_page_height_get(widget)) + row -= _elm_code_widget_cursor_move_page_height_get(widget); + else + row = 1; + + line = elm_code_file_line_get(pd->code->file, row); + column_width = elm_code_line_text_column_width(line, pd->tabstop); + if (col > column_width + 1) + col = column_width + 1; + + _elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE); +} + +static void +_elm_code_widget_cursor_move_pagedown(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; + unsigned int row, col, column_width; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + row = pd->cursor_line; + col = pd->cursor_col; + + if (pd->cursor_line >= elm_code_file_lines_get(pd->code->file)) + return; + + row += _elm_code_widget_cursor_move_page_height_get(widget); + if (row > elm_code_file_lines_get(pd->code->file)) + row = elm_code_file_lines_get(pd->code->file); + + line = elm_code_file_line_get(pd->code->file, row); + column_width = elm_code_line_text_column_width(line, pd->tabstop); + if (col > column_width + 1) + col = column_width + 1; + + _elm_code_widget_cursor_move(widget, pd, col, row, EINA_TRUE); +} + static Eina_Bool _elm_code_widget_delete_selection(Elm_Code_Widget *widget) { @@ -1102,6 +1164,10 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, _elm_code_widget_cursor_move_home(widget); else if (!strcmp(ev->key, "End")) _elm_code_widget_cursor_move_end(widget); + else if (!strcmp(ev->key, "Prior")) + _elm_code_widget_cursor_move_pageup(widget); + else if (!strcmp(ev->key, "Next")) + _elm_code_widget_cursor_move_pagedown(widget); else if (!strcmp(ev->key, "KP_Enter") || !strcmp(ev->key, "Return")) _elm_code_widget_newline(widget); @@ -1197,6 +1263,17 @@ _elm_code_widget_line_visible_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, return EINA_TRUE;; } +EOAPI unsigned int +_elm_code_widget_lines_visible_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) +{ + Evas_Coord cellh, viewh; + + elm_scroller_region_get(pd->scroller, NULL, NULL, NULL, &viewh); + evas_object_textgrid_cell_size_get(pd->grid, NULL, &cellh); + + return viewh / cellh; +} + EOLIAN static void _elm_code_widget_font_size_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Evas_Font_Size font_size) { diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index 8ea95d7b3a..b1f4eff087 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -191,6 +191,9 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) } return: bool; /*@ true if the line specified is currently visible within the scroll region. */ } + lines_visible_get { + return: uint; /*@ the number of lines currently visible in the widget. */ + } /* text functions */ text_left_gutter_width_get { From 1c5717ffb1facf9ebc6ca0f160391d5e544ccafd Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 18 May 2015 15:49:24 +0100 Subject: [PATCH 166/254] editor: fix nulls being appended to lines Should resolve issues with nulls being inserted and also crashes on pasting into a selection --- legacy/elm_code/src/lib/elm_code_text.c | 6 +++--- legacy/elm_code/src/lib/widget/elm_code_widget_selection.c | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 2ae3432849..8d779a7c1b 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -32,7 +32,7 @@ elm_code_line_text_set(Elm_Code_Line *line, const char *chars, unsigned int leng if (line->modified) free(line->modified); - newtext = malloc(sizeof(char) * length + 1); + newtext = malloc(sizeof(char) * length); strncpy(newtext, chars, length); line->modified = newtext; line->length = length; @@ -144,7 +144,7 @@ elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char if (!line) return; - inserted = malloc(sizeof(char) * line->length + length + 1); + inserted = malloc(sizeof(char) * line->length + length); if (position > 0) position--; if (position > line->length) @@ -183,7 +183,7 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length if (!line) return; - removed = malloc(sizeof(char) * line->length - length + 1); + removed = malloc(sizeof(char) * line->length - length); if (position > 0) position--; if (position > line->length) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 3838c107bb..cd837cfa44 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -117,8 +117,9 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd) line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); old = elm_code_line_text_get(line, &old_length); - length = line->length - (pd->selection->end_col - pd->selection->start_col); - content = malloc(sizeof(char) * (length + 1)); + length = line->length - (pd->selection->end_col - pd->selection->start_col + 1); + content = malloc(sizeof(char) * length); + snprintf(content, pd->selection->start_col, old); snprintf(content + pd->selection->start_col - 1, old_length - pd->selection->end_col + 1, old + pd->selection->end_col); From c84b148670fa1fe4d97a2b5a40920e84706cc046 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 18 May 2015 19:24:01 +0100 Subject: [PATCH 167/254] Update to latest .eo file type --- .../src/lib/widget/elm_code_widget.eo | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index b1f4eff087..1bde7c73c6 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -18,7 +18,7 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) @ingroup Data */ } values { - Elm_Code *code; /*@ Our underlying Elm_Code object */ + code: Elm_Code *; /*@ Our underlying Elm_Code object */ } } @property font_size { @@ -35,7 +35,7 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) @ingroup Style */ } values { - Evas_Font_Size font_size; /*@ The font size of the widgget */ + font_size: Evas_Font_Size; /*@ The font size of the widgget */ } } @property gravity { @@ -55,8 +55,8 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) @ingroup Layout */ } values { - double x; /*@ The horizontal value of the scroller gravity - valid values are 0.0 and 1.0 */ - double y; /*@ The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 */ + x: double; /*@ The horizontal value of the scroller gravity - valid values are 0.0 and 1.0 */ + y: double; /*@ The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 */ } } @property tabstop { @@ -76,7 +76,7 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) @ingroup Layout */ } values { - uint tabstop; /*@ Maximum width of a tab character */ + tabstop: uint; /*@ Maximum width of a tab character */ } } @property editable { @@ -102,7 +102,7 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) @ingroup Features */ } values { - Eina_Bool editable; /*@ The editable state of the widget */ + editable: Eina_Bool; /*@ The editable state of the widget */ } } @property line_numbers { @@ -122,7 +122,7 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) @ingroup Features */ } values { - Eina_Bool line_numbers; /*@ Whether or not line numbers (or their placeholder) should be shown */ + line_numbers: Eina_Bool; /*@ Whether or not line numbers (or their placeholder) should be shown */ } } @property line_width_marker { @@ -142,7 +142,7 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) @ingroup Features */ } values { - uint line_width_marker; /*@ Where to display a line width marker, if at all */ + line_width_marker: uint; /*@ Where to display a line width marker, if at all */ } } @property show_whitespace { @@ -159,7 +159,7 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) @ingroup Features */ } values { - Eina_Bool show_whitespace; /*@ Whether or not we show whitespace characters */ + show_whitespace: Eina_Bool; /*@ Whether or not we show whitespace characters */ } } @property cursor_position { @@ -176,18 +176,18 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) @ingroup Editing */ } values { - uint col; /*@ The horizontal position of the cursor, starting from column 1 */ - uint line; /*@ The vertical position of the cursor - the top row is 1 an */ + col: uint; /*@ The horizontal position of the cursor, starting from column 1 */ + line: uint; /*@ The vertical position of the cursor - the top row is 1 an */ } } line_refresh { params { - Elm_Code_Line *line; /*@ @in The line to refresh. */ + line: Elm_Code_Line *; /*@ @in The line to refresh. */ } } line_visible_get { params { - Elm_Code_Line *line; /*@ @in The line to test for visibility. */ + line: Elm_Code_Line *; /*@ @in The line to test for visibility. */ } return: bool; /*@ true if the line specified is currently visible within the scroll region. */ } From 8d9f952958e08cfe4bbdf3b6df50983d2d50c535 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 18 May 2015 19:40:06 +0100 Subject: [PATCH 168/254] Fixup tests Fixing compile errors and out of date tests. oops. --- legacy/elm_code/src/lib/elm_code_private.h | 2 +- legacy/elm_code/src/tests/elm_code_test_text.c | 7 +++++-- legacy/elm_code/src/tests/widget/elm_code_test_widget.c | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h index 1f16c8f4f3..372f78c02e 100644 --- a/legacy/elm_code/src/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -1,7 +1,7 @@ #ifndef ELM_CODE_PRIVATE_H # define ELM_CODE_PRIVATE_H -extern int _elm_code_lib_log_dom; +int _elm_code_lib_log_dom; #ifdef ERR # undef ERR diff --git a/legacy/elm_code/src/tests/elm_code_test_text.c b/legacy/elm_code/src/tests/elm_code_test_text.c index 1798433203..c291569793 100644 --- a/legacy/elm_code/src/tests/elm_code_test_text.c +++ b/legacy/elm_code/src/tests/elm_code_test_text.c @@ -83,11 +83,14 @@ END_TEST START_TEST (elm_code_text_newline_position_test) { + short nllen; const char *unixtext = "a test\nwith newline"; const char *wintext = "a windows\r\nnewline"; - ck_assert_int_eq(6, elm_code_text_newlinenpos(unixtext, strlen(unixtext))); - ck_assert_int_eq(9, elm_code_text_newlinenpos(wintext, strlen(wintext))); + ck_assert_int_eq(6, elm_code_text_newlinenpos(unixtext, strlen(unixtext), &nllen)); + ck_assert_int_eq(1, nllen); + ck_assert_int_eq(9, elm_code_text_newlinenpos(wintext, strlen(wintext), &nllen)); + ck_assert_int_eq(2, nllen); } END_TEST diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c index 54c102c397..b2f3d182f8 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c @@ -5,6 +5,7 @@ #include "elm_code_suite.h" #include "widget/elm_code_widget.c" +#include "widget/elm_code_widget_tooltip.c" static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type, int id) { From 4c00c9e1fc4b4715f6997bdca0620ef15822ac38 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 20 May 2015 14:18:20 +0100 Subject: [PATCH 169/254] Update to latest eolian (getting stable we hope). Also mark code as a construction property --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 8 +++++--- legacy/elm_code/src/lib/widget/elm_code_widget.eo | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 48a32a222b..341f034c46 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -45,21 +45,23 @@ Eina_Unicode status_icons[] = { } \ } while (0) -EOLIAN static void +EOLIAN static Eo * _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd) { - eo_do_super(obj, ELM_CODE_WIDGET_CLASS, eo_constructor()); + obj = eo_do_super_ret(obj, ELM_CODE_WIDGET_CLASS, obj, eo_constructor()); pd->cursor_line = 1; pd->cursor_col = 1; pd->tabstop = 8; + + return obj; } EOLIAN static Eo * _elm_code_widget_eo_base_finalize(Eo *obj, Elm_Code_Widget_Data *pd) { - eo_do_super(obj, ELM_CODE_WIDGET_CLASS, eo_finalize()); + obj = eo_do_super_ret(obj, ELM_CODE_WIDGET_CLASS, obj, eo_finalize()); if (pd->code) return obj; diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index 1bde7c73c6..b9fad3baf0 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -212,6 +212,9 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) Elm.Widget.focus_next_manager_is; Elm.Widget.focus_direction_manager_is; } + constructors { + .code; + } events { line,clicked; line,gutter,clicked; From de37470730e0e358517efdd903546d83472d83d7 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 24 May 2015 12:58:39 +0100 Subject: [PATCH 170/254] selection: fix crash when deleting large selection snprintf is not the tool for simple string copy - especially if not null terminated --- .../src/lib/widget/elm_code_widget_selection.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index cd837cfa44..5413dafd7f 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -120,9 +120,9 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd) length = line->length - (pd->selection->end_col - pd->selection->start_col + 1); content = malloc(sizeof(char) * length); - snprintf(content, pd->selection->start_col, old); - snprintf(content + pd->selection->start_col - 1, old_length - pd->selection->end_col + 1, - old + pd->selection->end_col); + strncpy(content, old, pd->selection->start_col - 1); + strncpy(content + pd->selection->start_col - 1, old + pd->selection->end_col, + old_length - pd->selection->end_col); elm_code_line_text_set(line, content, length); free(content); } @@ -143,10 +143,10 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget_Data *pd) line = elm_code_file_line_get(pd->code->file, pd->selection->end_line); last = elm_code_line_text_get(line, &last_length); length = pd->selection->start_col + last_length - pd->selection->end_col + 1; - content = malloc(sizeof(char) * (length + 1)); - snprintf(content, pd->selection->start_col, first); - snprintf(content + pd->selection->start_col - 1, last_length - pd->selection->end_col + 1, - last + pd->selection->end_col); + content = malloc(sizeof(char) * length); + strncpy(content, first, pd->selection->start_col - 1); + strncpy(content + pd->selection->start_col - 1, last + pd->selection->end_col, + last_length - pd->selection->end_col); for (i = line->number; i > pd->selection->start_line; i--) elm_code_file_line_remove(pd->code->file, i); From fcce45fc82d7d7b8e6135f78a037b8cf4bd21d2c Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 29 May 2015 13:10:25 +0100 Subject: [PATCH 171/254] Fix deletion inserting random data. Off by one error (doubled). Classic. Lesson: Run the tests you write! --- legacy/elm_code/src/lib/widget/elm_code_widget_selection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 5413dafd7f..6f0e65768e 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -142,7 +142,7 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget_Data *pd) first = elm_code_line_text_get(line, NULL); line = elm_code_file_line_get(pd->code->file, pd->selection->end_line); last = elm_code_line_text_get(line, &last_length); - length = pd->selection->start_col + last_length - pd->selection->end_col + 1; + length = pd->selection->start_col + last_length - (pd->selection->end_col + 1); content = malloc(sizeof(char) * length); strncpy(content, first, pd->selection->start_col - 1); strncpy(content + pd->selection->start_col - 1, last + pd->selection->end_col, From 642bb0ba857a5839426ac86e9c8bde639b71385b Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 24 May 2015 18:39:57 +0100 Subject: [PATCH 172/254] elm_code: support setting custom fonts For EDI create the config that would allow this to be altered. Actual setting widget to follow... --- legacy/elm_code/src/bin/elm_code_test_main.c | 12 ++++----- .../elm_code/src/lib/elm_code_diff_widget.c | 6 ++--- .../elm_code/src/lib/elm_code_diff_widget.h | 2 +- .../elm_code/src/lib/widget/elm_code_widget.c | 26 ++++++++++++++----- .../src/lib/widget/elm_code_widget.eo | 11 +++++--- .../src/lib/widget/elm_code_widget_private.h | 1 + 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 1522cbcf76..ebca4d4f8c 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -71,7 +71,7 @@ _elm_code_test_welcome_setup(Evas_Object *parent) widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_code_widget_code_set(code)); eo_do(widget, - elm_code_widget_font_size_set(12), + elm_code_widget_font_set(NULL, 12), eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_test_line_done_cb, NULL); eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code)); @@ -101,7 +101,7 @@ _elm_code_test_editor_setup(Evas_Object *parent) widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_code_widget_code_set(code)); eo_do(widget, - elm_code_widget_font_size_set(14), + elm_code_widget_font_set(NULL, 14), elm_code_widget_editable_set(EINA_TRUE), elm_code_widget_show_whitespace_set(EINA_TRUE), elm_code_widget_line_numbers_set(EINA_TRUE)); @@ -123,14 +123,14 @@ _elm_code_test_editor_setup(Evas_Object *parent) } static Evas_Object * -_elm_code_test_mirror_setup(Elm_Code *code, Evas_Object *parent) +_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_code_widget_code_set(code)); eo_do(widget, - elm_code_widget_font_size_set(11), + elm_code_widget_font_set(font_name, 11), elm_code_widget_line_numbers_set(EINA_TRUE)); evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -212,8 +212,8 @@ _elm_code_test_welcome_mirror_cb(void *data, Evas_Object *obj EINA_UNUSED, void code = elm_code_widget_code_get()); elm_box_pack_end(screen, widget); - elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, screen)); - elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, screen)); + 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", diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.c b/legacy/elm_code/src/lib/elm_code_diff_widget.c index 368872414c..eba3b37fa7 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/src/lib/elm_code_diff_widget.c @@ -121,13 +121,13 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) } EAPI void -elm_code_diff_widget_font_size_set(Evas_Object *widget, int size) +elm_code_diff_widget_font_set(Evas_Object *widget, char *name, int size) { Elm_Code_Widget *child; child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_LEFT); - eo_do(child, elm_code_widget_font_size_set(size)); + eo_do(child, elm_code_widget_font_set(name, size)); child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_RIGHT); - eo_do(child, elm_code_widget_font_size_set(size)); + eo_do(child, elm_code_widget_font_set(name, size)); } diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.h b/legacy/elm_code/src/lib/elm_code_diff_widget.h index b6605bbd56..895dd55698 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.h +++ b/legacy/elm_code/src/lib/elm_code_diff_widget.h @@ -23,7 +23,7 @@ extern "C" { EAPI Evas_Object *elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code); -EAPI void elm_code_diff_widget_font_size_set(Evas_Object *widget, int size); +EAPI void elm_code_diff_widget_font_set(Evas_Object *widget, char *name, int size); /** * @} diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 341f034c46..7ae845c71e 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1277,16 +1277,28 @@ _elm_code_widget_lines_visible_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd } EOLIAN static void -_elm_code_widget_font_size_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Evas_Font_Size font_size) +_elm_code_widget_font_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, char *name, + Evas_Font_Size size) { - evas_object_textgrid_font_set(pd->grid, "Mono", font_size * elm_config_scale_get()); - pd->font_size = font_size; + char *face = name; + if (!face) + face = "Mono"; + + evas_object_textgrid_font_set(pd->grid, face, size * elm_config_scale_get()); + if (pd->font_name) + free((char *)pd->font_name); + pd->font_name = strdup(face); + pd->font_size = size; } -EOLIAN static Evas_Font_Size -_elm_code_widget_font_size_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) +EOLIAN static void +_elm_code_widget_font_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, char **name, + Evas_Font_Size *size) { - return pd->font_size; + if (name) + *name = strdup((const char *)pd->font_name); + if (size) + *size = pd->font_size; } EOLIAN static void @@ -1517,7 +1529,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, _elm_code_widget_selection_cb, obj), eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_cb, obj)); - _elm_code_widget_font_size_set(obj, pd, 10); + _elm_code_widget_font_set(obj, pd, NULL, 10); } #include "elm_code_widget_text.c" diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index b9fad3baf0..583d8c84d0 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -21,21 +21,24 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) code: Elm_Code *; /*@ Our underlying Elm_Code object */ } } - @property font_size { + @property font { set { /*@ - Set the font size that this widget uses, the font will always be a system monospaced font + Set the font that this widget uses, the font should be a monospaced scalable font. + Passing NULL will load the default system monospaced font. @ingroup Style */ } get { /*@ - Get the font size currently in use + Get the font currently in use. + The font name is a copy ad should be freed once it is no longer needed @ingroup Style */ } values { - font_size: Evas_Font_Size; /*@ The font size of the widgget */ + name: char *; /*@ The name of the font to load */ + size: Evas_Font_Size; /*@ The font size for the widget */ } } @property gravity { diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h index 0f758c7409..a1dc7b1475 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h @@ -15,6 +15,7 @@ typedef struct Elm_Code *code; Evas_Object *grid, *scroller; + const char *font_name; Evas_Font_Size font_size; double gravity_x, gravity_y; From fe89f7fbdeebeccd321a095aa10280fa3c7651d4 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 30 May 2015 10:13:11 +0100 Subject: [PATCH 173/254] editor: trigger saves if selection cut or pasted --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 7ae845c71e..8e98cef380 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1124,11 +1124,19 @@ _elm_code_widget_control_key_down_cb(Elm_Code_Widget *widget, const char *key) return; if (!strcmp("c", key)) - elm_code_widget_selection_copy(widget); - else if (!strcmp("v", key)) + { + elm_code_widget_selection_copy(widget); + return; + } + + if (!strcmp("v", key)) elm_code_widget_selection_paste(widget); else if (!strcmp("x", key)) elm_code_widget_selection_cut(widget); + + eo_do(widget, +// TODO construct and pass a change object + eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } static void From 704cec0ae75d3d989cce6fc27a5cef4274153bd1 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 30 May 2015 10:26:51 +0100 Subject: [PATCH 174/254] setting: Add a font picker Monospace only so we get a deccent looking result. Mostly from the terminology project - thanks guys --- .../elm_code/src/lib/widget/elm_code_widget.c | 12 ++++++++++++ .../elm_code/src/lib/widget/elm_code_widget.eo | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 8e98cef380..a320c9e58a 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1339,6 +1339,18 @@ _elm_code_widget_gravity_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, doub *y = pd->gravity_y; } +EOLIAN static void +_elm_code_widget_policy_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v) +{ + elm_scroller_policy_set(pd->scroller, policy_h, policy_v); +} + +EOLIAN static void +_elm_code_widget_policy_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v) +{ + elm_scroller_policy_get(pd->scroller, policy_h, policy_v); +} + EOLIAN static void _elm_code_widget_tabstop_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, unsigned int tabstop) { diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index 583d8c84d0..f430965494 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -62,6 +62,24 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) y: double; /*@ The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 */ } } + @property policy { + set { + /*@ + Set the policy for scrollbar visibility. + + @ingroup Layout */ + } + get { + /*@ + Get the widget's policy for scrollbar visibility. + + @ingroup Layout */ + } + values { + policy_h: Elm_Scroller_Policy; /*@ The horizontal scrollbar visibility policy */ + policy_v: Elm_Scroller_Policy; /*@ The vertical scrollbar visibility policy */ + } + } @property tabstop { set { /*@ From 906cfc9a2cbf8e3ac02211e6ac9fedb28b4583e8 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 30 May 2015 20:46:34 +0100 Subject: [PATCH 175/254] fix crash when deleting over a line ending --- legacy/elm_code/src/lib/elm_code_text.c | 4 +-- .../lib/widget/elm_code_widget_selection.c | 32 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 8d779a7c1b..e789942281 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -303,12 +303,12 @@ elm_code_line_text_position_for_column_get(Elm_Code_Line *line, unsigned int col else chars = line->content; - while ((unsigned int) count < column && index <= (int) line->length) + while ((unsigned int) count < column && index < (int) line->length) { unicode = eina_unicode_utf8_next_get(chars, &index); if (unicode == 0) - return line->length + 1; + return line->length; else if (unicode == '\t') count += elm_code_text_tabwidth_at_position(count, tabstop); else diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 6f0e65768e..88642de2eb 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -109,7 +109,7 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd) { Elm_Code_Line *line; const char *old; - unsigned int old_length, length; + unsigned int old_length, start, end, length; char *content; if (pd->selection->end_col < pd->selection->start_col) @@ -117,12 +117,16 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd) line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); old = elm_code_line_text_get(line, &old_length); - length = line->length - (pd->selection->end_col - pd->selection->start_col + 1); - content = malloc(sizeof(char) * length); + start = elm_code_line_text_position_for_column_get(line, pd->selection->start_col, + pd->tabstop) - 1; + end = elm_code_line_text_position_for_column_get(line, pd->selection->end_col, + pd->tabstop) - 1; + length = line->length - (end - start + 1); - strncpy(content, old, pd->selection->start_col - 1); - strncpy(content + pd->selection->start_col - 1, old + pd->selection->end_col, - old_length - pd->selection->end_col); + content = malloc(sizeof(char) * length); + strncpy(content, old, start); + strncpy(content + start, old + end + 1, + old_length - (end + 1)); elm_code_line_text_set(line, content, length); free(content); } @@ -132,7 +136,7 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget_Data *pd) { Elm_Code_Line *line; const char *first, *last; - unsigned int last_length, length, i; + unsigned int last_length, start, end, length, i; char *content; if (pd->selection->end_line <= pd->selection->start_line) @@ -140,13 +144,19 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget_Data *pd) line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); first = elm_code_line_text_get(line, NULL); + start = elm_code_line_text_position_for_column_get(line, pd->selection->start_col, + pd->tabstop) - 1; + line = elm_code_file_line_get(pd->code->file, pd->selection->end_line); last = elm_code_line_text_get(line, &last_length); - length = pd->selection->start_col + last_length - (pd->selection->end_col + 1); + end = elm_code_line_text_position_for_column_get(line, pd->selection->end_col, + pd->tabstop) - 1; + + length = start + last_length - (end + 1); content = malloc(sizeof(char) * length); - strncpy(content, first, pd->selection->start_col - 1); - strncpy(content + pd->selection->start_col - 1, last + pd->selection->end_col, - last_length - pd->selection->end_col); + strncpy(content, first, start); + strncpy(content + start, last + end + 1, + last_length - (end + 1)); for (i = line->number; i > pd->selection->start_line; i--) elm_code_file_line_remove(pd->code->file, i); From b07cc34de68de0af1157a99046641fe6627e7181 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 30 May 2015 22:48:35 +0100 Subject: [PATCH 176/254] performance: Fix issue where EDI would slow down a bad circular problem where an error with tooltips causes more tooltips to be spawned... --- legacy/elm_code/src/lib/widget/elm_code_widget_tooltip.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_tooltip.c b/legacy/elm_code/src/lib/widget/elm_code_widget_tooltip.c index f08c18ec7f..44abe9168a 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_tooltip.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_tooltip.c @@ -14,9 +14,12 @@ _elm_code_widget_tooltip_text_set(Evas_Object *widget, const char *text) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (!text) - elm_object_tooltip_hide(widget); - else - elm_object_tooltip_show(widget); + { + elm_object_tooltip_hide(widget); + return; + } + + elm_object_tooltip_show(widget); if (pd->tooltip) // will have been created by the callback below... elm_object_text_set(pd->tooltip, text); From fc68e6c198310eff10bc33313af9d955e5b4f4d3 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 31 May 2015 21:18:18 +0100 Subject: [PATCH 177/254] Fix many warnings. Make the font face const char * and use eina_stringshare --- legacy/elm_code/src/lib/elm_code_diff_widget.c | 2 +- legacy/elm_code/src/lib/elm_code_diff_widget.h | 3 ++- legacy/elm_code/src/lib/widget/elm_code_widget.c | 14 +++++++------- legacy/elm_code/src/lib/widget/elm_code_widget.eo | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.c b/legacy/elm_code/src/lib/elm_code_diff_widget.c index eba3b37fa7..e07b9cb771 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/src/lib/elm_code_diff_widget.c @@ -121,7 +121,7 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) } EAPI void -elm_code_diff_widget_font_set(Evas_Object *widget, char *name, int size) +elm_code_diff_widget_font_set(Evas_Object *widget, const char *name, int size) { Elm_Code_Widget *child; diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.h b/legacy/elm_code/src/lib/elm_code_diff_widget.h index 895dd55698..7a6f2d6412 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.h +++ b/legacy/elm_code/src/lib/elm_code_diff_widget.h @@ -23,7 +23,8 @@ extern "C" { 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, char *name, int size); +EAPI void elm_code_diff_widget_font_set(Evas_Object *widget, const char *name, + int size); /** * @} diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index a320c9e58a..bf63c35e9e 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1285,23 +1285,23 @@ _elm_code_widget_lines_visible_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd } EOLIAN static void -_elm_code_widget_font_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, char *name, - Evas_Font_Size size) +_elm_code_widget_font_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, + const char *name, Evas_Font_Size size) { - char *face = name; + const char *face = name; if (!face) face = "Mono"; evas_object_textgrid_font_set(pd->grid, face, size * elm_config_scale_get()); if (pd->font_name) - free((char *)pd->font_name); - pd->font_name = strdup(face); + eina_stringshare_del((char *)pd->font_name); + pd->font_name = eina_stringshare_add(face); pd->font_size = size; } EOLIAN static void -_elm_code_widget_font_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, char **name, - Evas_Font_Size *size) +_elm_code_widget_font_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, + const char **name, Evas_Font_Size *size) { if (name) *name = strdup((const char *)pd->font_name); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index f430965494..61e8b87f14 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -37,7 +37,7 @@ class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) @ingroup Style */ } values { - name: char *; /*@ The name of the font to load */ + name: const(char) *; /*@ The name of the font to load */ size: Evas_Font_Size; /*@ The font size for the widget */ } } From 782957e6aee524e06855c03bb0882d86b5a06d6e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 1 Jun 2015 00:25:38 +0100 Subject: [PATCH 178/254] Fix header location --- legacy/elm_code/src/lib/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index 8d674f00e8..ecac3e6b21 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -40,7 +40,7 @@ widget/elm_code_widget.c \ elm_code_diff_widget.c \ elm_code.c \ elm_code_private.h \ -elm_code_widget_private.h +widget/elm_code_widget_private.h libelm_code_la_LIBADD = @EFL_LIBS@ -lm libelm_code_la_LDFLAGS = -no-undefined @EFL_LTLIBRARY_FLAGS@ From 72c3cc924a0b3719bbe29bad68730910fd73e26a Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 1 Jun 2015 23:07:53 +0100 Subject: [PATCH 179/254] Fixing make dist --- legacy/elm_code/src/lib/Makefile.am | 1 + legacy/elm_code/src/tests/Makefile.am | 1 + 2 files changed, 2 insertions(+) diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index ecac3e6b21..b9f7b045e0 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -34,6 +34,7 @@ elm_code_line.c \ elm_code_text.c \ elm_code_file.c \ elm_code_parse.c \ +widget/elm_code_widget_text.c \ widget/elm_code_widget_tooltip.c \ widget/elm_code_widget_selection.c \ widget/elm_code_widget.c \ diff --git a/legacy/elm_code/src/tests/Makefile.am b/legacy/elm_code/src/tests/Makefile.am index 45476e5960..4bb0cc0b64 100644 --- a/legacy/elm_code/src/tests/Makefile.am +++ b/legacy/elm_code/src/tests/Makefile.am @@ -35,6 +35,7 @@ elm_code_suite_DEPENDENCIES = $(top_builddir)/elm_code/src/lib/libelm_code.la testdir = $(PACKAGE_TESTS_DIR) test_DATA = \ testfile.txt \ +testfile-windows.txt \ testfile-withblanks.txt \ testdiff.diff From ac21aac0e1deb6653134e64b764ddac8ad2d199e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 2 Jun 2015 08:22:36 +0100 Subject: [PATCH 180/254] elm_code: add legacy API. Refactor eo API in line with elm_obj_* elsewhere --- legacy/elm_code/src/bin/elm_code_test_main.c | 24 ++++---- legacy/elm_code/src/lib/Elm_Code.h | 1 + legacy/elm_code/src/lib/Makefile.am | 5 +- .../elm_code/src/lib/elm_code_diff_widget.c | 8 +-- .../elm_code/src/lib/widget/elm_code_widget.c | 59 +++++++++++-------- .../src/lib/widget/elm_code_widget.eo | 5 +- .../src/lib/widget/elm_code_widget_legacy.h | 13 ++++ .../lib/widget/elm_code_widget_selection.c | 8 +-- .../src/tests/widget/elm_code_test_widget.c | 6 +- .../widget/elm_code_test_widget_selection.c | 21 +++---- 10 files changed, 85 insertions(+), 65 deletions(-) create mode 100644 legacy/elm_code/src/lib/widget/elm_code_widget_legacy.h diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index ebca4d4f8c..a7ec071333 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -69,9 +69,9 @@ _elm_code_test_welcome_setup(Evas_Object *parent) code = elm_code_create(); widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, - elm_code_widget_code_set(code)); + elm_obj_code_widget_code_set(code)); eo_do(widget, - elm_code_widget_font_set(NULL, 12), + elm_obj_code_widget_font_set(NULL, 12), eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_test_line_done_cb, NULL); eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code)); @@ -99,12 +99,12 @@ _elm_code_test_editor_setup(Evas_Object *parent) code = elm_code_create(); widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, - elm_code_widget_code_set(code)); + elm_obj_code_widget_code_set(code)); eo_do(widget, - elm_code_widget_font_set(NULL, 14), - elm_code_widget_editable_set(EINA_TRUE), - elm_code_widget_show_whitespace_set(EINA_TRUE), - elm_code_widget_line_numbers_set(EINA_TRUE)); + elm_obj_code_widget_font_set(NULL, 14), + elm_obj_code_widget_editable_set(EINA_TRUE), + elm_obj_code_widget_show_whitespace_set(EINA_TRUE), + elm_obj_code_widget_line_numbers_set(EINA_TRUE)); _append_line(code->file, "Edit me :)"); _append_line(code->file, ""); @@ -128,10 +128,10 @@ _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_code_widget_code_set(code)); + elm_obj_code_widget_code_set(code)); eo_do(widget, - elm_code_widget_font_set(font_name, 11), - elm_code_widget_line_numbers_set(EINA_TRUE)); + elm_obj_code_widget_font_set(font_name, 11), + elm_obj_code_widget_line_numbers_set(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); @@ -153,7 +153,7 @@ _elm_code_test_diff_inline_setup(Evas_Object *parent) elm_code_file_open(code, path); diff = eo_add(ELM_CODE_WIDGET_CLASS, parent, - elm_code_widget_code_set(code)); + elm_obj_code_widget_code_set(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); @@ -209,7 +209,7 @@ _elm_code_test_welcome_mirror_cb(void *data, Evas_Object *obj EINA_UNUSED, void widget = _elm_code_test_editor_setup(screen); eo_do(widget, - code = elm_code_widget_code_get()); + code = elm_obj_code_widget_code_get()); elm_box_pack_end(screen, widget); elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, "Mono:style=Oblique", screen)); diff --git a/legacy/elm_code/src/lib/Elm_Code.h b/legacy/elm_code/src/lib/Elm_Code.h index 83d8d27687..9d14b400ec 100644 --- a/legacy/elm_code/src/lib/Elm_Code.h +++ b/legacy/elm_code/src/lib/Elm_Code.h @@ -39,6 +39,7 @@ #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" diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index b9f7b045e0..087f863baa 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -24,6 +24,7 @@ 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_selection.h \ elm_code_diff_widget.h \ Elm_Code.h @@ -51,10 +52,12 @@ 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_h) \ + $(elm_code_eolian_legacy_h) elmcodeeolianfilesdir = $(datadir)/eolian/include/elm_code-@VMAJ@ elmcodeeolianfiles_DATA = $(elm_code_eolian_files) diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.c b/legacy/elm_code/src/lib/elm_code_diff_widget.c index e07b9cb771..a16ecbfdf5 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/src/lib/elm_code_diff_widget.c @@ -96,7 +96,7 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) 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_code_widget_code_set(wcode1)); + elm_obj_code_widget_code_set(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); @@ -108,7 +108,7 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) 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_code_widget_code_set(wcode2)); + elm_obj_code_widget_code_set(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); @@ -126,8 +126,8 @@ 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); - eo_do(child, elm_code_widget_font_set(name, size)); + eo_do(child, elm_obj_code_widget_font_set(name, size)); child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_RIGHT); - eo_do(child, elm_code_widget_font_set(name, size)); + eo_do(child, elm_obj_code_widget_font_set(name, size)); } diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index bf63c35e9e..c231d44ceb 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -6,6 +6,8 @@ #include "elm_code_private.h" #include "elm_code_widget_private.h" +#define MY_CLASS ELM_CODE_WIDGET_CLASS + typedef enum { ELM_CODE_WIDGET_COLOR_GUTTER_BG = ELM_CODE_TOKEN_TYPE_COUNT, ELM_CODE_WIDGET_COLOR_GUTTER_FG, @@ -45,6 +47,15 @@ Eina_Unicode status_icons[] = { } \ } while (0) +EAPI Evas_Object * +elm_code_widget_add(Evas_Object *parent, Elm_Code *code) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL); + Evas_Object *obj = eo_add(MY_CLASS, parent, + elm_obj_code_widget_code_set(code)); + return obj; +} + EOLIAN static Eo * _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd) { @@ -101,7 +112,7 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - eo_do(widget, gutter = elm_code_widget_text_left_gutter_width_get()); + eo_do(widget, gutter = elm_obj_code_widget_text_left_gutter_width_get()); if (!pd->code) return; @@ -172,7 +183,7 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c unsigned int token_start_col, token_end_col; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - eo_do(widget, offset = elm_code_widget_text_left_gutter_width_get()); + eo_do(widget, offset = elm_obj_code_widget_text_left_gutter_width_get()); start = offset; length = elm_code_line_text_column_width(line, pd->tabstop) + offset; @@ -205,7 +216,7 @@ _elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - eo_do(widget, gutter = elm_code_widget_text_left_gutter_width_get()); + eo_do(widget, gutter = elm_obj_code_widget_text_left_gutter_width_get()); evas_object_textgrid_size_get(pd->grid, &w, NULL); @@ -320,7 +331,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - eo_do(widget, gutter = elm_code_widget_text_left_gutter_width_get()); + eo_do(widget, gutter = elm_obj_code_widget_text_left_gutter_width_get()); evas_object_textgrid_size_get(pd->grid, &w, NULL); cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); @@ -373,7 +384,7 @@ _elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number) Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - eo_do(widget, gutter = elm_code_widget_text_left_gutter_width_get()); + eo_do(widget, gutter = elm_obj_code_widget_text_left_gutter_width_get()); evas_object_textgrid_size_get(pd->grid, &w, NULL); cells = evas_object_textgrid_cellrow_get(pd->grid, number - 1); @@ -424,7 +435,7 @@ _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, line = (Elm_Code_Line *)event_info; widget = (Elm_Code_Widget *)data; - eo_do(widget, visible = elm_code_widget_line_visible_get(line)); + eo_do(widget, visible = elm_obj_code_widget_line_visible_get(line)); if (!visible) return EO_CALLBACK_CONTINUE; @@ -534,7 +545,7 @@ _elm_code_widget_cursor_ensure_visible(Elm_Code_Widget *widget) elm_scroller_region_get(pd->scroller, &viewx, &viewy, &vieww, &viewh); evas_object_textgrid_cell_size_get(pd->grid, &cellw, &cellh); - eo_do(widget, gutter = elm_code_widget_text_left_gutter_width_get()); + eo_do(widget, gutter = elm_obj_code_widget_text_left_gutter_width_get()); curx = (pd->cursor_col + gutter - 1) * cellw; cury = (pd->cursor_line - 1) * cellh; @@ -588,7 +599,7 @@ _elm_code_widget_position_at_coordinates_get(Elm_Code_Widget *widget, Elm_Code_W y = y + sy - oy; evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); - eo_do(widget, gutter = elm_code_widget_text_left_gutter_width_get()); + eo_do(widget, gutter = elm_obj_code_widget_text_left_gutter_width_get()); number = ((double) y / ch) + 1; if (col) *col = ((double) x / cw) - gutter + 1; @@ -866,7 +877,7 @@ _elm_code_widget_cursor_move_page_height_get(Elm_Code_Widget *widget) { unsigned int lines; - eo_do(widget, lines = elm_code_widget_lines_visible_get()); + eo_do(widget, lines = elm_obj_code_widget_lines_visible_get()); return lines * 0.85; } @@ -949,8 +960,8 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text _elm_code_widget_delete_selection(widget); eo_do(widget, - code = elm_code_widget_code_get(), - elm_code_widget_cursor_position_get(&col, &row)); + code = elm_obj_code_widget_code_get(), + elm_obj_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); @@ -959,7 +970,7 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text elm_code_line_text_column_width_to_position(line, position, pd->tabstop); eo_do(widget, - elm_code_widget_cursor_position_set(col + col_width, row), + elm_obj_code_widget_cursor_position_set(col + col_width, row), // TODO construct and pass a change object eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } @@ -975,15 +986,15 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); _elm_code_widget_delete_selection(widget); eo_do(widget, - code = elm_code_widget_code_get(), - elm_code_widget_cursor_position_get(&col, &row)); + code = elm_obj_code_widget_code_get(), + elm_obj_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); elm_code_line_split_at(line, position); eo_do(widget, - elm_code_widget_cursor_position_set(1, row + 1), + elm_obj_code_widget_cursor_position_set(1, row + 1), // TODO construct and pass a change object eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } @@ -1001,8 +1012,8 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) unsigned int length1, length2; eo_do(widget, - code = elm_code_widget_code_get(), - elm_code_widget_cursor_position_get(&col, &row)); + code = elm_obj_code_widget_code_get(), + elm_obj_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); if (nextline) @@ -1033,7 +1044,7 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) position = elm_code_line_text_column_width_to_position(line, length1, pd->tabstop); eo_do(widget, - elm_code_widget_cursor_position_set(position + 1, row - 1)); + elm_obj_code_widget_cursor_position_set(position + 1, row - 1)); } // TODO construct and pass a change object eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); @@ -1051,8 +1062,8 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) return; eo_do(widget, - code = elm_code_widget_code_get(), - elm_code_widget_cursor_position_get(&col, &row)); + code = elm_obj_code_widget_code_get(), + elm_obj_code_widget_cursor_position_get(&col, &row)); pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (col <= 1) @@ -1073,7 +1084,7 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) elm_code_line_text_remove(line, position, char_width?char_width:1); eo_do(widget, - elm_code_widget_cursor_position_set(start_col + 1, row)); + elm_obj_code_widget_cursor_position_set(start_col + 1, row)); // TODO construct and pass a change object eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); @@ -1093,8 +1104,8 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) return; eo_do(widget, - code = elm_code_widget_code_get(), - elm_code_widget_cursor_position_get(&col, &row)); + code = elm_obj_code_widget_code_get(), + elm_obj_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); if (col > elm_code_line_text_column_width(line, pd->tabstop)) { @@ -1112,7 +1123,7 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) elm_code_line_text_remove(line, position, char_width?char_width:1); eo_do(widget, - elm_code_widget_cursor_position_set(start_col + 1, row), + elm_obj_code_widget_cursor_position_set(start_col + 1, row), // TODO construct and pass a change object eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index 61e8b87f14..cd8be42db2 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -1,6 +1,7 @@ -class Elm_Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) +class Elm.Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) { - eo_prefix: elm_code_widget; + eo_prefix: elm_obj_code_widget; + legacy_prefix: elm_code_widget; methods { @property code { set { diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_legacy.h b/legacy/elm_code/src/lib/widget/elm_code_widget_legacy.h new file mode 100644 index 0000000000..5110e301e2 --- /dev/null +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_legacy.h @@ -0,0 +1,13 @@ +/** + * @brief Add a new elm_code widget to the parent + * + * @param parent The parent object + * @return The new object or NULL if it cannot be created + * + * @see elm_code_widget_code_set + * + * @ingroup Data + */ +EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code); + +#include "elm_code_widget.eo.legacy.h" diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 88642de2eb..a410e277a6 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -62,7 +62,7 @@ elm_code_widget_selection_start(Evas_Object *widget, pd->selection->start_col = col; eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget), - elm_code_widget_cursor_position_set(col, line)); + elm_obj_code_widget_cursor_position_set(col, line)); } EAPI void @@ -311,7 +311,7 @@ _selection_paste_single(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_C newcol = elm_code_line_text_column_width_to_position(line, position + len, pd->tabstop); eo_do(widget, - elm_code_widget_cursor_position_set(newcol + 1, row)); + elm_obj_code_widget_cursor_position_set(newcol + 1, row)); } static void @@ -364,8 +364,8 @@ _selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data return EINA_TRUE; eo_do(widget, - code = elm_code_widget_code_get(), - elm_code_widget_cursor_position_get(&col, &row)); + code = elm_obj_code_widget_code_get(), + elm_obj_code_widget_cursor_position_get(&col, &row)); if (elm_code_text_newlinenpos(ev->data, ev->len, NULL) == ELM_CODE_TEXT_NOT_FOUND) _selection_paste_single(widget, pd, code, col, row, ev->data, ev->len - 1); diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c index b2f3d182f8..cd10319c21 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c @@ -28,8 +28,7 @@ START_TEST (elm_code_widget_token_render_simple_test) code = elm_code_create(); win = elm_win_add(NULL, "code", ELM_WIN_BASIC); - widget = eo_add(ELM_CODE_WIDGET_CLASS, win, - elm_code_widget_code_set(code)); + widget = elm_code_widget_add(win, code); file = code->file; elm_code_file_line_append(file, "some \"test content\", 45", 23, NULL); @@ -62,8 +61,7 @@ START_TEST (elm_code_widget_construct) code = elm_code_create(); win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); - widget = eo_add(ELM_CODE_WIDGET_CLASS, win, - elm_code_widget_code_set(code)); + widget = elm_code_widget_add(win, code); ck_assert(!!widget); elm_code_free(code); diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c index 3463c455a7..bb52747619 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c @@ -19,8 +19,7 @@ START_TEST (elm_code_test_widget_selection_set) elm_code_file_line_append(file, "test", 4, NULL); win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); - widget = eo_add(ELM_CODE_WIDGET_CLASS, win, - elm_code_widget_code_set(code)); + widget = elm_code_widget_add(win, code); elm_code_widget_selection_start(widget, 1, 2); elm_code_widget_selection_end(widget, 1, 3); @@ -45,8 +44,7 @@ START_TEST (elm_code_test_widget_selection_text_get) elm_code_file_line_append(file, "test", 4, NULL); win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); - widget = eo_add(ELM_CODE_WIDGET_CLASS, win, - elm_code_widget_code_set(code)); + widget = elm_code_widget_add(win, code); ck_assert_str_eq("", elm_code_widget_selection_text_get(widget)); @@ -80,8 +78,7 @@ START_TEST (elm_code_test_widget_selection_text_get_twoline) elm_code_file_line_append(file, "test", 4, NULL); win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); - widget = eo_add(ELM_CODE_WIDGET_CLASS, win, - elm_code_widget_code_set(code)); + widget = elm_code_widget_add(win, code); elm_code_widget_selection_start(widget, 1, 3); elm_code_widget_selection_end(widget, 2, 2); @@ -111,8 +108,7 @@ START_TEST (elm_code_test_widget_selection_text_get_multiline) elm_code_file_line_append(file, "test", 4, NULL); win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); - widget = eo_add(ELM_CODE_WIDGET_CLASS, win, - elm_code_widget_code_set(code)); + widget = elm_code_widget_add(win, code); elm_code_widget_selection_start(widget, 1, 3); elm_code_widget_selection_end(widget, 3, 2); @@ -141,8 +137,7 @@ START_TEST (elm_code_test_widget_selection_delete) elm_code_file_line_append(file, "text", 4, NULL); win = elm_win_add(NULL, "code", ELM_WIN_BASIC); - widget = eo_add(ELM_CODE_WIDGET_CLASS, win, - elm_code_widget_code_set(code)); + widget = elm_code_widget_add(win, code); line = elm_code_file_line_get(file, 1); text = elm_code_line_text_get(line, NULL); ck_assert_str_eq("text", text); @@ -176,8 +171,7 @@ START_TEST (elm_code_test_widget_selection_delete_twoline) elm_code_file_line_append(file, "TEXT", 4, NULL); win = elm_win_add(NULL, "code", ELM_WIN_BASIC); - widget = eo_add(ELM_CODE_WIDGET_CLASS, win, - elm_code_widget_code_set(code)); + widget = elm_code_widget_add(win, code); line = elm_code_file_line_get(file, 1); text = elm_code_line_text_get(line, NULL); ck_assert_str_eq("text", text); @@ -214,8 +208,7 @@ START_TEST (elm_code_test_widget_selection_delete_multiline) elm_code_file_line_append(file, "TEXT", 4, NULL); win = elm_win_add(NULL, "code", ELM_WIN_BASIC); - widget = eo_add(ELM_CODE_WIDGET_CLASS, win, - elm_code_widget_code_set(code)); + widget = elm_code_widget_add(win, code); line = elm_code_file_line_get(file, 1); text = elm_code_line_text_get(line, NULL); ck_assert_str_eq("text", text); From 74b3905885867403120deaadd7b440c736c33e64 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 3 Jun 2015 21:29:31 +0100 Subject: [PATCH 181/254] elm_code: consistently use 0 based text index This means it's more familiar as regular string work when using the elm_code_line APIs. It's also more distinct from the elm_code_widget layout which is still 1 based columns. To support unicode we must convert correctly. Now FIXED! --- legacy/elm_code/src/bin/elm_code_test_main.c | 4 +- legacy/elm_code/src/lib/elm_code_line.c | 2 +- legacy/elm_code/src/lib/elm_code_text.c | 77 +------------------ legacy/elm_code/src/lib/elm_code_text.h | 6 -- .../elm_code/src/lib/widget/elm_code_widget.c | 76 ++++++++---------- .../src/lib/widget/elm_code_widget.eo | 23 +++++- .../lib/widget/elm_code_widget_selection.c | 70 ++++++++--------- .../src/lib/widget/elm_code_widget_text.c | 70 +++++++++++++++++ .../elm_code/src/tests/elm_code_test_text.c | 2 +- .../src/tests/widget/elm_code_test_widget.c | 4 +- 10 files changed, 163 insertions(+), 171 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index a7ec071333..8e2c9a0c3d 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -54,7 +54,7 @@ _elm_code_test_line_done_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, line = (Elm_Code_Line *)event_info; if (line->number == 1) - elm_code_line_token_add(line, 18, 25, 1, ELM_CODE_TOKEN_TYPE_COMMENT); + 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; @@ -112,7 +112,7 @@ _elm_code_test_editor_setup(Evas_Object *parent) _append_line(code->file, "...Please?"); line = elm_code_file_line_get(code->file, 1); - elm_code_line_token_add(line, 6, 7, 1, ELM_CODE_TOKEN_TYPE_COMMENT); + 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); diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index f9d3b0856f..e0de0d519e 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -83,7 +83,7 @@ EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int l if (end_line > line->number) { next_line = elm_code_file_line_get(line->file, line->number + 1); - elm_code_line_token_add(next_line, 1, end, lines - 1, type); + elm_code_line_token_add(next_line, 0, end, lines - 1, type); } } diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index e789942281..9d42e4ee2e 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -145,12 +145,10 @@ elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, const char return; inserted = malloc(sizeof(char) * line->length + length); - if (position > 0) - position--; if (position > line->length) position = line->length; - _elm_code_line_tokens_move_right(line, position + 1, length); + _elm_code_line_tokens_move_right(line, position, length); if (line->modified) { @@ -184,12 +182,10 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length return; removed = malloc(sizeof(char) * line->length - length); - if (position > 0) - position--; if (position > line->length) position = line->length; - _elm_code_line_tokens_move_left(line, position + 1, length); + _elm_code_line_tokens_move_left(line, position, length); if (line->modified) { @@ -248,72 +244,3 @@ elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen) return crpos; } -EAPI unsigned int -elm_code_line_text_column_width_to_position(Elm_Code_Line *line, unsigned int position, unsigned int tabstop) -{ - Eina_Unicode unicode; - unsigned int count = 0; - int index = 0; - const char *chars; - - if (line->length == 0) - return 0; - - if (line->modified) - chars = line->modified; - else - chars = line->content; - if (position > line->length) - position = line->length; - - while ((unsigned int) index < position) - { - unicode = eina_unicode_utf8_next_get(chars, &index); - if (unicode == 0) - break; - - if (unicode == '\t') - count += elm_code_text_tabwidth_at_position(count, tabstop); - else - count++; - } - - return count; -} - -EAPI unsigned int -elm_code_line_text_column_width(Elm_Code_Line *line, unsigned int tabstop) -{ - return elm_code_line_text_column_width_to_position(line, line->length, tabstop); -} - -EAPI unsigned int -elm_code_line_text_position_for_column_get(Elm_Code_Line *line, unsigned int column, unsigned int tabstop) -{ - Eina_Unicode unicode; - unsigned int count = 0; - int index = 0; - const char *chars; - - if (line->length == 0) - return 0; - - if (line->modified) - chars = line->modified; - else - chars = line->content; - - while ((unsigned int) count < column && index < (int) line->length) - { - unicode = eina_unicode_utf8_next_get(chars, &index); - - if (unicode == 0) - return line->length; - else if (unicode == '\t') - count += elm_code_text_tabwidth_at_position(count, tabstop); - else - count++; - } - - return (unsigned int) index; -} diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 07eced913a..f547891cf6 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -54,12 +54,6 @@ EAPI int elm_code_text_strnpos(const char *text, unsigned int length, const char EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen); -EAPI unsigned int elm_code_line_text_column_width_to_position(Elm_Code_Line *line, unsigned int length, unsigned int tabstop); - -EAPI unsigned int elm_code_line_text_column_width(Elm_Code_Line *line, unsigned int tabstop); - -EAPI unsigned int elm_code_line_text_position_for_column_get(Elm_Code_Line *line, unsigned int column, unsigned int tabstop); - /** * @} */ diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index c231d44ceb..22ba56bf68 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -126,7 +126,7 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) h = elm_code_file_lines_get(pd->code->file); EINA_LIST_FOREACH(pd->code->file->lines, item, line) { - line_width = elm_code_line_text_column_width(line, pd->tabstop); + line_width = elm_code_widget_line_text_column_width_get(widget, line); if ((int) line_width + gutter + 1 > w) w = (int) line_width + gutter + 1; } @@ -152,7 +152,7 @@ _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start for (x = start; x <= end && x < count; x++) { - cells[x].fg = type; + cells[x - 1].fg = type; } } @@ -176,21 +176,19 @@ static void _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, unsigned int count, Elm_Code_Line *line) { - Elm_Code_Widget_Data *pd; Eina_List *item; Elm_Code_Token *token; unsigned int start, end, length, offset; unsigned int token_start_col, token_end_col; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); eo_do(widget, offset = elm_obj_code_widget_text_left_gutter_width_get()); start = offset; - length = elm_code_line_text_column_width(line, pd->tabstop) + offset; + length = elm_code_widget_line_text_column_width_get(widget, line) + offset; EINA_LIST_FOREACH(line->tokens, item, token) { - token_start_col = elm_code_line_text_column_width_to_position(line, token->start - 1, pd->tabstop) + offset; - token_end_col = elm_code_line_text_column_width_to_position(line, token->end - 1, pd->tabstop) + offset; + token_start_col = elm_code_widget_line_text_column_width_to_position(widget, line, token->start) + offset; + token_end_col = elm_code_widget_line_text_column_width_to_position(widget, line, token->end) + offset; if (token_start_col > start) _elm_code_widget_fill_line_token(cells, count, start, token_start_col, ELM_CODE_TOKEN_TYPE_DEFAULT); @@ -339,7 +337,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) _elm_code_widget_fill_gutter(widget, cells, line->status, line->number); _elm_code_widget_fill_line_tokens(widget, cells, w, line); - length = elm_code_line_text_column_width(line, pd->tabstop); + length = elm_code_widget_line_text_column_width_get(widget, line); chrpos = 0; chr = (char *)elm_code_line_text_get(line, NULL); @@ -499,7 +497,7 @@ _elm_code_widget_cursor_key_will_move(Elm_Code_Widget *widget, const char *key) else if (!strcmp(key, "Left")) return pd->cursor_col > 1 || pd->cursor_line > 1; else if (!strcmp(key, "Right")) - return pd->cursor_col < elm_code_line_text_column_width(line, pd->tabstop) + 1 || + return pd->cursor_col < elm_code_widget_line_text_column_width_get(widget, line) + 1 || pd->cursor_line < elm_code_file_lines_get(pd->code->file); else return EINA_FALSE; @@ -637,7 +635,7 @@ _elm_code_widget_clicked_editable_cb(Elm_Code_Widget *widget, unsigned int row, line = elm_code_file_line_get(pd->code->file, row); if (!line) return; - column_width = elm_code_line_text_column_width(line, pd->tabstop); + column_width = elm_code_widget_line_text_column_width_get(widget, line); if (col > column_width + 1) col = column_width + 1; @@ -777,7 +775,7 @@ _elm_code_widget_cursor_move_end(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); line = elm_code_file_line_get(pd->code->file, pd->cursor_line); - lastcol = elm_code_line_text_column_width(line, pd->tabstop); + lastcol = elm_code_widget_line_text_column_width_get(widget, line); if (pd->cursor_col > lastcol + 1) return; @@ -800,7 +798,7 @@ _elm_code_widget_cursor_move_up(Elm_Code_Widget *widget) row--; line = elm_code_file_line_get(pd->code->file, row); - column_width = elm_code_line_text_column_width(line, pd->tabstop); + column_width = elm_code_widget_line_text_column_width_get(widget, line); if (col > column_width + 1) col = column_width + 1; @@ -823,7 +821,7 @@ _elm_code_widget_cursor_move_down(Elm_Code_Widget *widget) row++; line = elm_code_file_line_get(pd->code->file, row); - column_width = elm_code_line_text_column_width(line, pd->tabstop); + column_width = elm_code_widget_line_text_column_width_get(widget, line); if (col > column_width + 1) col = column_width + 1; @@ -859,7 +857,7 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); line = elm_code_file_line_get(pd->code->file, pd->cursor_line); - if (pd->cursor_col > elm_code_line_text_column_width(line, pd->tabstop)) + if (pd->cursor_col > elm_code_widget_line_text_column_width_get(widget, line)) { if (pd->cursor_line < elm_code_file_lines_get(pd->code->file)) { @@ -901,7 +899,7 @@ _elm_code_widget_cursor_move_pageup(Elm_Code_Widget *widget) row = 1; line = elm_code_file_line_get(pd->code->file, row); - column_width = elm_code_line_text_column_width(line, pd->tabstop); + column_width = elm_code_widget_line_text_column_width_get(widget, line); if (col > column_width + 1) col = column_width + 1; @@ -927,7 +925,7 @@ _elm_code_widget_cursor_move_pagedown(Elm_Code_Widget *widget) row = elm_code_file_lines_get(pd->code->file); line = elm_code_file_line_get(pd->code->file, row); - column_width = elm_code_line_text_column_width(line, pd->tabstop); + column_width = elm_code_widget_line_text_column_width_get(widget, line); if (col > column_width + 1) col = column_width + 1; @@ -953,21 +951,18 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text { Elm_Code *code; Elm_Code_Line *line; - Elm_Code_Widget_Data *pd; unsigned int row, col, position, col_width; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - _elm_code_widget_delete_selection(widget); eo_do(widget, code = elm_obj_code_widget_code_get(), elm_obj_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); - position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); - elm_code_line_text_insert(line, position + 1, text, length); - col_width = elm_code_line_text_column_width_to_position(line, position + length, pd->tabstop) - - elm_code_line_text_column_width_to_position(line, position, pd->tabstop); + position = elm_code_widget_line_text_position_for_column_get(widget, line, col); + elm_code_line_text_insert(line, position, text, length); + col_width = elm_code_widget_line_text_column_width_to_position(widget, line, position + length) - + elm_code_widget_line_text_column_width_to_position(widget, line, position); eo_do(widget, elm_obj_code_widget_cursor_position_set(col + col_width, row), @@ -980,17 +975,15 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) { Elm_Code *code; Elm_Code_Line *line; - Elm_Code_Widget_Data *pd; unsigned int row, col, position; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); _elm_code_widget_delete_selection(widget); eo_do(widget, code = elm_obj_code_widget_code_get(), elm_obj_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); - position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); + position = elm_code_widget_line_text_position_for_column_get(widget, line, col); elm_code_line_split_at(line, position); eo_do(widget, @@ -1004,7 +997,6 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) { Elm_Code *code; Elm_Code_Line *line, *otherline; - Elm_Code_Widget_Data *pd; unsigned int row, col, position; const char *text1, *text2; @@ -1040,11 +1032,10 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) free(newtext); if (!nextline) { - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - position = elm_code_line_text_column_width_to_position(line, length1, pd->tabstop); + position = elm_code_widget_line_text_column_width_to_position(widget, line, length1); eo_do(widget, - elm_obj_code_widget_cursor_position_set(position + 1, row - 1)); + elm_obj_code_widget_cursor_position_set(position, row - 1)); } // TODO construct and pass a change object eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); @@ -1055,7 +1046,6 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) { Elm_Code *code; Elm_Code_Line *line; - Elm_Code_Widget_Data *pd; unsigned int row, col, position, start_col, char_width; if (_elm_code_widget_delete_selection(widget)) @@ -1064,7 +1054,6 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) eo_do(widget, code = elm_obj_code_widget_code_get(), elm_obj_code_widget_cursor_position_get(&col, &row)); - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (col <= 1) { @@ -1077,14 +1066,13 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) line = elm_code_file_line_get(code->file, row); - position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); - char_width = elm_code_line_text_position_for_column_get(line, col, pd->tabstop) - - elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); - start_col = elm_code_line_text_column_width_to_position(line, position - 1, pd->tabstop); + position = elm_code_widget_line_text_position_for_column_get(widget, line, col - 1); + char_width = elm_code_widget_line_text_position_for_column_get(widget, line, col) - position; + start_col = elm_code_widget_line_text_column_width_to_position(widget, line, position); elm_code_line_text_remove(line, position, char_width?char_width:1); eo_do(widget, - elm_obj_code_widget_cursor_position_set(start_col + 1, row)); + elm_obj_code_widget_cursor_position_set(start_col, row)); // TODO construct and pass a change object eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); @@ -1096,9 +1084,6 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) Elm_Code *code; Elm_Code_Line *line; unsigned int row, col, position, char_width, start_col; - Elm_Code_Widget_Data *pd; - - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (_elm_code_widget_delete_selection(widget)) return; @@ -1107,7 +1092,7 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) code = elm_obj_code_widget_code_get(), elm_obj_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); - if (col > elm_code_line_text_column_width(line, pd->tabstop)) + if (col > elm_code_widget_line_text_column_width_get(widget, line)) { if (row == elm_code_file_lines_get(code->file)) return; @@ -1116,14 +1101,13 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) return; } - position = elm_code_line_text_position_for_column_get(line, col, pd->tabstop); - char_width = elm_code_line_text_position_for_column_get(line, col, pd->tabstop) - - elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); - start_col = elm_code_line_text_column_width_to_position(line, position - 1, pd->tabstop); + position = elm_code_widget_line_text_position_for_column_get(widget, line, col); + char_width = elm_code_widget_line_text_position_for_column_get(widget, line, col + 1) - position; + start_col = elm_code_widget_line_text_column_width_to_position(widget, line, position); elm_code_line_text_remove(line, position, char_width?char_width:1); eo_do(widget, - elm_obj_code_widget_cursor_position_set(start_col + 1, row), + elm_obj_code_widget_cursor_position_set(start_col, row), // TODO construct and pass a change object eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index cd8be42db2..fde1902fd1 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -199,7 +199,7 @@ class Elm.Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) } values { col: uint; /*@ The horizontal position of the cursor, starting from column 1 */ - line: uint; /*@ The vertical position of the cursor - the top row is 1 an */ + line: uint; /*@ The vertical position of the cursor - the top row is 1 */ } } line_refresh { @@ -224,6 +224,27 @@ class Elm.Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) text_line_number_width_get { return: int; /*@ the column width required to represent the number of lines in the widget. */ } + + line_text_column_width_to_position { + params { + line: Elm_Code_Line *; + position: uint; + } + return: uint; + } + line_text_column_width_get { + params { + line: Elm_Code_Line *; + } + return: uint; + } + line_text_position_for_column_get { + params { + line: Elm_Code_Line *; + column: uint; + } + return: uint; + } } implements { class.constructor; diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index a410e277a6..9774526113 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -30,7 +30,7 @@ _elm_code_widget_selection_limit(Evas_Object *widget EINA_UNUSED, Elm_Code_Widge *row = elm_code_file_lines_get(file); line = elm_code_file_line_get(file, *row); - width = elm_code_line_text_column_width(line, pd->tabstop); + width = elm_code_widget_line_text_column_width_get(widget, line); if (*col > width + 1) *col = width + 1; @@ -105,7 +105,7 @@ elm_code_widget_selection_clear(Evas_Object *widget) } static void -_elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd) +_elm_code_widget_selection_delete_single(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd) { Elm_Code_Line *line; const char *old; @@ -117,10 +117,8 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd) line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); old = elm_code_line_text_get(line, &old_length); - start = elm_code_line_text_position_for_column_get(line, pd->selection->start_col, - pd->tabstop) - 1; - end = elm_code_line_text_position_for_column_get(line, pd->selection->end_col, - pd->tabstop) - 1; + start = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->start_col); + end = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->end_col); length = line->length - (end - start + 1); content = malloc(sizeof(char) * length); @@ -132,7 +130,7 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget_Data *pd) } static void -_elm_code_widget_selection_delete_multi(Elm_Code_Widget_Data *pd) +_elm_code_widget_selection_delete_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd) { Elm_Code_Line *line; const char *first, *last; @@ -144,13 +142,11 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget_Data *pd) line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); first = elm_code_line_text_get(line, NULL); - start = elm_code_line_text_position_for_column_get(line, pd->selection->start_col, - pd->tabstop) - 1; + start = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->start_col); line = elm_code_file_line_get(pd->code->file, pd->selection->end_line); last = elm_code_line_text_get(line, &last_length); - end = elm_code_line_text_position_for_column_get(line, pd->selection->end_col, - pd->tabstop) - 1; + end = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->end_col); length = start + last_length - (end + 1); content = malloc(sizeof(char) * length); @@ -177,9 +173,9 @@ elm_code_widget_selection_delete(Evas_Object *widget) return; if (pd->selection->start_line == pd->selection->end_line) - _elm_code_widget_selection_delete_single(pd); + _elm_code_widget_selection_delete_single(widget, pd); else - _elm_code_widget_selection_delete_multi(pd); + _elm_code_widget_selection_delete_multi(widget, pd); free(pd->selection); pd->selection = NULL; @@ -187,34 +183,37 @@ elm_code_widget_selection_delete(Evas_Object *widget) } static char * -_elm_code_widget_selection_text_single_get(Elm_Code_Widget_Data *pd) +_elm_code_widget_selection_text_single_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd) { Elm_Code_Line *line; + unsigned int start, end; line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); + start = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->start_col); + end = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->end_col + 1); - return elm_code_line_text_substr(line, pd->selection->start_col - 1, - pd->selection->end_col - pd->selection->start_col + 1); + return elm_code_line_text_substr(line, start, end - start); } static char * -_elm_code_widget_selection_text_multi_get(Elm_Code_Widget_Data *pd) +_elm_code_widget_selection_text_multi_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd) { Elm_Code_Line *line; char *first, *last, *ret, *ptr; const char *newline; short newline_len; int ret_len; - unsigned int row; + unsigned int row, start, end; newline = elm_code_file_line_ending_chars_get(pd->code->file, &newline_len); line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); - first = elm_code_line_text_substr(line, pd->selection->start_col - 1, - line->length - pd->selection->start_col + 1); + start = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->start_col); + first = elm_code_line_text_substr(line, start, line->length - start + 1); line = elm_code_file_line_get(pd->code->file, pd->selection->end_line); - last = elm_code_line_text_substr(line, 0, pd->selection->end_col); + end = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->end_col + 1); + last = elm_code_line_text_substr(line, 0, end); ret_len = strlen(first) + strlen(last) + newline_len; @@ -259,9 +258,9 @@ elm_code_widget_selection_text_get(Evas_Object *widget) return strdup(""); if (pd->selection->start_line == pd->selection->end_line) - return _elm_code_widget_selection_text_single_get(pd); + return _elm_code_widget_selection_text_single_get(widget, pd); else - return _elm_code_widget_selection_text_multi_get(pd); + return _elm_code_widget_selection_text_multi_get(widget, pd); } static void @@ -299,23 +298,23 @@ elm_code_widget_selection_copy(Evas_Object *widget) } static void -_selection_paste_single(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Code *code, +_selection_paste_single(Elm_Code_Widget *widget, Elm_Code *code, unsigned int col, unsigned int row, const char *text, unsigned int len) { Elm_Code_Line *line; unsigned int position, newcol; line = elm_code_file_line_get(code->file, row); - position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); - elm_code_line_text_insert(line, position + 1, text, len); + position = elm_code_widget_line_text_position_for_column_get(widget, line, col); + elm_code_line_text_insert(line, position, text, len); - newcol = elm_code_line_text_column_width_to_position(line, position + len, pd->tabstop); + newcol = elm_code_widget_line_text_column_width_to_position(widget, line, position + len); eo_do(widget, - elm_obj_code_widget_cursor_position_set(newcol + 1, row)); + elm_obj_code_widget_cursor_position_set(newcol, row)); } static void -_selection_paste_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Code *code, +_selection_paste_multi(Elm_Code_Widget *widget, Elm_Code *code, unsigned int col, unsigned int row, const char *text, unsigned int len) { Elm_Code_Line *line; @@ -325,7 +324,7 @@ _selection_paste_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Co char *ptr; line = elm_code_file_line_get(code->file, row); - position = elm_code_line_text_position_for_column_get(line, col - 1, pd->tabstop); + position = elm_code_widget_line_text_position_for_column_get(widget, line, col); elm_code_line_split_at(line, position); newrow = row; @@ -334,7 +333,7 @@ _selection_paste_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Co while ((nlpos = elm_code_text_newlinenpos(ptr, remain, &nllen)) != ELM_CODE_TEXT_NOT_FOUND) { if (newrow == row) - _selection_paste_single(widget, pd, code, col, row, text, nlpos); + _selection_paste_single(widget, code, col, row, text, nlpos); else elm_code_file_line_insert(code->file, newrow, ptr, nlpos, NULL); @@ -343,7 +342,7 @@ _selection_paste_multi(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, Elm_Co newrow++; } - _selection_paste_single(widget, pd, code, 1, newrow, ptr, len - (ptr - text)); + _selection_paste_single(widget, code, 1, newrow, ptr, len - (ptr - text)); } static Eina_Bool @@ -351,15 +350,12 @@ _selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data { Elm_Code *code; Elm_Code_Widget *widget; - Elm_Code_Widget_Data *pd; unsigned int row, col; widget = (Elm_Code_Widget *)data; - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (ev->format != ELM_SEL_FORMAT_TEXT) return EINA_TRUE; - if (ev->len <= 0) return EINA_TRUE; @@ -368,9 +364,9 @@ _selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data elm_obj_code_widget_cursor_position_get(&col, &row)); if (elm_code_text_newlinenpos(ev->data, ev->len, NULL) == ELM_CODE_TEXT_NOT_FOUND) - _selection_paste_single(widget, pd, code, col, row, ev->data, ev->len - 1); + _selection_paste_single(widget, code, col, row, ev->data, ev->len - 1); else - _selection_paste_multi(widget, pd, code, col, row, ev->data, ev->len - 1); + _selection_paste_multi(widget, code, col, row, ev->data, ev->len - 1); return EINA_TRUE; } diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_text.c b/legacy/elm_code/src/lib/widget/elm_code_widget_text.c index 696fc30801..b3be1176fe 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_text.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_text.c @@ -33,3 +33,73 @@ _elm_code_widget_text_left_gutter_width_get(Eo *obj, Elm_Code_Widget_Data *pd) return width; } + +static unsigned int +_elm_code_widget_line_text_column_width_to_position(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Code_Line *line, unsigned int position) +{ + Eina_Unicode unicode; + unsigned int count = 1; + int index = 0; + const char *chars; + + if (line->length == 0) + return 1; + + if (line->modified) + chars = line->modified; + else + chars = line->content; + if (position > line->length) + position = line->length; + + while ((unsigned int) index < position) + { + unicode = eina_unicode_utf8_next_get(chars, &index); + if (unicode == 0) + break; + + if (unicode == '\t') + count += elm_code_text_tabwidth_at_position(count, pd->tabstop); + else + count++; + } + + return count; +} + +static unsigned int +_elm_code_widget_line_text_column_width_get(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code_Line *line) +{ + return _elm_code_widget_line_text_column_width_to_position(obj, pd, line, line->length) - 1; +} + +static unsigned int +_elm_code_widget_line_text_position_for_column_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Code_Line *line, unsigned int column) +{ + Eina_Unicode unicode; + unsigned int count = 1; + int index = 0; + const char *chars; + + if (line->length == 0 || column == 1) + return 0; + + if (line->modified) + chars = line->modified; + else + chars = line->content; + + while ((unsigned int) count < column && index < (int) line->length) + { + unicode = eina_unicode_utf8_next_get(chars, &index); + + if (unicode == 0) + return line->length; + else if (unicode == '\t') + count += elm_code_text_tabwidth_at_position(count, pd->tabstop); + else + count++; + } + + return (unsigned int) index; +} diff --git a/legacy/elm_code/src/tests/elm_code_test_text.c b/legacy/elm_code/src/tests/elm_code_test_text.c index c291569793..85784a43a8 100644 --- a/legacy/elm_code/src/tests/elm_code_test_text.c +++ b/legacy/elm_code/src/tests/elm_code_test_text.c @@ -32,7 +32,7 @@ START_TEST (elm_code_text_insert_test) elm_code_file_line_append(file, "test", 4, NULL); line = elm_code_file_line_get(file, 1); - elm_code_line_text_insert(line, 5, "ing", 3); + elm_code_line_text_insert(line, 4, "ing", 3); ck_assert_str_eq("testing", elm_code_line_text_get(line, NULL)); } END_TEST diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c index cd10319c21..a30e6ea099 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c @@ -35,8 +35,8 @@ START_TEST (elm_code_widget_token_render_simple_test) line = elm_code_file_line_get(file, 1); length = line->length; - elm_code_line_token_add(line, 6+1, 17+1, 1, ELM_CODE_TOKEN_TYPE_COMMENT); - elm_code_line_token_add(line, 21+1, 22+1, 1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 6, 17, 1, ELM_CODE_TOKEN_TYPE_COMMENT); + elm_code_line_token_add(line, 21, 22, 1, ELM_CODE_TOKEN_TYPE_COMMENT); _elm_code_widget_fill_line_tokens(widget, cells, length+1, line); _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT, 1); From 24d3a01e562c3a130daf24fc9f80e9070b42fe2f Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 7 Jun 2015 23:11:25 +0100 Subject: [PATCH 182/254] elm_code: indent lines to match whitespace above We can look at more complex scope based indenting later --- legacy/elm_code/src/lib/elm_code_text.c | 18 ++++++++++++++++++ legacy/elm_code/src/lib/elm_code_text.h | 2 ++ .../elm_code/src/lib/widget/elm_code_widget.c | 11 +++++++++-- .../elm_code/src/tests/elm_code_test_text.c | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 9d42e4ee2e..7480b4a950 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -244,3 +244,21 @@ elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen) return crpos; } +EAPI unsigned int +elm_code_text_leading_whitespace_length(const char *text, unsigned int length) +{ + unsigned int count = 0; + char *ptr = (char *)text; + + while (count < length) + { + if (!(*ptr == ' ' || *ptr == '\t')) + break; + + count++; + ptr++; + } + + return count; +} + diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index f547891cf6..07e139dc44 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -54,6 +54,8 @@ EAPI int elm_code_text_strnpos(const char *text, unsigned int length, const char EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen); +EAPI unsigned int elm_code_text_leading_whitespace_length(const char *text, unsigned int length); + /** * @} */ diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 22ba56bf68..bf34af4f6f 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -975,19 +975,26 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) { Elm_Code *code; Elm_Code_Line *line; - unsigned int row, col, position; + unsigned int row, col, position, oldlen, leading; + const char *oldtext; _elm_code_widget_delete_selection(widget); eo_do(widget, code = elm_obj_code_widget_code_get(), elm_obj_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); + oldtext = elm_code_line_text_get(line, &oldlen); position = elm_code_widget_line_text_position_for_column_get(widget, line, col); elm_code_line_split_at(line, position); + line = elm_code_file_line_get(code->file, row + 1); + leading = elm_code_text_leading_whitespace_length(oldtext, oldlen); + elm_code_line_text_insert(line, 0, oldtext, leading); + eo_do(widget, - elm_obj_code_widget_cursor_position_set(1, row + 1), + elm_obj_code_widget_cursor_position_set( + elm_obj_code_widget_line_text_column_width_to_position(line, leading), row + 1), // TODO construct and pass a change object eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } diff --git a/legacy/elm_code/src/tests/elm_code_test_text.c b/legacy/elm_code/src/tests/elm_code_test_text.c index 85784a43a8..5391eb6922 100644 --- a/legacy/elm_code/src/tests/elm_code_test_text.c +++ b/legacy/elm_code/src/tests/elm_code_test_text.c @@ -94,6 +94,24 @@ START_TEST (elm_code_text_newline_position_test) } END_TEST +START_TEST (elm_code_text_leading_whitespace_test) +{ + const char *text; + + text = "testing"; + ck_assert_int_eq(0, elm_code_text_leading_whitespace_length(text, strlen(text))); + + text = " spaces"; + ck_assert_int_eq(2, elm_code_text_leading_whitespace_length(text, strlen(text))); + + text = "\t\ttabs"; + ck_assert_int_eq(2, elm_code_text_leading_whitespace_length(text, strlen(text))); + + text = " \t mix"; + ck_assert_int_eq(3, elm_code_text_leading_whitespace_length(text, strlen(text))); +} +END_TEST + void elm_code_test_text(TCase *tc) { tcase_add_test(tc, elm_code_text_get_test); @@ -101,4 +119,5 @@ void elm_code_test_text(TCase *tc) tcase_add_test(tc, elm_code_text_contains_test); tcase_add_test(tc, elm_code_text_strpos_test); tcase_add_test(tc, elm_code_text_newline_position_test); + tcase_add_test(tc, elm_code_text_leading_whitespace_test); } From cf322a63886069bde057099be52bb2bcf31c4a3c Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 7 Jun 2015 23:12:05 +0100 Subject: [PATCH 183/254] texts: fix tests broken in previous refactor --- legacy/elm_code/src/tests/widget/elm_code_test_widget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c index a30e6ea099..3471e3ca2a 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c @@ -41,10 +41,10 @@ START_TEST (elm_code_widget_token_render_simple_test) _elm_code_widget_fill_line_tokens(widget, cells, length+1, line); _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT, 1); _assert_cell_type(cells[4], ELM_CODE_TOKEN_TYPE_DEFAULT, 4); - _assert_cell_type(cells[6], ELM_CODE_TOKEN_TYPE_DEFAULT, 6); + _assert_cell_type(cells[5], ELM_CODE_TOKEN_TYPE_DEFAULT, 5); _assert_cell_type(cells[16], ELM_CODE_TOKEN_TYPE_COMMENT, 16); _assert_cell_type(cells[20], ELM_CODE_TOKEN_TYPE_DEFAULT, 20); - _assert_cell_type(cells[23], ELM_CODE_TOKEN_TYPE_COMMENT, 23); + _assert_cell_type(cells[22], ELM_CODE_TOKEN_TYPE_COMMENT, 22); elm_code_free(code); elm_shutdown(); From 06fa3d494b346ef76d1897c833b4978e17cdc8a1 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 7 Jun 2015 23:13:26 +0100 Subject: [PATCH 184/254] elm_code: remove selections if moving cursor The selection remaining after cursor move was getting confusing --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index bf34af4f6f..a2888d2171 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -758,6 +758,7 @@ _elm_code_widget_cursor_move_home(Elm_Code_Widget *widget) Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + elm_code_widget_selection_clear(widget); if (pd->cursor_col <= 1) return; @@ -773,6 +774,7 @@ _elm_code_widget_cursor_move_end(Elm_Code_Widget *widget) unsigned int lastcol; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + elm_code_widget_selection_clear(widget); line = elm_code_file_line_get(pd->code->file, pd->cursor_line); lastcol = elm_code_widget_line_text_column_width_get(widget, line); @@ -792,6 +794,7 @@ _elm_code_widget_cursor_move_up(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); row = pd->cursor_line; col = pd->cursor_col; + elm_code_widget_selection_clear(widget); if (pd->cursor_line <= 1) return; @@ -815,6 +818,7 @@ _elm_code_widget_cursor_move_down(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); row = pd->cursor_line; col = pd->cursor_col; + elm_code_widget_selection_clear(widget); if (pd->cursor_line >= elm_code_file_lines_get(pd->code->file)) return; @@ -834,6 +838,7 @@ _elm_code_widget_cursor_move_left(Elm_Code_Widget *widget) Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + elm_code_widget_selection_clear(widget); if (pd->cursor_col <= 1) { @@ -855,6 +860,7 @@ _elm_code_widget_cursor_move_right(Elm_Code_Widget *widget) Elm_Code_Line *line; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + elm_code_widget_selection_clear(widget); line = elm_code_file_line_get(pd->code->file, pd->cursor_line); if (pd->cursor_col > elm_code_widget_line_text_column_width_get(widget, line)) @@ -890,6 +896,7 @@ _elm_code_widget_cursor_move_pageup(Elm_Code_Widget *widget) row = pd->cursor_line; col = pd->cursor_col; + elm_code_widget_selection_clear(widget); if (pd->cursor_line <= 1) return; @@ -917,6 +924,7 @@ _elm_code_widget_cursor_move_pagedown(Elm_Code_Widget *widget) row = pd->cursor_line; col = pd->cursor_col; + elm_code_widget_selection_clear(widget); if (pd->cursor_line >= elm_code_file_lines_get(pd->code->file)) return; From dd4c0fa217b4341a3b57bf244709f4bcea0c1c88 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 8 Jun 2015 23:13:03 +0100 Subject: [PATCH 185/254] elm_code: Fix tab behaviour following API changes Moved the tabwidth calculations to widget as that's where they actually make sense --- legacy/elm_code/src/lib/elm_code_text.c | 6 -- legacy/elm_code/src/lib/elm_code_text.h | 2 - .../elm_code/src/lib/widget/elm_code_widget.c | 11 ++-- .../src/lib/widget/elm_code_widget.eo | 6 ++ .../src/lib/widget/elm_code_widget_text.c | 22 ++++--- legacy/elm_code/src/tests/Makefile.am | 1 + legacy/elm_code/src/tests/elm_code_suite.c | 1 + legacy/elm_code/src/tests/elm_code_suite.h | 1 + .../tests/widget/elm_code_test_widget_text.c | 59 +++++++++++++++++++ 9 files changed, 89 insertions(+), 20 deletions(-) create mode 100644 legacy/elm_code/src/tests/widget/elm_code_test_widget_text.c diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 7480b4a950..9e7a7c0cbd 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -209,12 +209,6 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length /* generic text functions */ -EAPI unsigned int -elm_code_text_tabwidth_at_position(unsigned int position, unsigned int tabstop) -{ - return tabstop - (position % tabstop); -} - EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen) { diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 07e139dc44..2370599385 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -48,8 +48,6 @@ EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, * */ -EAPI unsigned int elm_code_text_tabwidth_at_position(unsigned int position, unsigned int tabstop); - EAPI int elm_code_text_strnpos(const char *text, unsigned int length, const char *search, int offset); EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index a2888d2171..ac2a058485 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -350,7 +350,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) charwidth = 1; if (unichr == '\t') - charwidth = elm_code_text_tabwidth_at_position(x - gutter, pd->tabstop); + charwidth = elm_code_widget_text_tabwidth_at_column_get(widget, x - gutter + 1); for (i = x + 1; i < x + charwidth; i++) { cells[i].codepoint = 0; @@ -1081,11 +1081,12 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) line = elm_code_file_line_get(code->file, row); - position = elm_code_widget_line_text_position_for_column_get(widget, line, col - 1); - char_width = elm_code_widget_line_text_position_for_column_get(widget, line, col) - position; - start_col = elm_code_widget_line_text_column_width_to_position(widget, line, position); + position = elm_code_widget_line_text_position_for_column_get(widget, line, col); + start_col = elm_code_widget_line_text_column_width_to_position(widget, line, + elm_code_widget_line_text_position_for_column_get(widget, line, col - 1)); + char_width = position - elm_code_widget_line_text_position_for_column_get(widget, line, start_col); - elm_code_line_text_remove(line, position, char_width?char_width:1); + elm_code_line_text_remove(line, position - char_width, char_width); eo_do(widget, elm_obj_code_widget_cursor_position_set(start_col, row)); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index fde1902fd1..294d86096c 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -245,6 +245,12 @@ class Elm.Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) } return: uint; } + text_tabwidth_at_column_get { + params { + column: uint; + } + return: uint; + } } implements { class.constructor; diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_text.c b/legacy/elm_code/src/lib/widget/elm_code_widget_text.c index b3be1176fe..b7b131e157 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_text.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_text.c @@ -35,7 +35,7 @@ _elm_code_widget_text_left_gutter_width_get(Eo *obj, Elm_Code_Widget_Data *pd) } static unsigned int -_elm_code_widget_line_text_column_width_to_position(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Code_Line *line, unsigned int position) +_elm_code_widget_line_text_column_width_to_position(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm_Code_Line *line, unsigned int position) { Eina_Unicode unicode; unsigned int count = 1; @@ -59,7 +59,7 @@ _elm_code_widget_line_text_column_width_to_position(Eo *obj EINA_UNUSED, Elm_Cod break; if (unicode == '\t') - count += elm_code_text_tabwidth_at_position(count, pd->tabstop); + count += elm_code_widget_text_tabwidth_at_column_get(obj, count); else count++; } @@ -74,10 +74,10 @@ _elm_code_widget_line_text_column_width_get(Eo *obj, Elm_Code_Widget_Data *pd, E } static unsigned int -_elm_code_widget_line_text_position_for_column_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Code_Line *line, unsigned int column) +_elm_code_widget_line_text_position_for_column_get(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm_Code_Line *line, unsigned int column) { Eina_Unicode unicode; - unsigned int count = 1; + unsigned int count = 1, position = 0; int index = 0; const char *chars; @@ -89,17 +89,25 @@ _elm_code_widget_line_text_position_for_column_get(Eo *obj EINA_UNUSED, Elm_Code else chars = line->content; - while ((unsigned int) count < column && index < (int) line->length) + while ((unsigned int) count <= column && index <= (int) line->length) { + position = (unsigned int) index; unicode = eina_unicode_utf8_next_get(chars, &index); if (unicode == 0) return line->length; else if (unicode == '\t') - count += elm_code_text_tabwidth_at_position(count, pd->tabstop); + count += elm_code_widget_text_tabwidth_at_column_get(obj, count); else count++; } - return (unsigned int) index; + return position; } + +static unsigned int +_elm_code_widget_text_tabwidth_at_column_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, unsigned int column) +{ + return pd->tabstop - ((column - 1) % pd->tabstop); +} + diff --git a/legacy/elm_code/src/tests/Makefile.am b/legacy/elm_code/src/tests/Makefile.am index 4bb0cc0b64..86acce2f1a 100644 --- a/legacy/elm_code/src/tests/Makefile.am +++ b/legacy/elm_code/src/tests/Makefile.am @@ -13,6 +13,7 @@ elm_code_test_line.c \ elm_code_test_parse.c \ elm_code_test_text.c \ widget/elm_code_test_widget.c \ +widget/elm_code_test_widget_text.c \ widget/elm_code_test_widget_selection.c \ elm_code_suite.c diff --git a/legacy/elm_code/src/tests/elm_code_suite.c b/legacy/elm_code/src/tests/elm_code_suite.c index d45976869f..f562b80363 100644 --- a/legacy/elm_code/src/tests/elm_code_suite.c +++ b/legacy/elm_code/src/tests/elm_code_suite.c @@ -19,6 +19,7 @@ static const struct { { "text", elm_code_test_text }, { "basic", elm_code_test_basic }, { "widget", elm_code_test_widget }, + { "widget_text", elm_code_test_widget_text }, { "widget_selection", elm_code_test_widget_selection }, }; diff --git a/legacy/elm_code/src/tests/elm_code_suite.h b/legacy/elm_code/src/tests/elm_code_suite.h index 5a7f4e3662..489e8fd517 100644 --- a/legacy/elm_code/src/tests/elm_code_suite.h +++ b/legacy/elm_code/src/tests/elm_code_suite.h @@ -12,6 +12,7 @@ void elm_code_test_line(TCase *tc); void elm_code_test_parse(TCase *tc); void elm_code_test_text(TCase *tc); void elm_code_test_widget(TCase *tc); +void elm_code_test_widget_text(TCase *tc); void elm_code_test_widget_selection(TCase *tc); #endif /* _EDLM_CODE_SUITE_H */ diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_text.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget_text.c new file mode 100644 index 0000000000..86d4a33e51 --- /dev/null +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget_text.c @@ -0,0 +1,59 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "elm_code_suite.h" + +START_TEST (elm_code_test_widget_text_tab_width) +{ + Elm_Code *code; + Elm_Code_Widget *widget; + Evas_Object *win; + + elm_init(1, NULL); + code = elm_code_create(); + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + elm_code_widget_tabstop_set(widget, 8); + + ck_assert_int_eq(8, elm_code_widget_text_tabwidth_at_column_get(widget, 1)); + ck_assert_int_eq(8, elm_code_widget_text_tabwidth_at_column_get(widget, 9)); + ck_assert_int_eq(6, elm_code_widget_text_tabwidth_at_column_get(widget, 3)); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + +START_TEST (elm_code_test_widget_text_position) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + Elm_Code_Widget *widget; + Evas_Object *win; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "a\tb", 4, NULL); + line = elm_code_file_line_get(file, 1); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + elm_code_widget_tabstop_set(widget, 8); + + ck_assert_int_eq(0, elm_code_widget_line_text_position_for_column_get(widget, line, 1)); + ck_assert_int_eq(1, elm_code_widget_line_text_position_for_column_get(widget, line, 2)); + + ck_assert_int_eq(2, elm_code_widget_line_text_position_for_column_get(widget, line, 9)); + ck_assert_int_eq(1, elm_code_widget_line_text_position_for_column_get(widget, line, 7)); +} +END_TEST + +void elm_code_test_widget_text(TCase *tc) +{ + tcase_add_test(tc, elm_code_test_widget_text_tab_width); + tcase_add_test(tc, elm_code_test_widget_text_position); +} + From ab8f56af52da55dfddd0e98977ece2c7f19bbd08 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 9 Jun 2015 22:31:57 +0100 Subject: [PATCH 186/254] editor: fix a strange crash in calculations Seems that gutter was not always correct after eo_do --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index ac2a058485..33f3723adb 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -214,7 +214,7 @@ _elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - eo_do(widget, gutter = elm_obj_code_widget_text_left_gutter_width_get()); + gutter = elm_code_widget_text_left_gutter_width_get(widget); evas_object_textgrid_size_get(pd->grid, &w, NULL); From 556d5790fb2e2f40d6f38c69462ac1c43bbe047a Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 10 Jun 2015 23:32:15 +0100 Subject: [PATCH 187/254] editor: Fix crash opening empty files --- legacy/elm_code/src/lib/widget/elm_code_widget_text.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_text.c b/legacy/elm_code/src/lib/widget/elm_code_widget_text.c index b7b131e157..0ae2595563 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_text.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_text.c @@ -70,6 +70,9 @@ _elm_code_widget_line_text_column_width_to_position(Eo *obj, Elm_Code_Widget_Dat static unsigned int _elm_code_widget_line_text_column_width_get(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code_Line *line) { + if (!line) + return 0; + return _elm_code_widget_line_text_column_width_to_position(obj, pd, line, line->length) - 1; } From 4c6fb9cc801a4e5719426782b4a4822cc8196ff9 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 10 Jun 2015 23:33:46 +0100 Subject: [PATCH 188/254] editor: allow cursor placement in blank file This way we can start editing a newly created file! --- .../elm_code/src/lib/widget/elm_code_widget.c | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 33f3723adb..0fd9479a20 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -278,14 +278,14 @@ _elm_code_widget_fill_whitespace(Elm_Code_Widget *widget, Eina_Unicode character } static void -_elm_code_widget_fill_cursor(Elm_Code_Widget *widget, Elm_Code_Line *line, Evas_Textgrid_Cell *cells, - int gutter, int w) +_elm_code_widget_fill_cursor(Elm_Code_Widget *widget, unsigned int number, + Evas_Textgrid_Cell *cells, int gutter, int w) { Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (pd->editable && pd->focussed && pd->cursor_line == line->number) + if (pd->editable && pd->focussed && pd->cursor_line == number) { if (pd->cursor_col + gutter - 1 < (unsigned int) w) cells[pd->cursor_col + gutter - 1].bg = ELM_CODE_WIDGET_COLOR_CURSOR; @@ -366,7 +366,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) } _elm_code_widget_fill_selection(widget, line, cells, gutter, w); - _elm_code_widget_fill_cursor(widget, line, cells, gutter, w); + _elm_code_widget_fill_cursor(widget, line->number, cells, gutter, w); if (line->number < elm_code_file_lines_get(line->file)) _elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]); @@ -394,6 +394,7 @@ _elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number) cells[x].bg = _elm_code_widget_status_type_get(widget, ELM_CODE_STATUS_TYPE_DEFAULT, x - gutter + 1); } + _elm_code_widget_fill_cursor(widget, number, cells, gutter, w); evas_object_textgrid_update_add(pd->grid, 0, number - 1, w, 1); } @@ -678,7 +679,7 @@ _elm_code_widget_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj return; _elm_code_widget_position_at_coordinates_get(widget, pd, event->canvas.x, event->canvas.y, &row, &col); - if (col > 0) + if (col > 0 && row <= elm_code_file_lines_get(pd->code->file)) elm_code_widget_selection_start(widget, row, col); } @@ -966,6 +967,12 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text code = elm_obj_code_widget_code_get(), elm_obj_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); + if (line == NULL) + { + elm_code_file_line_append(code->file, "", 0, NULL); + row = elm_code_file_lines_get(code->file); + line = elm_code_file_line_get(code->file, row); + } position = elm_code_widget_line_text_position_for_column_get(widget, line, col); elm_code_line_text_insert(line, position, text, length); @@ -991,6 +998,12 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) code = elm_obj_code_widget_code_get(), elm_obj_code_widget_cursor_position_get(&col, &row)); line = elm_code_file_line_get(code->file, row); + if (line == NULL) + { + elm_code_file_line_append(code->file, "", 0, NULL); + row = elm_code_file_lines_get(code->file); + line = elm_code_file_line_get(code->file, row); + } oldtext = elm_code_line_text_get(line, &oldlen); position = elm_code_widget_line_text_position_for_column_get(widget, line, col); From b1fd31d3a29ce22b3aaa85bcaae37a8edb95430b Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 23 Aug 2015 23:23:07 +0100 Subject: [PATCH 189/254] Fix some bad memory access during widget creation --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 0fd9479a20..fe6430ef3c 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -207,7 +207,7 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c static void _elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, - Elm_Code_Status_Type status, int line) + int width, Elm_Code_Status_Type status, int line) { char *number = NULL; int w, gutter, g; @@ -216,6 +216,8 @@ _elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); gutter = elm_code_widget_text_left_gutter_width_get(widget); + if (width < gutter) + return; evas_object_textgrid_size_get(pd->grid, &w, NULL); cells[gutter-1].codepoint = status_icons[status]; @@ -334,7 +336,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) evas_object_textgrid_size_get(pd->grid, &w, NULL); cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); - _elm_code_widget_fill_gutter(widget, cells, line->status, line->number); + _elm_code_widget_fill_gutter(widget, cells, w, line->status, line->number); _elm_code_widget_fill_line_tokens(widget, cells, w, line); length = elm_code_widget_line_text_column_width_get(widget, line); @@ -386,7 +388,7 @@ _elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number) evas_object_textgrid_size_get(pd->grid, &w, NULL); cells = evas_object_textgrid_cellrow_get(pd->grid, number - 1); - _elm_code_widget_fill_gutter(widget, cells, ELM_CODE_STATUS_TYPE_DEFAULT, 0); + _elm_code_widget_fill_gutter(widget, cells, w, ELM_CODE_STATUS_TYPE_DEFAULT, 0); for (x = gutter; x < (unsigned int) w; x++) { From d5804b08374268c108c32c5775bf1abed56894e2 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 28 Aug 2015 00:15:55 +0100 Subject: [PATCH 190/254] [elm_code] Trim empty lines on save When writing out a document set line length to 0 if it only contains whitespace --- legacy/elm_code/src/lib/elm_code_file.c | 5 +++++ legacy/elm_code/src/lib/elm_code_text.c | 10 ++++++++++ legacy/elm_code/src/lib/elm_code_text.h | 2 ++ legacy/elm_code/src/tests/elm_code_test_text.c | 16 ++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index 0b164bba53..8832fe0ad7 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -179,6 +179,11 @@ EAPI void elm_code_file_save(Elm_Code_File *file) EINA_LIST_FOREACH(file->lines, item, line_item) { content = elm_code_line_text_get(line_item, &length); + if (elm_code_text_is_whitespace(content, length)) + { + length = 0; + elm_code_line_text_set(line_item, "", 0); + } fwrite(content, sizeof(char), length, out); fwrite(crchars, sizeof(char), crlength, out); } diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 9e7a7c0cbd..83216c6cba 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -256,3 +256,13 @@ elm_code_text_leading_whitespace_length(const char *text, unsigned int length) return count; } +EAPI unsigned int +elm_code_text_is_whitespace(const char *text, unsigned int length) +{ + unsigned int leading; + + leading = elm_code_text_leading_whitespace_length(text, length); + + return leading == length; +} + diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 2370599385..66bfbffb3f 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -54,6 +54,8 @@ EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length, short EAPI unsigned int elm_code_text_leading_whitespace_length(const char *text, unsigned int length); +EAPI unsigned int elm_code_text_is_whitespace(const char *text, unsigned int length); + /** * @} */ diff --git a/legacy/elm_code/src/tests/elm_code_test_text.c b/legacy/elm_code/src/tests/elm_code_test_text.c index 5391eb6922..9644ba203b 100644 --- a/legacy/elm_code/src/tests/elm_code_test_text.c +++ b/legacy/elm_code/src/tests/elm_code_test_text.c @@ -112,6 +112,21 @@ START_TEST (elm_code_text_leading_whitespace_test) } END_TEST +START_TEST (elm_code_text_is_whitespace_test) +{ + const char *text; + + text = " "; + ck_assert_int_eq(1, elm_code_text_is_whitespace(text, strlen(text))); + + text = " \t\t "; + ck_assert_int_eq(1, elm_code_text_is_whitespace(text, strlen(text))); + + text = " . "; + ck_assert_int_eq(0, elm_code_text_is_whitespace(text, strlen(text))); +} +END_TEST + void elm_code_test_text(TCase *tc) { tcase_add_test(tc, elm_code_text_get_test); @@ -120,4 +135,5 @@ void elm_code_test_text(TCase *tc) tcase_add_test(tc, elm_code_text_strpos_test); tcase_add_test(tc, elm_code_text_newline_position_test); tcase_add_test(tc, elm_code_text_leading_whitespace_test); + tcase_add_test(tc, elm_code_text_is_whitespace_test); } From 1e5e74d94707158d686c8718a8205049f4b6ac30 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 29 Aug 2015 12:05:56 +0100 Subject: [PATCH 191/254] [elm_code] trim all trailing whitespace on save Rather than just blank lines remove all trailing whitespace from lines --- legacy/elm_code/src/lib/elm_code_file.c | 7 +-- legacy/elm_code/src/lib/elm_code_text.c | 53 +++++++++++++++++-- legacy/elm_code/src/lib/elm_code_text.h | 4 ++ .../elm_code/src/tests/elm_code_test_text.c | 19 +++++++ 4 files changed, 74 insertions(+), 9 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index 8832fe0ad7..387e249d47 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -178,12 +178,9 @@ EAPI void elm_code_file_save(Elm_Code_File *file) EINA_LIST_FOREACH(file->lines, item, line_item) { + elm_code_line_text_trailing_whitespace_strip(line_item); content = elm_code_line_text_get(line_item, &length); - if (elm_code_text_is_whitespace(content, length)) - { - length = 0; - elm_code_line_text_set(line_item, "", 0); - } + fwrite(content, sizeof(char), length, out); fwrite(crchars, sizeof(char), crlength, out); } diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 83216c6cba..abb5a6968d 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -24,19 +24,22 @@ EAPI void elm_code_line_text_set(Elm_Code_Line *line, const char *chars, unsigned int length) { Elm_Code_File *file; - char *newtext; + char *newtext, *oldtext = NULL; if (!line) return; if (line->modified) - free(line->modified); + oldtext = line->modified; newtext = malloc(sizeof(char) * length); strncpy(newtext, chars, length); line->modified = newtext; line->length = length; + if (oldtext) + free(oldtext); + file = line->file; if (file->parent) { @@ -207,6 +210,20 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); } +EAPI void elm_code_line_text_trailing_whitespace_strip(Elm_Code_Line *line) +{ + unsigned int length, trailing; + const char *content; + + content = elm_code_line_text_get(line, &length); + trailing = elm_code_text_trailing_whitespace_length(content, length); + if (trailing == 0) + return; + + length -= trailing;; + elm_code_line_text_set(line, content, length); +} + /* generic text functions */ EAPI int @@ -238,6 +255,12 @@ elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen) return crpos; } +static Eina_Bool +_elm_code_text_char_is_whitespace(char c) +{ + return c == ' ' || c == '\t'; +} + EAPI unsigned int elm_code_text_leading_whitespace_length(const char *text, unsigned int length) { @@ -246,7 +269,7 @@ elm_code_text_leading_whitespace_length(const char *text, unsigned int length) while (count < length) { - if (!(*ptr == ' ' || *ptr == '\t')) + if (!_elm_code_text_char_is_whitespace(*ptr)) break; count++; @@ -256,12 +279,34 @@ elm_code_text_leading_whitespace_length(const char *text, unsigned int length) return count; } +EAPI unsigned int +elm_code_text_trailing_whitespace_length(const char *text, unsigned int length) +{ + unsigned int count = 0; + char *ptr; + + if (length == 0) + return 0; + + ptr = (char *)text + length - 1; + while (count < length) + { + if (!_elm_code_text_char_is_whitespace(*ptr)) + break; + + count++; + ptr--; + } + + return count; +} + EAPI unsigned int elm_code_text_is_whitespace(const char *text, unsigned int length) { unsigned int leading; - leading = elm_code_text_leading_whitespace_length(text, length); + leading = elm_code_text_trailing_whitespace_length(text, length); return leading == length; } diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 66bfbffb3f..02d2cc4ad5 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -36,6 +36,8 @@ EAPI void elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length); +EAPI void elm_code_line_text_trailing_whitespace_strip(Elm_Code_Line *line); + /** * @} * @@ -54,6 +56,8 @@ EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length, short EAPI unsigned int elm_code_text_leading_whitespace_length(const char *text, unsigned int length); +EAPI unsigned int elm_code_text_trailing_whitespace_length(const char *text, unsigned int length); + EAPI unsigned int elm_code_text_is_whitespace(const char *text, unsigned int length); /** diff --git a/legacy/elm_code/src/tests/elm_code_test_text.c b/legacy/elm_code/src/tests/elm_code_test_text.c index 9644ba203b..26e1aa18de 100644 --- a/legacy/elm_code/src/tests/elm_code_test_text.c +++ b/legacy/elm_code/src/tests/elm_code_test_text.c @@ -112,6 +112,24 @@ START_TEST (elm_code_text_leading_whitespace_test) } END_TEST +START_TEST (elm_code_text_trailing_whitespace_test) +{ + const char *text; + + text = "testing"; + ck_assert_int_eq(0, elm_code_text_trailing_whitespace_length(text, strlen(text))); + + text = "spaces "; + ck_assert_int_eq(2, elm_code_text_trailing_whitespace_length(text, strlen(text))); + + text = "tabs\t\t"; + ck_assert_int_eq(2, elm_code_text_trailing_whitespace_length(text, strlen(text))); + + text = "mix \t "; + ck_assert_int_eq(3, elm_code_text_trailing_whitespace_length(text, strlen(text))); +} +END_TEST + START_TEST (elm_code_text_is_whitespace_test) { const char *text; @@ -135,5 +153,6 @@ void elm_code_test_text(TCase *tc) tcase_add_test(tc, elm_code_text_strpos_test); tcase_add_test(tc, elm_code_text_newline_position_test); tcase_add_test(tc, elm_code_text_leading_whitespace_test); + tcase_add_test(tc, elm_code_text_trailing_whitespace_test); tcase_add_test(tc, elm_code_text_is_whitespace_test); } From 20162692f0feb9fbd34c4d8ecc0d5c5a9fa5727c Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 29 Aug 2015 12:06:30 +0100 Subject: [PATCH 192/254] [tests] Correct checking of just length chars Avoid traversing beyond string length --- legacy/elm_code/src/tests/elm_code_suite.h | 10 ++++++++++ .../src/tests/widget/elm_code_test_widget_selection.c | 11 +++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/legacy/elm_code/src/tests/elm_code_suite.h b/legacy/elm_code/src/tests/elm_code_suite.h index 489e8fd517..fddba5bfcd 100644 --- a/legacy/elm_code/src/tests/elm_code_suite.h +++ b/legacy/elm_code/src/tests/elm_code_suite.h @@ -3,6 +3,16 @@ #include +#define ck_assert_strn_eq(str1, str2, len) \ + { \ + unsigned int i = 0; \ + while (i < len) \ + { \ + ck_assert_int_eq(*(str1 + i), *(str2 + i)); \ + i++; \ + } \ + } + #include void elm_code_file_test_load(TCase *tc); diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c index bb52747619..53d2f11dc2 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c @@ -130,6 +130,7 @@ START_TEST (elm_code_test_widget_selection_delete) Elm_Code_Widget *widget; Evas_Object *win; const char *text; + unsigned int length; elm_init(1, NULL); code = elm_code_create(); @@ -139,16 +140,18 @@ START_TEST (elm_code_test_widget_selection_delete) win = elm_win_add(NULL, "code", ELM_WIN_BASIC); widget = elm_code_widget_add(win, code); line = elm_code_file_line_get(file, 1); - text = elm_code_line_text_get(line, NULL); - ck_assert_str_eq("text", text); + text = elm_code_line_text_get(line, &length); + ck_assert_int_eq(4, length); + ck_assert_strn_eq("text", text, length); elm_code_widget_selection_start(widget, 1, 2); elm_code_widget_selection_end(widget, 1, 3); elm_code_widget_selection_delete(widget); line = elm_code_file_line_get(file, 1); - text = elm_code_line_text_get(line, NULL); - ck_assert_str_eq("tt", text); + text = elm_code_line_text_get(line, &length); + ck_assert_int_eq(2, length); + ck_assert_strn_eq("tt", text, length); elm_code_free(code); elm_shutdown(); From 9f96fa0c00fe569ad5fbb5746f60c940c8fe9f8e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 29 Aug 2015 14:11:40 +0100 Subject: [PATCH 193/254] [elm_code] don't strip whitespace on current line When saving if any widget has a cursor on the line we shouldn't strip the trailing whitespace --- legacy/elm_code/src/lib/elm_code_file.c | 3 ++- legacy/elm_code/src/lib/elm_code_line.c | 21 +++++++++++++++++++++ legacy/elm_code/src/lib/elm_code_line.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index 387e249d47..07ff643953 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -178,7 +178,8 @@ EAPI void elm_code_file_save(Elm_Code_File *file) EINA_LIST_FOREACH(file->lines, item, line_item) { - elm_code_line_text_trailing_whitespace_strip(line_item); + if (!elm_code_line_contains_widget_cursor(line_item)) + elm_code_line_text_trailing_whitespace_strip(line_item); content = elm_code_line_text_get(line_item, &length); fwrite(content, sizeof(char), length, out); diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index e0de0d519e..ae921f7751 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -106,3 +106,24 @@ EAPI void elm_code_line_status_clear(Elm_Code_Line *line) } } +EAPI Eina_Bool +elm_code_line_contains_widget_cursor(Elm_Code_Line *line) +{ + Elm_Code *code = line->file->parent; + Eina_List *item; + Eo *widget; + unsigned int col, number; + + if (!code) + return EINA_FALSE; + + EINA_LIST_FOREACH(code->widgets, item, widget) + { + elm_code_widget_cursor_position_get(widget, &col, &number); + + if (number == line->number) + return EINA_TRUE; + } + + return EINA_FALSE; +} diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index 6a0f767d6f..822cbea642 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -69,6 +69,8 @@ EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int l EAPI void elm_code_line_tokens_clear(Elm_Code_Line *line); +EAPI Eina_Bool elm_code_line_contains_widget_cursor(Elm_Code_Line *line); + /** * @} */ From 7455ec0f08ab68387892dcf96169015bcd0b9c2c Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 29 Aug 2015 14:46:18 +0100 Subject: [PATCH 194/254] [editor] Make whitespace trimming an option Add a global setting to turn off the behaviour --- legacy/elm_code/src/lib/elm_code_common.h | 7 +++++++ legacy/elm_code/src/lib/elm_code_file.c | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code_common.h b/legacy/elm_code/src/lib/elm_code_common.h index 9c8ec5ab2e..5efe685d27 100644 --- a/legacy/elm_code/src/lib/elm_code_common.h +++ b/legacy/elm_code/src/lib/elm_code_common.h @@ -61,11 +61,18 @@ extern "C" { * @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; }; /** diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/legacy/elm_code/src/lib/elm_code_file.c index 07ff643953..5db1bfa9f2 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/legacy/elm_code/src/lib/elm_code_file.c @@ -158,6 +158,7 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path) 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; @@ -165,6 +166,7 @@ EAPI void elm_code_file_save(Elm_Code_File *file) short crlength; FILE *out; + code = file->parent; path = elm_code_file_path_get(file); tmp = _elm_code_file_tmp_path_get(file); crchars = elm_code_file_line_ending_chars_get(file, &crlength); @@ -178,7 +180,8 @@ EAPI void elm_code_file_save(Elm_Code_File *file) EINA_LIST_FOREACH(file->lines, item, line_item) { - if (!elm_code_line_contains_widget_cursor(line_item)) + if (code && code->config.trim_whitespace && + !elm_code_line_contains_widget_cursor(line_item)) elm_code_line_text_trailing_whitespace_strip(line_item); content = elm_code_line_text_get(line_item, &length); From 456140085ebd132870770cd694d6c8bb7c697fc4 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 29 Aug 2015 20:56:22 +0100 Subject: [PATCH 195/254] Fix make distcheck --- legacy/elm_code/src/lib/Makefile.am | 9 +++++++++ legacy/elm_code/src/lib/widget/Makefile.am | 0 legacy/elm_code/src/tests/Makefile.am | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 legacy/elm_code/src/lib/widget/Makefile.am diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index 087f863baa..95129e852b 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -1,5 +1,7 @@ MAINTAINERCLEANFILES = Makefile.in +SUBDIRS = widget + CLEANFILES= EOLIAN_FLAGS = @DEPS_EOLIAN_FLAGS@ \ @@ -9,6 +11,9 @@ 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 \ @@ -25,6 +30,7 @@ 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 @@ -62,3 +68,6 @@ BUILT_SOURCES = \ elmcodeeolianfilesdir = $(datadir)/eolian/include/elm_code-@VMAJ@ elmcodeeolianfiles_DATA = $(elm_code_eolian_files) EXTRA_DIST = ${elmcodeeolianfiles_DATA} + +CLEANFILES += $(elm_code_eolian_h) $(elm_code_eolian_legacy_h) + diff --git a/legacy/elm_code/src/lib/widget/Makefile.am b/legacy/elm_code/src/lib/widget/Makefile.am new file mode 100644 index 0000000000..e69de29bb2 diff --git a/legacy/elm_code/src/tests/Makefile.am b/legacy/elm_code/src/tests/Makefile.am index 86acce2f1a..6256c35f5b 100644 --- a/legacy/elm_code/src/tests/Makefile.am +++ b/legacy/elm_code/src/tests/Makefile.am @@ -17,10 +17,13 @@ widget/elm_code_test_widget_text.c \ widget/elm_code_test_widget_selection.c \ elm_code_suite.c -elm_code_suite_CPPFLAGS = -I$(top_builddir)/elm_code/src/lib/ \ +elm_code_suite_CPPFLAGS = \ -DEFL_BETA_API_SUPPORT \ -DEFL_EO_API_SUPPORT \ -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)\" \ -DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/src/tests/\" \ -DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/src/tests/\" \ From 8fcd3c11e88d5b625b264d9db9e1c99158600ef7 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 7 Sep 2015 23:12:08 +0100 Subject: [PATCH 196/254] Update to latest eolian spec Documents updated though not quite as feature-ful --- .../src/lib/widget/elm_code_widget.eo | 166 ++++++------------ 1 file changed, 53 insertions(+), 113 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index 294d86096c..1bbcc1803e 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -5,224 +5,164 @@ class Elm.Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) methods { @property code { set { - /*@ - Set the underlying code object that this widget renders. + [[Set the underlying code object that this widget renders. This can only be set during construction, once the widget is created the - backing code object cannot be changed. - - @ingroup Data */ + backing code object cannot be changed.]] } get { - /*@ - Get the underlying code object we are rendering - - @ingroup Data */ + [[Get the underlying code object we are rendering]] } values { - code: Elm_Code *; /*@ Our underlying Elm_Code object */ + code: Elm_Code *; [[Our underlying Elm_Code object]] } } @property font { set { - /*@ - Set the font that this widget uses, the font should be a monospaced scalable font. - Passing NULL will load the default system monospaced font. - - @ingroup Style */ + [[Set the font that this widget uses, the font should be a monospaced scalable font. + Passing NULL will load the default system monospaced font.]] } get { - /*@ - Get the font currently in use. - The font name is a copy ad should be freed once it is no longer needed - - @ingroup Style */ + [[Get the font currently in use. + The font name is a copy ad should be freed once it is no longer needed]] } values { - name: const(char) *; /*@ The name of the font to load */ - size: Evas_Font_Size; /*@ The font size for the widget */ + name: const(char) *; [[The name of the font to load]] + size: Evas_Font_Size; [[The font size for the widget]] } } @property gravity { set { - /*@ - Set how this widget's scroller should respond to new lines being added. + [[Set how this widget's scroller should respond to new lines being added. An x value of 0.0 will maintain the distance from the left edge, 1.0 will ensure the rightmost edge (of the longest line) is respected - With 0.0 for y the view will keep it's position relative to the top whereas 1.0 will scroll downward as lines are added. - - @ingroup Layout */ + With 0.0 for y the view will keep it's position relative to the top whereas 1.0 will scroll downward as lines are added.]] } get { - /*@ - Get the current x and y gravity of the widget's scroller - - @ingroup Layout */ + [[Get the current x and y gravity of the widget's scroller]] } values { - x: double; /*@ The horizontal value of the scroller gravity - valid values are 0.0 and 1.0 */ - y: double; /*@ The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0 */ + x: double; [[The horizontal value of the scroller gravity - valid values are 0.0 and 1.0]] + y: double; [[The vertical gravity of the widget's scroller - valid values are 0.0 and 1.0]] } } @property policy { set { - /*@ - Set the policy for scrollbar visibility. - - @ingroup Layout */ + [[Set the policy for scrollbar visibility.]] } get { - /*@ - Get the widget's policy for scrollbar visibility. - - @ingroup Layout */ + [[Get the widget's policy for scrollbar visibility.]] } values { - policy_h: Elm_Scroller_Policy; /*@ The horizontal scrollbar visibility policy */ - policy_v: Elm_Scroller_Policy; /*@ The vertical scrollbar visibility policy */ + policy_h: Elm_Scroller_Policy; [[The horizontal scrollbar visibility policy]] + policy_v: Elm_Scroller_Policy; [[The vertical scrollbar visibility policy]] } } @property tabstop { set { - /*@ - Set the width of a tab stop, used purely for visual layout of tab characters. + [[Set the width of a tab stop, used purely for visual layout of tab characters. - Recommended value is between 2 and 8. - - @ingroup Layout */ + Recommended value is between 2 and 8.]] } get { - /*@ - Get the current width of a tab stop. - This is used to determine where characters after a tab should appear in the line.. - - @ingroup Layout */ + [[Get the current width of a tab stop. + This is used to determine where characters after a tab should appear in the line.]] } values { - tabstop: uint; /*@ Maximum width of a tab character */ + tabstop: uint; [[Maximum width of a tab character]] } } @property editable { set { - /*@ - Set whether this widget allows editing + [[Set whether this widget allows editing - If @a editable then the widget will allow user input to manipulate + If editable then the widget will allow user input to manipulate the underlying Elm_Code_File of this Elm_Code instance. Any other Elm_Code_Widget's connected to this Elm_Code will - update to reflect the changes. - - @ingroup Features */ + update to reflect the changes.]] } get { - /*@ - Get the current editable state of this widget + [[Get the current editable state of this widget - @return EINA_TRUE if the widget is editable, EINA_FALSE otherwise. + returns EINA_TRUE if the widget is editable, EINA_FALSE otherwise. If this widget is not editable the underlying Elm_Code_File could - still be manipulated by a different widget or the filesystem. - - @ingroup Features */ + still be manipulated by a different widget or the filesystem.]] } values { - editable: Eina_Bool; /*@ The editable state of the widget */ + editable: Eina_Bool; [[The editable state of the widget]] } } @property line_numbers { set { - /*@ - Set whether line numbers should be displayed in the left gutter. + [[Set whether line numbers should be displayed in the left gutter. Passing EINA_TRUE will reserve a space for showing line numbers, - EINA_FALSE will turn this off. - - @ingroup Features */ + EINA_FALSE will turn this off.]] } get { - /*@ - Get the status of line number display for this widget. - - @ingroup Features */ + [[Get the status of line number display for this widget.]] } values { - line_numbers: Eina_Bool; /*@ Whether or not line numbers (or their placeholder) should be shown */ + line_numbers: Eina_Bool; [[Whether or not line numbers (or their placeholder) should be shown]] } } @property line_width_marker { set { - /*@ - Set where the line width market should be shown. + [[Set where the line width market should be shown. Passing a non-zero value will set which line width to mark with a vertical line. - Passing 0 will hide this marker. - - @ingroup Features */ + Passing 0 will hide this marker.]] } get { - /*@ - Get the position of the line width marker, any positive return indicates where the marker appears. - - @ingroup Features */ + [[Get the position of the line width marker, any positive return indicates where the marker appears.]] } values { - line_width_marker: uint; /*@ Where to display a line width marker, if at all */ + line_width_marker: uint; [[Where to display a line width marker, if at all]] } } @property show_whitespace { set { - /*@ - Set where white space should be shown. - - @ingroup Features */ + [[Set where white space should be shown.]] } get { - /*@ - Get whether or not white space will be visible. - - @ingroup Features */ + [[Get whether or not white space will be visible.]] } values { - show_whitespace: Eina_Bool; /*@ Whether or not we show whitespace characters */ + show_whitespace: Eina_Bool; [[Whether or not we show whitespace characters]] } } @property cursor_position { set { - /*@ - Set the current location of the text cursor. - - @ingroup Editing */ + [[Set the current location of the text cursor.]] } get { - /*@ - Get the current x and y position of the widget's cursor - - @ingroup Editing */ + [[Get the current x and y position of the widget's cursor.]] } values { - col: uint; /*@ The horizontal position of the cursor, starting from column 1 */ - line: uint; /*@ The vertical position of the cursor - the top row is 1 */ + col: uint; [[The horizontal position of the cursor, starting from column 1]] + line: uint; [[The vertical position of the cursor - the top row is 1]] } } line_refresh { params { - line: Elm_Code_Line *; /*@ @in The line to refresh. */ + line: Elm_Code_Line *; [[The line to refresh.]] } } line_visible_get { params { - line: Elm_Code_Line *; /*@ @in The line to test for visibility. */ + line: Elm_Code_Line *; [[The line to test for visibility.]] } - return: bool; /*@ true if the line specified is currently visible within the scroll region. */ + return: bool; [[true if the line specified is currently visible within the scroll region.]] } lines_visible_get { - return: uint; /*@ the number of lines currently visible in the widget. */ + return: uint; [[the number of lines currently visible in the widget.]] } - /* text functions */ + //text functions text_left_gutter_width_get { - return: int; /*@ the current column width of the gutter for the widget. */ + return: int; [[the current column width of the gutter for the widget.]] } text_line_number_width_get { - return: int; /*@ the column width required to represent the number of lines in the widget. */ + return: int; [[the column width required to represent the number of lines in the widget.]] } line_text_column_width_to_position { From cf71473fdb3427710bde851e4bab3b565c9144c5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 16 Sep 2015 10:44:38 +0100 Subject: [PATCH 197/254] [editor] Fix indenting of newlines Changes in memory handling of line splits broke this in some cases (like tapping return twice). --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index fe6430ef3c..ee3ca73a08 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -140,7 +140,7 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) evas_object_size_hint_min_set(pd->grid, w*cw, h*ch); if (pd->gravity_x == 1.0 || pd->gravity_y == 1.0) - _elm_code_widget_scroll_by(widget, + _elm_code_widget_scroll_by(widget, (pd->gravity_x == 1.0 && ww > old_width) ? ww - old_width : 0, (pd->gravity_y == 1.0 && wh > old_height) ? wh - old_height : 0); } @@ -993,7 +993,7 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) Elm_Code *code; Elm_Code_Line *line; unsigned int row, col, position, oldlen, leading; - const char *oldtext; + char *oldtext; _elm_code_widget_delete_selection(widget); eo_do(widget, @@ -1006,7 +1006,8 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) row = elm_code_file_lines_get(code->file); line = elm_code_file_line_get(code->file, row); } - oldtext = elm_code_line_text_get(line, &oldlen); + oldtext = (char *) elm_code_line_text_get(line, &oldlen); + oldtext = strndup(oldtext, oldlen); position = elm_code_widget_line_text_position_for_column_get(widget, line, col); elm_code_line_split_at(line, position); @@ -1014,6 +1015,7 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) line = elm_code_file_line_get(code->file, row + 1); leading = elm_code_text_leading_whitespace_length(oldtext, oldlen); elm_code_line_text_insert(line, 0, oldtext, leading); + free(oldtext); eo_do(widget, elm_obj_code_widget_cursor_position_set( @@ -1551,7 +1553,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) elm_object_focus_allow_set(scroller, EINA_FALSE); pd->scroller = scroller; - grid = evas_object_textgrid_add(obj); + grid = evas_object_textgrid_add(obj); evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(grid); From 65a32dddd1fb7f01e65a322ba4499c6e8de8dde6 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 16 Sep 2015 12:32:25 +0100 Subject: [PATCH 198/254] [selection] Fix so selecting backwards works highlight, text get and deletion working --- .../elm_code/src/lib/widget/elm_code_widget.c | 24 +- .../src/lib/widget/elm_code_widget_private.h | 2 +- .../lib/widget/elm_code_widget_selection.c | 96 +++++-- .../widget/elm_code_test_widget_selection.c | 251 ++++++++++++++++++ 4 files changed, 342 insertions(+), 31 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index ee3ca73a08..8b1a7a2c34 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -300,21 +300,26 @@ _elm_code_widget_fill_selection(Elm_Code_Widget *widget, Elm_Code_Line *line, Ev { Elm_Code_Widget_Data *pd; unsigned int x, start, end; + Elm_Code_Widget_Selection_Data *selection; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (!pd->selection) return; - if (pd->selection->start_line > line->number || pd->selection->end_line < line->number) - return; + selection = elm_code_widget_selection_normalized_get(widget); + if (selection->start_line > line->number || selection->end_line < line->number) + { + free(selection); + return; + } - start = pd->selection->start_col; - if (pd->selection->start_line < line->number) + start = selection->start_col; + if (selection->start_line < line->number) start = 1; - end = pd->selection->end_col; - if (pd->selection->end_line > line->number) + end = selection->end_col; + if (selection->end_line > line->number) end = w; + free(selection); for (x = gutter + start - 1; x < gutter + end && x < (unsigned int) w; x++) cells[x].bg = ELM_CODE_WIDGET_COLOR_SELECTION; @@ -947,13 +952,18 @@ static Eina_Bool _elm_code_widget_delete_selection(Elm_Code_Widget *widget) { Elm_Code_Widget_Data *pd; + Elm_Code_Widget_Selection_Data *selection; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (!pd->selection) return EINA_FALSE; + selection = elm_code_widget_selection_normalized_get(widget); elm_code_widget_selection_delete(widget); + elm_code_widget_cursor_position_set(widget, selection->start_col, selection->start_line); + free(selection); + return EINA_TRUE; } diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h index a1dc7b1475..b89973fd0f 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h @@ -35,6 +35,6 @@ void _elm_code_widget_tooltip_text_set(Evas_Object *widget, const char *text); void _elm_code_widget_tooltip_add(Evas_Object *widget); - +EAPI Elm_Code_Widget_Selection_Data *elm_code_widget_selection_normalized_get(Evas_Object *widget); #endif diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 9774526113..dd3ee74ac4 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -90,6 +90,47 @@ elm_code_widget_selection_end(Evas_Object *widget, eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget)); } +EAPI Elm_Code_Widget_Selection_Data * +elm_code_widget_selection_normalized_get(Evas_Object *widget) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Widget_Selection_Data *selection; + Eina_Bool reverse; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + selection = _elm_code_widget_selection_new(); + + if (!pd->selection) + { + selection->start_line = selection->end_line = 1; + selection->start_col = selection->end_col = 1; + + return selection; + } + + if (pd->selection->start_line == pd->selection->end_line) + reverse = pd->selection->start_col > pd->selection->end_col; + else + reverse = pd->selection->start_line > pd->selection->end_line; + + if (reverse) + { + selection->start_line = pd->selection->end_line; + selection->start_col = pd->selection->end_col; + selection->end_line = pd->selection->start_line; + selection->end_col = pd->selection->start_col; + } + else + { + selection->start_line = pd->selection->start_line; + selection->start_col = pd->selection->start_col; + selection->end_line = pd->selection->end_line; + selection->end_col = pd->selection->end_col; + } + + return selection; +} + EAPI void elm_code_widget_selection_clear(Evas_Object *widget) { @@ -111,14 +152,13 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget *widget, Elm_Code_Widge const char *old; unsigned int old_length, start, end, length; char *content; + Elm_Code_Widget_Selection_Data *selection; - if (pd->selection->end_col < pd->selection->start_col) - return; - - line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); + selection = elm_code_widget_selection_normalized_get(widget); + line = elm_code_file_line_get(pd->code->file, selection->start_line); old = elm_code_line_text_get(line, &old_length); - start = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->start_col); - end = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->end_col); + start = elm_code_widget_line_text_position_for_column_get(widget, line, selection->start_col); + end = elm_code_widget_line_text_position_for_column_get(widget, line, selection->end_col); length = line->length - (end - start + 1); content = malloc(sizeof(char) * length); @@ -127,6 +167,7 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget *widget, Elm_Code_Widge old_length - (end + 1)); elm_code_line_text_set(line, content, length); free(content); + free(selection); } static void @@ -136,17 +177,19 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget *widget, Elm_Code_Widget const char *first, *last; unsigned int last_length, start, end, length, i; char *content; + Elm_Code_Widget_Selection_Data *selection; - if (pd->selection->end_line <= pd->selection->start_line) + if (pd->selection->end_line == pd->selection->start_line) return; - line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); + selection = elm_code_widget_selection_normalized_get(widget); + line = elm_code_file_line_get(pd->code->file, selection->start_line); first = elm_code_line_text_get(line, NULL); - start = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->start_col); + start = elm_code_widget_line_text_position_for_column_get(widget, line, selection->start_col); - line = elm_code_file_line_get(pd->code->file, pd->selection->end_line); + line = elm_code_file_line_get(pd->code->file, selection->end_line); last = elm_code_line_text_get(line, &last_length); - end = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->end_col); + end = elm_code_widget_line_text_position_for_column_get(widget, line, selection->end_col); length = start + last_length - (end + 1); content = malloc(sizeof(char) * length); @@ -154,12 +197,13 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget *widget, Elm_Code_Widget strncpy(content + start, last + end + 1, last_length - (end + 1)); - for (i = line->number; i > pd->selection->start_line; i--) + for (i = line->number; i > selection->start_line; i--) elm_code_file_line_remove(pd->code->file, i); - line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); + line = elm_code_file_line_get(pd->code->file, selection->start_line); elm_code_line_text_set(line, content, length); free(content); + free(selection); } EAPI void @@ -187,10 +231,13 @@ _elm_code_widget_selection_text_single_get(Elm_Code_Widget *widget, Elm_Code_Wid { Elm_Code_Line *line; unsigned int start, end; + Elm_Code_Widget_Selection_Data *selection; - line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); - start = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->start_col); - end = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->end_col + 1); + selection = elm_code_widget_selection_normalized_get(widget); + line = elm_code_file_line_get(pd->code->file, selection->start_line); + start = elm_code_widget_line_text_position_for_column_get(widget, line, selection->start_col); + end = elm_code_widget_line_text_position_for_column_get(widget, line, selection->end_col + 1); + free(selection); return elm_code_line_text_substr(line, start, end - start); } @@ -204,20 +251,22 @@ _elm_code_widget_selection_text_multi_get(Elm_Code_Widget *widget, Elm_Code_Widg short newline_len; int ret_len; unsigned int row, start, end; + Elm_Code_Widget_Selection_Data *selection; + selection = elm_code_widget_selection_normalized_get(widget); newline = elm_code_file_line_ending_chars_get(pd->code->file, &newline_len); - line = elm_code_file_line_get(pd->code->file, pd->selection->start_line); - start = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->start_col); + line = elm_code_file_line_get(pd->code->file, selection->start_line); + start = elm_code_widget_line_text_position_for_column_get(widget, line, selection->start_col); first = elm_code_line_text_substr(line, start, line->length - start + 1); - line = elm_code_file_line_get(pd->code->file, pd->selection->end_line); - end = elm_code_widget_line_text_position_for_column_get(widget, line, pd->selection->end_col + 1); + line = elm_code_file_line_get(pd->code->file, selection->end_line); + end = elm_code_widget_line_text_position_for_column_get(widget, line, selection->end_col + 1); last = elm_code_line_text_substr(line, 0, end); ret_len = strlen(first) + strlen(last) + newline_len; - for (row = pd->selection->start_line + 1; row < pd->selection->end_line; row++) + for (row = pd->selection->start_line + 1; row < selection->end_line; row++) { line = elm_code_file_line_get(pd->code->file, row); ret_len += line->length + newline_len; @@ -229,7 +278,7 @@ _elm_code_widget_selection_text_multi_get(Elm_Code_Widget *widget, Elm_Code_Widg ptr = ret; ptr += strlen(first) + newline_len; - for (row = pd->selection->start_line + 1; row < pd->selection->end_line; row++) + for (row = selection->start_line + 1; row < selection->end_line; row++) { line = elm_code_file_line_get(pd->code->file, row); if (line->modified) @@ -242,6 +291,7 @@ _elm_code_widget_selection_text_multi_get(Elm_Code_Widget *widget, Elm_Code_Widg } snprintf(ptr, strlen(last) + 1, "%s", last); + free(selection); free(first); free(last); return ret; @@ -254,7 +304,7 @@ elm_code_widget_selection_text_get(Evas_Object *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (!pd->selection || pd->selection->end_line < pd->selection->start_line) + if (!pd->selection) return strdup(""); if (pd->selection->start_line == pd->selection->end_line) diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c index 53d2f11dc2..7135e4a9c5 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c @@ -4,6 +4,8 @@ #include "elm_code_suite.h" +#include "elm_code_widget_private.h" + #include "widget/elm_code_widget_selection.h" START_TEST (elm_code_test_widget_selection_set) @@ -30,6 +32,48 @@ START_TEST (elm_code_test_widget_selection_set) } END_TEST +START_TEST (elm_code_test_widget_selection_normalized_get) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Widget *widget; + Elm_Code_Widget_Selection_Data *selection; + Evas_Object *win; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "test", 4, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + + elm_code_widget_selection_start(widget, 1, 3); + elm_code_widget_selection_end(widget, 1, 2); + selection = elm_code_widget_selection_normalized_get(widget); + + ck_assert_int_eq(selection->start_col, 2); + ck_assert_int_eq(selection->end_col, 3); + elm_code_widget_selection_clear(widget); + free(selection); + + elm_code_file_line_append(file, "another", 7, NULL); + elm_code_widget_selection_start(widget, 2, 2); + elm_code_widget_selection_end(widget, 1, 3); + selection = elm_code_widget_selection_normalized_get(widget); + + ck_assert_int_eq(selection->start_line, 1); + ck_assert_int_eq(selection->start_col, 3); + ck_assert_int_eq(selection->end_line, 2); + ck_assert_int_eq(selection->end_col, 2); + elm_code_widget_selection_clear(widget); + free(selection); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + START_TEST (elm_code_test_widget_selection_text_get) { Elm_Code *code; @@ -63,6 +107,39 @@ START_TEST (elm_code_test_widget_selection_text_get) } END_TEST +START_TEST (elm_code_test_widget_selection_reverse_text_get) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Widget *widget; + Evas_Object *win; + char *selection; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "test", 4, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + + ck_assert_str_eq("", elm_code_widget_selection_text_get(widget)); + + elm_code_widget_selection_start(widget, 1, 3); + elm_code_widget_selection_end(widget, 1, 2); + + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("es", selection); + free(selection); + + elm_code_widget_selection_clear(widget); + ck_assert_str_eq("", elm_code_widget_selection_text_get(widget)); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + START_TEST (elm_code_test_widget_selection_text_get_twoline) { Elm_Code *code; @@ -92,6 +169,35 @@ START_TEST (elm_code_test_widget_selection_text_get_twoline) } END_TEST +START_TEST (elm_code_test_widget_selection_reverse_text_get_twoline) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Widget *widget; + Evas_Object *win; + char *selection; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "test", 4, NULL); + elm_code_file_line_append(file, "test", 4, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + + elm_code_widget_selection_start(widget, 2, 2); + elm_code_widget_selection_end(widget, 1, 3); + + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("st\nte", selection); + free(selection); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + START_TEST (elm_code_test_widget_selection_text_get_multiline) { Elm_Code *code; @@ -122,6 +228,36 @@ START_TEST (elm_code_test_widget_selection_text_get_multiline) } END_TEST +START_TEST (elm_code_test_widget_selection_reverse_text_get_multiline) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Widget *widget; + Evas_Object *win; + char *selection; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "test", 4, NULL); + elm_code_file_line_append(file, "test", 4, NULL); + elm_code_file_line_append(file, "test", 4, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + + elm_code_widget_selection_start(widget, 3, 2); + elm_code_widget_selection_end(widget, 1, 3); + + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("st\ntest\nte", selection); + free(selection); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + START_TEST (elm_code_test_widget_selection_delete) { Elm_Code *code; @@ -158,6 +294,42 @@ START_TEST (elm_code_test_widget_selection_delete) } END_TEST +START_TEST (elm_code_test_widget_selection_reverse_delete) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + Elm_Code_Widget *widget; + Evas_Object *win; + const char *text; + unsigned int length; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "text", 4, NULL); + + win = elm_win_add(NULL, "code", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + line = elm_code_file_line_get(file, 1); + text = elm_code_line_text_get(line, &length); + ck_assert_int_eq(4, length); + ck_assert_strn_eq("text", text, length); + + elm_code_widget_selection_start(widget, 1, 3); + elm_code_widget_selection_end(widget, 1, 2); + elm_code_widget_selection_delete(widget); + + line = elm_code_file_line_get(file, 1); + text = elm_code_line_text_get(line, &length); + ck_assert_int_eq(2, length); + ck_assert_strn_eq("tt", text, length); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + START_TEST (elm_code_test_widget_selection_delete_twoline) { Elm_Code *code; @@ -194,6 +366,42 @@ START_TEST (elm_code_test_widget_selection_delete_twoline) } END_TEST +START_TEST (elm_code_test_widget_selection_reverse_delete_twoline) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + Elm_Code_Widget *widget; + Evas_Object *win; + const char *text; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "text", 4, NULL); + elm_code_file_line_append(file, "TEXT", 4, NULL); + + win = elm_win_add(NULL, "code", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + line = elm_code_file_line_get(file, 1); + text = elm_code_line_text_get(line, NULL); + ck_assert_str_eq("text", text); + ck_assert_int_eq(2, elm_code_file_lines_get(file)); + + elm_code_widget_selection_start(widget, 2, 2); + elm_code_widget_selection_end(widget, 1, 3); + elm_code_widget_selection_delete(widget); + + line = elm_code_file_line_get(file, 1); + text = elm_code_line_text_get(line, NULL); + ck_assert_str_eq("teXT", text); + ck_assert_int_eq(1, elm_code_file_lines_get(file)); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + START_TEST (elm_code_test_widget_selection_delete_multiline) { Elm_Code *code; @@ -231,14 +439,57 @@ START_TEST (elm_code_test_widget_selection_delete_multiline) } END_TEST +START_TEST (elm_code_test_widget_selection_reverse_delete_multiline) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + Elm_Code_Widget *widget; + Evas_Object *win; + const char *text; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "text", 4, NULL); + elm_code_file_line_append(file, "remove", 6, NULL); + elm_code_file_line_append(file, "TEXT", 4, NULL); + + win = elm_win_add(NULL, "code", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + line = elm_code_file_line_get(file, 1); + text = elm_code_line_text_get(line, NULL); + ck_assert_str_eq("text", text); + ck_assert_int_eq(3, elm_code_file_lines_get(file)); + + elm_code_widget_selection_start(widget, 3, 2); + elm_code_widget_selection_end(widget, 1, 3); + elm_code_widget_selection_delete(widget); + + line = elm_code_file_line_get(file, 1); + text = elm_code_line_text_get(line, NULL); + ck_assert_str_eq("teXT", text); + ck_assert_int_eq(1, elm_code_file_lines_get(file)); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST void elm_code_test_widget_selection(TCase *tc) { tcase_add_test(tc, elm_code_test_widget_selection_set); + tcase_add_test(tc, elm_code_test_widget_selection_normalized_get); tcase_add_test(tc, elm_code_test_widget_selection_text_get); + tcase_add_test(tc, elm_code_test_widget_selection_reverse_text_get); tcase_add_test(tc, elm_code_test_widget_selection_text_get_twoline); + tcase_add_test(tc, elm_code_test_widget_selection_reverse_text_get_twoline); tcase_add_test(tc, elm_code_test_widget_selection_text_get_multiline); + tcase_add_test(tc, elm_code_test_widget_selection_reverse_text_get_multiline); tcase_add_test(tc, elm_code_test_widget_selection_delete); + tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete); tcase_add_test(tc, elm_code_test_widget_selection_delete_twoline); + tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete_twoline); tcase_add_test(tc, elm_code_test_widget_selection_delete_multiline); + tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete_multiline); } From d1e3481b32ccb86868585947140f031f3b8c007d Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 20 Sep 2015 10:39:33 +0100 Subject: [PATCH 199/254] [highlight] Split highlight tokens on line split Instead of blanking colours work out what to do with them. Refactor the token carry over to simply note if there's a continuation. --- legacy/elm_code/src/lib/elm_code_line.c | 59 ++++++++++++++++--- legacy/elm_code/src/lib/elm_code_line.h | 2 +- .../elm_code/src/lib/widget/elm_code_widget.c | 2 +- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index ae921f7751..c8b03b7199 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -20,9 +20,51 @@ elm_code_line_free(Elm_Code_Line *line) free(line); } +static void +_elm_code_line_tokens_split_at(Elm_Code_Line *oldline, Elm_Code_Line *newline, + Eina_List *tokens, int position) +{ + Eina_List *item, *next; + Elm_Code_Token *token, *newtoken; + + EINA_LIST_FOREACH_SAFE(tokens, item, next, token) + { + if (!token->continues && token->end < position) + { + oldline->tokens = eina_list_append(oldline->tokens, token); + continue; + } + if (token->start >= position) + { + token->start -= position; + token->end -= position; + newline->tokens = eina_list_append(newline->tokens, token); + continue; + } + + if (token->continues) + elm_code_line_token_add(newline, 0, token->end, 1, token->type); + else + { + elm_code_line_token_add(newline, 0, token->end - position, 1, token->type); + token->end = position - 1; + } + + newtoken = eina_list_data_get(newline->tokens); + newtoken->continues = token->continues; + token->continues = EINA_TRUE; + oldline->tokens = eina_list_append(oldline->tokens, token); + } + + elm_code_callback_fire(oldline->file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, oldline); + elm_code_callback_fire(newline->file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, newline); +} + EAPI void elm_code_line_split_at(Elm_Code_Line *line, unsigned int position) { Elm_Code_Line *newline; + Elm_Code_Token *token EINA_UNUSED; + Eina_List *tokens; char *content; unsigned int length; @@ -30,11 +72,14 @@ EAPI void elm_code_line_split_at(Elm_Code_Line *line, unsigned int position) content = strndup(content, length); elm_code_file_line_insert(line->file, line->number + 1, "", 0, NULL); newline = elm_code_file_line_get(line->file, line->number + 1); -// TODO we need to split tokens from these lines + tokens = line->tokens; + line->tokens = NULL; elm_code_line_text_set(newline, content + position, length - position); elm_code_line_text_set(line, content, position); + _elm_code_line_tokens_split_at(line, newline, tokens, position); + EINA_LIST_FREE(tokens, token) {} // don't free tokens, we re-used them free(content); } @@ -61,7 +106,6 @@ EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int l Elm_Code_Token_Type type) { Elm_Code_Token *tok; - unsigned int end_line; Elm_Code_Line *next_line; if (!line) @@ -69,18 +113,14 @@ EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int l tok = calloc(1, sizeof(Elm_Code_Token)); - end_line = line->number; - if (lines > 1) - end_line += lines - 1; - tok->start = start; tok->end = end; - tok->end_line = end_line; + tok->continues = lines > 1; tok->type = type; line->tokens = eina_list_append(line->tokens, tok); - if (end_line > line->number) + if (lines > 1) { next_line = elm_code_file_line_get(line->file, line->number + 1); elm_code_line_token_add(next_line, 0, end, lines - 1, type); @@ -91,6 +131,9 @@ EAPI void elm_code_line_tokens_clear(Elm_Code_Line *line) { Elm_Code_Token *token; + if (!line->tokens) + return; + EINA_LIST_FREE(line->tokens, token) free(token); line->tokens = NULL; diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index 822cbea642..f9492aafee 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -13,7 +13,7 @@ extern "C" { typedef struct _Elm_Code_Token { int start, end; - unsigned int end_line; + Eina_Bool continues; Elm_Code_Token_Type type; diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 8b1a7a2c34..71867e570e 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -195,7 +195,7 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c // TODO handle a token starting before the previous finishes end = token_end_col; - if (token->end_line > line->number) + if (token->continues) end = length + offset; _elm_code_widget_fill_line_token(cells, count, token_start_col, end, token->type); From 9056a16ec68a1a529ef6e3df878bcdb2bf24dcd5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 20 Sep 2015 10:59:52 +0100 Subject: [PATCH 200/254] [highlight] Merge highlight tokens on line merge Instead of blanking colours we append them as with the content. --- legacy/elm_code/src/lib/elm_code_line.c | 62 +++++++++++++++++++ legacy/elm_code/src/lib/elm_code_line.h | 35 +++++++++++ .../elm_code/src/lib/widget/elm_code_widget.c | 32 +++------- 3 files changed, 104 insertions(+), 25 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/legacy/elm_code/src/lib/elm_code_line.c index c8b03b7199..b2ee71419a 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/legacy/elm_code/src/lib/elm_code_line.c @@ -83,6 +83,68 @@ EAPI void elm_code_line_split_at(Elm_Code_Line *line, unsigned int position) free(content); } +static void +_elm_code_line_merge_into(Elm_Code_Line *line1, Elm_Code_Line *line2) +{ + Eina_List *tokens1, *tokens2; + Elm_Code_Token *token; + const char *text1, *text2; + char *newtext; + unsigned int length1, length2; + + text1 = elm_code_line_text_get(line1, &length1); + text2 = elm_code_line_text_get(line2, &length2); + + newtext = malloc(sizeof(char) * (length1 + length2 + 1)); + snprintf(newtext, length1 + 1, "%s", text1); + snprintf(newtext + length1, length2 + 1, "%s", text2); + + tokens1 = line1->tokens; + line1->tokens = NULL; + tokens2 = line2->tokens; + line2->tokens = NULL; + elm_code_file_line_remove(line2->file, line2->number); + elm_code_line_text_set(line1, newtext, length1 + length2); + + EINA_LIST_FREE(tokens1, token) + { + token->continues = EINA_FALSE; + line1->tokens = eina_list_append(line1->tokens, token); + } + EINA_LIST_FREE(tokens2, token) + { + token->start += length1; + token->end += length1; + + line1->tokens = eina_list_append(line1->tokens, token); + } + + elm_code_callback_fire(line1->file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line1); + free(newtext); +} + +EAPI void +elm_code_line_merge_up(Elm_Code_Line *line) +{ + Elm_Code_Line *other; + + other = elm_code_file_line_get(line->file, line->number - 1); + + if (other) + _elm_code_line_merge_into(other, line); +} + +EAPI void +elm_code_line_merge_down(Elm_Code_Line *line) +{ + Elm_Code_Line *other; + + other = elm_code_file_line_get(line->file, line->number + 1); + + if (other) + _elm_code_line_merge_into(line, other); +} + EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status) { if (!line) diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/legacy/elm_code/src/lib/elm_code_line.h index f9492aafee..88196893de 100644 --- a/legacy/elm_code/src/lib/elm_code_line.h +++ b/legacy/elm_code/src/lib/elm_code_line.h @@ -45,8 +45,43 @@ EAPI void elm_code_line_free(Elm_Code_Line *line); * Functions for changing the content of lines in an Elm_Code_File */ +/** + * Split the given line into two at the specified character position. + * The additional line will be inserted into the file immediately below the specified line. + * + * @param line The line to split + * @param position The character position to split at + * + * @ingroup Content + */ EAPI void elm_code_line_split_at(Elm_Code_Line *line, unsigned int position); +/** + * Merge the specified line with the line above. + * The content of the specified line will be added to the end of the previous line. + * The specified line will then be removed from the file. + * + * If there is no previous line this method does nothing. + * + * @param line The line to merge with the previous line. + * + * @ingroup Content + */ +EAPI void elm_code_line_merge_up(Elm_Code_Line *line); + +/** + * Merge the specified line with the line below. + * The content of the specified line will have the contents of the next line added to the end. + * The next line will then be removed from the file. + * + * If there is no next line this method does nothing. + * + * @param line The line to merge with the next line. + * + * @ingroup Content + */ +EAPI void elm_code_line_merge_down(Elm_Code_Line *line); + /** * @} * diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 71867e570e..9d2b587220 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1038,12 +1038,8 @@ static void _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) { Elm_Code *code; - Elm_Code_Line *line, *otherline; - unsigned int row, col, position; - - const char *text1, *text2; - char *newtext; - unsigned int length1, length2; + Elm_Code_Line *line, *oldline; + unsigned int row, col, oldlength, position; eo_do(widget, code = elm_obj_code_widget_code_get(), @@ -1052,29 +1048,15 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) if (nextline) { - otherline = elm_code_file_line_get(code->file, row + 1); - text1 = elm_code_line_text_get(line, &length1); - text2 = elm_code_line_text_get(otherline, &length2); + elm_code_line_merge_down(line); } else { - otherline = elm_code_file_line_get(code->file, row - 1); - text1 = elm_code_line_text_get(otherline, &length1); - text2 = elm_code_line_text_get(line, &length2); - } + oldline = elm_code_file_line_get(code->file, row - 1); + elm_code_line_text_get(oldline, &oldlength); + elm_code_line_merge_up(line); - newtext = malloc(sizeof(char) * (length1 + length2 + 1)); - snprintf(newtext, length1 + 1, "%s", text1); - snprintf(newtext + length1, length2 + 1, "%s", text2); - -// TODO we need to merge tokens from these lines (move this to elm_code_line?) - elm_code_file_line_remove(code->file, otherline->number); - elm_code_line_text_set(line, newtext, length1 + length2); - - free(newtext); - if (!nextline) - { - position = elm_code_widget_line_text_column_width_to_position(widget, line, length1); + position = elm_code_widget_line_text_column_width_to_position(widget, oldline, oldlength); eo_do(widget, elm_obj_code_widget_cursor_position_set(position, row - 1)); From 2b56b1f3956af00e84a859ea583e33294852ec93 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 29 Sep 2015 00:30:31 +0100 Subject: [PATCH 201/254] Update to efl on git --- legacy/elm_code/src/lib/elm_code.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code.c b/legacy/elm_code/src/lib/elm_code.c index b951d2b1f8..2d326a742e 100644 --- a/legacy/elm_code/src/lib/elm_code.c +++ b/legacy/elm_code/src/lib/elm_code.c @@ -13,9 +13,9 @@ 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", ""); + EO_EVENT_DESCRIPTION("line,load,done"); EAPI const Eo_Event_Description ELM_CODE_EVENT_FILE_LOAD_DONE = - EO_EVENT_DESCRIPTION("file,load,done", ""); + EO_EVENT_DESCRIPTION("file,load,done"); EAPI int From d6b9a3f82cdee0b7776f32ae083b0f3f8c8a55fc Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 10 Oct 2015 12:00:43 -0700 Subject: [PATCH 202/254] [editor] Show a highlight for the current cursor line --- legacy/elm_code/src/lib/elm_code_common.h | 1 + .../elm_code/src/lib/widget/elm_code_widget.c | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_common.h b/legacy/elm_code/src/lib/elm_code_common.h index 5efe685d27..163bbae072 100644 --- a/legacy/elm_code/src/lib/elm_code_common.h +++ b/legacy/elm_code/src/lib/elm_code_common.h @@ -11,6 +11,7 @@ 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, diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 9d2b587220..4b433a18f4 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -157,14 +157,17 @@ _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start } static unsigned int -_elm_code_widget_status_type_get(Elm_Code_Widget *widget, Elm_Code_Status_Type set_type, unsigned int col) +_elm_code_widget_status_type_get(Elm_Code_Widget *widget, Elm_Code_Line *line, unsigned int col) { Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (set_type != ELM_CODE_STATUS_TYPE_DEFAULT) - return set_type; + if (line->status != ELM_CODE_STATUS_TYPE_DEFAULT) + return line->status; + + if (pd->editable && pd->focussed && pd->cursor_line == line->number) + return ELM_CODE_STATUS_TYPE_CURRENT; if (pd->line_width_marker == col) return ELM_CODE_WIDGET_COLOR_GUTTER_BG; @@ -353,7 +356,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) unichr = eina_unicode_utf8_next_get(chr, &chrpos); cells[x].codepoint = unichr; - cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); + cells[x].bg = _elm_code_widget_status_type_get(widget, line, x - gutter + 1); charwidth = 1; if (unichr == '\t') @@ -361,7 +364,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) for (i = x + 1; i < x + charwidth; i++) { cells[i].codepoint = 0; - cells[i].bg = _elm_code_widget_status_type_get(widget, line->status, i - gutter + 1); + cells[i].bg = _elm_code_widget_status_type_get(widget, line, i - gutter + 1); } _elm_code_widget_fill_whitespace(widget, unichr, &cells[x]); @@ -369,7 +372,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) for (; x < (unsigned int) w; x++) { cells[x].codepoint = 0; - cells[x].bg = _elm_code_widget_status_type_get(widget, line->status, x - gutter + 1); + cells[x].bg = _elm_code_widget_status_type_get(widget, line, x - gutter + 1); } _elm_code_widget_fill_selection(widget, line, cells, gutter, w); @@ -398,7 +401,10 @@ _elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number) for (x = gutter; x < (unsigned int) w; x++) { cells[x].codepoint = 0; - cells[x].bg = _elm_code_widget_status_type_get(widget, ELM_CODE_STATUS_TYPE_DEFAULT, x - gutter + 1); + if (pd->editable && pd->focussed && pd->cursor_line == number) + cells[x].bg = ELM_CODE_STATUS_TYPE_CURRENT; + else + cells[x].bg = ELM_CODE_STATUS_TYPE_DEFAULT; } _elm_code_widget_fill_cursor(widget, number, cells, gutter, w); @@ -1456,6 +1462,8 @@ _elm_code_widget_setup_palette(Evas_Object *o) // setup status colors evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, 36, 36, 36, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CURRENT, + 12, 12, 12, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_IGNORED, 36, 36, 36, 255); evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_NOTE, From e6a49ec22fe6df1a810d314cebd6bbab60b8c3aa Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 10 Oct 2015 14:09:02 -0700 Subject: [PATCH 203/254] [whitespace] Fix indentation after newline when splitting. Make sure that whitespace to the right is ignored --- legacy/elm_code/src/lib/elm_code_text.c | 16 ++++++++++++++-- legacy/elm_code/src/lib/elm_code_text.h | 2 ++ legacy/elm_code/src/lib/widget/elm_code_widget.c | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index abb5a6968d..7e7e9947a7 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -210,6 +210,19 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); } +EAPI void elm_code_line_text_leading_whitespace_strip(Elm_Code_Line *line) +{ + unsigned int length, leading; + const char *content; + + content = elm_code_line_text_get(line, &length); + leading = elm_code_text_leading_whitespace_length(content, length); + if (leading == 0) + return; + + elm_code_line_text_remove(line, 0, leading); +} + EAPI void elm_code_line_text_trailing_whitespace_strip(Elm_Code_Line *line) { unsigned int length, trailing; @@ -220,8 +233,7 @@ EAPI void elm_code_line_text_trailing_whitespace_strip(Elm_Code_Line *line) if (trailing == 0) return; - length -= trailing;; - elm_code_line_text_set(line, content, length); + elm_code_line_text_remove(line, length - trailing, trailing); } /* generic text functions */ diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/legacy/elm_code/src/lib/elm_code_text.h index 02d2cc4ad5..54b64d165a 100644 --- a/legacy/elm_code/src/lib/elm_code_text.h +++ b/legacy/elm_code/src/lib/elm_code_text.h @@ -36,6 +36,8 @@ EAPI void elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length); +EAPI void elm_code_line_text_leading_whitespace_strip(Elm_Code_Line *line); + EAPI void elm_code_line_text_trailing_whitespace_strip(Elm_Code_Line *line); /** diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 4b433a18f4..3d9067afa8 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1030,6 +1030,7 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) line = elm_code_file_line_get(code->file, row + 1); leading = elm_code_text_leading_whitespace_length(oldtext, oldlen); + elm_code_line_text_leading_whitespace_strip(line); elm_code_line_text_insert(line, 0, oldtext, leading); free(oldtext); From 12047f896777359330605ad0fa691fc858b888a5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 16 Jan 2016 18:21:32 +0000 Subject: [PATCH 204/254] [elm_code] Update line status icons for additions Missed a warning line and the addition of TODO as well --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 3d9067afa8..98811bda14 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -25,6 +25,7 @@ Eina_Unicode status_icons[] = { ' ', '!', '!', + '!', '+', '-', @@ -33,6 +34,8 @@ Eina_Unicode status_icons[] = { 0x2713, 0x2717, + 0x2610, + 0 }; From eedcb872412be0530bb0a56ea8eea9d390948fd7 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 17 Jan 2016 17:48:07 +0000 Subject: [PATCH 205/254] Supress libtool warning on windows Thanks to Vincent Torri for the patch --- legacy/elm_code/src/bin/Makefile.am | 3 --- 1 file changed, 3 deletions(-) diff --git a/legacy/elm_code/src/bin/Makefile.am b/legacy/elm_code/src/bin/Makefile.am index 74d06a849a..847a3c7526 100644 --- a/legacy/elm_code/src/bin/Makefile.am +++ b/legacy/elm_code/src/bin/Makefile.am @@ -16,6 +16,3 @@ 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 - -elm_code_test_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ - From 0d11f3d7d8fff83a42a7ee84b761a8eb638d9c7e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 17 Jan 2016 17:51:13 +0000 Subject: [PATCH 206/254] Fix maybe-uninitialized warnings --- legacy/elm_code/src/lib/elm_code_text.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/legacy/elm_code/src/lib/elm_code_text.c index 7e7e9947a7..901b6aefb9 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/legacy/elm_code/src/lib/elm_code_text.c @@ -75,7 +75,7 @@ elm_code_text_strnpos(const char *content, unsigned int length, const char *sear EAPI int elm_code_line_text_strpos(Elm_Code_Line *line, const char *search, int offset) { - unsigned int length; + unsigned int length = 0; const char *content; content = elm_code_line_text_get(line, &length); @@ -212,7 +212,8 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length EAPI void elm_code_line_text_leading_whitespace_strip(Elm_Code_Line *line) { - unsigned int length, leading; + unsigned int length = 0; + unsigned int leading; const char *content; content = elm_code_line_text_get(line, &length); @@ -225,7 +226,8 @@ EAPI void elm_code_line_text_leading_whitespace_strip(Elm_Code_Line *line) EAPI void elm_code_line_text_trailing_whitespace_strip(Elm_Code_Line *line) { - unsigned int length, trailing; + unsigned int length = 0; + unsigned int trailing; const char *content; content = elm_code_line_text_get(line, &length); From 70471e0ad89554bbe6368f649bc8a9c36147eac7 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 9 Feb 2016 00:32:16 +0000 Subject: [PATCH 207/254] [editor] Support space insertion instead of tabs Elm_Code support and option in Edi to use spaces when the Tab key is pressed - make this default too. --- .../elm_code/src/lib/widget/elm_code_widget.c | 39 +++++++++++++++++++ .../src/lib/widget/elm_code_widget.eo | 11 ++++++ .../src/lib/widget/elm_code_widget_private.h | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 98811bda14..a6cde05b3f 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1006,6 +1006,30 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } +static void +_elm_code_widget_tab_at_cursor_insert(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + unsigned int col, row; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + if (!pd->tab_inserts_spaces) + { + _elm_code_widget_text_at_cursor_insert(widget, "\t", 1); + return; + } + + eo_do(widget, + elm_obj_code_widget_cursor_position_get(&col, &row)); + col = (col - 1) % pd->tabstop; + + while (col < pd->tabstop) + { + _elm_code_widget_text_at_cursor_insert(widget, " ", 1); + col++; + } +} + static void _elm_code_widget_newline(Elm_Code_Widget *widget) { @@ -1215,6 +1239,8 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, _elm_code_widget_backspace(widget); else if (!strcmp(ev->key, "Delete")) _elm_code_widget_delete(widget); + else if (!strcmp(ev->key, "Tab")) + _elm_code_widget_tab_at_cursor_insert(widget); else if (ev->string && strlen(ev->string) == 1) _elm_code_widget_text_at_cursor_insert(widget, ev->string, 1); @@ -1445,6 +1471,19 @@ _elm_code_widget_show_whitespace_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data * return pd->show_whitespace; } +EOLIAN static void +_elm_code_widget_tab_inserts_spaces_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool spaces) +{ + pd->tab_inserts_spaces = spaces; + _elm_code_widget_fill(obj); +} + +EOLIAN static Eina_Bool +_elm_code_widget_tab_inserts_spaces_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) +{ + return pd->tab_inserts_spaces; +} + EOLIAN static void _elm_code_widget_cursor_position_set(Eo *obj, Elm_Code_Widget_Data *pd, unsigned int col, unsigned int line) { diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index 1bbcc1803e..0e11331dbc 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -130,6 +130,17 @@ class Elm.Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) show_whitespace: Eina_Bool; [[Whether or not we show whitespace characters]] } } + @property tab_inserts_spaces { + set { + [[Set whether space characters should be inserted instead of tabs.]] + } + get { + [[Get whether or not space characters will be inserted instead of tabs.]] + } + values { + tab_inserts_spaces: Eina_Bool; [[EINA_TRUE if we should insert space characters instead of a tab when the Tab key is pressed]] + } + } @property cursor_position { set { [[Set the current location of the text cursor.]] diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h index b89973fd0f..b9f8ad296d 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h @@ -23,7 +23,7 @@ typedef struct Eina_Bool editable, focussed; Eina_Bool show_line_numbers; unsigned int line_width_marker, tabstop; - Eina_Bool show_whitespace; + Eina_Bool show_whitespace, tab_inserts_spaces; Elm_Code_Widget_Selection_Data *selection; Evas_Object *tooltip; From d15de4309e6d82681e436581a7b6492c0844fa4a Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 9 Feb 2016 09:11:26 +0000 Subject: [PATCH 208/254] Fix out of source builds. --- legacy/elm_code/src/bin/Makefile.am | 1 + legacy/elm_code/src/lib/widget/elm_code_widget_legacy.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/bin/Makefile.am b/legacy/elm_code/src/bin/Makefile.am index 847a3c7526..c71bf8b893 100644 --- a/legacy/elm_code/src/bin/Makefile.am +++ b/legacy/elm_code/src/bin/Makefile.am @@ -7,6 +7,7 @@ AM_CPPFLAGS = \ -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\" \ -DEFL_BETA_API_SUPPORT \ @EFL_CFLAGS@ diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_legacy.h b/legacy/elm_code/src/lib/widget/elm_code_widget_legacy.h index 5110e301e2..450f4adeae 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_legacy.h +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_legacy.h @@ -10,4 +10,4 @@ */ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code); -#include "elm_code_widget.eo.legacy.h" +#include "widget/elm_code_widget.eo.legacy.h" From b38510e8304b729d544c6f36bc0c34fe4d3fa9c0 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 15 Feb 2016 17:20:41 +0000 Subject: [PATCH 209/254] Elm_Interface_Atspi_Text changed to Elm.Interface_Atspi_Text. @author conr2d --- legacy/elm_code/src/lib/widget/elm_code_widget.eo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index 0e11331dbc..b8ab71dcb4 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -1,4 +1,4 @@ -class Elm.Code_Widget (Elm.Layout, Elm_Interface_Atspi_Text) +class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) { eo_prefix: elm_obj_code_widget; legacy_prefix: elm_code_widget; From 1dbc1965ff6856820943c80649ecf8b15c4c1fb5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 15 Feb 2016 22:54:12 +0000 Subject: [PATCH 210/254] [editor] double click and triple do selections double for a word (space or tab delimited for now) triple selects whole line. --- .../elm_code/src/lib/widget/elm_code_widget.c | 15 ++++- .../lib/widget/elm_code_widget_selection.c | 65 ++++++++++++++++++ .../lib/widget/elm_code_widget_selection.h | 4 ++ .../widget/elm_code_test_widget_selection.c | 66 +++++++++++++++++++ 4 files changed, 148 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index a6cde05b3f..a5ef0dec4b 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -678,7 +678,7 @@ _elm_code_widget_clicked_readonly_cb(Elm_Code_Widget *widget, unsigned int row) static void _elm_code_widget_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, - void *event_info) + void *event_info) { Elm_Code_Widget *widget; Elm_Code_Widget_Data *pd; @@ -689,12 +689,23 @@ _elm_code_widget_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj widget = (Elm_Code_Widget *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); event = (Evas_Event_Mouse_Down *)event_info; + _elm_code_widget_position_at_coordinates_get(widget, pd, event->canvas.x, event->canvas.y, &row, &col); elm_code_widget_selection_clear(widget); + if (event->flags & EVAS_BUTTON_TRIPLE_CLICK) + { + elm_code_widget_selection_select_line(widget, row); + return; + } + else if (event->flags & EVAS_BUTTON_DOUBLE_CLICK) + { + elm_code_widget_selection_select_word(widget, row, col); + return; + } + if (!pd->editable) return; - _elm_code_widget_position_at_coordinates_get(widget, pd, event->canvas.x, event->canvas.y, &row, &col); if (col > 0 && row <= elm_code_file_lines_get(pd->code->file)) elm_code_widget_selection_start(widget, row, col); } diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index dd3ee74ac4..ae2d1226cf 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -226,6 +226,71 @@ elm_code_widget_selection_delete(Evas_Object *widget) eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget)); } +EAPI void +elm_code_widget_selection_select_line(Evas_Object *widget, unsigned int line) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Line *lineobj; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + lineobj = elm_code_file_line_get(pd->code->file, line); + + if (!lineobj) + return; + + elm_code_widget_selection_start(widget, line, 1); + elm_code_widget_selection_end(widget, line, lineobj->length); +} + +static Eina_Bool +_elm_code_widget_selection_char_breaks(char chr) +{ + if (chr == 0) + return EINA_TRUE; + else if (chr == ' ') + return EINA_TRUE; + else if (chr == '\t') + return EINA_TRUE; + + return EINA_FALSE; +} + +EAPI void +elm_code_widget_selection_select_word(Evas_Object *widget, unsigned int line, unsigned int col) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Line *lineobj; + unsigned int colpos, length, pos; + const char *content; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + lineobj = elm_code_file_line_get(pd->code->file, line); + content = elm_code_line_text_get(lineobj, &length); + + _elm_code_widget_selection_limit(widget, pd, &line, &col); + colpos = elm_code_widget_line_text_position_for_column_get(widget, lineobj, col); + + pos = colpos; + while (pos > 0) + { + if (_elm_code_widget_selection_char_breaks(content[pos - 1])) + break; + pos--; + } + elm_code_widget_selection_start(widget, line, + elm_code_widget_line_text_column_width_to_position(widget, lineobj, pos)); + + pos = colpos; + while (pos < length - 1) + { + if (_elm_code_widget_selection_char_breaks(content[pos + 1])) + break; + pos++; + } + elm_code_widget_selection_end(widget, line, + elm_code_widget_line_text_column_width_to_position(widget, lineobj, pos)); +} + static char * _elm_code_widget_selection_text_single_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd) { diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.h b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.h index 0e476a20b5..b79abc763f 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.h +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.h @@ -23,6 +23,10 @@ EAPI void elm_code_widget_selection_clear(Evas_Object *widget); EAPI void elm_code_widget_selection_delete(Evas_Object *widget); +EAPI void elm_code_widget_selection_select_line(Evas_Object *widget, unsigned int line); + +EAPI void elm_code_widget_selection_select_word(Evas_Object *widget, unsigned int line, unsigned int col); + EAPI char *elm_code_widget_selection_text_get(Evas_Object *widget); EAPI void elm_code_widget_selection_cut(Evas_Object *widget); diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c index 7135e4a9c5..71e63bfe3e 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c @@ -475,6 +475,70 @@ START_TEST (elm_code_test_widget_selection_reverse_delete_multiline) elm_shutdown(); } END_TEST + +START_TEST (elm_code_test_widget_selection_select_line) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Widget *widget; + Evas_Object *win; + char *selection; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "line selection", 14, NULL); + elm_code_file_line_append(file, "line2", 5, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + + elm_code_widget_selection_select_line(widget, 1); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("line selection", selection); + free(selection); + + elm_code_widget_selection_select_line(widget, 2); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("line2", selection); + free(selection); +} +END_TEST + +START_TEST (elm_code_test_widget_selection_select_word) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Widget *widget; + Evas_Object *win; + char *selection; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "word selection test", 19, NULL); + elm_code_file_line_append(file, "more stuff\tto test", 18, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + + elm_code_widget_selection_select_word(widget, 1, 3); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("word", selection); + free(selection); + + elm_code_widget_selection_select_word(widget, 1, 16); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("test", selection); + free(selection); + + elm_code_widget_selection_select_word(widget, 2, 9); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("stuff", selection); + free(selection); +} +END_TEST + void elm_code_test_widget_selection(TCase *tc) { tcase_add_test(tc, elm_code_test_widget_selection_set); @@ -491,5 +555,7 @@ void elm_code_test_widget_selection(TCase *tc) tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete_twoline); tcase_add_test(tc, elm_code_test_widget_selection_delete_multiline); tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete_multiline); + tcase_add_test(tc, elm_code_test_widget_selection_select_line); + tcase_add_test(tc, elm_code_test_widget_selection_select_word); } From d985b3a9cd50b16097b5cefc9e6050b7aeba3e29 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 15 Feb 2016 23:51:51 +0000 Subject: [PATCH 211/254] [editor] stop auto selection on symbols too --- .../lib/widget/elm_code_widget_selection.c | 13 +++- .../widget/elm_code_test_widget_selection.c | 78 +++++++++++++++++++ 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index ae2d1226cf..6479123ff5 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -6,6 +6,8 @@ #include "elm_code_widget_private.h" +static char _breaking_chars[] = " \t,.?!;:()[]{}"; + static Elm_Code_Widget_Selection_Data * _elm_code_widget_selection_new() { @@ -245,12 +247,15 @@ elm_code_widget_selection_select_line(Evas_Object *widget, unsigned int line) static Eina_Bool _elm_code_widget_selection_char_breaks(char chr) { + unsigned int i; + if (chr == 0) return EINA_TRUE; - else if (chr == ' ') - return EINA_TRUE; - else if (chr == '\t') - return EINA_TRUE; + + for (i = 0; i < sizeof(_breaking_chars); i++) + if (chr == _breaking_chars[i]) + return EINA_TRUE; + return EINA_FALSE; } diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c index 71e63bfe3e..9769f6bcd0 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c @@ -539,6 +539,82 @@ START_TEST (elm_code_test_widget_selection_select_word) } END_TEST +START_TEST (elm_code_test_widget_selection_select_word_punctuation) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Widget *widget; + Evas_Object *win; + char *selection; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "comma, stop. question? mark!", 38, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + + elm_code_widget_selection_select_word(widget, 1, 3); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("comma", selection); + free(selection); + + elm_code_widget_selection_select_word(widget, 1, 10); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("stop", selection); + free(selection); + + elm_code_widget_selection_select_word(widget, 1, 20); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("question", selection); + free(selection); + + elm_code_widget_selection_select_word(widget, 1, 25); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("mark", selection); + free(selection); +} +END_TEST + +START_TEST (elm_code_test_widget_selection_select_word_symbols) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Widget *widget; + Evas_Object *win; + char *selection; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "colon: [array] (brackets) {braces}", 38, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + + elm_code_widget_selection_select_word(widget, 1, 3); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("colon", selection); + free(selection); + + elm_code_widget_selection_select_word(widget, 1, 10); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("array", selection); + free(selection); + + elm_code_widget_selection_select_word(widget, 1, 20); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("brackets", selection); + free(selection); + + elm_code_widget_selection_select_word(widget, 1, 30); + selection = elm_code_widget_selection_text_get(widget); + ck_assert_str_eq("braces", selection); + free(selection); +} +END_TEST + void elm_code_test_widget_selection(TCase *tc) { tcase_add_test(tc, elm_code_test_widget_selection_set); @@ -557,5 +633,7 @@ void elm_code_test_widget_selection(TCase *tc) tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete_multiline); tcase_add_test(tc, elm_code_test_widget_selection_select_line); tcase_add_test(tc, elm_code_test_widget_selection_select_word); + tcase_add_test(tc, elm_code_test_widget_selection_select_word_punctuation); + tcase_add_test(tc, elm_code_test_widget_selection_select_word_symbols); } From 3c80041cdd493f3b3d00c27f7819b0470ad12c05 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 21 Feb 2016 17:51:56 +0000 Subject: [PATCH 212/254] [editor] various tidies use flag for todo status, ignore escape key when tapped. Fix some build warnings due to double inclusion. --- legacy/elm_code/src/lib/Makefile.am | 1 - legacy/elm_code/src/lib/widget/elm_code_widget.c | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index 95129e852b..319acae178 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -41,7 +41,6 @@ elm_code_line.c \ elm_code_text.c \ elm_code_file.c \ elm_code_parse.c \ -widget/elm_code_widget_text.c \ widget/elm_code_widget_tooltip.c \ widget/elm_code_widget_selection.c \ widget/elm_code_widget.c \ diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index a5ef0dec4b..7fa5653bb4 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -34,7 +34,7 @@ Eina_Unicode status_icons[] = { 0x2713, 0x2717, - 0x2610, + 0x2691, 0 }; @@ -1253,6 +1253,9 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas EINA_UNUSED, else if (!strcmp(ev->key, "Tab")) _elm_code_widget_tab_at_cursor_insert(widget); + else if (!strcmp(ev->key, "Escape")) + DBG("TODO - Escape not yet captured"); + else if (ev->string && strlen(ev->string) == 1) _elm_code_widget_text_at_cursor_insert(widget, ev->string, 1); else From fcf2318d2bec4b3233138c10505c5ab176b21863 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 21 Feb 2016 18:03:29 +0000 Subject: [PATCH 213/254] [editor] Fix crash when deleting selections If the selection ended in the carriage return the editor could craash. @fix --- .../lib/widget/elm_code_widget_selection.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 6479123ff5..04df2232b4 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -193,11 +193,20 @@ _elm_code_widget_selection_delete_multi(Elm_Code_Widget *widget, Elm_Code_Widget last = elm_code_line_text_get(line, &last_length); end = elm_code_widget_line_text_position_for_column_get(widget, line, selection->end_col); - length = start + last_length - (end + 1); - content = malloc(sizeof(char) * length); - strncpy(content, first, start); - strncpy(content + start, last + end + 1, - last_length - (end + 1)); + if (last_length == end) + { + length = start + last_length - end; + content = malloc(sizeof(char) * length); + strncpy(content, first, start); + } + else + { + length = start + last_length - (end + 1); + content = malloc(sizeof(char) * length); + strncpy(content, first, start); + + strncpy(content + start, last + end + 1, last_length - (end + 1)); + } for (i = line->number; i > selection->start_line; i--) elm_code_file_line_remove(pd->code->file, i); From 16331682b3430a194848ab2459a1b77b1436dc87 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 21 Feb 2016 18:04:49 +0000 Subject: [PATCH 214/254] easier debugging of ck_assert_strn_eq --- legacy/elm_code/src/tests/elm_code_suite.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/legacy/elm_code/src/tests/elm_code_suite.h b/legacy/elm_code/src/tests/elm_code_suite.h index fddba5bfcd..d541e9bea3 100644 --- a/legacy/elm_code/src/tests/elm_code_suite.h +++ b/legacy/elm_code/src/tests/elm_code_suite.h @@ -3,14 +3,16 @@ #include -#define ck_assert_strn_eq(str1, str2, len) \ +#define ck_assert_strn_eq(s1, s2, len) \ { \ - unsigned int i = 0; \ - while (i < len) \ - { \ - ck_assert_int_eq(*(str1 + i), *(str2 + i)); \ - i++; \ - } \ + char expected[len+1], actual[len+1]; \ +\ + strncpy(expected, s1, len); \ + expected[len] = '\0'; \ + strncpy(actual, s2, len); \ + actual[len] = '\0'; \ +\ + ck_assert_str_eq(expected, actual); \ } #include From 7457546dedf7f9e68dd002162cedefd1bfa245af Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 21 Feb 2016 18:11:33 +0000 Subject: [PATCH 215/254] [editor] begin re-adding the undo feature. This is provided completely by elm_code so can be reused in other editors. For now this is just text/newline insertion... Still have to add undo for deletion and selection --- .../elm_code/src/lib/widget/elm_code_widget.c | 68 ++++++++++-- .../src/lib/widget/elm_code_widget.eo | 2 + .../src/lib/widget/elm_code_widget_private.h | 19 ++++ .../src/lib/widget/elm_code_widget_undo.c | 56 ++++++++++ legacy/elm_code/src/tests/Makefile.am | 1 + legacy/elm_code/src/tests/elm_code_suite.c | 1 + legacy/elm_code/src/tests/elm_code_suite.h | 1 + .../tests/widget/elm_code_test_widget_undo.c | 101 ++++++++++++++++++ 8 files changed, 238 insertions(+), 11 deletions(-) create mode 100644 legacy/elm_code/src/lib/widget/elm_code_widget_undo.c create mode 100644 legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 7fa5653bb4..56f85077d3 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -987,11 +987,41 @@ _elm_code_widget_delete_selection(Elm_Code_Widget *widget) return EINA_TRUE; } +static Elm_Code_Widget_Change_Info * +_elm_code_widget_change_create_insert(unsigned int start_col, unsigned int start_line, + unsigned int end_col, unsigned int end_line, + const char *text, unsigned int length) +{ + Elm_Code_Widget_Change_Info *info; + + info = calloc(1, sizeof(*info)); + info->insert = EINA_TRUE; + + info->start_col = start_col; + info->start_line = start_line; + info->end_col = end_col; + info->end_line = end_line; + + info->content = malloc((length + 1) * sizeof(char)); + strncpy((char *)info->content, text, length + 1); + info->length = length; + + return info; +} + static void +_elm_code_widget_change_free(Elm_Code_Widget_Change_Info *info) +{ + free((char *)info->content); + free(info); +} + +void _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text, int length) { Elm_Code *code; Elm_Code_Line *line; + Elm_Code_Widget_Change_Info *change; unsigned int row, col, position, col_width; _elm_code_widget_delete_selection(widget); @@ -1013,15 +1043,19 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text eo_do(widget, elm_obj_code_widget_cursor_position_set(col + col_width, row), -// TODO construct and pass a change object eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); + + change = _elm_code_widget_change_create_insert(col, row, col + col_width - 1, row, text, length); + _elm_code_widget_undo_change_add(widget, change); + _elm_code_widget_change_free(change); } static void _elm_code_widget_tab_at_cursor_insert(Elm_Code_Widget *widget) { Elm_Code_Widget_Data *pd; - unsigned int col, row; + Elm_Code_Widget_Change_Info *change; + unsigned int col, row, rem; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (!pd->tab_inserts_spaces) @@ -1032,21 +1066,26 @@ _elm_code_widget_tab_at_cursor_insert(Elm_Code_Widget *widget) eo_do(widget, elm_obj_code_widget_cursor_position_get(&col, &row)); - col = (col - 1) % pd->tabstop; + rem = (col - 1) % pd->tabstop; - while (col < pd->tabstop) + while (rem < pd->tabstop) { _elm_code_widget_text_at_cursor_insert(widget, " ", 1); - col++; + rem++; } + + change = _elm_code_widget_change_create_insert(col, row, (col - 1) % pd ->tabstop, row, "\t", 1); + _elm_code_widget_undo_change_add(widget, change); + _elm_code_widget_change_free(change); } -static void +void _elm_code_widget_newline(Elm_Code_Widget *widget) { Elm_Code *code; Elm_Code_Line *line; - unsigned int row, col, position, oldlen, leading; + Elm_Code_Widget_Change_Info *change; + unsigned int row, col, position, oldlen, leading, width, indent; char *oldtext; _elm_code_widget_delete_selection(widget); @@ -1065,6 +1104,7 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) position = elm_code_widget_line_text_position_for_column_get(widget, line, col); elm_code_line_split_at(line, position); + width = elm_code_widget_line_text_column_width_get(widget, line); line = elm_code_file_line_get(code->file, row + 1); leading = elm_code_text_leading_whitespace_length(oldtext, oldlen); @@ -1072,11 +1112,14 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) elm_code_line_text_insert(line, 0, oldtext, leading); free(oldtext); + indent = elm_obj_code_widget_line_text_column_width_to_position(line, leading); eo_do(widget, - elm_obj_code_widget_cursor_position_set( - elm_obj_code_widget_line_text_column_width_to_position(line, leading), row + 1), -// TODO construct and pass a change object + elm_obj_code_widget_cursor_position_set(indent, row + 1), eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); + + change = _elm_code_widget_change_create_insert(width + 1, row, indent - 1, row + 1, "\n", 1); + _elm_code_widget_undo_change_add(widget, change); + _elm_code_widget_change_free(change); } static void @@ -1198,9 +1241,11 @@ _elm_code_widget_control_key_down_cb(Elm_Code_Widget *widget, const char *key) elm_code_widget_selection_paste(widget); else if (!strcmp("x", key)) elm_code_widget_selection_cut(widget); + else if (!strcmp("z", key)) + elm_code_widget_undo(widget); eo_do(widget, -// TODO construct and pass a change object +// TODO construct and pass a change object for cut and paste eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } @@ -1638,4 +1683,5 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) } #include "elm_code_widget_text.c" +#include "elm_code_widget_undo.c" #include "elm_code_widget.eo.c" diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index b8ab71dcb4..e07459a5b7 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -202,6 +202,8 @@ class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) } return: uint; } + undo { + } } implements { class.constructor; diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h index b9f8ad296d..fab43c257a 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h @@ -27,14 +27,33 @@ typedef struct Elm_Code_Widget_Selection_Data *selection; Evas_Object *tooltip; + + /* Undo stack */ + Eina_List *undo_stack; + Eina_List *undo_stack_ptr; } Elm_Code_Widget_Data; +typedef struct +{ + const char *content; + unsigned int length; + unsigned int start_line, start_col, end_line, end_col; + + Eina_Bool insert : 1; /**< True if the change is an insertion */ +} Elm_Code_Widget_Change_Info; + /* Private widget methods */ +void _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text, int length); + +void _elm_code_widget_newline(Elm_Code_Widget *widget); + void _elm_code_widget_tooltip_text_set(Evas_Object *widget, const char *text); void _elm_code_widget_tooltip_add(Evas_Object *widget); EAPI Elm_Code_Widget_Selection_Data *elm_code_widget_selection_normalized_get(Evas_Object *widget); +void _elm_code_widget_undo_change_add(Evas_Object *widget, Elm_Code_Widget_Change_Info *info); + #endif diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c b/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c new file mode 100644 index 0000000000..d51cc5ff7e --- /dev/null +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c @@ -0,0 +1,56 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include "Elm_Code.h" + +#include "elm_code_widget_private.h" + +void +_elm_code_widget_undo_change_add(Evas_Object *widget, + Elm_Code_Widget_Change_Info *info) +{ + Elm_Code_Widget_Data *pd; + Elm_Code_Widget_Change_Info *info_copy; + + info_copy = calloc(1, sizeof(*info)); + memcpy(info_copy, info, sizeof(*info)); + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + pd->undo_stack_ptr = eina_list_prepend(pd->undo_stack_ptr, info_copy); + pd->undo_stack = pd->undo_stack_ptr; +} + +static void +_elm_code_widget_undo_change(Evas_Object *widget, + Elm_Code_Widget_Change_Info *info) +{ + if (info->insert) + { + elm_code_widget_selection_start(widget, info->start_line, info->start_col); + elm_code_widget_selection_end(widget, info->end_line, info->end_col); + elm_code_widget_selection_delete(widget); + } + else + { + } +} + +static void +_elm_code_widget_undo(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) +{ + Elm_Code_Widget_Change_Info *info; + + if (!pd->undo_stack_ptr) + return; + + info = eina_list_data_get(pd->undo_stack_ptr); + _elm_code_widget_undo_change(obj, info); + + if (eina_list_next(pd->undo_stack_ptr)) + pd->undo_stack_ptr = eina_list_next(pd->undo_stack_ptr); + else + pd->undo_stack_ptr = NULL; +} + diff --git a/legacy/elm_code/src/tests/Makefile.am b/legacy/elm_code/src/tests/Makefile.am index 6256c35f5b..6150c6f6e0 100644 --- a/legacy/elm_code/src/tests/Makefile.am +++ b/legacy/elm_code/src/tests/Makefile.am @@ -15,6 +15,7 @@ elm_code_test_text.c \ widget/elm_code_test_widget.c \ widget/elm_code_test_widget_text.c \ widget/elm_code_test_widget_selection.c \ +widget/elm_code_test_widget_undo.c \ elm_code_suite.c elm_code_suite_CPPFLAGS = \ diff --git a/legacy/elm_code/src/tests/elm_code_suite.c b/legacy/elm_code/src/tests/elm_code_suite.c index f562b80363..31ea7d9f0e 100644 --- a/legacy/elm_code/src/tests/elm_code_suite.c +++ b/legacy/elm_code/src/tests/elm_code_suite.c @@ -21,6 +21,7 @@ static const struct { { "widget", elm_code_test_widget }, { "widget_text", elm_code_test_widget_text }, { "widget_selection", elm_code_test_widget_selection }, + { "widget_undo", elm_code_test_widget_undo }, }; START_TEST(elm_code_initialization) diff --git a/legacy/elm_code/src/tests/elm_code_suite.h b/legacy/elm_code/src/tests/elm_code_suite.h index d541e9bea3..750bfd7f18 100644 --- a/legacy/elm_code/src/tests/elm_code_suite.h +++ b/legacy/elm_code/src/tests/elm_code_suite.h @@ -26,5 +26,6 @@ void elm_code_test_text(TCase *tc); void elm_code_test_widget(TCase *tc); void elm_code_test_widget_text(TCase *tc); void elm_code_test_widget_selection(TCase *tc); +void elm_code_test_widget_undo(TCase *tc); #endif /* _EDLM_CODE_SUITE_H */ diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c new file mode 100644 index 0000000000..f6c13f0451 --- /dev/null +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c @@ -0,0 +1,101 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "elm_code_suite.h" + +#include "elm_code_widget_private.h" + +START_TEST (elm_code_test_widget_undo_text_insert) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + Elm_Code_Widget *widget; + Evas_Object *win; + unsigned int length; + const char *content; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "test", 4, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + + _elm_code_widget_text_at_cursor_insert(widget, "a", 1); + line = elm_code_file_line_get(file, 1); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("atest", content, length); + + elm_code_widget_undo(widget); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("test", content, length); + + elm_code_widget_cursor_position_set(widget, 3, 1); + _elm_code_widget_text_at_cursor_insert(widget, "r", 1); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("terst", content, length); + + elm_code_widget_undo(widget); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("test", content, length); + + elm_code_widget_cursor_position_set(widget, 4, 1); + _elm_code_widget_text_at_cursor_insert(widget, "\t", 1); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("tes\tt", content, length); + + elm_code_widget_undo(widget); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("test", content, length); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + +START_TEST (elm_code_test_widget_undo_newline) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + Elm_Code_Widget *widget; + Evas_Object *win; + unsigned int length; + const char *content; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "test", 4, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + + elm_code_widget_cursor_position_set(widget, 5, 1); + _elm_code_widget_newline(widget); + ck_assert_int_eq(2, elm_code_file_lines_get(file)); + line = elm_code_file_line_get(file, 1); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("test", content, 1); + + elm_code_widget_undo(widget); + + ck_assert_int_eq(1, elm_code_file_lines_get(file)); + line = elm_code_file_line_get(file, 1); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("test", content, 4); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + +void elm_code_test_widget_undo(TCase *tc) +{ + tcase_add_test(tc, elm_code_test_widget_undo_text_insert); + tcase_add_test(tc, elm_code_test_widget_undo_newline); +} + From 0bcd87a2af98b9e0e2c89d826c955f8378d1ae3f Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 21 Feb 2016 18:39:43 +0000 Subject: [PATCH 216/254] Fix crash when undoing a soft tab insert --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 56f85077d3..fe78a82d83 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1073,10 +1073,6 @@ _elm_code_widget_tab_at_cursor_insert(Elm_Code_Widget *widget) _elm_code_widget_text_at_cursor_insert(widget, " ", 1); rem++; } - - change = _elm_code_widget_change_create_insert(col, row, (col - 1) % pd ->tabstop, row, "\t", 1); - _elm_code_widget_undo_change_add(widget, change); - _elm_code_widget_change_free(change); } void From 9b491f8efac18f4e0d9fba9d6b9e4fef8bb6da28 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 21 Feb 2016 18:48:07 +0000 Subject: [PATCH 217/254] Complete the ending newline crash fix --- .../lib/widget/elm_code_widget_selection.c | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 04df2232b4..9a558ecc6b 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -163,10 +163,22 @@ _elm_code_widget_selection_delete_single(Elm_Code_Widget *widget, Elm_Code_Widge end = elm_code_widget_line_text_position_for_column_get(widget, line, selection->end_col); length = line->length - (end - start + 1); - content = malloc(sizeof(char) * length); - strncpy(content, old, start); - strncpy(content + start, old + end + 1, - old_length - (end + 1)); + if (end == line->length) + { + length = line->length - (end - start); + + content = malloc(sizeof(char) * length); + strncpy(content, old, start); + } + else + { + length = line->length - (end - start + 1); + + content = malloc(sizeof(char) * length); + strncpy(content, old, start); + strncpy(content + start, old + end + 1, + old_length - (end + 1)); + } elm_code_line_text_set(line, content, length); free(content); free(selection); From b61b460c997a5850e5c3b9d524a9b11864d6b19f Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 21 Feb 2016 23:46:10 +0000 Subject: [PATCH 218/254] [editor] add delete and backspace undo hooks --- .../elm_code/src/lib/widget/elm_code_widget.c | 40 ++++++--- .../src/lib/widget/elm_code_widget.eo | 9 ++ .../src/lib/widget/elm_code_widget_private.h | 6 +- .../lib/widget/elm_code_widget_selection.c | 85 +++---------------- .../src/lib/widget/elm_code_widget_text.c | 81 ++++++++++++++++++ .../src/lib/widget/elm_code_widget_undo.c | 27 +++++- .../tests/widget/elm_code_test_widget_undo.c | 46 ++++++++++ 7 files changed, 201 insertions(+), 93 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index fe78a82d83..203c1d1be4 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -988,14 +988,14 @@ _elm_code_widget_delete_selection(Elm_Code_Widget *widget) } static Elm_Code_Widget_Change_Info * -_elm_code_widget_change_create_insert(unsigned int start_col, unsigned int start_line, - unsigned int end_col, unsigned int end_line, - const char *text, unsigned int length) +_elm_code_widget_change_create(unsigned int start_col, unsigned int start_line, + unsigned int end_col, unsigned int end_line, + const char *text, unsigned int length, Eina_Bool insert) { Elm_Code_Widget_Change_Info *info; info = calloc(1, sizeof(*info)); - info->insert = EINA_TRUE; + info->insert = insert; info->start_col = start_col; info->start_line = start_line; @@ -1003,7 +1003,8 @@ _elm_code_widget_change_create_insert(unsigned int start_col, unsigned int start info->end_line = end_line; info->content = malloc((length + 1) * sizeof(char)); - strncpy((char *)info->content, text, length + 1); + strncpy(info->content, text, length); + info->content[length] = '\0'; info->length = length; return info; @@ -1045,7 +1046,7 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text elm_obj_code_widget_cursor_position_set(col + col_width, row), eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); - change = _elm_code_widget_change_create_insert(col, row, col + col_width - 1, row, text, length); + change = _elm_code_widget_change_create(col, row, col + col_width - 1, row, text, length, EINA_TRUE); _elm_code_widget_undo_change_add(widget, change); _elm_code_widget_change_free(change); } @@ -1054,7 +1055,6 @@ static void _elm_code_widget_tab_at_cursor_insert(Elm_Code_Widget *widget) { Elm_Code_Widget_Data *pd; - Elm_Code_Widget_Change_Info *change; unsigned int col, row, rem; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); @@ -1113,7 +1113,7 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) elm_obj_code_widget_cursor_position_set(indent, row + 1), eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); - change = _elm_code_widget_change_create_insert(width + 1, row, indent - 1, row + 1, "\n", 1); + change = _elm_code_widget_change_create(width + 1, row, indent - 1, row + 1, "\n", 1, EINA_TRUE); _elm_code_widget_undo_change_add(widget, change); _elm_code_widget_change_free(change); } @@ -1149,15 +1149,17 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); } -static void +void _elm_code_widget_backspace(Elm_Code_Widget *widget) { Elm_Code *code; Elm_Code_Line *line; + Elm_Code_Widget_Change_Info *change; unsigned int row, col, position, start_col, char_width; + const char *text; if (_elm_code_widget_delete_selection(widget)) - return; + return; // TODO fire the change and log it eo_do(widget, code = elm_obj_code_widget_code_get(), @@ -1179,23 +1181,29 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) elm_code_widget_line_text_position_for_column_get(widget, line, col - 1)); char_width = position - elm_code_widget_line_text_position_for_column_get(widget, line, start_col); + text = elm_code_widget_text_between_positions_get(widget, start_col, row, start_col, row); elm_code_line_text_remove(line, position - char_width, char_width); eo_do(widget, elm_obj_code_widget_cursor_position_set(start_col, row)); -// TODO construct and pass a change object eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); + + change = _elm_code_widget_change_create(start_col, row, col, row, text, char_width, EINA_FALSE); + _elm_code_widget_undo_change_add(widget, change); + _elm_code_widget_change_free(change); } -static void +void _elm_code_widget_delete(Elm_Code_Widget *widget) { Elm_Code *code; Elm_Code_Line *line; + Elm_Code_Widget_Change_Info *change; unsigned int row, col, position, char_width, start_col; + const char *text; if (_elm_code_widget_delete_selection(widget)) - return; + return; // TODO fire the change and log it eo_do(widget, code = elm_obj_code_widget_code_get(), @@ -1214,11 +1222,15 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) char_width = elm_code_widget_line_text_position_for_column_get(widget, line, col + 1) - position; start_col = elm_code_widget_line_text_column_width_to_position(widget, line, position); + text = elm_code_widget_text_between_positions_get(widget, start_col, row, start_col, row); elm_code_line_text_remove(line, position, char_width?char_width:1); eo_do(widget, elm_obj_code_widget_cursor_position_set(start_col, row), -// TODO construct and pass a change object eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); + + change = _elm_code_widget_change_create(start_col, row, col, row, text, char_width, EINA_FALSE); + _elm_code_widget_undo_change_add(widget, change); + _elm_code_widget_change_free(change); } static void diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index e07459a5b7..ace043a764 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -175,6 +175,15 @@ class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) text_line_number_width_get { return: int; [[the column width required to represent the number of lines in the widget.]] } + text_between_positions_get { + params { + start_col: uint; [[the widget column of the first character to get]] + start_line: uint; [[the line of the first character to get]] + end_col: uint; [[the widget column of the last character to get]] + end_line: uint; [[the line of the last character to get]] + } + return: char *; [[the text content between start and end positions]] + } line_text_column_width_to_position { params { diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h index fab43c257a..b4e19007b0 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h @@ -35,7 +35,7 @@ typedef struct typedef struct { - const char *content; + char *content; unsigned int length; unsigned int start_line, start_col, end_line, end_col; @@ -48,6 +48,10 @@ void _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char void _elm_code_widget_newline(Elm_Code_Widget *widget); +void _elm_code_widget_backspace(Elm_Code_Widget *widget); + +void _elm_code_widget_delete(Elm_Code_Widget *widget); + void _elm_code_widget_tooltip_text_set(Evas_Object *widget, const char *text); void _elm_code_widget_tooltip_add(Evas_Object *widget); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 9a558ecc6b..d4d214241b 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -317,91 +317,26 @@ elm_code_widget_selection_select_word(Evas_Object *widget, unsigned int line, un elm_code_widget_line_text_column_width_to_position(widget, lineobj, pos)); } -static char * -_elm_code_widget_selection_text_single_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd) -{ - Elm_Code_Line *line; - unsigned int start, end; - Elm_Code_Widget_Selection_Data *selection; - - selection = elm_code_widget_selection_normalized_get(widget); - line = elm_code_file_line_get(pd->code->file, selection->start_line); - start = elm_code_widget_line_text_position_for_column_get(widget, line, selection->start_col); - end = elm_code_widget_line_text_position_for_column_get(widget, line, selection->end_col + 1); - free(selection); - - return elm_code_line_text_substr(line, start, end - start); -} - -static char * -_elm_code_widget_selection_text_multi_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd) -{ - Elm_Code_Line *line; - char *first, *last, *ret, *ptr; - const char *newline; - short newline_len; - int ret_len; - unsigned int row, start, end; - Elm_Code_Widget_Selection_Data *selection; - - selection = elm_code_widget_selection_normalized_get(widget); - newline = elm_code_file_line_ending_chars_get(pd->code->file, &newline_len); - - line = elm_code_file_line_get(pd->code->file, selection->start_line); - start = elm_code_widget_line_text_position_for_column_get(widget, line, selection->start_col); - first = elm_code_line_text_substr(line, start, line->length - start + 1); - - line = elm_code_file_line_get(pd->code->file, selection->end_line); - end = elm_code_widget_line_text_position_for_column_get(widget, line, selection->end_col + 1); - last = elm_code_line_text_substr(line, 0, end); - - ret_len = strlen(first) + strlen(last) + newline_len; - - for (row = pd->selection->start_line + 1; row < selection->end_line; row++) - { - line = elm_code_file_line_get(pd->code->file, row); - ret_len += line->length + newline_len; - } - - ret = malloc(sizeof(char) * (ret_len + 1)); - snprintf(ret, strlen(first) + newline_len + 1, "%s%s", first, newline); - - ptr = ret; - ptr += strlen(first) + newline_len; - - for (row = selection->start_line + 1; row < selection->end_line; row++) - { - line = elm_code_file_line_get(pd->code->file, row); - if (line->modified) - snprintf(ptr, line->length + 1, "%s", line->modified); - else - snprintf(ptr, line->length + 1, "%s", line->content); - - snprintf(ptr + line->length, newline_len + 1, "%s", newline); - ptr += line->length + newline_len; - } - snprintf(ptr, strlen(last) + 1, "%s", last); - - free(selection); - free(first); - free(last); - return ret; -} - EAPI char * elm_code_widget_selection_text_get(Evas_Object *widget) { Elm_Code_Widget_Data *pd; + Elm_Code_Widget_Selection_Data *selection; + char *text; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); if (!pd->selection) return strdup(""); - if (pd->selection->start_line == pd->selection->end_line) - return _elm_code_widget_selection_text_single_get(widget, pd); - else - return _elm_code_widget_selection_text_multi_get(widget, pd); + selection = elm_code_widget_selection_normalized_get(widget); + + text = elm_code_widget_text_between_positions_get(widget, + selection->start_col, selection->start_line, + selection->end_col, selection->end_line); + + free(selection); + return text; } static void diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_text.c b/legacy/elm_code/src/lib/widget/elm_code_widget_text.c index 0ae2595563..3689e8284a 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_text.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_text.c @@ -34,6 +34,87 @@ _elm_code_widget_text_left_gutter_width_get(Eo *obj, Elm_Code_Widget_Data *pd) return width; } +static char * +_elm_code_widget_text_multi_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, + unsigned int start_col, unsigned int start_line, + unsigned int end_col, unsigned int end_line) +{ + Elm_Code_Line *line; + char *first, *last, *ret, *ptr; + const char *newline; + short newline_len; + int ret_len; + unsigned int row, start, end; + + newline = elm_code_file_line_ending_chars_get(pd->code->file, &newline_len); + + line = elm_code_file_line_get(pd->code->file, start_line); + start = elm_code_widget_line_text_position_for_column_get(widget, line, start_col); + first = elm_code_line_text_substr(line, start, line->length - start + 1); + + line = elm_code_file_line_get(pd->code->file, end_line); + end = elm_code_widget_line_text_position_for_column_get(widget, line, end_col + 1); + last = elm_code_line_text_substr(line, 0, end); + + ret_len = strlen(first) + strlen(last) + newline_len; + + for (row = pd->selection->start_line + 1; row < end_line; row++) + { + line = elm_code_file_line_get(pd->code->file, row); + ret_len += line->length + newline_len; + } + + ret = malloc(sizeof(char) * (ret_len + 1)); + + snprintf(ret, strlen(first) + newline_len + 1, "%s%s", first, newline); + + ptr = ret; + ptr += strlen(first) + newline_len; + + for (row = start_line + 1; row < end_line; row++) + { + line = elm_code_file_line_get(pd->code->file, row); + if (line->modified) + snprintf(ptr, line->length + 1, "%s", line->modified); + else + snprintf(ptr, line->length + 1, "%s", line->content); + + snprintf(ptr + line->length, newline_len + 1, "%s", newline); + ptr += line->length + newline_len; + } + snprintf(ptr, strlen(last) + 1, "%s", last); + + free(first); + free(last); + return ret; +} + +static char * +_elm_code_widget_text_single_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, + unsigned int start_col, unsigned int start_line, + unsigned int end_col) +{ + Elm_Code_Line *line; + unsigned int start, end; + + line = elm_code_file_line_get(pd->code->file, start_line); + start = elm_code_widget_line_text_position_for_column_get(widget, line, start_col); + end = elm_code_widget_line_text_position_for_column_get(widget, line, end_col + 1); + + return elm_code_line_text_substr(line, start, end - start); +} + +static char * +_elm_code_widget_text_between_positions_get(Eo *widget, Elm_Code_Widget_Data *pd, + unsigned int start_col, unsigned int start_line, + unsigned int end_col, unsigned int end_line) +{ + if (start_line == end_line) + return _elm_code_widget_text_single_get(widget, pd, start_col, start_line, end_col); + else + return _elm_code_widget_text_multi_get(widget, pd, start_col, start_line, end_col, end_line); +} + static unsigned int _elm_code_widget_line_text_column_width_to_position(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm_Code_Line *line, unsigned int position) { diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c b/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c index d51cc5ff7e..6511be7602 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c @@ -6,6 +6,19 @@ #include "elm_code_widget_private.h" +Elm_Code_Widget_Change_Info * +_elm_code_widget_undo_info_copy(Elm_Code_Widget_Change_Info *info) +{ + Elm_Code_Widget_Change_Info *copy; + + copy = calloc(1, sizeof(*info)); + memcpy(copy, info, sizeof(*info)); + copy->content = malloc(sizeof(char) * (info->length + 1)); + strncpy(copy->content, info->content, info->length); + + return copy; +} + void _elm_code_widget_undo_change_add(Evas_Object *widget, Elm_Code_Widget_Change_Info *info) @@ -13,9 +26,7 @@ _elm_code_widget_undo_change_add(Evas_Object *widget, Elm_Code_Widget_Data *pd; Elm_Code_Widget_Change_Info *info_copy; - info_copy = calloc(1, sizeof(*info)); - memcpy(info_copy, info, sizeof(*info)); - + info_copy = _elm_code_widget_undo_info_copy(info); pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); pd->undo_stack_ptr = eina_list_prepend(pd->undo_stack_ptr, info_copy); @@ -26,6 +37,10 @@ static void _elm_code_widget_undo_change(Evas_Object *widget, Elm_Code_Widget_Change_Info *info) { + Elm_Code_Line *line; + Elm_Code_Widget_Data *pd; + unsigned int position; + if (info->insert) { elm_code_widget_selection_start(widget, info->start_line, info->start_col); @@ -34,6 +49,12 @@ _elm_code_widget_undo_change(Evas_Object *widget, } else { + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + line = elm_code_file_line_get(pd->code->file, info->start_line); + position = elm_code_widget_line_text_position_for_column_get(widget, line, info->start_col); + + elm_code_line_text_insert(line, position, info->content, info->length); + elm_code_widget_cursor_position_set(widget, info->end_col, info->end_line); } } diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c index f6c13f0451..6f20909651 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c @@ -93,9 +93,55 @@ START_TEST (elm_code_test_widget_undo_newline) } END_TEST +START_TEST (elm_code_test_widget_undo_delete) +{ + Elm_Code *code; + Elm_Code_File *file; + Elm_Code_Line *line; + Elm_Code_Widget *widget; + Evas_Object *win; + unsigned int length; + const char *content; + + elm_init(1, NULL); + code = elm_code_create(); + file = elm_code_file_new(code); + elm_code_file_line_append(file, "test", 4, NULL); + + win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); + widget = elm_code_widget_add(win, code); + + elm_code_widget_cursor_position_set(widget, 4, 1); + _elm_code_widget_backspace(widget); + + line = elm_code_file_line_get(file, 1); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("tet", content, length); + + elm_code_widget_undo(widget); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("test", content, length); + + elm_code_widget_cursor_position_set(widget, 2, 1); + _elm_code_widget_delete(widget); + + line = elm_code_file_line_get(file, 1); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("tst", content, length); + + elm_code_widget_undo(widget); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("test", content, length); + + elm_code_free(code); + elm_shutdown(); +} +END_TEST + void elm_code_test_widget_undo(TCase *tc) { tcase_add_test(tc, elm_code_test_widget_undo_text_insert); tcase_add_test(tc, elm_code_test_widget_undo_newline); + tcase_add_test(tc, elm_code_test_widget_undo_delete); } From 87f719e83b02919fed4502294f54a7ebac3548b0 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 25 Feb 2016 15:50:34 +0000 Subject: [PATCH 219/254] [editor] a bunch of optimisations for redraw Avoid drawing too much in many common scenarios --- .../elm_code/src/lib/widget/elm_code_widget.c | 78 +++++++++++++++---- .../lib/widget/elm_code_widget_selection.c | 5 +- 2 files changed, 64 insertions(+), 19 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 203c1d1be4..10aa690bbd 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -415,19 +415,19 @@ _elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number) } static void -_elm_code_widget_fill(Elm_Code_Widget *widget) +_elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, unsigned int last_row) { Elm_Code_Line *line; - int w, h; + int h; unsigned int y; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); _elm_code_widget_resize(widget); - evas_object_textgrid_size_get(pd->grid, &w, &h); + h = elm_code_widget_lines_visible_get(widget); - for (y = 1; y <= (unsigned int) h && y <= elm_code_file_lines_get(pd->code->file); y++) + for (y = first_row; y <= last_row; y++) { line = elm_code_file_line_get(pd->code->file, y); @@ -439,6 +439,38 @@ _elm_code_widget_fill(Elm_Code_Widget *widget) } } +static void +_elm_code_widget_refresh(Elm_Code_Widget *widget) +{ + Evas_Coord scroll_y, scroll_h, ch; + unsigned int first_row, last_row; + + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + evas_object_textgrid_cell_size_get(pd->grid, NULL, &ch); + elm_scroller_region_get(pd->scroller, NULL, &scroll_y, NULL, &scroll_h); + + first_row = scroll_y / ch + 1; + last_row = (scroll_y + scroll_h) / ch + 1; + + if (last_row > elm_code_file_lines_get(pd->code->file)) + last_row = elm_code_file_lines_get(pd->code->file); + + _elm_code_widget_fill_range(widget, first_row, last_row); +} + +static void +_elm_code_widget_fill(Elm_Code_Widget *widget) +{ + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + _elm_code_widget_fill_range(widget, 1, elm_code_file_lines_get(pd->code->file)); +} + static Eina_Bool _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) @@ -455,7 +487,7 @@ _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, return EO_CALLBACK_CONTINUE; // FIXME refresh just the row unless we have resized (by being the result of a row append) - _elm_code_widget_fill(widget); + _elm_code_widget_refresh(widget); return EO_CALLBACK_CONTINUE; } @@ -480,6 +512,18 @@ _elm_code_widget_selection_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_De widget = (Elm_Code_Widget *)data; + _elm_code_widget_refresh(widget); + return EO_CALLBACK_CONTINUE; +} + +static Eina_Bool +_elm_code_widget_selection_clear_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + Elm_Code_Widget *widget; + + widget = (Elm_Code_Widget *)data; + _elm_code_widget_fill(widget); return EO_CALLBACK_CONTINUE; } @@ -492,7 +536,7 @@ _elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EIN widget = (Elm_Code_Widget *)data; - _elm_code_widget_fill(widget); + _elm_code_widget_refresh(widget); } static Eina_Bool @@ -703,11 +747,8 @@ _elm_code_widget_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj return; } - if (!pd->editable) - return; - - if (col > 0 && row <= elm_code_file_lines_get(pd->code->file)) - elm_code_widget_selection_start(widget, row, col); + if (pd->editable) + _elm_code_widget_clicked_editable_cb(widget, row, (unsigned int) col); } static void @@ -735,9 +776,12 @@ _elm_code_widget_mouse_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj _elm_code_widget_tooltip_text_set(widget, line->status_text); } - if (!pd->editable || !pd->selection || !event->buttons) + if (!pd->editable || !event->buttons) return; + if (!pd->selection) + if (col > 0 && row <= elm_code_file_lines_get(pd->code->file)) + elm_code_widget_selection_start(widget, row, col); elm_code_widget_selection_end(widget, row, col); } @@ -1328,7 +1372,7 @@ _elm_code_widget_focused_event_cb(void *data, Evas_Object *obj, pd->focussed = EINA_TRUE; _elm_code_widget_update_focus_directions(widget); - _elm_code_widget_fill(obj); + _elm_code_widget_refresh(obj); } static void @@ -1342,7 +1386,7 @@ _elm_code_widget_unfocused_event_cb(void *data, Evas_Object *obj, pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); pd->focussed = EINA_FALSE; - _elm_code_widget_fill(obj); + _elm_code_widget_refresh(obj); } EOLIAN static Eina_Bool @@ -1539,10 +1583,10 @@ _elm_code_widget_show_whitespace_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data * } EOLIAN static void -_elm_code_widget_tab_inserts_spaces_set(Eo *obj, Elm_Code_Widget_Data *pd, Eina_Bool spaces) +_elm_code_widget_tab_inserts_spaces_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, + Eina_Bool spaces) { pd->tab_inserts_spaces = spaces; - _elm_code_widget_fill(obj); } EOLIAN static Eina_Bool @@ -1685,7 +1729,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_widget_line_cb, obj), eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj), eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, _elm_code_widget_selection_cb, obj), - eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_cb, obj)); + eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_clear_cb, obj)); _elm_code_widget_font_set(obj, pd, NULL, 10); } diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index d4d214241b..ad7f7c46d8 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -140,9 +140,10 @@ elm_code_widget_selection_clear(Evas_Object *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - if (pd->selection) - free(pd->selection); + if (!pd->selection) + return; + free(pd->selection); pd->selection = NULL; eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget)); } From 4aa4635da41dab5e6e5d06940ae50e88c3a6737c Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 25 Feb 2016 15:51:08 +0000 Subject: [PATCH 220/254] [editor] draw line width marker after file end A ore uniform look if the marker goes all the way down the screen --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 10aa690bbd..145d6b1248 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -406,6 +406,8 @@ _elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number) cells[x].codepoint = 0; if (pd->editable && pd->focussed && pd->cursor_line == number) cells[x].bg = ELM_CODE_STATUS_TYPE_CURRENT; + else if (pd->line_width_marker == x - gutter + 1) + cells[x].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG; else cells[x].bg = ELM_CODE_STATUS_TYPE_DEFAULT; } From 99f6a6adc2cec5e8d65618b615eabc1533e8131b Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 1 Mar 2016 21:20:15 +0000 Subject: [PATCH 221/254] Update to new eo event callback signature --- legacy/elm_code/src/bin/elm_code_test_main.c | 10 ++++------ legacy/elm_code/src/lib/widget/elm_code_widget.c | 14 +++++--------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 8e2c9a0c3d..97e312c333 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -34,24 +34,22 @@ static void _append_line(Elm_Code_File *file, const char *line) } static Eina_Bool -_elm_code_test_line_clicked_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, - const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +_elm_code_test_line_clicked_cb(void *data EINA_UNUSED, const Eo_Event *event) { Elm_Code_Line *line; - line = (Elm_Code_Line *)event_info; + line = (Elm_Code_Line *)event->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, Eo *obj EINA_UNUSED, - const Eo_Event_Description *desc EINA_UNUSED, void *event_info) +_elm_code_test_line_done_cb(void *data EINA_UNUSED, const Eo_Event *event) { Elm_Code_Line *line; - line = (Elm_Code_Line *)event_info; + line = (Elm_Code_Line *)event->event_info; if (line->number == 1) elm_code_line_token_add(line, 17, 24, 1, ELM_CODE_TOKEN_TYPE_COMMENT); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 145d6b1248..034162845e 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -474,14 +474,13 @@ _elm_code_widget_fill(Elm_Code_Widget *widget) } static Eina_Bool -_elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, - const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) +_elm_code_widget_line_cb(void *data, const Eo_Event *event) { Elm_Code_Line *line; Elm_Code_Widget *widget; Eina_Bool visible; - line = (Elm_Code_Line *)event_info; + line = (Elm_Code_Line *)event->event_info; widget = (Elm_Code_Widget *)data; eo_do(widget, visible = elm_obj_code_widget_line_visible_get(line)); @@ -495,8 +494,7 @@ _elm_code_widget_line_cb(void *data, Eo *obj EINA_UNUSED, } static Eina_Bool -_elm_code_widget_file_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, - void *event_info EINA_UNUSED) +_elm_code_widget_file_cb(void *data, const Eo_Event *event EINA_UNUSED) { Elm_Code_Widget *widget; @@ -507,8 +505,7 @@ _elm_code_widget_file_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Descrip } static Eina_Bool -_elm_code_widget_selection_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, - void *event_info EINA_UNUSED) +_elm_code_widget_selection_cb(void *data, const Eo_Event *event EINA_UNUSED) { Elm_Code_Widget *widget; @@ -519,8 +516,7 @@ _elm_code_widget_selection_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_De } static Eina_Bool -_elm_code_widget_selection_clear_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, - void *event_info EINA_UNUSED) +_elm_code_widget_selection_clear_cb(void *data, const Eo_Event *event EINA_UNUSED) { Elm_Code_Widget *widget; From 12311d2eb9b3577da0c943eb80d50177ecdf6de5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 8 Mar 2016 22:53:36 +0000 Subject: [PATCH 222/254] Fix make dist --- legacy/elm_code/src/lib/Makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index 319acae178..08efd7aaee 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -66,7 +66,9 @@ BUILT_SOURCES = \ elmcodeeolianfilesdir = $(datadir)/eolian/include/elm_code-@VMAJ@ elmcodeeolianfiles_DATA = $(elm_code_eolian_files) -EXTRA_DIST = ${elmcodeeolianfiles_DATA} +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) From 8b46904ca4c4684ac083e013dc118e64abb030c2 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 10 Mar 2016 00:06:50 +0000 Subject: [PATCH 223/254] Update to latest eo syntax Thanks for the script Tom :) --- legacy/elm_code/src/bin/elm_code_test_main.c | 36 +++--- legacy/elm_code/src/lib/elm_code.c | 2 +- .../elm_code/src/lib/elm_code_diff_widget.c | 10 +- .../elm_code/src/lib/widget/elm_code_widget.c | 103 ++++++++---------- .../lib/widget/elm_code_widget_selection.c | 19 ++-- .../src/tests/widget/elm_code_test_widget.c | 2 +- 6 files changed, 73 insertions(+), 99 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 97e312c333..126f8a7c8e 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -66,12 +66,10 @@ _elm_code_test_welcome_setup(Evas_Object *parent) Elm_Code_Widget *widget; code = elm_code_create(); - widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, - elm_obj_code_widget_code_set(code)); - eo_do(widget, - elm_obj_code_widget_font_set(NULL, 12), - eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_test_line_done_cb, NULL); - eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code)); + eo_add(&widget, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget, 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_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code); _append_line(code->file, "❤ Hello World, Elm Code! ❤"); _append_line(code->file, ""); @@ -96,13 +94,11 @@ _elm_code_test_editor_setup(Evas_Object *parent) Elm_Code_Widget *widget; code = elm_code_create(); - widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, - elm_obj_code_widget_code_set(code)); - eo_do(widget, - elm_obj_code_widget_font_set(NULL, 14), - elm_obj_code_widget_editable_set(EINA_TRUE), - elm_obj_code_widget_show_whitespace_set(EINA_TRUE), - elm_obj_code_widget_line_numbers_set(EINA_TRUE)); + eo_add(&widget, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget, 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); _append_line(code->file, "Edit me :)"); _append_line(code->file, ""); @@ -125,11 +121,9 @@ _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(code)); - eo_do(widget, - elm_obj_code_widget_font_set(font_name, 11), - elm_obj_code_widget_line_numbers_set(EINA_TRUE)); + eo_add(&widget, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget, 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); @@ -150,8 +144,7 @@ _elm_code_test_diff_inline_setup(Evas_Object *parent) code = elm_code_create(); elm_code_file_open(code, path); - diff = eo_add(ELM_CODE_WIDGET_CLASS, parent, - elm_obj_code_widget_code_set(code)); + eo_add(&diff, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(diff, 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); @@ -206,8 +199,7 @@ _elm_code_test_welcome_mirror_cb(void *data, Evas_Object *obj EINA_UNUSED, void evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); widget = _elm_code_test_editor_setup(screen); - eo_do(widget, - code = elm_obj_code_widget_code_get()); + 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)); diff --git a/legacy/elm_code/src/lib/elm_code.c b/legacy/elm_code/src/lib/elm_code.c index 2d326a742e..782830ca9e 100644 --- a/legacy/elm_code/src/lib/elm_code.c +++ b/legacy/elm_code/src/lib/elm_code.c @@ -109,7 +109,7 @@ elm_code_callback_fire(Elm_Code *code, const Eo_Event_Description *signal, void EINA_LIST_FOREACH(code->widgets, item, widget) { - eo_do(widget, eo_event_callback_call(signal, data)); + eo_event_callback_call(widget, signal, data); } } diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.c b/legacy/elm_code/src/lib/elm_code_diff_widget.c index a16ecbfdf5..ac66d36413 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/src/lib/elm_code_diff_widget.c @@ -95,8 +95,7 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // 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(wcode1)); + eo_add(&widget_left, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget_left, 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); @@ -107,8 +106,7 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // 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(wcode2)); + eo_add(&widget_right, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget_right, 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); @@ -126,8 +124,8 @@ 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); - eo_do(child, elm_obj_code_widget_font_set(name, size)); + elm_obj_code_widget_font_set(child, name, size); child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_RIGHT); - eo_do(child, elm_obj_code_widget_font_set(name, size)); + elm_obj_code_widget_font_set(child, name, size); } diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 034162845e..ed19d61bfd 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -42,7 +42,7 @@ Eina_Unicode status_icons[] = { #define EO_CONSTRUCTOR_CHECK_RETURN(obj) do { \ Eina_Bool finalized; \ \ - eo_do(obj, finalized = eo_finalized_get()); \ + finalized = eo_finalized_get(obj); \ if (finalized) \ { \ ERR("This function is only allowed during construction."); \ @@ -54,15 +54,15 @@ EAPI Evas_Object * elm_code_widget_add(Evas_Object *parent, Elm_Code *code) { EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL); - Evas_Object *obj = eo_add(MY_CLASS, parent, - elm_obj_code_widget_code_set(code)); + Evas_Object *obj = NULL; + eo_add(&obj, MY_CLASS, parent, elm_obj_code_widget_code_set(obj, code)); return obj; } EOLIAN static Eo * _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd) { - obj = eo_do_super_ret(obj, ELM_CODE_WIDGET_CLASS, obj, eo_constructor()); + obj = eo_constructor(eo_super(obj, ELM_CODE_WIDGET_CLASS)); pd->cursor_line = 1; pd->cursor_col = 1; @@ -75,7 +75,7 @@ _elm_code_widget_eo_base_constructor(Eo *obj, Elm_Code_Widget_Data *pd) EOLIAN static Eo * _elm_code_widget_eo_base_finalize(Eo *obj, Elm_Code_Widget_Data *pd) { - obj = eo_do_super_ret(obj, ELM_CODE_WIDGET_CLASS, obj, eo_finalize()); + obj = eo_finalize(eo_super(obj, ELM_CODE_WIDGET_CLASS)); if (pd->code) return obj; @@ -115,7 +115,7 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - eo_do(widget, gutter = elm_obj_code_widget_text_left_gutter_width_get()); + gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); if (!pd->code) return; @@ -187,7 +187,7 @@ _elm_code_widget_fill_line_tokens(Elm_Code_Widget *widget, Evas_Textgrid_Cell *c unsigned int start, end, length, offset; unsigned int token_start_col, token_end_col; - eo_do(widget, offset = elm_obj_code_widget_text_left_gutter_width_get()); + offset = elm_obj_code_widget_text_left_gutter_width_get(widget); start = offset; length = elm_code_widget_line_text_column_width_get(widget, line) + offset; @@ -342,7 +342,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - eo_do(widget, gutter = elm_obj_code_widget_text_left_gutter_width_get()); + gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); evas_object_textgrid_size_get(pd->grid, &w, NULL); cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); @@ -395,7 +395,7 @@ _elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number) Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - eo_do(widget, gutter = elm_obj_code_widget_text_left_gutter_width_get()); + gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); evas_object_textgrid_size_get(pd->grid, &w, NULL); cells = evas_object_textgrid_cellrow_get(pd->grid, number - 1); @@ -483,7 +483,7 @@ _elm_code_widget_line_cb(void *data, const Eo_Event *event) line = (Elm_Code_Line *)event->event_info; widget = (Elm_Code_Widget *)data; - eo_do(widget, visible = elm_obj_code_widget_line_visible_get(line)); + visible = elm_obj_code_widget_line_visible_get(widget, line); if (!visible) return EO_CALLBACK_CONTINUE; @@ -602,7 +602,7 @@ _elm_code_widget_cursor_ensure_visible(Elm_Code_Widget *widget) elm_scroller_region_get(pd->scroller, &viewx, &viewy, &vieww, &viewh); evas_object_textgrid_cell_size_get(pd->grid, &cellw, &cellh); - eo_do(widget, gutter = elm_obj_code_widget_text_left_gutter_width_get()); + gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); curx = (pd->cursor_col + gutter - 1) * cellw; cury = (pd->cursor_line - 1) * cellh; @@ -626,7 +626,7 @@ _elm_code_widget_cursor_move(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, if (!was_key) _elm_code_widget_update_focus_directions(widget); - eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CURSOR_CHANGED, widget)); + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CURSOR_CHANGED, widget); _elm_code_widget_cursor_ensure_visible(widget); if (oldrow != pd->cursor_line) @@ -656,7 +656,7 @@ _elm_code_widget_position_at_coordinates_get(Elm_Code_Widget *widget, Elm_Code_W y = y + sy - oy; evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); - eo_do(widget, gutter = elm_obj_code_widget_text_left_gutter_width_get()); + gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); number = ((double) y / ch) + 1; if (col) *col = ((double) x / cw) - gutter + 1; @@ -679,7 +679,7 @@ _elm_code_widget_clicked_gutter_cb(Elm_Code_Widget *widget, unsigned int row) if (!line) return; - eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_LINE_GUTTER_CLICKED, line)); + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_LINE_GUTTER_CLICKED, line); } static void @@ -715,7 +715,7 @@ _elm_code_widget_clicked_readonly_cb(Elm_Code_Widget *widget, unsigned int row) if (!line) return; - eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, line)); + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_LINE_CLICKED, line); } static void @@ -951,7 +951,7 @@ _elm_code_widget_cursor_move_page_height_get(Elm_Code_Widget *widget) { unsigned int lines; - eo_do(widget, lines = elm_obj_code_widget_lines_visible_get()); + lines = elm_obj_code_widget_lines_visible_get(widget); return lines * 0.85; } @@ -1068,9 +1068,8 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text unsigned int row, col, position, col_width; _elm_code_widget_delete_selection(widget); - eo_do(widget, - code = elm_obj_code_widget_code_get(), - elm_obj_code_widget_cursor_position_get(&col, &row)); + code = elm_obj_code_widget_code_get(widget); + elm_obj_code_widget_cursor_position_get(widget, &col, &row); line = elm_code_file_line_get(code->file, row); if (line == NULL) { @@ -1084,9 +1083,8 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text col_width = elm_code_widget_line_text_column_width_to_position(widget, line, position + length) - elm_code_widget_line_text_column_width_to_position(widget, line, position); - eo_do(widget, - elm_obj_code_widget_cursor_position_set(col + col_width, row), - eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); + elm_obj_code_widget_cursor_position_set(widget, col + col_width, row); + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); change = _elm_code_widget_change_create(col, row, col + col_width - 1, row, text, length, EINA_TRUE); _elm_code_widget_undo_change_add(widget, change); @@ -1106,8 +1104,7 @@ _elm_code_widget_tab_at_cursor_insert(Elm_Code_Widget *widget) return; } - eo_do(widget, - elm_obj_code_widget_cursor_position_get(&col, &row)); + elm_obj_code_widget_cursor_position_get(widget, &col, &row); rem = (col - 1) % pd->tabstop; while (rem < pd->tabstop) @@ -1127,9 +1124,8 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) char *oldtext; _elm_code_widget_delete_selection(widget); - eo_do(widget, - code = elm_obj_code_widget_code_get(), - elm_obj_code_widget_cursor_position_get(&col, &row)); + code = elm_obj_code_widget_code_get(widget); + elm_obj_code_widget_cursor_position_get(widget, &col, &row); line = elm_code_file_line_get(code->file, row); if (line == NULL) { @@ -1150,10 +1146,9 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) elm_code_line_text_insert(line, 0, oldtext, leading); free(oldtext); - indent = elm_obj_code_widget_line_text_column_width_to_position(line, leading); - eo_do(widget, - elm_obj_code_widget_cursor_position_set(indent, row + 1), - eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); + indent = elm_obj_code_widget_line_text_column_width_to_position(widget, line, leading); + elm_obj_code_widget_cursor_position_set(widget, indent, row + 1); + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); change = _elm_code_widget_change_create(width + 1, row, indent - 1, row + 1, "\n", 1, EINA_TRUE); _elm_code_widget_undo_change_add(widget, change); @@ -1167,9 +1162,8 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) Elm_Code_Line *line, *oldline; unsigned int row, col, oldlength, position; - eo_do(widget, - code = elm_obj_code_widget_code_get(), - elm_obj_code_widget_cursor_position_get(&col, &row)); + code = elm_obj_code_widget_code_get(widget); + elm_obj_code_widget_cursor_position_get(widget, &col, &row); line = elm_code_file_line_get(code->file, row); if (nextline) @@ -1184,11 +1178,10 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) position = elm_code_widget_line_text_column_width_to_position(widget, oldline, oldlength); - eo_do(widget, - elm_obj_code_widget_cursor_position_set(position, row - 1)); + elm_obj_code_widget_cursor_position_set(widget, position, row - 1); } // TODO construct and pass a change object - eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); } void @@ -1203,9 +1196,8 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) if (_elm_code_widget_delete_selection(widget)) return; // TODO fire the change and log it - eo_do(widget, - code = elm_obj_code_widget_code_get(), - elm_obj_code_widget_cursor_position_get(&col, &row)); + code = elm_obj_code_widget_code_get(widget); + elm_obj_code_widget_cursor_position_get(widget, &col, &row); if (col <= 1) { @@ -1225,10 +1217,9 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) text = elm_code_widget_text_between_positions_get(widget, start_col, row, start_col, row); elm_code_line_text_remove(line, position - char_width, char_width); - eo_do(widget, - elm_obj_code_widget_cursor_position_set(start_col, row)); + elm_obj_code_widget_cursor_position_set(widget, start_col, row); - eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); change = _elm_code_widget_change_create(start_col, row, col, row, text, char_width, EINA_FALSE); _elm_code_widget_undo_change_add(widget, change); @@ -1247,9 +1238,8 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) if (_elm_code_widget_delete_selection(widget)) return; // TODO fire the change and log it - eo_do(widget, - code = elm_obj_code_widget_code_get(), - elm_obj_code_widget_cursor_position_get(&col, &row)); + code = elm_obj_code_widget_code_get(widget); + elm_obj_code_widget_cursor_position_get(widget, &col, &row); line = elm_code_file_line_get(code->file, row); if (col > elm_code_widget_line_text_column_width_get(widget, line)) { @@ -1266,9 +1256,8 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) text = elm_code_widget_text_between_positions_get(widget, start_col, row, start_col, row); elm_code_line_text_remove(line, position, char_width?char_width:1); - eo_do(widget, - elm_obj_code_widget_cursor_position_set(start_col, row), - eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); + elm_obj_code_widget_cursor_position_set(widget, start_col, row); + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); change = _elm_code_widget_change_create(start_col, row, col, row, text, char_width, EINA_FALSE); _elm_code_widget_undo_change_add(widget, change); @@ -1294,9 +1283,8 @@ _elm_code_widget_control_key_down_cb(Elm_Code_Widget *widget, const char *key) else if (!strcmp("z", key)) elm_code_widget_undo(widget); - eo_do(widget, -// TODO construct and pass a change object for cut and paste - eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL)); + // TODO construct and pass a change object for cut and paste + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); } static void @@ -1692,7 +1680,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) { Evas_Object *grid, *scroller; - eo_do_super(obj, ELM_CODE_WIDGET_CLASS, evas_obj_smart_add()); + evas_obj_smart_add(eo_super(obj, ELM_CODE_WIDGET_CLASS)); elm_object_focus_allow_set(obj, EINA_TRUE); elm_layout_file_set(obj, PACKAGE_DATA_DIR "/themes/elm_code.edj", "elm_code/layout/default"); @@ -1723,11 +1711,10 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) evas_object_smart_callback_add(obj, "focused", _elm_code_widget_focused_event_cb, obj); evas_object_smart_callback_add(obj, "unfocused", _elm_code_widget_unfocused_event_cb, obj); - eo_do(obj, - eo_event_callback_add(&ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_widget_line_cb, obj), - eo_event_callback_add(&ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj), - eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, _elm_code_widget_selection_cb, obj), - eo_event_callback_add(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_clear_cb, obj)); + eo_event_callback_add(obj, &ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_widget_line_cb, obj); + eo_event_callback_add(obj, &ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj); + eo_event_callback_add(obj, ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, _elm_code_widget_selection_cb, obj); + eo_event_callback_add(obj, ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_clear_cb, obj); _elm_code_widget_font_set(obj, pd, NULL, 10); } diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index ad7f7c46d8..8f43890008 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -62,9 +62,8 @@ elm_code_widget_selection_start(Evas_Object *widget, pd->selection->start_line = line; pd->selection->start_col = col; - eo_do(widget, - eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget), - elm_obj_code_widget_cursor_position_set(col, line)); + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget); + elm_obj_code_widget_cursor_position_set(widget, col, line); } EAPI void @@ -89,7 +88,7 @@ elm_code_widget_selection_end(Evas_Object *widget, pd->selection->end_line = line; pd->selection->end_col = col; - eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget)); + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget); } EAPI Elm_Code_Widget_Selection_Data * @@ -145,7 +144,7 @@ elm_code_widget_selection_clear(Evas_Object *widget) free(pd->selection); pd->selection = NULL; - eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget)); + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget); } static void @@ -247,7 +246,7 @@ elm_code_widget_selection_delete(Evas_Object *widget) free(pd->selection); pd->selection = NULL; - eo_do(widget, eo_event_callback_call(ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget)); + eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget); } EAPI void @@ -386,8 +385,7 @@ _selection_paste_single(Elm_Code_Widget *widget, Elm_Code *code, elm_code_line_text_insert(line, position, text, len); newcol = elm_code_widget_line_text_column_width_to_position(widget, line, position + len); - eo_do(widget, - elm_obj_code_widget_cursor_position_set(newcol, row)); + elm_obj_code_widget_cursor_position_set(widget, newcol, row); } static void @@ -436,9 +434,8 @@ _selection_paste_cb(void *data, Evas_Object *obj EINA_UNUSED, Elm_Selection_Data if (ev->len <= 0) return EINA_TRUE; - eo_do(widget, - code = elm_obj_code_widget_code_get(), - elm_obj_code_widget_cursor_position_get(&col, &row)); + code = elm_obj_code_widget_code_get(widget); + elm_obj_code_widget_cursor_position_get(widget, &col, &row); if (elm_code_text_newlinenpos(ev->data, ev->len, NULL) == ELM_CODE_TEXT_NOT_FOUND) _selection_paste_single(widget, code, col, row, ev->data, ev->len - 1); diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c index 3471e3ca2a..c65d6b835c 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c @@ -77,7 +77,7 @@ START_TEST (elm_code_widget_construct_nocode) elm_init(1, NULL); win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); - widget = eo_add(ELM_CODE_WIDGET_CLASS, win); + eo_add(&widget, ELM_CODE_WIDGET_CLASS, win); ck_assert(!widget); elm_shutdown(); From a86bef2d6a7f6379c970edfc92ad32d3bc6551c0 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 18 Mar 2016 19:42:07 +0000 Subject: [PATCH 224/254] Update to latest eo_add syntax --- legacy/elm_code/src/bin/elm_code_test_main.c | 8 ++++---- legacy/elm_code/src/lib/elm_code_diff_widget.c | 4 ++-- legacy/elm_code/src/lib/widget/elm_code_widget.c | 2 +- legacy/elm_code/src/tests/widget/elm_code_test_widget.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 126f8a7c8e..5779ee77ba 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -66,7 +66,7 @@ _elm_code_test_welcome_setup(Evas_Object *parent) Elm_Code_Widget *widget; code = elm_code_create(); - eo_add(&widget, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget, code)); + 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_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code); @@ -94,7 +94,7 @@ _elm_code_test_editor_setup(Evas_Object *parent) Elm_Code_Widget *widget; code = elm_code_create(); - eo_add(&widget, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget, code)); + 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); @@ -121,7 +121,7 @@ _elm_code_test_mirror_setup(Elm_Code *code, char *font_name, Evas_Object *parent { Elm_Code_Widget *widget; - eo_add(&widget, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget, code)); + 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); @@ -144,7 +144,7 @@ _elm_code_test_diff_inline_setup(Evas_Object *parent) code = elm_code_create(); elm_code_file_open(code, path); - eo_add(&diff, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(diff, code)); + 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); diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.c b/legacy/elm_code/src/lib/elm_code_diff_widget.c index ac66d36413..7efb84894c 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/src/lib/elm_code_diff_widget.c @@ -95,7 +95,7 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // left side of diff wcode1 = elm_code_create(); elm_code_parser_standard_add(wcode1, ELM_CODE_PARSER_STANDARD_DIFF); - eo_add(&widget_left, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget_left, wcode1)); + 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); @@ -106,7 +106,7 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // right side of diff wcode2 = elm_code_create(); elm_code_parser_standard_add(wcode2, ELM_CODE_PARSER_STANDARD_DIFF); - eo_add(&widget_right, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget_right, wcode2)); + 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); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index ed19d61bfd..1b91391f05 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -55,7 +55,7 @@ elm_code_widget_add(Evas_Object *parent, Elm_Code *code) { EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL); Evas_Object *obj = NULL; - eo_add(&obj, MY_CLASS, parent, elm_obj_code_widget_code_set(obj, code)); + obj = eo_add(MY_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code)); return obj; } diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c index c65d6b835c..3471e3ca2a 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c @@ -77,7 +77,7 @@ START_TEST (elm_code_widget_construct_nocode) elm_init(1, NULL); win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); - eo_add(&widget, ELM_CODE_WIDGET_CLASS, win); + widget = eo_add(ELM_CODE_WIDGET_CLASS, win); ck_assert(!widget); elm_shutdown(); From d689266254966212fece19850daf97585ddf0014 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 18 Mar 2016 19:42:07 +0000 Subject: [PATCH 225/254] Update to latest eo_add syntax --- legacy/elm_code/src/bin/elm_code_test_main.c | 8 ++++---- legacy/elm_code/src/lib/elm_code_diff_widget.c | 4 ++-- legacy/elm_code/src/lib/widget/elm_code_widget.c | 2 +- legacy/elm_code/src/tests/widget/elm_code_test_widget.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 126f8a7c8e..5779ee77ba 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -66,7 +66,7 @@ _elm_code_test_welcome_setup(Evas_Object *parent) Elm_Code_Widget *widget; code = elm_code_create(); - eo_add(&widget, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget, code)); + 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_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code); @@ -94,7 +94,7 @@ _elm_code_test_editor_setup(Evas_Object *parent) Elm_Code_Widget *widget; code = elm_code_create(); - eo_add(&widget, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget, code)); + 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); @@ -121,7 +121,7 @@ _elm_code_test_mirror_setup(Elm_Code *code, char *font_name, Evas_Object *parent { Elm_Code_Widget *widget; - eo_add(&widget, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget, code)); + 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); @@ -144,7 +144,7 @@ _elm_code_test_diff_inline_setup(Evas_Object *parent) code = elm_code_create(); elm_code_file_open(code, path); - eo_add(&diff, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(diff, code)); + 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); diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.c b/legacy/elm_code/src/lib/elm_code_diff_widget.c index ac66d36413..7efb84894c 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.c +++ b/legacy/elm_code/src/lib/elm_code_diff_widget.c @@ -95,7 +95,7 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // left side of diff wcode1 = elm_code_create(); elm_code_parser_standard_add(wcode1, ELM_CODE_PARSER_STANDARD_DIFF); - eo_add(&widget_left, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget_left, wcode1)); + 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); @@ -106,7 +106,7 @@ elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code) // right side of diff wcode2 = elm_code_create(); elm_code_parser_standard_add(wcode2, ELM_CODE_PARSER_STANDARD_DIFF); - eo_add(&widget_right, ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(widget_right, wcode2)); + 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); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index ed19d61bfd..1b91391f05 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -55,7 +55,7 @@ elm_code_widget_add(Evas_Object *parent, Elm_Code *code) { EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL); Evas_Object *obj = NULL; - eo_add(&obj, MY_CLASS, parent, elm_obj_code_widget_code_set(obj, code)); + obj = eo_add(MY_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code)); return obj; } diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c index c65d6b835c..3471e3ca2a 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c @@ -77,7 +77,7 @@ START_TEST (elm_code_widget_construct_nocode) elm_init(1, NULL); win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); - eo_add(&widget, ELM_CODE_WIDGET_CLASS, win); + widget = eo_add(ELM_CODE_WIDGET_CLASS, win); ck_assert(!widget); elm_shutdown(); From 30bf19285fcdb1d183a8a603c8176c358bb0aaf5 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 22 Mar 2016 13:10:04 +0000 Subject: [PATCH 226/254] Fix the local lookup of diffs in the test app. This is not portable but I think it's a temporary app anyhow --- legacy/elm_code/src/bin/Makefile.am | 1 + legacy/elm_code/src/bin/elm_code_test_main.c | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/legacy/elm_code/src/bin/Makefile.am b/legacy/elm_code/src/bin/Makefile.am index c71bf8b893..58105bcfc7 100644 --- a/legacy/elm_code/src/bin/Makefile.am +++ b/legacy/elm_code/src/bin/Makefile.am @@ -9,6 +9,7 @@ AM_CPPFLAGS = \ -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@ diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 5779ee77ba..b4bcf3039b 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -135,15 +135,10 @@ _elm_code_test_mirror_setup(Elm_Code *code, char *font_name, Evas_Object *parent static Evas_Object * _elm_code_test_diff_inline_setup(Evas_Object *parent) { - char path[PATH_MAX]; Evas_Object *diff; Elm_Code *code; - snprintf(path, sizeof(path), "%s/../edi/data/testdiff.diff", elm_app_data_dir_get()); - code = elm_code_create(); - elm_code_file_open(code, path); - 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); @@ -151,7 +146,7 @@ _elm_code_test_diff_inline_setup(Evas_Object *parent) evas_object_show(diff); elm_code_parser_standard_add(code, ELM_CODE_PARSER_STANDARD_DIFF); - elm_code_file_open(code, path); + elm_code_file_open(code, DATA_DIR "testdiff.diff"); return diff; } @@ -159,14 +154,11 @@ _elm_code_test_diff_inline_setup(Evas_Object *parent) static Evas_Object * _elm_code_test_diff_setup(Evas_Object *parent) { - char path[PATH_MAX]; Evas_Object *diff; Elm_Code *code; - snprintf(path, sizeof(path), "%s/../edi/data/testdiff.diff", elm_app_data_dir_get()); - code = elm_code_create(); - elm_code_file_open(code, path); + elm_code_file_open(code, DATA_DIR "testdiff.diff"); diff = elm_code_diff_widget_add(parent, code); return diff; From bf0a5ae4f541314f2a08739cf202f69e8f4fbe27 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 22 Mar 2016 13:10:04 +0000 Subject: [PATCH 227/254] Fix the local lookup of diffs in the test app. This is not portable but I think it's a temporary app anyhow --- legacy/elm_code/src/bin/Makefile.am | 1 + legacy/elm_code/src/bin/elm_code_test_main.c | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/legacy/elm_code/src/bin/Makefile.am b/legacy/elm_code/src/bin/Makefile.am index c71bf8b893..58105bcfc7 100644 --- a/legacy/elm_code/src/bin/Makefile.am +++ b/legacy/elm_code/src/bin/Makefile.am @@ -9,6 +9,7 @@ AM_CPPFLAGS = \ -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@ diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 5779ee77ba..b4bcf3039b 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -135,15 +135,10 @@ _elm_code_test_mirror_setup(Elm_Code *code, char *font_name, Evas_Object *parent static Evas_Object * _elm_code_test_diff_inline_setup(Evas_Object *parent) { - char path[PATH_MAX]; Evas_Object *diff; Elm_Code *code; - snprintf(path, sizeof(path), "%s/../edi/data/testdiff.diff", elm_app_data_dir_get()); - code = elm_code_create(); - elm_code_file_open(code, path); - 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); @@ -151,7 +146,7 @@ _elm_code_test_diff_inline_setup(Evas_Object *parent) evas_object_show(diff); elm_code_parser_standard_add(code, ELM_CODE_PARSER_STANDARD_DIFF); - elm_code_file_open(code, path); + elm_code_file_open(code, DATA_DIR "testdiff.diff"); return diff; } @@ -159,14 +154,11 @@ _elm_code_test_diff_inline_setup(Evas_Object *parent) static Evas_Object * _elm_code_test_diff_setup(Evas_Object *parent) { - char path[PATH_MAX]; Evas_Object *diff; Elm_Code *code; - snprintf(path, sizeof(path), "%s/../edi/data/testdiff.diff", elm_app_data_dir_get()); - code = elm_code_create(); - elm_code_file_open(code, path); + elm_code_file_open(code, DATA_DIR "testdiff.diff"); diff = elm_code_diff_widget_add(parent, code); return diff; From 6b079b2478c4d5b81bc7b30b66918e14f48f14bb Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 30 Mar 2016 03:58:39 +0100 Subject: [PATCH 228/254] [editor] split out the grid into rendered rows. This allows cool stuff to be inserted in between the rows --- .../elm_code/src/lib/widget/elm_code_widget.c | 458 ++++++++++-------- .../src/lib/widget/elm_code_widget.eo | 10 + .../src/lib/widget/elm_code_widget_private.h | 6 +- 3 files changed, 277 insertions(+), 197 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 1b91391f05..c1f82bd7a2 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -50,6 +50,8 @@ Eina_Unicode status_icons[] = { } \ } while (0) +static void _elm_code_widget_resize(Elm_Code_Widget *widget); + EAPI Evas_Object * elm_code_widget_add(Evas_Object *parent, Elm_Code *code) { @@ -90,6 +92,24 @@ _elm_code_widget_class_constructor(Eo_Class *klass EINA_UNUSED) } +void +_elm_code_widget_cell_size_get(Elm_Code_Widget *widget, Evas_Coord *width, Evas_Coord *height) +{ + Elm_Code_Widget_Data *pd; + Evas_Object *grid; + Evas_Coord w, h; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + grid = eina_list_nth(pd->grids, 0); + evas_object_textgrid_cell_size_get(grid, &w, &h); + if (w == 0) w = 5; + if (h == 0) h = 10; + + if (width) *width = w; + if (height) *height = h; +} + static void _elm_code_widget_scroll_by(Elm_Code_Widget *widget, int by_x, int by_y) { @@ -104,50 +124,6 @@ _elm_code_widget_scroll_by(Elm_Code_Widget *widget, int by_x, int by_y) elm_scroller_region_show(pd->scroller, x, y, w, h); } -static void -_elm_code_widget_resize(Elm_Code_Widget *widget) -{ - Elm_Code_Line *line; - Eina_List *item; - Evas_Coord ww, wh, old_width, old_height; - int w, h, cw, ch, gutter; - unsigned int line_width; - Elm_Code_Widget_Data *pd; - - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); - - if (!pd->code) - return; - - evas_object_geometry_get(widget, NULL, NULL, &ww, &wh); - evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); - old_width = ww; - old_height = wh; - - w = 0; - h = elm_code_file_lines_get(pd->code->file); - EINA_LIST_FOREACH(pd->code->file->lines, item, line) - { - line_width = elm_code_widget_line_text_column_width_get(widget, line); - if ((int) line_width + gutter + 1 > w) - w = (int) line_width + gutter + 1; - } - - if (w*cw > ww) - ww = w*cw; - if (h*ch > wh) - wh = h*ch; - - evas_object_textgrid_size_set(pd->grid, ww/cw+1, wh/ch+1); - evas_object_size_hint_min_set(pd->grid, w*cw, h*ch); - - if (pd->gravity_x == 1.0 || pd->gravity_y == 1.0) - _elm_code_widget_scroll_by(widget, - (pd->gravity_x == 1.0 && ww > old_width) ? ww - old_width : 0, - (pd->gravity_y == 1.0 && wh > old_height) ? wh - old_height : 0); -} - static void _elm_code_widget_fill_line_token(Evas_Textgrid_Cell *cells, int count, int start, int end, Elm_Code_Token_Type type) { @@ -216,7 +192,7 @@ _elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, int width, Elm_Code_Status_Type status, int line) { char *number = NULL; - int w, gutter, g; + int gutter, g; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); @@ -224,7 +200,6 @@ _elm_code_widget_fill_gutter(Elm_Code_Widget *widget, Evas_Textgrid_Cell *cells, if (width < gutter) return; - evas_object_textgrid_size_get(pd->grid, &w, NULL); cells[gutter-1].codepoint = status_icons[status]; cells[gutter-1].bold = 1; @@ -336,16 +311,20 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) { char *chr; Eina_Unicode unichr; - unsigned int length, x, charwidth, i; - int w, chrpos, gutter; + unsigned int length, x, charwidth, i, w; + int chrpos, gutter; + Evas_Object *grid; Evas_Textgrid_Cell *cells; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); + if (eina_list_count(pd->grids) < line->number) + return; - evas_object_textgrid_size_get(pd->grid, &w, NULL); - cells = evas_object_textgrid_cellrow_get(pd->grid, line->number - 1); + w = elm_code_widget_columns_get(widget); + grid = eina_list_nth(pd->grids, line->number - 1); + cells = evas_object_textgrid_cellrow_get(grid, 0); _elm_code_widget_fill_gutter(widget, cells, w, line->status, line->number); _elm_code_widget_fill_line_tokens(widget, cells, w, line); @@ -383,51 +362,18 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) if (line->number < elm_code_file_lines_get(line->file)) _elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]); - evas_object_textgrid_update_add(pd->grid, 0, line->number - 1, w, 1); -} - -static void -_elm_code_widget_empty_line(Elm_Code_Widget *widget, unsigned int number) -{ - unsigned int x; - int w, gutter; - Evas_Textgrid_Cell *cells; - Elm_Code_Widget_Data *pd; - - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); - - evas_object_textgrid_size_get(pd->grid, &w, NULL); - cells = evas_object_textgrid_cellrow_get(pd->grid, number - 1); - _elm_code_widget_fill_gutter(widget, cells, w, ELM_CODE_STATUS_TYPE_DEFAULT, 0); - - for (x = gutter; x < (unsigned int) w; x++) - { - cells[x].codepoint = 0; - if (pd->editable && pd->focussed && pd->cursor_line == number) - cells[x].bg = ELM_CODE_STATUS_TYPE_CURRENT; - else if (pd->line_width_marker == x - gutter + 1) - cells[x].bg = ELM_CODE_WIDGET_COLOR_GUTTER_BG; - else - cells[x].bg = ELM_CODE_STATUS_TYPE_DEFAULT; - } - - _elm_code_widget_fill_cursor(widget, number, cells, gutter, w); - evas_object_textgrid_update_add(pd->grid, 0, number - 1, w, 1); + evas_object_textgrid_update_add(grid, 0, 0, w, 1); } static void _elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, unsigned int last_row) { Elm_Code_Line *line; - int h; unsigned int y; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - _elm_code_widget_resize(widget); - h = elm_code_widget_lines_visible_get(widget); for (y = first_row; y <= last_row; y++) { @@ -435,10 +381,6 @@ _elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, uns _elm_code_widget_fill_line(widget, line); } - for (; y <= (unsigned int) h; y++) - { - _elm_code_widget_empty_line(widget, y); - } } static void @@ -451,7 +393,7 @@ _elm_code_widget_refresh(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - evas_object_textgrid_cell_size_get(pd->grid, NULL, &ch); + _elm_code_widget_cell_size_get(widget, NULL, &ch); elm_scroller_region_get(pd->scroller, NULL, &scroll_y, NULL, &scroll_h); first_row = scroll_y / ch + 1; @@ -600,7 +542,7 @@ _elm_code_widget_cursor_ensure_visible(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); elm_scroller_region_get(pd->scroller, &viewx, &viewy, &vieww, &viewh); - evas_object_textgrid_cell_size_get(pd->grid, &cellw, &cellh); + _elm_code_widget_cell_size_get(widget, &cellw, &cellh); gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); curx = (pd->cursor_col + gutter - 1) * cellw; @@ -634,8 +576,6 @@ _elm_code_widget_cursor_move(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, code = pd->code; if (oldrow <= elm_code_file_lines_get(code->file)) _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, oldrow)); - else - _elm_code_widget_empty_line(widget, oldrow); } _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, pd->cursor_line)); } @@ -645,19 +585,37 @@ _elm_code_widget_position_at_coordinates_get(Elm_Code_Widget *widget, Elm_Code_W Evas_Coord x, Evas_Coord y, unsigned int *row, int *col) { + Eina_List *item; Elm_Code_Line *line; - Evas_Coord ox, oy, sx, sy; + Evas_Coord ox, oy, sx, sy, rowy; + Evas_Object *grid; int cw, ch, gutter; - unsigned int number; + unsigned int guess, number; evas_object_geometry_get(widget, &ox, &oy, NULL, NULL); elm_scroller_region_get(pd->scroller, &sx, &sy, NULL, NULL); x = x + sx - ox; y = y + sy - oy; - evas_object_textgrid_cell_size_get(pd->grid, &cw, &ch); + _elm_code_widget_cell_size_get(widget, &cw, &ch); gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); - number = ((double) y / ch) + 1; + + guess = ((double) y / ch) + 1; + number = guess; + + // unfortunately EINA_LIST_REVERSE_FOREACH skips to the end of the list... + for (item = eina_list_nth_list(pd->grids, guess - 1), grid = eina_list_data_get(item); + item; + item = eina_list_prev(item), grid = eina_list_data_get(item)) + { + evas_object_geometry_get(grid, NULL, &rowy, NULL, NULL); + + if (rowy - oy < y) + break; + + number--; + } + if (col) *col = ((double) x / cw) - gutter + 1; if (row) @@ -1406,6 +1364,182 @@ _elm_code_widget_elm_widget_focus_direction_manager_is(Eo *obj EINA_UNUSED, return EINA_TRUE; } +static void +_elm_code_widget_setup_palette(Evas_Object *o) +{ + double feint = 0.5; + + // setup status colors + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, + 36, 36, 36, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CURRENT, + 12, 12, 12, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_IGNORED, + 36, 36, 36, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_NOTE, + 255, 153, 0, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_WARNING, + 255, 153, 0, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ERROR, + 205, 54, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FATAL, + 205, 54, 54, 255); + + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ADDED, + 36, 96, 36, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_REMOVED, + 96, 36, 36, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CHANGED, + 36, 36, 96, 255); + + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_PASSED, + 54, 96, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FAILED, + 96, 54, 54, 255); + + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_TODO, + 54, 54, 96, 255); + + // setup token colors + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT, + 205, 205, 205, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_COMMENT, + 51, 153, 255, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_STRING, + 255, 90, 53, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_NUMBER, + 212, 212, 42, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_BRACE, + 101, 101, 101, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_TYPE, + 51, 153, 255, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CLASS, + 114, 170, 212, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_FUNCTION, + 114, 170, 212, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_PARAM, + 255, 255, 255, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_KEYWORD, + 255, 153, 0, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_PREPROCESSOR, + 0, 176, 0, 255); + + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_ADDED, + 54, 255, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_REMOVED, + 255, 54, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CHANGED, + 54, 54, 255, 255); + + // other styles that the widget uses + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_CURSOR, + 205, 205, 54, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_SELECTION, + 51, 153, 255, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_BG, + 75, 75, 75, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_FG, + 139, 139, 139, 255); + evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_WHITESPACE, + 101 * feint, 101 * feint, 101 * feint, 255 * feint); +} + +static void +_elm_code_widget_ensure_n_grid_rows(Elm_Code_Widget *widget, int rows) +{ + Evas_Object *grid; + int existing, i; + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + existing = eina_list_count(pd->grids); + + // trim unneeded rows in our rendering + if (rows < existing) + { + for (i = existing - rows; i > 0; i--) + { + grid = eina_list_data_get(eina_list_last(pd->grids)); + evas_object_hide(grid); + elm_box_unpack(pd->gridbox, grid); + pd->grids = eina_list_remove_list(pd->grids, eina_list_last(pd->grids)); + } + rows = existing; + } + + if (rows == existing) + return; + + for (int i = existing; i < rows; i++) + { + grid = evas_object_textgrid_add(pd->gridbox); + evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, 0.0); + evas_object_show(grid); + _elm_code_widget_setup_palette(grid); + + elm_box_pack_end(pd->gridbox, grid); + pd->grids = eina_list_append(pd->grids, grid); + + evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_DOWN, _elm_code_widget_mouse_down_cb, widget); + evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_MOVE, _elm_code_widget_mouse_move_cb, widget); + evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_mouse_up_cb, widget); + + evas_object_textgrid_font_set(grid, pd->font_name, pd->font_size * elm_config_scale_get()); + } +} + +static void +_elm_code_widget_resize(Elm_Code_Widget *widget) +{ + Elm_Code_Line *line; + Eina_List *item; + Evas_Object *grid; + Evas_Coord ww, wh, old_width, old_height; + int w, h, cw, ch, gutter; + unsigned int line_width; + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); + + if (!pd->code) + return; + + evas_object_geometry_get(widget, NULL, NULL, &ww, &wh); + + old_width = ww; + old_height = wh; + + w = 0; + h = elm_code_file_lines_get(pd->code->file); + EINA_LIST_FOREACH(pd->code->file->lines, item, line) + { + line_width = elm_code_widget_line_text_column_width_get(widget, line); + if ((int) line_width + gutter + 1 > w) + w = (int) line_width + gutter + 1; + } + + _elm_code_widget_ensure_n_grid_rows(widget, h); + _elm_code_widget_cell_size_get(widget, &cw, &ch); + if (w*cw > ww) + ww = w*cw; + if (h*ch > wh) + wh = h*ch; + pd->col_count = ww/cw + 1; + + EINA_LIST_FOREACH(pd->grids, item, grid) + { + evas_object_textgrid_size_set(grid, pd->col_count, 1); + evas_object_size_hint_min_set(grid, w*cw, ch); + } + + if (pd->gravity_x == 1.0 || pd->gravity_y == 1.0) + _elm_code_widget_scroll_by(widget, + (pd->gravity_x == 1.0 && ww > old_width) ? ww - old_width : 0, + (pd->gravity_y == 1.0 && wh > old_height) ? wh - old_height : 0); +} + EOAPI void _elm_code_widget_line_refresh(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm_Code_Line *line) { @@ -1413,12 +1547,12 @@ _elm_code_widget_line_refresh(Eo *obj, Elm_Code_Widget_Data *pd EINA_UNUSED, Elm } EOAPI Eina_Bool -_elm_code_widget_line_visible_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, Elm_Code_Line *line) +_elm_code_widget_line_visible_get(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code_Line *line) { Evas_Coord cellh, viewy, viewh; elm_scroller_region_get(pd->scroller, NULL, &viewy, NULL, &viewh); - evas_object_textgrid_cell_size_get(pd->grid, NULL, &cellh); + _elm_code_widget_cell_size_get(obj, NULL, &cellh); if (((int)line->number - 1) * cellh > viewy + viewh || (int)line->number * cellh < viewy) return EINA_FALSE; @@ -1427,25 +1561,31 @@ _elm_code_widget_line_visible_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, } EOAPI unsigned int -_elm_code_widget_lines_visible_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) +_elm_code_widget_lines_visible_get(Eo *obj, Elm_Code_Widget_Data *pd) { Evas_Coord cellh, viewh; elm_scroller_region_get(pd->scroller, NULL, NULL, NULL, &viewh); - evas_object_textgrid_cell_size_get(pd->grid, NULL, &cellh); + _elm_code_widget_cell_size_get(obj, NULL, &cellh); - return viewh / cellh; + return viewh / cellh + 1; } EOLIAN static void _elm_code_widget_font_set(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, const char *name, Evas_Font_Size size) { + Eina_List *item; + Evas_Object *grid; + const char *face = name; if (!face) face = "Mono"; - evas_object_textgrid_font_set(pd->grid, face, size * elm_config_scale_get()); + EINA_LIST_FOREACH(pd->grids, item, grid) + { + evas_object_textgrid_font_set(grid, face, size * elm_config_scale_get()); + } if (pd->font_name) eina_stringshare_del((char *)pd->font_name); pd->font_name = eina_stringshare_add(face); @@ -1462,6 +1602,12 @@ _elm_code_widget_font_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd, *size = pd->font_size; } +EOLIAN static unsigned int +_elm_code_widget_columns_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd) +{ + return pd->col_count; +} + EOLIAN static void _elm_code_widget_code_set(Eo *obj, Elm_Code_Widget_Data *pd, Elm_Code *code) { @@ -1594,91 +1740,10 @@ _elm_code_widget_cursor_position_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data * *line = pd->cursor_line; } -static void -_elm_code_widget_setup_palette(Evas_Object *o) -{ - double feint = 0.5; - - // setup status colors - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_DEFAULT, - 36, 36, 36, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CURRENT, - 12, 12, 12, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_IGNORED, - 36, 36, 36, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_NOTE, - 255, 153, 0, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_WARNING, - 255, 153, 0, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ERROR, - 205, 54, 54, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FATAL, - 205, 54, 54, 255); - - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_ADDED, - 36, 96, 36, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_REMOVED, - 96, 36, 36, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_CHANGED, - 36, 36, 96, 255); - - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_PASSED, - 54, 96, 54, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_FAILED, - 96, 54, 54, 255); - - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_STATUS_TYPE_TODO, - 54, 54, 96, 255); - - // setup token colors - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_DEFAULT, - 205, 205, 205, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_COMMENT, - 51, 153, 255, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_STRING, - 255, 90, 53, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_NUMBER, - 212, 212, 42, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_BRACE, - 101, 101, 101, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_TYPE, - 51, 153, 255, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CLASS, - 114, 170, 212, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_FUNCTION, - 114, 170, 212, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_PARAM, - 255, 255, 255, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_KEYWORD, - 255, 153, 0, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_PREPROCESSOR, - 0, 176, 0, 255); - - - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_ADDED, - 54, 255, 54, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_REMOVED, - 255, 54, 54, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_TOKEN_TYPE_CHANGED, - 54, 54, 255, 255); - - // other styles that the widget uses - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_CURSOR, - 205, 205, 54, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_SELECTION, - 51, 153, 255, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_BG, - 75, 75, 75, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_GUTTER_FG, - 139, 139, 139, 255); - evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, ELM_CODE_WIDGET_COLOR_WHITESPACE, - 101 * feint, 101 * feint, 101 * feint, 255 * feint); -} - EOLIAN static void _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) { - Evas_Object *grid, *scroller; + Evas_Object *background, *gridrows, *scroller; evas_obj_smart_add(eo_super(obj, ELM_CODE_WIDGET_CLASS)); elm_object_focus_allow_set(obj, EINA_TRUE); @@ -1693,19 +1758,22 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) elm_object_focus_allow_set(scroller, EINA_FALSE); pd->scroller = scroller; - grid = evas_object_textgrid_add(obj); - evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(grid); + background = elm_bg_add(scroller); + evas_object_color_set(background, 145, 145, 145, 255); + evas_object_size_hint_weight_set(background, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(background, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(background); + elm_object_part_content_set(scroller, "elm.swallow.background", background); + + gridrows = elm_box_add(scroller); + evas_object_size_hint_weight_set(gridrows, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(gridrows, EVAS_HINT_FILL, 0.0); + elm_object_content_set(scroller, gridrows); + pd->gridbox = gridrows; + _elm_code_widget_tooltip_add(obj); - elm_object_content_set(scroller, grid); - pd->grid = grid; - _elm_code_widget_setup_palette(grid); evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, obj); - evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_DOWN, _elm_code_widget_mouse_down_cb, obj); - evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_MOVE, _elm_code_widget_mouse_move_cb, obj); - evas_object_event_callback_add(grid, EVAS_CALLBACK_MOUSE_UP, _elm_code_widget_mouse_up_cb, obj); evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget_key_down_cb, obj); evas_object_smart_callback_add(obj, "focused", _elm_code_widget_focused_event_cb, obj); @@ -1715,8 +1783,6 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) eo_event_callback_add(obj, &ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj); eo_event_callback_add(obj, ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, _elm_code_widget_selection_cb, obj); eo_event_callback_add(obj, ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_clear_cb, obj); - - _elm_code_widget_font_set(obj, pd, NULL, 10); } #include "elm_code_widget_text.c" diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index ace043a764..b55b2fc04d 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -30,6 +30,16 @@ class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) size: Evas_Font_Size; [[The font size for the widget]] } } + @property columns { + get { + [[Get the number of columns in the widget currently. + This will be the max of the number of columns to represent the longest line and + the minimum required to fill the visible widget width.]] + } + values { + columns: uint; [[The number of columns required to render the widget]] + } + } @property gravity { set { [[Set how this widget's scroller should respond to new lines being added. diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h index b4e19007b0..1c7b2ae007 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h @@ -13,7 +13,9 @@ typedef struct typedef struct { Elm_Code *code; - Evas_Object *grid, *scroller; + Eina_List *grids; + unsigned int col_count; + Evas_Object *scroller, *gridbox; const char *font_name; Evas_Font_Size font_size; @@ -44,6 +46,8 @@ typedef struct /* Private widget methods */ +void _elm_code_widget_cell_size_get(Elm_Code_Widget *widget, Evas_Coord *width, Evas_Coord *height); + void _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text, int length); void _elm_code_widget_newline(Elm_Code_Widget *widget); From c9fb87d551f3f0186e3d987a97bfce7f8a8113a3 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 30 Mar 2016 16:44:50 +0100 Subject: [PATCH 229/254] [editor] move tooltips to inline error meessages Not perfect on refresh times but much easier to read than before --- legacy/elm_code/src/lib/Makefile.am | 1 - .../elm_code/src/lib/widget/elm_code_widget.c | 38 ++++++++++----- .../src/lib/widget/elm_code_widget_private.h | 1 - .../src/lib/widget/elm_code_widget_tooltip.c | 47 ------------------- .../src/tests/widget/elm_code_test_widget.c | 1 - 5 files changed, 25 insertions(+), 63 deletions(-) delete mode 100644 legacy/elm_code/src/lib/widget/elm_code_widget_tooltip.c diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index 08efd7aaee..91bf637d34 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -41,7 +41,6 @@ elm_code_line.c \ elm_code_text.c \ elm_code_file.c \ elm_code_parse.c \ -widget/elm_code_widget_tooltip.c \ widget/elm_code_widget_selection.c \ widget/elm_code_widget.c \ elm_code_diff_widget.c \ diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index c1f82bd7a2..a5ca616f3d 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -313,7 +313,7 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) Eina_Unicode unichr; unsigned int length, x, charwidth, i, w; int chrpos, gutter; - Evas_Object *grid; + Evas_Object *grid, *status; Evas_Textgrid_Cell *cells; Elm_Code_Widget_Data *pd; @@ -363,6 +363,29 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) _elm_code_widget_fill_whitespace(widget, '\n', &cells[length + gutter]); evas_object_textgrid_update_add(grid, 0, 0, w, 1); + + // add a status below the line if needed (and remove those no longer needed) + status = evas_object_data_get(grid, "status"); + if (line->status_text) + { + if (!status) + { + status = elm_label_add(pd->gridbox); + evas_object_size_hint_weight_set(status, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(status, 0.05, EVAS_HINT_FILL); + evas_object_show(status); + + elm_box_pack_after(pd->gridbox, status, grid); + evas_object_data_set(grid, "status", status); + } + elm_object_text_set(status, line->status_text); + } + else if (status) + { + elm_box_unpack(pd->gridbox, status); + evas_object_hide(status); + evas_object_data_set(grid, "status", NULL); + } } static void @@ -713,24 +736,15 @@ _elm_code_widget_mouse_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj { Elm_Code_Widget *widget; Elm_Code_Widget_Data *pd; - Elm_Code_Line *line; Evas_Event_Mouse_Move *event; unsigned int row; int col; - Eina_Bool hasline; widget = (Elm_Code_Widget *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); event = (Evas_Event_Mouse_Move *)event_info; - hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, event->cur.canvas.x, event->cur.canvas.y, &row, &col); - if (!hasline) - _elm_code_widget_tooltip_text_set(widget, NULL); - else - { - line = elm_code_file_line_get(pd->code->file, row); - _elm_code_widget_tooltip_text_set(widget, line->status_text); - } + _elm_code_widget_position_at_coordinates_get(widget, pd, event->cur.canvas.x, event->cur.canvas.y, &row, &col); if (!pd->editable || !event->buttons) return; @@ -1771,8 +1785,6 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) elm_object_content_set(scroller, gridrows); pd->gridbox = gridrows; - _elm_code_widget_tooltip_add(obj); - evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _elm_code_widget_resize_cb, obj); evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _elm_code_widget_key_down_cb, obj); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h index 1c7b2ae007..09c5003994 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_private.h @@ -28,7 +28,6 @@ typedef struct Eina_Bool show_whitespace, tab_inserts_spaces; Elm_Code_Widget_Selection_Data *selection; - Evas_Object *tooltip; /* Undo stack */ Eina_List *undo_stack; diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_tooltip.c b/legacy/elm_code/src/lib/widget/elm_code_widget_tooltip.c deleted file mode 100644 index 44abe9168a..0000000000 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_tooltip.c +++ /dev/null @@ -1,47 +0,0 @@ -#ifdef HAVE_CONFIG -# include "config.h" -#endif - -#include "Elm_Code.h" - -#include "elm_code_widget_private.h" - -void -_elm_code_widget_tooltip_text_set(Evas_Object *widget, const char *text) -{ - Elm_Code_Widget_Data *pd; - - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - - if (!text) - { - elm_object_tooltip_hide(widget); - return; - } - - elm_object_tooltip_show(widget); - - if (pd->tooltip) // will have been created by the callback below... - elm_object_text_set(pd->tooltip, text); -} - -static Evas_Object * -_elm_code_widget_tooltip_cb(void *data EINA_UNUSED, Evas_Object *obj, Evas_Object *tooltip) -{ - Elm_Code_Widget_Data *pd; - Evas_Object *label; - - pd = eo_data_scope_get(obj, ELM_CODE_WIDGET_CLASS); - - label = elm_label_add(tooltip); - pd->tooltip = label; - - return label; -} - -void -_elm_code_widget_tooltip_add(Evas_Object *widget) -{ - elm_object_tooltip_content_cb_set(widget, _elm_code_widget_tooltip_cb, NULL, NULL); -} - diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c index 3471e3ca2a..7f2303ff4d 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget.c @@ -5,7 +5,6 @@ #include "elm_code_suite.h" #include "widget/elm_code_widget.c" -#include "widget/elm_code_widget_tooltip.c" static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type, int id) { From ac2297e736dab95a23a253e49bcfad8196e397a7 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 7 Apr 2016 16:27:20 +0100 Subject: [PATCH 230/254] [editor] fix line geometry when scrolled --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index a5ca616f3d..7c4d681ee5 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -633,7 +633,7 @@ _elm_code_widget_position_at_coordinates_get(Elm_Code_Widget *widget, Elm_Code_W { evas_object_geometry_get(grid, NULL, &rowy, NULL, NULL); - if (rowy - oy < y) + if (rowy + sy - oy < y) break; number--; From d3ae71510cc166185975dbfaa462a69260156a8e Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 7 Apr 2016 17:43:31 +0100 Subject: [PATCH 231/254] [selection] split words on * and & also Pretty important for C... --- legacy/elm_code/src/lib/widget/elm_code_widget_selection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 8f43890008..94102342c7 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -6,7 +6,7 @@ #include "elm_code_widget_private.h" -static char _breaking_chars[] = " \t,.?!;:()[]{}"; +static char _breaking_chars[] = " \t,.?!;:*&()[]{}"; static Elm_Code_Widget_Selection_Data * _elm_code_widget_selection_new() From a1c47c1e9b05deed8b2c3930fd2f338f31485a10 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 7 Apr 2016 17:44:12 +0100 Subject: [PATCH 232/254] [help] Stub out a right-click-help UI Not looking anything up yet but we're getting started --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 6 ++++-- legacy/elm_code/src/lib/widget/elm_code_widget.eo | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 7c4d681ee5..2ce6496028 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -603,11 +603,12 @@ _elm_code_widget_cursor_move(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, _elm_code_widget_fill_line(widget, elm_code_file_line_get(pd->code->file, pd->cursor_line)); } -static Eina_Bool -_elm_code_widget_position_at_coordinates_get(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, +EOLIAN static Eina_Bool +_elm_code_widget_position_at_coordinates_get(Eo *obj, Elm_Code_Widget_Data *pd, Evas_Coord x, Evas_Coord y, unsigned int *row, int *col) { + Elm_Code_Widget *widget; Eina_List *item; Elm_Code_Line *line; Evas_Coord ox, oy, sx, sy, rowy; @@ -615,6 +616,7 @@ _elm_code_widget_position_at_coordinates_get(Elm_Code_Widget *widget, Elm_Code_W int cw, ch, gutter; unsigned int guess, number; + widget = (Elm_Code_Widget *)obj; evas_object_geometry_get(widget, &ox, &oy, NULL, NULL); elm_scroller_region_get(pd->scroller, &sx, &sy, NULL, NULL); x = x + sx - ox; diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index b55b2fc04d..6354ecdb63 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -177,6 +177,16 @@ class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) lines_visible_get { return: uint; [[the number of lines currently visible in the widget.]] } + position_at_coordinates_get { + [[get the row, col position for a given coordinate on the widget.]] + params { + x: Evas_Coord; [[the x coordinate in the widget]] + y: Evas_Coord; [[the y coordinate in the widget]] + row: uint *; [[the row for the coordinates]] + col: int *; [[the column for the coordinates]] + } + return: bool; [[true if a line exists at these coordinates]] + } //text functions text_left_gutter_width_get { From 6871f68ffc42bfc515214643ee3466d2b142c802 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Sat, 9 Apr 2016 09:48:15 +0900 Subject: [PATCH 233/254] remove duplicated variable declaration. --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 2ce6496028..abb766b376 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1486,7 +1486,7 @@ _elm_code_widget_ensure_n_grid_rows(Elm_Code_Widget *widget, int rows) if (rows == existing) return; - for (int i = existing; i < rows; i++) + for (i = existing; i < rows; i++) { grid = evas_object_textgrid_add(pd->gridbox); evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, 0.0); From ea16ca83dc074031cafb5a3597d3cec99bffb4be Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Thu, 14 Apr 2016 10:48:33 +0900 Subject: [PATCH 234/254] fix build break. eo event interface has been changed. just updated it. --- legacy/elm_code/src/bin/elm_code_test_main.c | 4 ++-- legacy/elm_code/src/lib/widget/elm_code_widget.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index b4bcf3039b..a1840a6b2a 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -38,7 +38,7 @@ _elm_code_test_line_clicked_cb(void *data EINA_UNUSED, const Eo_Event *event) { Elm_Code_Line *line; - line = (Elm_Code_Line *)event->event_info; + line = (Elm_Code_Line *)event->info; printf("CLICKED line %d\n", line->number); return EO_CALLBACK_CONTINUE; @@ -49,7 +49,7 @@ _elm_code_test_line_done_cb(void *data EINA_UNUSED, const Eo_Event *event) { Elm_Code_Line *line; - line = (Elm_Code_Line *)event->event_info; + line = (Elm_Code_Line *)event->info; if (line->number == 1) elm_code_line_token_add(line, 17, 24, 1, ELM_CODE_TOKEN_TYPE_COMMENT); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index abb766b376..6433f2dcd7 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -445,7 +445,7 @@ _elm_code_widget_line_cb(void *data, const Eo_Event *event) Elm_Code_Widget *widget; Eina_Bool visible; - line = (Elm_Code_Line *)event->event_info; + line = (Elm_Code_Line *)event->info; widget = (Elm_Code_Widget *)data; visible = elm_obj_code_widget_line_visible_get(widget, line); From 2987e4e7d87f6ee0b95df2aa41021b468d824240 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 24 Apr 2016 22:48:58 +0100 Subject: [PATCH 235/254] Update to latest eo specs --- .../src/lib/widget/elm_code_widget.eo | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index 6354ecdb63..fad17477c2 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -1,3 +1,10 @@ +import evas_types; +import edje_types; +import elm_interface_scrollable; + +struct @extern Elm_Code; /* The main interface currently defined in code */ +struct @extern Elm_Code_Line; /* Parts of the interface currently defined in code */ + class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) { eo_prefix: elm_obj_code_widget; @@ -27,7 +34,7 @@ class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) } values { name: const(char) *; [[The name of the font to load]] - size: Evas_Font_Size; [[The font size for the widget]] + size: Evas.Font.Size; [[The font size for the widget]] } } @property columns { @@ -63,8 +70,8 @@ class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) [[Get the widget's policy for scrollbar visibility.]] } values { - policy_h: Elm_Scroller_Policy; [[The horizontal scrollbar visibility policy]] - policy_v: Elm_Scroller_Policy; [[The vertical scrollbar visibility policy]] + policy_h: Elm.Scroller.Policy; [[The horizontal scrollbar visibility policy]] + policy_v: Elm.Scroller.Policy; [[The vertical scrollbar visibility policy]] } } @property tabstop { @@ -98,7 +105,7 @@ class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) still be manipulated by a different widget or the filesystem.]] } values { - editable: Eina_Bool; [[The editable state of the widget]] + editable: bool; [[The editable state of the widget]] } } @property line_numbers { @@ -112,7 +119,7 @@ class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) [[Get the status of line number display for this widget.]] } values { - line_numbers: Eina_Bool; [[Whether or not line numbers (or their placeholder) should be shown]] + line_numbers: bool; [[Whether or not line numbers (or their placeholder) should be shown]] } } @property line_width_marker { @@ -137,7 +144,7 @@ class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) [[Get whether or not white space will be visible.]] } values { - show_whitespace: Eina_Bool; [[Whether or not we show whitespace characters]] + show_whitespace: bool; [[Whether or not we show whitespace characters]] } } @property tab_inserts_spaces { @@ -148,7 +155,7 @@ class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) [[Get whether or not space characters will be inserted instead of tabs.]] } values { - tab_inserts_spaces: Eina_Bool; [[EINA_TRUE if we should insert space characters instead of a tab when the Tab key is pressed]] + tab_inserts_spaces: bool; [[EINA_TRUE if we should insert space characters instead of a tab when the Tab key is pressed]] } } @property cursor_position { @@ -180,8 +187,8 @@ class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) position_at_coordinates_get { [[get the row, col position for a given coordinate on the widget.]] params { - x: Evas_Coord; [[the x coordinate in the widget]] - y: Evas_Coord; [[the y coordinate in the widget]] + x: Evas.Coord; [[the x coordinate in the widget]] + y: Evas.Coord; [[the y coordinate in the widget]] row: uint *; [[the row for the coordinates]] col: int *; [[the column for the coordinates]] } From b2eb741a30e424ee4e0fd9f356c08ea0ecee1912 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 28 Apr 2016 22:32:43 +0100 Subject: [PATCH 236/254] [editor] Stop jumping around on click If there were many errors in the file the visibility calculations got screwy --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 6433f2dcd7..175849e515 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -558,18 +558,23 @@ static void _elm_code_widget_cursor_ensure_visible(Elm_Code_Widget *widget) { Evas_Coord viewx, viewy, vieww, viewh, cellw, cellh; - Evas_Coord curx, cury; + Evas_Coord curx, cury, oy, rowy; + Evas_Object *grid; Elm_Code_Widget_Data *pd; int gutter; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + evas_object_geometry_get(widget, NULL, &oy, NULL, NULL); elm_scroller_region_get(pd->scroller, &viewx, &viewy, &vieww, &viewh); _elm_code_widget_cell_size_get(widget, &cellw, &cellh); + grid = eina_list_data_get(eina_list_nth_list(pd->grids, pd->cursor_line - 1)); + evas_object_geometry_get(grid, NULL, &rowy, NULL, NULL); + gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); curx = (pd->cursor_col + gutter - 1) * cellw; - cury = (pd->cursor_line - 1) * cellh; + cury = rowy + viewy - oy; if (curx >= viewx && cury >= viewy && curx + cellw <= viewx + vieww && cury + cellh <= viewy + viewh) return; From 006372ae26cbb48b38de989ef1b0d8bed151459d Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 28 Apr 2016 22:51:03 +0100 Subject: [PATCH 237/254] [editor] fix issue where selections didn't refresh Around the extremities of the ui it was possible to not refresh correctly - fixed. --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 175849e515..daf7b18acb 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -409,18 +409,20 @@ _elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, uns static void _elm_code_widget_refresh(Elm_Code_Widget *widget) { - Evas_Coord scroll_y, scroll_h, ch; + Evas_Coord scroll_y, scroll_h, oy; unsigned int first_row, last_row; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - _elm_code_widget_cell_size_get(widget, NULL, &ch); + evas_object_geometry_get(widget, NULL, &oy, NULL, NULL); elm_scroller_region_get(pd->scroller, NULL, &scroll_y, NULL, &scroll_h); + if (scroll_h == 0) + return; - first_row = scroll_y / ch + 1; - last_row = (scroll_y + scroll_h) / ch + 1; + elm_code_widget_position_at_coordinates_get(widget, 0, oy, &first_row, NULL); + elm_code_widget_position_at_coordinates_get(widget, 0, oy + scroll_h, &last_row, NULL); if (last_row > elm_code_file_lines_get(pd->code->file)) last_row = elm_code_file_lines_get(pd->code->file); @@ -640,7 +642,7 @@ _elm_code_widget_position_at_coordinates_get(Eo *obj, Elm_Code_Widget_Data *pd, { evas_object_geometry_get(grid, NULL, &rowy, NULL, NULL); - if (rowy + sy - oy < y) + if (rowy + sy - oy - 1<= y) break; number--; From d5944ab4741f86994768a4227f96817c66858994 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 14 May 2016 11:20:08 +0100 Subject: [PATCH 238/254] Fix build for latest API --- legacy/elm_code/src/lib/widget/elm_code_widget.eo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/legacy/elm_code/src/lib/widget/elm_code_widget.eo index fad17477c2..65dd56a780 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.eo @@ -5,7 +5,7 @@ import elm_interface_scrollable; struct @extern Elm_Code; /* The main interface currently defined in code */ struct @extern Elm_Code_Line; /* Parts of the interface currently defined in code */ -class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) +class Elm.Code_Widget (Elm.Layout, Elm.Interface.Atspi.Text) { eo_prefix: elm_obj_code_widget; legacy_prefix: elm_code_widget; @@ -245,7 +245,7 @@ class Elm.Code_Widget (Elm.Layout, Elm.Interface_Atspi_Text) class.constructor; Eo.Base.constructor; Eo.Base.finalize; - Evas.Object_Smart.add; + Evas.Object.Smart.add; Elm.Widget.event; Elm.Widget.focus_next_manager_is; Elm.Widget.focus_direction_manager_is; From c9ba79af9113df498f3524c4da7c8602c66e1283 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ANDRE Date: Mon, 16 May 2016 01:24:42 +0900 Subject: [PATCH 239/254] tests: add a test case for log viewer there is a bug that i'm tracking down... this is a good test case for it --- legacy/elm_code/src/bin/elm_code_test_main.c | 86 +++++++++++++++++--- 1 file changed, 76 insertions(+), 10 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index a1840a6b2a..92049d5001 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -87,7 +87,7 @@ _elm_code_test_welcome_setup(Evas_Object *parent) } static Evas_Object * -_elm_code_test_editor_setup(Evas_Object *parent) +_elm_code_test_editor_setup(Evas_Object *parent, Eina_Bool log) { Elm_Code *code; Elm_Code_Line *line; @@ -100,14 +100,17 @@ _elm_code_test_editor_setup(Evas_Object *parent) elm_obj_code_widget_show_whitespace_set(widget, EINA_TRUE); elm_obj_code_widget_line_numbers_set(widget, EINA_TRUE); - _append_line(code->file, "Edit me :)"); - _append_line(code->file, ""); - _append_line(code->file, ""); - _append_line(code->file, "...Please?"); + 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); + 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); @@ -164,6 +167,36 @@ _elm_code_test_diff_setup(Evas_Object *parent) 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) { @@ -172,7 +205,31 @@ _elm_code_test_welcome_editor_cb(void *data, Evas_Object *obj EINA_UNUSED, void 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)); + 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", @@ -190,7 +247,7 @@ _elm_code_test_welcome_mirror_cb(void *data, Evas_Object *obj EINA_UNUSED, void 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); + widget = _elm_code_test_editor_setup(screen, EINA_FALSE); code = elm_obj_code_widget_code_get(widget); elm_box_pack_end(screen, widget); @@ -264,6 +321,15 @@ elm_code_test_win_setup(void) 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); From 828bfb4d272bbb064a4a4b0b4eef03bfb9061425 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ANDRE Date: Mon, 16 May 2016 18:03:25 +0900 Subject: [PATCH 240/254] elm_code: Fix log test case An uninitialized variable was causing all the trouble. Somehow I believe this is not the complete fix, as grid probably shouldn't be NULL. --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index daf7b18acb..025ca910a4 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -97,7 +97,7 @@ _elm_code_widget_cell_size_get(Elm_Code_Widget *widget, Evas_Coord *width, Evas_ { Elm_Code_Widget_Data *pd; Evas_Object *grid; - Evas_Coord w, h; + Evas_Coord w = 0, h = 0; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); From b1cc9c787683e3c4d538018547e273f96401ba4c Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 16 May 2016 11:01:12 +0100 Subject: [PATCH 241/254] [elm_code] don't double free standard parsers --- legacy/elm_code/src/lib/elm_code.c | 2 +- legacy/elm_code/src/lib/elm_code_parse.c | 12 ++++++++++++ legacy/elm_code/src/lib/elm_code_private.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/legacy/elm_code/src/lib/elm_code.c b/legacy/elm_code/src/lib/elm_code.c index 782830ca9e..598f928622 100644 --- a/legacy/elm_code/src/lib/elm_code.c +++ b/legacy/elm_code/src/lib/elm_code.c @@ -95,7 +95,7 @@ elm_code_free(Elm_Code *code) EINA_LIST_FREE(code->parsers, parser) { - free(parser); + _elm_code_parser_free(parser); } free(code); diff --git a/legacy/elm_code/src/lib/elm_code_parse.c b/legacy/elm_code/src/lib/elm_code_parse.c index 87627f75ef..f7fd97ee77 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.c +++ b/legacy/elm_code/src/lib/elm_code_parse.c @@ -13,6 +13,7 @@ struct _Elm_Code_Parser void (*parse_file)(Elm_Code_File *, void *); void *data; + Eina_Bool standard; }; @@ -69,6 +70,7 @@ _elm_code_parser_new(void (*parse_line)(Elm_Code_Line *, void *), parser->parse_line = parse_line; parser->parse_file = parse_file; + parser->standard = EINA_FALSE; return parser; } @@ -95,6 +97,7 @@ elm_code_parser_standard_add(Elm_Code *code, Elm_Code_Parser *parser) if (!parser || !code) return; + parser->standard = EINA_TRUE; code->parsers = eina_list_append(code->parsers, parser); } @@ -185,6 +188,15 @@ _elm_code_parser_todo_parse_line(Elm_Code_Line *line, void *data EINA_UNUSED) elm_code_line_status_set(line, ELM_CODE_STATUS_TYPE_TODO); } +void +_elm_code_parser_free(Elm_Code_Parser *parser) +{ + if (parser->standard) + return; + + free(parser); +} + void _elm_code_parse_setup() { diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h index 372f78c02e..39f89bdd5e 100644 --- a/legacy/elm_code/src/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -34,5 +34,6 @@ void _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file); void _elm_code_parse_reset_file(Elm_Code *code, Elm_Code_File *file); +void _elm_code_parser_free(Elm_Code_Parser *parser); #endif From 38810142b392ea178bad3177367f1de6cae40e1e Mon Sep 17 00:00:00 2001 From: Jean-Philippe ANDRE Date: Mon, 16 May 2016 19:28:11 +0900 Subject: [PATCH 242/254] elm_code: Fix scroller size when appending new lines This tries to optimize the new box size calc in case we're adding a new line, by not walking all the objects again. --- .../elm_code/src/lib/widget/elm_code_widget.c | 67 +++++++++++++------ 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 025ca910a4..4593a83af2 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -50,7 +50,7 @@ Eina_Unicode status_icons[] = { } \ } while (0) -static void _elm_code_widget_resize(Elm_Code_Widget *widget); +static void _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline); EAPI Evas_Object * elm_code_widget_add(Evas_Object *parent, Elm_Code *code) @@ -389,14 +389,19 @@ _elm_code_widget_fill_line(Elm_Code_Widget *widget, Elm_Code_Line *line) } static void -_elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, unsigned int last_row) +_elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, unsigned int last_row, + Elm_Code_Line *newline) { Elm_Code_Line *line; unsigned int y; Elm_Code_Widget_Data *pd; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - _elm_code_widget_resize(widget); + _elm_code_widget_resize(widget, newline); + + // if called from new line cb, no need to update whole range unless visible + if (newline && !elm_obj_code_widget_line_visible_get(widget, newline)) + return; for (y = first_row; y <= last_row; y++) { @@ -407,7 +412,7 @@ _elm_code_widget_fill_range(Elm_Code_Widget *widget, unsigned int first_row, uns } static void -_elm_code_widget_refresh(Elm_Code_Widget *widget) +_elm_code_widget_refresh(Elm_Code_Widget *widget, Elm_Code_Line *line) { Evas_Coord scroll_y, scroll_h, oy; unsigned int first_row, last_row; @@ -427,7 +432,7 @@ _elm_code_widget_refresh(Elm_Code_Widget *widget) if (last_row > elm_code_file_lines_get(pd->code->file)) last_row = elm_code_file_lines_get(pd->code->file); - _elm_code_widget_fill_range(widget, first_row, last_row); + _elm_code_widget_fill_range(widget, first_row, last_row, line); } static void @@ -437,7 +442,7 @@ _elm_code_widget_fill(Elm_Code_Widget *widget) pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - _elm_code_widget_fill_range(widget, 1, elm_code_file_lines_get(pd->code->file)); + _elm_code_widget_fill_range(widget, 1, elm_code_file_lines_get(pd->code->file), NULL); } static Eina_Bool @@ -445,17 +450,11 @@ _elm_code_widget_line_cb(void *data, const Eo_Event *event) { Elm_Code_Line *line; Elm_Code_Widget *widget; - Eina_Bool visible; line = (Elm_Code_Line *)event->info; widget = (Elm_Code_Widget *)data; - visible = elm_obj_code_widget_line_visible_get(widget, line); - if (!visible) - return EO_CALLBACK_CONTINUE; - - // FIXME refresh just the row unless we have resized (by being the result of a row append) - _elm_code_widget_refresh(widget); + _elm_code_widget_refresh(widget, line); return EO_CALLBACK_CONTINUE; } @@ -478,7 +477,7 @@ _elm_code_widget_selection_cb(void *data, const Eo_Event *event EINA_UNUSED) widget = (Elm_Code_Widget *)data; - _elm_code_widget_refresh(widget); + _elm_code_widget_refresh(widget, NULL); return EO_CALLBACK_CONTINUE; } @@ -501,7 +500,7 @@ _elm_code_widget_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EIN widget = (Elm_Code_Widget *)data; - _elm_code_widget_refresh(widget); + _elm_code_widget_refresh(widget, NULL); } static Eina_Bool @@ -1339,7 +1338,7 @@ _elm_code_widget_focused_event_cb(void *data, Evas_Object *obj, pd->focussed = EINA_TRUE; _elm_code_widget_update_focus_directions(widget); - _elm_code_widget_refresh(obj); + _elm_code_widget_refresh(obj, NULL); } static void @@ -1353,7 +1352,7 @@ _elm_code_widget_unfocused_event_cb(void *data, Evas_Object *obj, pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); pd->focussed = EINA_FALSE; - _elm_code_widget_refresh(obj); + _elm_code_widget_refresh(obj, NULL); } EOLIAN static Eina_Bool @@ -1513,7 +1512,7 @@ _elm_code_widget_ensure_n_grid_rows(Elm_Code_Widget *widget, int rows) } static void -_elm_code_widget_resize(Elm_Code_Widget *widget) +_elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline) { Elm_Code_Line *line; Eina_List *item; @@ -1522,6 +1521,7 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) int w, h, cw, ch, gutter; unsigned int line_width; Elm_Code_Widget_Data *pd; + Eina_Bool neww = EINA_FALSE; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); @@ -1533,15 +1533,31 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) old_width = ww; old_height = wh; - w = 0; h = elm_code_file_lines_get(pd->code->file); - EINA_LIST_FOREACH(pd->code->file->lines, item, line) + + if (newline) { + line = eina_list_data_get(pd->code->file->lines); + if (line) + { + line_width = elm_code_widget_line_text_column_width_get(widget, newline); + w = (int) line_width + gutter + 1; + } line_width = elm_code_widget_line_text_column_width_get(widget, line); if ((int) line_width + gutter + 1 > w) w = (int) line_width + gutter + 1; } + else + { + neww = EINA_TRUE; + EINA_LIST_FOREACH(pd->code->file->lines, item, line) + { + line_width = elm_code_widget_line_text_column_width_get(widget, line); + if ((int) line_width + gutter + 1 > w) + w = (int) line_width + gutter + 1; + } + } _elm_code_widget_ensure_n_grid_rows(widget, h); _elm_code_widget_cell_size_get(widget, &cw, &ch); @@ -1551,11 +1567,20 @@ _elm_code_widget_resize(Elm_Code_Widget *widget) wh = h*ch; pd->col_count = ww/cw + 1; - EINA_LIST_FOREACH(pd->grids, item, grid) + if (newline) { + grid = eina_list_nth(pd->grids, newline->number - 1); evas_object_textgrid_size_set(grid, pd->col_count, 1); evas_object_size_hint_min_set(grid, w*cw, ch); } + else if (neww) + { + EINA_LIST_FOREACH(pd->grids, item, grid) + { + evas_object_textgrid_size_set(grid, pd->col_count, 1); + evas_object_size_hint_min_set(grid, w*cw, ch); + } + } if (pd->gravity_x == 1.0 || pd->gravity_y == 1.0) _elm_code_widget_scroll_by(widget, From a1e14da6256c179135164b0c1227d04bbc154803 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ANDRE Date: Mon, 16 May 2016 19:33:57 +0900 Subject: [PATCH 243/254] elm_code: remove useless variable --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 4593a83af2..01a0e24dc6 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1521,7 +1521,6 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline) int w, h, cw, ch, gutter; unsigned int line_width; Elm_Code_Widget_Data *pd; - Eina_Bool neww = EINA_FALSE; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); @@ -1550,7 +1549,6 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline) } else { - neww = EINA_TRUE; EINA_LIST_FOREACH(pd->code->file->lines, item, line) { line_width = elm_code_widget_line_text_column_width_get(widget, line); @@ -1573,7 +1571,7 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline) evas_object_textgrid_size_set(grid, pd->col_count, 1); evas_object_size_hint_min_set(grid, w*cw, ch); } - else if (neww) + else { EINA_LIST_FOREACH(pd->grids, item, grid) { From c73a696d018d53214f35d904e7f51cab562279d7 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ANDRE Date: Mon, 16 May 2016 19:52:35 +0900 Subject: [PATCH 244/254] elm_code: fix crash from previous commits sorry! i'm afraid this is not 100% stable yet --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 01a0e24dc6..8d4871cf5b 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1521,6 +1521,7 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline) int w, h, cw, ch, gutter; unsigned int line_width; Elm_Code_Widget_Data *pd; + Eina_Bool neww = EINA_FALSE; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); @@ -1545,10 +1546,14 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline) } line_width = elm_code_widget_line_text_column_width_get(widget, line); if ((int) line_width + gutter + 1 > w) - w = (int) line_width + gutter + 1; + { + neww = EINA_TRUE; + w = (int) line_width + gutter + 1; + } } else { + neww = EINA_TRUE; EINA_LIST_FOREACH(pd->code->file->lines, item, line) { line_width = elm_code_widget_line_text_column_width_get(widget, line); @@ -1565,7 +1570,7 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline) wh = h*ch; pd->col_count = ww/cw + 1; - if (newline) + if (newline && !neww) { grid = eina_list_nth(pd->grids, newline->number - 1); evas_object_textgrid_size_set(grid, pd->col_count, 1); From e947705cee68a9fa9e65a24d86e32495280140d4 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 16 May 2016 11:59:35 +0100 Subject: [PATCH 245/254] elm_code: ensure lines are visible when scrolling --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 8d4871cf5b..f3de34c06d 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1355,6 +1355,17 @@ _elm_code_widget_unfocused_event_cb(void *data, Evas_Object *obj, _elm_code_widget_refresh(obj, NULL); } +static void +_elm_code_widget_scroll_event_cb(void *data, Evas_Object *obj EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + Elm_Code_Widget *widget; + + widget = (Elm_Code_Widget *)data; + + _elm_code_widget_refresh(widget, NULL); +} + EOLIAN static Eina_Bool _elm_code_widget_elm_widget_event(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *pd EINA_UNUSED, Evas_Object *src EINA_UNUSED, Evas_Callback_Type type, void *event_info) @@ -1827,6 +1838,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) evas_object_smart_callback_add(obj, "focused", _elm_code_widget_focused_event_cb, obj); evas_object_smart_callback_add(obj, "unfocused", _elm_code_widget_unfocused_event_cb, obj); + evas_object_smart_callback_add(scroller, "scroll", _elm_code_widget_scroll_event_cb, obj); eo_event_callback_add(obj, &ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_widget_line_cb, obj); eo_event_callback_add(obj, &ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj); From 69efba3efcd63385153ef8658b5f3e41b67756d8 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ANDRE Date: Mon, 16 May 2016 23:15:21 +0900 Subject: [PATCH 246/254] elm_code: unbreak previous commit logs could not be scrolled anymore, because the scroll cb would scroll back to the end. --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index f3de34c06d..da6987e128 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1596,6 +1596,8 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline) } } + if (!newline) return; + if (pd->gravity_x == 1.0 || pd->gravity_y == 1.0) _elm_code_widget_scroll_by(widget, (pd->gravity_x == 1.0 && ww > old_width) ? ww - old_width : 0, From 769f5d8c96170b55f47563009f9422f75b029f1a Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 17 May 2016 17:25:28 +0100 Subject: [PATCH 247/254] elm_code: Fix crash when tabbing in a small widget avoid placing cursor outside of our column width --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index da6987e128..62b7f6c2b0 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1063,6 +1063,8 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text col_width = elm_code_widget_line_text_column_width_to_position(widget, line, position + length) - elm_code_widget_line_text_column_width_to_position(widget, line, position); + // a workaround for when the cursor position would be off the line width + _elm_code_widget_resize(widget, line); elm_obj_code_widget_cursor_position_set(widget, col + col_width, row); eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); From a5e530fc627f65d71a1fc703573850e5945e02f0 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 17 May 2016 23:20:35 +0100 Subject: [PATCH 248/254] elm_code: Revert an optimisation to fix a crash We made an assumption about the order lines were added. It wasn't true... --- legacy/elm_code/src/lib/widget/elm_code_widget.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index 62b7f6c2b0..b591050cc4 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1534,7 +1534,6 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline) int w, h, cw, ch, gutter; unsigned int line_width; Elm_Code_Widget_Data *pd; - Eina_Bool neww = EINA_FALSE; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); gutter = elm_obj_code_widget_text_left_gutter_width_get(widget); @@ -1560,13 +1559,11 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline) line_width = elm_code_widget_line_text_column_width_get(widget, line); if ((int) line_width + gutter + 1 > w) { - neww = EINA_TRUE; w = (int) line_width + gutter + 1; } } else { - neww = EINA_TRUE; EINA_LIST_FOREACH(pd->code->file->lines, item, line) { line_width = elm_code_widget_line_text_column_width_get(widget, line); @@ -1583,20 +1580,11 @@ _elm_code_widget_resize(Elm_Code_Widget *widget, Elm_Code_Line *newline) wh = h*ch; pd->col_count = ww/cw + 1; - if (newline && !neww) + EINA_LIST_FOREACH(pd->grids, item, grid) { - grid = eina_list_nth(pd->grids, newline->number - 1); evas_object_textgrid_size_set(grid, pd->col_count, 1); evas_object_size_hint_min_set(grid, w*cw, ch); } - else - { - EINA_LIST_FOREACH(pd->grids, item, grid) - { - evas_object_textgrid_size_set(grid, pd->col_count, 1); - evas_object_size_hint_min_set(grid, w*cw, ch); - } - } if (!newline) return; From eaf6b7a084e05740507afb43476a1bd4b919a263 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 18 May 2016 23:36:47 +0100 Subject: [PATCH 249/254] elm_code: Fix undo code for deleting tab When character can take up more than 1 column we had to handle delete and backspace with care --- .../elm_code/src/lib/widget/elm_code_widget.c | 16 ++++++++++------ .../src/lib/widget/elm_code_widget_undo.c | 12 ++---------- .../tests/widget/elm_code_test_widget_undo.c | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index b591050cc4..a319c3a155 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -1172,7 +1172,7 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) Elm_Code *code; Elm_Code_Line *line; Elm_Code_Widget_Change_Info *change; - unsigned int row, col, position, start_col, char_width; + unsigned int row, col, position, start_col, end_col, char_width; const char *text; if (_elm_code_widget_delete_selection(widget)) @@ -1193,17 +1193,18 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) line = elm_code_file_line_get(code->file, row); position = elm_code_widget_line_text_position_for_column_get(widget, line, col); + end_col = elm_code_widget_line_text_column_width_to_position(widget, line, position); start_col = elm_code_widget_line_text_column_width_to_position(widget, line, elm_code_widget_line_text_position_for_column_get(widget, line, col - 1)); char_width = position - elm_code_widget_line_text_position_for_column_get(widget, line, start_col); - text = elm_code_widget_text_between_positions_get(widget, start_col, row, start_col, row); + text = elm_code_widget_text_between_positions_get(widget, start_col, row, end_col, row); elm_code_line_text_remove(line, position - char_width, char_width); elm_obj_code_widget_cursor_position_set(widget, start_col, row); eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); - change = _elm_code_widget_change_create(start_col, row, col, row, text, char_width, EINA_FALSE); + change = _elm_code_widget_change_create(start_col, row, end_col, row, text, char_width, EINA_FALSE); _elm_code_widget_undo_change_add(widget, change); _elm_code_widget_change_free(change); } @@ -1214,7 +1215,7 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) Elm_Code *code; Elm_Code_Line *line; Elm_Code_Widget_Change_Info *change; - unsigned int row, col, position, char_width, start_col; + unsigned int row, col, position, char_width, start_col, end_col; const char *text; if (_elm_code_widget_delete_selection(widget)) @@ -1234,10 +1235,13 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) position = elm_code_widget_line_text_position_for_column_get(widget, line, col); char_width = elm_code_widget_line_text_position_for_column_get(widget, line, col + 1) - position; + if (char_width == 0) // a partial tab + char_width = 1; start_col = elm_code_widget_line_text_column_width_to_position(widget, line, position); + end_col = elm_code_widget_line_text_column_width_to_position(widget, line, position + char_width); - text = elm_code_widget_text_between_positions_get(widget, start_col, row, start_col, row); - elm_code_line_text_remove(line, position, char_width?char_width:1); + text = elm_code_widget_text_between_positions_get(widget, start_col, row, end_col, row); + elm_code_line_text_remove(line, position, char_width); elm_obj_code_widget_cursor_position_set(widget, start_col, row); eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c b/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c index 6511be7602..1eaceaaedc 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c @@ -37,10 +37,6 @@ static void _elm_code_widget_undo_change(Evas_Object *widget, Elm_Code_Widget_Change_Info *info) { - Elm_Code_Line *line; - Elm_Code_Widget_Data *pd; - unsigned int position; - if (info->insert) { elm_code_widget_selection_start(widget, info->start_line, info->start_col); @@ -49,12 +45,8 @@ _elm_code_widget_undo_change(Evas_Object *widget, } else { - pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); - line = elm_code_file_line_get(pd->code->file, info->start_line); - position = elm_code_widget_line_text_position_for_column_get(widget, line, info->start_col); - - elm_code_line_text_insert(line, position, info->content, info->length); - elm_code_widget_cursor_position_set(widget, info->end_col, info->end_line); + elm_code_widget_cursor_position_set(widget, info->start_col, info->start_line); + _elm_code_widget_text_at_cursor_insert(widget, info->content, info->length); } } diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c b/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c index 6f20909651..0de2cb91a5 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c +++ b/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c @@ -133,6 +133,23 @@ START_TEST (elm_code_test_widget_undo_delete) content = elm_code_line_text_get(line, &length); ck_assert_strn_eq("test", content, length); + elm_code_widget_cursor_position_set(widget, 4, 1); + _elm_code_widget_text_at_cursor_insert(widget, "\t", 1); + _elm_code_widget_backspace(widget); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("test", content, length); + elm_code_widget_undo(widget); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("tes\tt", content, length); + + elm_code_widget_cursor_position_set(widget, 4, 1); + _elm_code_widget_delete(widget); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("test", content, length); + elm_code_widget_undo(widget); + content = elm_code_line_text_get(line, &length); + ck_assert_strn_eq("tes\tt", content, length); + elm_code_free(code); elm_shutdown(); } From 1aa32dc591f757c6cbd305dcb75f81d063df83c6 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 19 May 2016 22:17:52 +0100 Subject: [PATCH 250/254] elm_code: Fix build for updated eolian_gen output --- legacy/elm_code/src/bin/elm_code_test_main.c | 2 +- .../elm_code/src/lib/widget/elm_code_widget.c | 22 +++++++++---------- .../lib/widget/elm_code_widget_selection.c | 8 +++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/legacy/elm_code/src/bin/elm_code_test_main.c index 92049d5001..b61484fdd9 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/legacy/elm_code/src/bin/elm_code_test_main.c @@ -69,7 +69,7 @@ _elm_code_test_welcome_setup(Evas_Object *parent) 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_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code); + 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, ""); diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/legacy/elm_code/src/lib/widget/elm_code_widget.c index a319c3a155..9af37bd6d8 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget.c @@ -597,7 +597,7 @@ _elm_code_widget_cursor_move(Elm_Code_Widget *widget, Elm_Code_Widget_Data *pd, if (!was_key) _elm_code_widget_update_focus_directions(widget); - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CURSOR_CHANGED, widget); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CURSOR_CHANGED, widget); _elm_code_widget_cursor_ensure_visible(widget); if (oldrow != pd->cursor_line) @@ -668,7 +668,7 @@ _elm_code_widget_clicked_gutter_cb(Elm_Code_Widget *widget, unsigned int row) if (!line) return; - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_LINE_GUTTER_CLICKED, line); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_LINE_GUTTER_CLICKED, line); } static void @@ -704,7 +704,7 @@ _elm_code_widget_clicked_readonly_cb(Elm_Code_Widget *widget, unsigned int row) if (!line) return; - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_LINE_CLICKED, line); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_LINE_CLICKED, line); } static void @@ -1066,7 +1066,7 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text // a workaround for when the cursor position would be off the line width _elm_code_widget_resize(widget, line); elm_obj_code_widget_cursor_position_set(widget, col + col_width, row); - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL); change = _elm_code_widget_change_create(col, row, col + col_width - 1, row, text, length, EINA_TRUE); _elm_code_widget_undo_change_add(widget, change); @@ -1130,7 +1130,7 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) indent = elm_obj_code_widget_line_text_column_width_to_position(widget, line, leading); elm_obj_code_widget_cursor_position_set(widget, indent, row + 1); - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL); change = _elm_code_widget_change_create(width + 1, row, indent - 1, row + 1, "\n", 1, EINA_TRUE); _elm_code_widget_undo_change_add(widget, change); @@ -1163,7 +1163,7 @@ _elm_code_widget_backspaceline(Elm_Code_Widget *widget, Eina_Bool nextline) elm_obj_code_widget_cursor_position_set(widget, position, row - 1); } // TODO construct and pass a change object - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL); } void @@ -1202,7 +1202,7 @@ _elm_code_widget_backspace(Elm_Code_Widget *widget) elm_code_line_text_remove(line, position - char_width, char_width); elm_obj_code_widget_cursor_position_set(widget, start_col, row); - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL); change = _elm_code_widget_change_create(start_col, row, end_col, row, text, char_width, EINA_FALSE); _elm_code_widget_undo_change_add(widget, change); @@ -1243,7 +1243,7 @@ _elm_code_widget_delete(Elm_Code_Widget *widget) text = elm_code_widget_text_between_positions_get(widget, start_col, row, end_col, row); elm_code_line_text_remove(line, position, char_width); elm_obj_code_widget_cursor_position_set(widget, start_col, row); - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL); change = _elm_code_widget_change_create(start_col, row, col, row, text, char_width, EINA_FALSE); _elm_code_widget_undo_change_add(widget, change); @@ -1270,7 +1270,7 @@ _elm_code_widget_control_key_down_cb(Elm_Code_Widget *widget, const char *key) elm_code_widget_undo(widget); // TODO construct and pass a change object for cut and paste - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_CHANGED_USER, NULL); } static void @@ -1838,8 +1838,8 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) eo_event_callback_add(obj, &ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_widget_line_cb, obj); eo_event_callback_add(obj, &ELM_CODE_EVENT_FILE_LOAD_DONE, _elm_code_widget_file_cb, obj); - eo_event_callback_add(obj, ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, _elm_code_widget_selection_cb, obj); - eo_event_callback_add(obj, ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_clear_cb, obj); + eo_event_callback_add(obj, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CHANGED, _elm_code_widget_selection_cb, obj); + eo_event_callback_add(obj, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CLEARED, _elm_code_widget_selection_clear_cb, obj); } #include "elm_code_widget_text.c" diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c index 94102342c7..9e82ac5456 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c @@ -62,7 +62,7 @@ elm_code_widget_selection_start(Evas_Object *widget, pd->selection->start_line = line; pd->selection->start_col = col; - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget); elm_obj_code_widget_cursor_position_set(widget, col, line); } @@ -88,7 +88,7 @@ elm_code_widget_selection_end(Evas_Object *widget, pd->selection->end_line = line; pd->selection->end_col = col; - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CHANGED, widget); } EAPI Elm_Code_Widget_Selection_Data * @@ -144,7 +144,7 @@ elm_code_widget_selection_clear(Evas_Object *widget) free(pd->selection); pd->selection = NULL; - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget); } static void @@ -246,7 +246,7 @@ elm_code_widget_selection_delete(Evas_Object *widget) free(pd->selection); pd->selection = NULL; - eo_event_callback_call(widget, ELM_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget); + eo_event_callback_call(widget, ELM_OBJ_CODE_WIDGET_EVENT_SELECTION_CLEARED, widget); } EAPI void From d384012307881898a2df49f68fa6b46a4cd9972d Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Thu, 2 Jun 2016 17:19:08 -0700 Subject: [PATCH 251/254] elementary: merging in elm_code widget. Theme is not there as it should be manually merged into the elementary default theme. --- legacy/elm_code/src/tests/elm_code_suite.c | 130 ------------------ legacy/elm_code/src/tests/elm_code_suite.h | 31 ----- src/Makefile_Elementary.am | 46 ++++++- src/lib/elementary/Elementary.h.in | 1 + .../src/lib => src/lib/elementary}/elm_code.c | 4 +- .../lib/elementary/elm_code.h | 38 +---- .../lib/elementary}/elm_code_common.h | 0 .../lib/elementary}/elm_code_diff_widget.c | 6 +- .../lib/elementary}/elm_code_diff_widget.h | 0 .../lib/elementary}/elm_code_file.c | 7 +- .../lib/elementary}/elm_code_file.h | 0 .../lib/elementary}/elm_code_line.c | 6 +- .../lib/elementary}/elm_code_line.h | 0 .../lib/elementary}/elm_code_parse.c | 6 +- .../lib/elementary}/elm_code_parse.h | 0 .../lib/elementary}/elm_code_private.h | 0 .../lib/elementary}/elm_code_text.c | 6 +- .../lib/elementary}/elm_code_text.h | 0 .../lib/elementary}/elm_code_widget.c | 9 +- .../lib/elementary}/elm_code_widget.eo | 1 + .../lib/elementary}/elm_code_widget_legacy.h | 2 +- .../lib/elementary}/elm_code_widget_private.h | 0 .../elementary}/elm_code_widget_selection.c | 6 +- .../elementary}/elm_code_widget_selection.h | 0 .../lib/elementary}/elm_code_widget_text.c | 6 +- .../lib/elementary}/elm_code_widget_undo.c | 6 +- .../elementary}/elm_code_file_test_load.c | 36 +++-- .../elementary}/elm_code_file_test_memory.c | 12 +- .../tests/elementary}/elm_code_test_basic.c | 12 +- .../tests/elementary}/elm_code_test_line.c | 14 +- .../tests/elementary}/elm_code_test_parse.c | 16 ++- .../tests/elementary}/elm_code_test_text.c | 23 +++- .../tests/elementary}/elm_code_test_widget.c | 9 +- .../elm_code_test_widget_selection.c | 14 +- .../elementary}/elm_code_test_widget_text.c | 9 +- .../elementary}/elm_code_test_widget_undo.c | 7 +- src/tests/elementary/elm_suite.c | 9 ++ src/tests/elementary/elm_suite.h | 11 ++ src/tests/elementary/elm_test_helper.h | 13 ++ .../tests/elementary}/testdiff.diff | 0 .../tests/elementary}/testfile-windows.txt | 0 .../tests/elementary}/testfile-withblanks.txt | 0 .../tests/elementary}/testfile.txt | 0 43 files changed, 225 insertions(+), 271 deletions(-) delete mode 100644 legacy/elm_code/src/tests/elm_code_suite.c delete mode 100644 legacy/elm_code/src/tests/elm_code_suite.h rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code.c (97%) rename legacy/elm_code/src/lib/Elm_Code.h => src/lib/elementary/elm_code.h (77%) rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code_common.h (100%) rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code_diff_widget.c (98%) rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code_diff_widget.h (100%) rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code_file.c (99%) rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code_file.h (100%) rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code_line.c (98%) rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code_line.h (100%) rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code_parse.c (98%) rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code_parse.h (100%) rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code_private.h (100%) rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code_text.c (98%) rename {legacy/elm_code/src/lib => src/lib/elementary}/elm_code_text.h (100%) rename {legacy/elm_code/src/lib/widget => src/lib/elementary}/elm_code_widget.c (99%) rename {legacy/elm_code/src/lib/widget => src/lib/elementary}/elm_code_widget.eo (99%) rename {legacy/elm_code/src/lib/widget => src/lib/elementary}/elm_code_widget_legacy.h (86%) rename {legacy/elm_code/src/lib/widget => src/lib/elementary}/elm_code_widget_private.h (100%) rename {legacy/elm_code/src/lib/widget => src/lib/elementary}/elm_code_widget_selection.c (99%) rename {legacy/elm_code/src/lib/widget => src/lib/elementary}/elm_code_widget_selection.h (100%) rename {legacy/elm_code/src/lib/widget => src/lib/elementary}/elm_code_widget_text.c (98%) rename {legacy/elm_code/src/lib/widget => src/lib/elementary}/elm_code_widget_undo.c (95%) rename {legacy/elm_code/src/tests => src/tests/elementary}/elm_code_file_test_load.c (80%) rename {legacy/elm_code/src/tests => src/tests/elementary}/elm_code_file_test_memory.c (82%) rename {legacy/elm_code/src/tests => src/tests/elementary}/elm_code_test_basic.c (59%) rename {legacy/elm_code/src/tests => src/tests/elementary}/elm_code_test_line.c (88%) rename {legacy/elm_code/src/tests => src/tests/elementary}/elm_code_test_parse.c (88%) rename {legacy/elm_code/src/tests => src/tests/elementary}/elm_code_test_text.c (91%) rename {legacy/elm_code/src/tests/widget => src/tests/elementary}/elm_code_test_widget.c (93%) rename {legacy/elm_code/src/tests/widget => src/tests/elementary}/elm_code_test_widget_selection.c (98%) rename {legacy/elm_code/src/tests/widget => src/tests/elementary}/elm_code_test_widget_text.c (92%) rename {legacy/elm_code/src/tests/widget => src/tests/elementary}/elm_code_test_widget_undo.c (97%) rename {legacy/elm_code/src/tests => src/tests/elementary}/testdiff.diff (100%) rename {legacy/elm_code/src/tests => src/tests/elementary}/testfile-windows.txt (100%) rename {legacy/elm_code/src/tests => src/tests/elementary}/testfile-withblanks.txt (100%) rename {legacy/elm_code/src/tests => src/tests/elementary}/testfile.txt (100%) diff --git a/legacy/elm_code/src/tests/elm_code_suite.c b/legacy/elm_code/src/tests/elm_code_suite.c deleted file mode 100644 index 31ea7d9f0e..0000000000 --- a/legacy/elm_code/src/tests/elm_code_suite.c +++ /dev/null @@ -1,130 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include - -#include "Elm_Code.h" -#include "elm_code_suite.h" - -#define COPYRIGHT "Copyright © 2014 Andy Williams and various contributors (see AUTHORS)." - -static const struct { - const char *name; - void (*build)(TCase *tc); -} tests[] = { - { "file_load", elm_code_file_test_load }, - { "file_memory", elm_code_file_test_memory }, - { "parse", elm_code_test_parse }, - { "text", elm_code_test_text }, - { "basic", elm_code_test_basic }, - { "widget", elm_code_test_widget }, - { "widget_text", elm_code_test_widget_text }, - { "widget_selection", elm_code_test_widget_selection }, - { "widget_undo", elm_code_test_widget_undo }, -}; - -START_TEST(elm_code_initialization) -{ - fail_if(elm_code_init() != 1); - -// TODO add other init checks here - - fail_if(elm_code_shutdown() != 0); -} -END_TEST - -void -edi_test_basic(TCase *tc) -{ - tcase_add_test(tc, elm_code_initialization); -} - -static const Ecore_Getopt optdesc = { - "elm_code", - "%prog [options]", - PACKAGE_VERSION, - COPYRIGHT, - "BSD with advertisement clause", - "Elm Code", - 0, - { - ECORE_GETOPT_STORE_TRUE('l', "list", "list available tests"), - ECORE_GETOPT_STORE_STR('t', "test", "test to run"), - ECORE_GETOPT_LICENSE('L', "license"), - ECORE_GETOPT_COPYRIGHT('C', "copyright"), - ECORE_GETOPT_VERSION('V', "version"), - ECORE_GETOPT_HELP('h', "help"), - ECORE_GETOPT_SENTINEL - } -}; - -int -main(int argc EINA_UNUSED, char **argv EINA_UNUSED) -{ - Suite *s; - SRunner *sr; - TCase *tc = NULL; - char *test = NULL; - unsigned int i; - int failed_count = -1; - int args; - Eina_Bool quit_option = EINA_FALSE; - Eina_Bool list_option = EINA_FALSE; - - Ecore_Getopt_Value values[] = { - ECORE_GETOPT_VALUE_BOOL(list_option), - ECORE_GETOPT_VALUE_STR(test), - 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 - }; - - eina_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; - } - else if (list_option) - { - fprintf(stdout, "Available tests :\n"); - for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) - fprintf(stdout, "\t%s\n", tests[i].name); - goto end; - } - - s = suite_create("Elm_Code"); - - for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) - { - if (test && strcmp(tests[i].name, test)) - continue ; - - tc = tcase_create(tests[i].name); - tcase_set_timeout(tc, 0); - - tests[i].build(tc); - suite_add_tcase(s, tc); - } - - sr = srunner_create(s); - srunner_set_xml(sr, PACKAGE_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); - - end: - eina_shutdown(); - - return (failed_count == 0) ? 0 : 255; -} diff --git a/legacy/elm_code/src/tests/elm_code_suite.h b/legacy/elm_code/src/tests/elm_code_suite.h deleted file mode 100644 index 750bfd7f18..0000000000 --- a/legacy/elm_code/src/tests/elm_code_suite.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef _ELM_CODE_SUITE_H -#define _ELM_CODE_SUITE_H - -#include - -#define ck_assert_strn_eq(s1, s2, len) \ - { \ - char expected[len+1], actual[len+1]; \ -\ - strncpy(expected, s1, len); \ - expected[len] = '\0'; \ - strncpy(actual, s2, len); \ - actual[len] = '\0'; \ -\ - ck_assert_str_eq(expected, actual); \ - } - -#include - -void elm_code_file_test_load(TCase *tc); -void elm_code_file_test_memory(TCase *tc); -void elm_code_test_basic(TCase *tc); -void elm_code_test_line(TCase *tc); -void elm_code_test_parse(TCase *tc); -void elm_code_test_text(TCase *tc); -void elm_code_test_widget(TCase *tc); -void elm_code_test_widget_text(TCase *tc); -void elm_code_test_widget_selection(TCase *tc); -void elm_code_test_widget_undo(TCase *tc); - -#endif /* _EDLM_CODE_SUITE_H */ diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am index 550a54a36a..c122a75bec 100644 --- a/src/Makefile_Elementary.am +++ b/src/Makefile_Elementary.am @@ -135,6 +135,7 @@ elm_public_eolian_files = \ lib/elementary/elm_progressbar_internal_part.eo \ lib/elementary/elm_popup_internal_part.eo \ lib/elementary/elm_scroller_internal_part.eo \ + lib/elementary/elm_code_widget.eo \ $(NULL) # Legacy classes - not part of public EO API @@ -252,7 +253,16 @@ includesunstable_HEADERS = \ lib/elementary/elm_widget_thumb.h \ lib/elementary/elm_widget_toolbar.h \ lib/elementary/elm_widget_video.h \ - lib/elementary/elm_widget_web.h + lib/elementary/elm_widget_web.h \ + lib/elementary/elm_code.h \ + lib/elementary/elm_code_widget_legacy.h \ + lib/elementary/elm_code_widget_selection.h \ + lib/elementary/elm_code_diff_widget.h \ + lib/elementary/elm_code_common.h \ + lib/elementary/elm_code_line.h \ + lib/elementary/elm_code_text.h \ + lib/elementary/elm_code_file.h \ + lib/elementary/elm_code_parse.h includesunstabledir = $(includedir)/elementary-@VMAJ@ nodist_includesunstable_HEADERS = \ @@ -562,6 +572,16 @@ lib_elementary_libelementary_la_SOURCES = \ lib/elementary/elm_check.c \ lib/elementary/elm_clock.c \ lib/elementary/elm_cnp.c \ + lib/elementary/elm_code_line.c \ + lib/elementary/elm_code_text.c \ + lib/elementary/elm_code_file.c \ + lib/elementary/elm_code_parse.c \ + lib/elementary/elm_code_widget_selection.c \ + lib/elementary/elm_code_widget.c \ + lib/elementary/elm_code_diff_widget.c \ + lib/elementary/elm_code.c \ + lib/elementary/elm_code_private.h \ + lib/elementary/elm_code_widget_private.h \ lib/elementary/elm_colorselector.c \ lib/elementary/elm_color_class.c \ lib/elementary/elc_combobox.c \ @@ -1214,6 +1234,11 @@ edje_external_elementary_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@ edje_external_elementary_module_la_LIBTOOLFLAGS = --tag=disable-static ### Tests +EXTRA_DIST += \ +tests/elementary/testfile.txt \ +tests/elementary/testfile-windows.txt \ +tests/elementary/testfile-withblanks.txt \ +tests/elementary/testdiff.diff if EFL_ENABLE_TESTS @@ -1291,12 +1316,24 @@ tests_elementary_elm_suite_SOURCES = \ tests/elementary/elm_test_panes.c \ tests/elementary/elm_test_slideshow.c \ tests/elementary/elm_test_spinner.c \ - tests/elementary/elm_test_plug.c + tests/elementary/elm_test_plug.c \ + tests/elementary/elm_code_file_test_load.c \ + tests/elementary/elm_code_file_test_memory.c \ + tests/elementary/elm_code_test_basic.c \ + tests/elementary/elm_code_test_line.c \ + tests/elementary/elm_code_test_parse.c \ + tests/elementary/elm_code_test_text.c \ + tests/elementary/elm_code_test_widget.c \ + tests/elementary/elm_code_test_widget_text.c \ + tests/elementary/elm_code_test_widget_selection.c \ + tests/elementary/elm_code_test_widget_undo.c tests_elementary_elm_suite_CPPFLAGS = \ -DTESTS_BUILD_DIR=\"${top_builddir}/src/tests/elementary\" \ + -DTESTS_SRC_DIR=\"${top_srcdir}/src/tests/elementary\" \ -DELM_IMAGE_DATA_DIR=\"${top_srcdir}/data/elementary\" \ -DELM_TEST_DATA_DIR=\"${abs_top_builddir}/data/elementary\" \ + -DPACKAGE_DATA_DIR=\"${abs_top_builddir}/data/elementary\" \ -I$(top_srcdir)/src/lib/elementary \ -I$(top_builddir)/src/lib/elementary \ @CHECK_CFLAGS@ \ @@ -1339,4 +1376,7 @@ tests/elementary/elm_suite.h \ tests/elementary/elm_test_helper.h \ lib/elementary/Makefile.am \ lib/elementary/Makefile.in \ -lib/elementary/Elementary.h.in +lib/elementary/Elementary.h.in \ +lib/elementary/elm_code_widget_text.c \ +lib/elementary/elm_code_widget_undo.c + diff --git a/src/lib/elementary/Elementary.h.in b/src/lib/elementary/Elementary.h.in index b85eaffaec..59d4081cea 100644 --- a/src/lib/elementary/Elementary.h.in +++ b/src/lib/elementary/Elementary.h.in @@ -202,6 +202,7 @@ EAPI extern Elm_Version *elm_version; #include #include #include +#include #include #include #include diff --git a/legacy/elm_code/src/lib/elm_code.c b/src/lib/elementary/elm_code.c similarity index 97% rename from legacy/elm_code/src/lib/elm_code.c rename to src/lib/elementary/elm_code.c index 598f928622..ff26ea063e 100644 --- a/legacy/elm_code/src/lib/elm_code.c +++ b/src/lib/elementary/elm_code.c @@ -1,11 +1,11 @@ #ifdef HAVE_CONFIG -# include "config.h" +# include "elementary_config.h" #endif #include #include -#include "Elm_Code.h" +#include "Elementary.h" #include "elm_code_private.h" diff --git a/legacy/elm_code/src/lib/Elm_Code.h b/src/lib/elementary/elm_code.h similarity index 77% rename from legacy/elm_code/src/lib/Elm_Code.h rename to src/lib/elementary/elm_code.h index 9d14b400ec..046cb6e965 100644 --- a/legacy/elm_code/src/lib/Elm_Code.h +++ b/src/lib/elementary/elm_code.h @@ -1,46 +1,14 @@ #ifndef ELM_CODE_H_ # define ELM_CODE_H_ -#include -#include -#include -#define ELM_INTERNAL_API_ARGESFSDFEFC -#include - -#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_widget.eo.h" +#include "elm_code_widget_legacy.h" +#include "elm_code_widget_selection.h" #include "elm_code_diff_widget.h" #ifdef __cplusplus diff --git a/legacy/elm_code/src/lib/elm_code_common.h b/src/lib/elementary/elm_code_common.h similarity index 100% rename from legacy/elm_code/src/lib/elm_code_common.h rename to src/lib/elementary/elm_code_common.h diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.c b/src/lib/elementary/elm_code_diff_widget.c similarity index 98% rename from legacy/elm_code/src/lib/elm_code_diff_widget.c rename to src/lib/elementary/elm_code_diff_widget.c index 7efb84894c..c874805cab 100644 --- a/legacy/elm_code/src/lib/elm_code_diff_widget.c +++ b/src/lib/elementary/elm_code_diff_widget.c @@ -1,8 +1,8 @@ -#ifdef HAVE_CONFIG -# include "config.h" +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" #endif -#include "Elm_Code.h" +#include "Elementary.h" #include "elm_code_private.h" diff --git a/legacy/elm_code/src/lib/elm_code_diff_widget.h b/src/lib/elementary/elm_code_diff_widget.h similarity index 100% rename from legacy/elm_code/src/lib/elm_code_diff_widget.h rename to src/lib/elementary/elm_code_diff_widget.h diff --git a/legacy/elm_code/src/lib/elm_code_file.c b/src/lib/elementary/elm_code_file.c similarity index 99% rename from legacy/elm_code/src/lib/elm_code_file.c rename to src/lib/elementary/elm_code_file.c index 5db1bfa9f2..4e8dee46b0 100644 --- a/legacy/elm_code/src/lib/elm_code_file.c +++ b/src/lib/elementary/elm_code_file.c @@ -1,8 +1,8 @@ -#ifdef HAVE_CONFIG -# include "config.h" +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" #endif -#include "Elm_Code.h" +#include "Elementary.h" #include "elm_code_private.h" @@ -319,4 +319,3 @@ EAPI Elm_Code_Line *elm_code_file_line_get(Elm_Code_File *file, unsigned int num { return eina_list_nth(file->lines, number - 1); } - diff --git a/legacy/elm_code/src/lib/elm_code_file.h b/src/lib/elementary/elm_code_file.h similarity index 100% rename from legacy/elm_code/src/lib/elm_code_file.h rename to src/lib/elementary/elm_code_file.h diff --git a/legacy/elm_code/src/lib/elm_code_line.c b/src/lib/elementary/elm_code_line.c similarity index 98% rename from legacy/elm_code/src/lib/elm_code_line.c rename to src/lib/elementary/elm_code_line.c index b2ee71419a..2b3281de66 100644 --- a/legacy/elm_code/src/lib/elm_code_line.c +++ b/src/lib/elementary/elm_code_line.c @@ -1,8 +1,8 @@ -#ifdef HAVE_CONFIG -# include "config.h" +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" #endif -#include "Elm_Code.h" +#include "Elementary.h" #include "elm_code_private.h" diff --git a/legacy/elm_code/src/lib/elm_code_line.h b/src/lib/elementary/elm_code_line.h similarity index 100% rename from legacy/elm_code/src/lib/elm_code_line.h rename to src/lib/elementary/elm_code_line.h diff --git a/legacy/elm_code/src/lib/elm_code_parse.c b/src/lib/elementary/elm_code_parse.c similarity index 98% rename from legacy/elm_code/src/lib/elm_code_parse.c rename to src/lib/elementary/elm_code_parse.c index f7fd97ee77..5869f8cf33 100644 --- a/legacy/elm_code/src/lib/elm_code_parse.c +++ b/src/lib/elementary/elm_code_parse.c @@ -1,8 +1,8 @@ -#ifdef HAVE_CONFIG -# include "config.h" +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" #endif -#include "Elm_Code.h" +#include "Elementary.h" #include "elm_code_private.h" diff --git a/legacy/elm_code/src/lib/elm_code_parse.h b/src/lib/elementary/elm_code_parse.h similarity index 100% rename from legacy/elm_code/src/lib/elm_code_parse.h rename to src/lib/elementary/elm_code_parse.h diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/src/lib/elementary/elm_code_private.h similarity index 100% rename from legacy/elm_code/src/lib/elm_code_private.h rename to src/lib/elementary/elm_code_private.h diff --git a/legacy/elm_code/src/lib/elm_code_text.c b/src/lib/elementary/elm_code_text.c similarity index 98% rename from legacy/elm_code/src/lib/elm_code_text.c rename to src/lib/elementary/elm_code_text.c index 901b6aefb9..f1503e7d09 100644 --- a/legacy/elm_code/src/lib/elm_code_text.c +++ b/src/lib/elementary/elm_code_text.c @@ -1,8 +1,8 @@ -#ifdef HAVE_CONFIG -# include "config.h" +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" #endif -#include "Elm_Code.h" +#include "Elementary.h" #include "elm_code_private.h" diff --git a/legacy/elm_code/src/lib/elm_code_text.h b/src/lib/elementary/elm_code_text.h similarity index 100% rename from legacy/elm_code/src/lib/elm_code_text.h rename to src/lib/elementary/elm_code_text.h diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.c b/src/lib/elementary/elm_code_widget.c similarity index 99% rename from legacy/elm_code/src/lib/widget/elm_code_widget.c rename to src/lib/elementary/elm_code_widget.c index 9af37bd6d8..9a9418e1ff 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.c +++ b/src/lib/elementary/elm_code_widget.c @@ -1,8 +1,11 @@ -#ifdef HAVE_CONFIG -# include "config.h" +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" #endif -#include "Elm_Code.h" +#include + +#include "elm_priv.h" + #include "elm_code_private.h" #include "elm_code_widget_private.h" diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget.eo b/src/lib/elementary/elm_code_widget.eo similarity index 99% rename from legacy/elm_code/src/lib/widget/elm_code_widget.eo rename to src/lib/elementary/elm_code_widget.eo index 65dd56a780..2a977ab9ea 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget.eo +++ b/src/lib/elementary/elm_code_widget.eo @@ -1,6 +1,7 @@ import evas_types; import edje_types; import elm_interface_scrollable; +import elm_general; struct @extern Elm_Code; /* The main interface currently defined in code */ struct @extern Elm_Code_Line; /* Parts of the interface currently defined in code */ diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_legacy.h b/src/lib/elementary/elm_code_widget_legacy.h similarity index 86% rename from legacy/elm_code/src/lib/widget/elm_code_widget_legacy.h rename to src/lib/elementary/elm_code_widget_legacy.h index 450f4adeae..5110e301e2 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_legacy.h +++ b/src/lib/elementary/elm_code_widget_legacy.h @@ -10,4 +10,4 @@ */ EAPI Evas_Object *elm_code_widget_add(Evas_Object *parent, Elm_Code *code); -#include "widget/elm_code_widget.eo.legacy.h" +#include "elm_code_widget.eo.legacy.h" diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_private.h b/src/lib/elementary/elm_code_widget_private.h similarity index 100% rename from legacy/elm_code/src/lib/widget/elm_code_widget_private.h rename to src/lib/elementary/elm_code_widget_private.h diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c b/src/lib/elementary/elm_code_widget_selection.c similarity index 99% rename from legacy/elm_code/src/lib/widget/elm_code_widget_selection.c rename to src/lib/elementary/elm_code_widget_selection.c index 9e82ac5456..33da3aaf9b 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.c +++ b/src/lib/elementary/elm_code_widget_selection.c @@ -1,8 +1,8 @@ -#ifdef HAVE_CONFIG -# include "config.h" +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" #endif -#include "Elm_Code.h" +#include "Elementary.h" #include "elm_code_widget_private.h" diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_selection.h b/src/lib/elementary/elm_code_widget_selection.h similarity index 100% rename from legacy/elm_code/src/lib/widget/elm_code_widget_selection.h rename to src/lib/elementary/elm_code_widget_selection.h diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_text.c b/src/lib/elementary/elm_code_widget_text.c similarity index 98% rename from legacy/elm_code/src/lib/widget/elm_code_widget_text.c rename to src/lib/elementary/elm_code_widget_text.c index 3689e8284a..bbcbdc3492 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_text.c +++ b/src/lib/elementary/elm_code_widget_text.c @@ -1,8 +1,8 @@ -#ifdef HAVE_CONFIG -# include "config.h" +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" #endif -#include "Elm_Code.h" +#include "Elementary.h" #include "elm_code_widget_private.h" diff --git a/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c b/src/lib/elementary/elm_code_widget_undo.c similarity index 95% rename from legacy/elm_code/src/lib/widget/elm_code_widget_undo.c rename to src/lib/elementary/elm_code_widget_undo.c index 1eaceaaedc..ccf621b300 100644 --- a/legacy/elm_code/src/lib/widget/elm_code_widget_undo.c +++ b/src/lib/elementary/elm_code_widget_undo.c @@ -1,8 +1,8 @@ -#ifdef HAVE_CONFIG -# include "config.h" +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" #endif -#include "Elm_Code.h" +#include "Elementary.h" #include "elm_code_widget_private.h" diff --git a/legacy/elm_code/src/tests/elm_code_file_test_load.c b/src/tests/elementary/elm_code_file_test_load.c similarity index 80% rename from legacy/elm_code/src/tests/elm_code_file_test_load.c rename to src/tests/elementary/elm_code_file_test_load.c index 02a6f7ee74..7e21b235f1 100644 --- a/legacy/elm_code/src/tests/elm_code_file_test_load.c +++ b/src/tests/elementary/elm_code_file_test_load.c @@ -1,16 +1,20 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "elementary_config.h" #endif -#include "elm_code_suite.h" +#define ELM_INTERNAL_API_ARGESFSDFEFC + +#include "elm_suite.h" +#include "Elementary.h" START_TEST (elm_code_file_load) { - char *path = TESTS_DIR "testfile.txt"; + char *path = TESTS_SRC_DIR "/testfile.txt"; char real[EINA_PATH_MAX]; Elm_Code_File *file; Elm_Code *code; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_open(code, path); realpath(path, real); @@ -19,51 +23,58 @@ START_TEST (elm_code_file_load) ck_assert_str_eq(real, elm_code_file_path_get(file)); elm_code_file_close(file); elm_code_free(code); + elm_shutdown(); } END_TEST START_TEST (elm_code_file_load_lines) { - char *path = TESTS_DIR "testfile.txt"; + char *path = TESTS_SRC_DIR "/testfile.txt"; Elm_Code_File *file; Elm_Code *code; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_open(code, path); ck_assert_uint_eq(4, elm_code_file_lines_get(file)); elm_code_file_close(file); elm_code_free(code); + elm_shutdown(); } END_TEST START_TEST (elm_code_file_load_blank_lines) { - char *path = TESTS_DIR "testfile-withblanks.txt"; + char *path = TESTS_SRC_DIR "/testfile-withblanks.txt"; Elm_Code_File *file; Elm_Code *code; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_open(code, path); ck_assert_uint_eq(8, elm_code_file_lines_get(file)); elm_code_file_close(file); elm_code_free(code); + elm_shutdown(); } END_TEST START_TEST (elm_code_file_load_windows) { - char *path = TESTS_DIR "testfile-windows.txt"; + char *path = TESTS_SRC_DIR "/testfile-windows.txt"; Elm_Code_File *file; Elm_Code *code; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_open(code, path); ck_assert_uint_eq(4, elm_code_file_lines_get(file)); elm_code_file_close(file); elm_code_free(code); + elm_shutdown(); } END_TEST @@ -81,10 +92,11 @@ static void _assert_line_content_eq(const char *content, Elm_Code_Line *line) START_TEST (elm_code_file_load_content) { - char *path = TESTS_DIR "testfile.txt"; + char *path = TESTS_SRC_DIR "/testfile.txt"; Elm_Code_File *file; Elm_Code *code; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_open(code, path); @@ -92,16 +104,18 @@ START_TEST (elm_code_file_load_content) _assert_line_content_eq("another line", elm_code_file_line_get(file, 4)); elm_code_file_close(file); elm_code_free(code); + elm_shutdown(); } END_TEST START_TEST (elm_code_file_line_ending_unix) { - char *path = TESTS_DIR "testfile.txt"; + char *path = TESTS_SRC_DIR "/testfile.txt"; Elm_Code_File *file; Elm_Code *code; short len; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_open(code, path); @@ -111,16 +125,18 @@ START_TEST (elm_code_file_line_ending_unix) elm_code_file_close(file); elm_code_free(code); + elm_shutdown(); } END_TEST START_TEST (elm_code_file_line_ending_windows) { - char *path = TESTS_DIR "testfile-windows.txt"; + char *path = TESTS_SRC_DIR "/testfile-windows.txt"; Elm_Code_File *file; Elm_Code *code; short len; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_open(code, path); @@ -130,6 +146,7 @@ START_TEST (elm_code_file_line_ending_windows) elm_code_file_close(file); elm_code_free(code); + elm_shutdown(); } END_TEST @@ -143,4 +160,3 @@ void elm_code_file_test_load(TCase *tc) tcase_add_test(tc, elm_code_file_line_ending_unix); tcase_add_test(tc, elm_code_file_line_ending_windows); } - diff --git a/legacy/elm_code/src/tests/elm_code_file_test_memory.c b/src/tests/elementary/elm_code_file_test_memory.c similarity index 82% rename from legacy/elm_code/src/tests/elm_code_file_test_memory.c rename to src/tests/elementary/elm_code_file_test_memory.c index b82ce2eda2..f39228d427 100644 --- a/legacy/elm_code/src/tests/elm_code_file_test_memory.c +++ b/src/tests/elementary/elm_code_file_test_memory.c @@ -1,13 +1,17 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "elementary_config.h" #endif -#include "elm_code_suite.h" +#define ELM_INTERNAL_API_ARGESFSDFEFC + +#include "elm_suite.h" +#include "Elementary.h" START_TEST (elm_code_file_memory_lines) { Elm_Code *code; + elm_init(1, NULL); code = elm_code_create(); ck_assert_uint_eq(0, elm_code_file_lines_get(code->file)); @@ -15,6 +19,7 @@ START_TEST (elm_code_file_memory_lines) ck_assert_uint_eq(1, elm_code_file_lines_get(code->file)); elm_code_free(code); + elm_shutdown(); } END_TEST @@ -24,6 +29,7 @@ START_TEST (elm_code_file_memory_tokens) Elm_Code_Line *line; Elm_Code *code; + elm_init(1, NULL); code = elm_code_create(); file = code->file; elm_code_file_line_append(file, "a line", 6, NULL); @@ -32,6 +38,7 @@ START_TEST (elm_code_file_memory_tokens) elm_code_line_token_add(line, 2, 5, 1, ELM_CODE_TOKEN_TYPE_COMMENT); ck_assert_uint_eq(1, eina_list_count(line->tokens)); elm_code_free(code); + elm_shutdown(); } END_TEST @@ -40,4 +47,3 @@ void elm_code_file_test_memory(TCase *tc) tcase_add_test(tc, elm_code_file_memory_lines); tcase_add_test(tc, elm_code_file_memory_tokens); } - diff --git a/legacy/elm_code/src/tests/elm_code_test_basic.c b/src/tests/elementary/elm_code_test_basic.c similarity index 59% rename from legacy/elm_code/src/tests/elm_code_test_basic.c rename to src/tests/elementary/elm_code_test_basic.c index b968e90523..9805a7508b 100644 --- a/legacy/elm_code/src/tests/elm_code_test_basic.c +++ b/src/tests/elementary/elm_code_test_basic.c @@ -1,19 +1,24 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "elementary_config.h" #endif -#include "elm_code_suite.h" +#define ELM_INTERNAL_API_ARGESFSDFEFC + +#include "elm_suite.h" +#include "Elementary.h" START_TEST (elm_code_create_test) { - char *path = "elm_code/src/tests/testfile.txt"; + char *path = TESTS_SRC_DIR "/testfile.txt"; Elm_Code *code; + elm_init(1, NULL); code = elm_code_create(); elm_code_file_open(code, path); ck_assert(!!code); elm_code_free(code); + elm_shutdown(); } END_TEST @@ -21,4 +26,3 @@ void elm_code_test_basic(TCase *tc) { tcase_add_test(tc, elm_code_create_test); } - diff --git a/legacy/elm_code/src/tests/elm_code_test_line.c b/src/tests/elementary/elm_code_test_line.c similarity index 88% rename from legacy/elm_code/src/tests/elm_code_test_line.c rename to src/tests/elementary/elm_code_test_line.c index b19bf615c3..cdbc628079 100644 --- a/legacy/elm_code/src/tests/elm_code_test_line.c +++ b/src/tests/elementary/elm_code_test_line.c @@ -1,8 +1,11 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "elementary_config.h" #endif -#include "elm_code_suite.h" +#define ELM_INTERNAL_API_ARGESFSDFEFC + +#include "elm_suite.h" +#include "Elementary.h" START_TEST (elm_code_line_create_test) { @@ -10,6 +13,7 @@ START_TEST (elm_code_line_create_test) Elm_Code_File *file; Elm_Code_Line *line; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_new(code); @@ -19,6 +23,7 @@ START_TEST (elm_code_line_create_test) ck_assert(!!line); elm_code_free(code); + elm_shutdown(); } END_TEST @@ -28,6 +33,7 @@ START_TEST (elm_code_line_token_count_test) Elm_Code_File *file; Elm_Code_Line *line; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_new(code); @@ -41,6 +47,7 @@ START_TEST (elm_code_line_token_count_test) ck_assert_int_eq(0, eina_list_count(line->tokens)); elm_code_free(code); + elm_shutdown(); } END_TEST @@ -50,6 +57,7 @@ START_TEST (elm_code_line_split_test) Elm_Code_File *file; Elm_Code_Line *line, *newline; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_new(code); @@ -63,6 +71,7 @@ START_TEST (elm_code_line_split_test) newline = elm_code_file_line_get(file, 2); ck_assert_int_eq(5, line->length); ck_assert_int_eq(5, newline->length); + elm_shutdown(); } END_TEST @@ -72,4 +81,3 @@ void elm_code_test_line(TCase *tc) tcase_add_test(tc, elm_code_line_token_count_test); tcase_add_test(tc, elm_code_line_split_test); } - diff --git a/legacy/elm_code/src/tests/elm_code_test_parse.c b/src/tests/elementary/elm_code_test_parse.c similarity index 88% rename from legacy/elm_code/src/tests/elm_code_test_parse.c rename to src/tests/elementary/elm_code_test_parse.c index e91845c3b5..4bd35b4b88 100644 --- a/legacy/elm_code/src/tests/elm_code_test_parse.c +++ b/src/tests/elementary/elm_code_test_parse.c @@ -1,8 +1,11 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "elementary_config.h" #endif -#include "elm_code_suite.h" +#define ELM_INTERNAL_API_ARGESFSDFEFC + +#include "elm_suite.h" +#include "Elementary.h" #include "elm_code_parse.h" static int line_calls, file_calls; @@ -25,6 +28,7 @@ START_TEST (elm_code_parse_hook_memory_test) line_calls = 0; file_calls = 0; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_new(code); @@ -35,6 +39,7 @@ START_TEST (elm_code_parse_hook_memory_test) ck_assert_int_eq(0, file_calls); elm_code_free(code); + elm_shutdown(); } END_TEST @@ -42,11 +47,12 @@ START_TEST (elm_code_parse_hook_file_test) { Elm_Code *code; Elm_Code_File *file; - char *path = TESTS_DIR "testfile.txt"; + char *path = TESTS_SRC_DIR "testfile.txt"; line_calls = 0; file_calls = 0; + elm_init(1, NULL); code = elm_code_create(); elm_code_parser_add(code, _parser_line_callback, _parser_file_callback, NULL); @@ -57,6 +63,7 @@ START_TEST (elm_code_parse_hook_file_test) elm_code_file_close(file); elm_code_free(code); + elm_shutdown(); } END_TEST @@ -66,6 +73,7 @@ START_TEST (elm_code_parse_todo_test) Elm_Code_File *file; Elm_Code_Line *line; + elm_init(1, NULL); elm_code_init(); code = elm_code_create(); @@ -82,6 +90,7 @@ START_TEST (elm_code_parse_todo_test) elm_code_line_text_set(line, "TOFIX", 5); ck_assert_int_eq(ELM_CODE_STATUS_TYPE_DEFAULT, line->status); elm_code_shutdown(); + elm_shutdown(); } END_TEST @@ -91,4 +100,3 @@ void elm_code_test_parse(TCase *tc) tcase_add_test(tc, elm_code_parse_hook_file_test); tcase_add_test(tc, elm_code_parse_todo_test); } - diff --git a/legacy/elm_code/src/tests/elm_code_test_text.c b/src/tests/elementary/elm_code_test_text.c similarity index 91% rename from legacy/elm_code/src/tests/elm_code_test_text.c rename to src/tests/elementary/elm_code_test_text.c index 26e1aa18de..934b98b425 100644 --- a/legacy/elm_code/src/tests/elm_code_test_text.c +++ b/src/tests/elementary/elm_code_test_text.c @@ -1,8 +1,11 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "elementary_config.h" #endif -#include "elm_code_suite.h" +#define ELM_INTERNAL_API_ARGESFSDFEFC + +#include "elm_suite.h" +#include "Elementary.h" #include "elm_code_text.h" START_TEST (elm_code_text_get_test) @@ -11,12 +14,14 @@ START_TEST (elm_code_text_get_test) Elm_Code_File *file; Elm_Code_Line *line; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_new(code); elm_code_file_line_append(file, "test", 4, NULL); line = elm_code_file_line_get(file, 1); ck_assert_str_eq("test", elm_code_line_text_get(line, NULL)); + elm_shutdown(); } END_TEST @@ -26,6 +31,7 @@ START_TEST (elm_code_text_insert_test) Elm_Code_File *file; Elm_Code_Line *line; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_new(code); @@ -34,6 +40,7 @@ START_TEST (elm_code_text_insert_test) elm_code_line_text_insert(line, 4, "ing", 3); ck_assert_str_eq("testing", elm_code_line_text_get(line, NULL)); + elm_shutdown(); } END_TEST @@ -43,6 +50,7 @@ START_TEST (elm_code_text_contains_test) Elm_Code_File *file; Elm_Code_Line *line; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_new(code); @@ -54,6 +62,7 @@ START_TEST (elm_code_text_contains_test) ck_assert_int_eq(EINA_TRUE, elm_code_line_text_contains(line, "a t")); ck_assert_int_eq(EINA_TRUE, elm_code_line_text_contains(line, "...")); + elm_shutdown(); } END_TEST @@ -63,6 +72,7 @@ START_TEST (elm_code_text_strpos_test) Elm_Code_File *file; Elm_Code_Line *line; + elm_init(1, NULL); code = elm_code_create(); file = elm_code_file_new(code); @@ -78,6 +88,7 @@ START_TEST (elm_code_text_strpos_test) ck_assert_int_eq(0, elm_code_line_text_strpos(line, "a t", 0)); ck_assert_int_eq(ELM_CODE_TEXT_NOT_FOUND, elm_code_line_text_strpos(line, "a t", 2)); ck_assert_int_eq(13, elm_code_line_text_strpos(line, "...", 0)); + elm_shutdown(); } END_TEST @@ -87,10 +98,12 @@ START_TEST (elm_code_text_newline_position_test) const char *unixtext = "a test\nwith newline"; const char *wintext = "a windows\r\nnewline"; + elm_init(1, NULL); ck_assert_int_eq(6, elm_code_text_newlinenpos(unixtext, strlen(unixtext), &nllen)); ck_assert_int_eq(1, nllen); ck_assert_int_eq(9, elm_code_text_newlinenpos(wintext, strlen(wintext), &nllen)); ck_assert_int_eq(2, nllen); + elm_shutdown(); } END_TEST @@ -98,6 +111,7 @@ START_TEST (elm_code_text_leading_whitespace_test) { const char *text; + elm_init(1, NULL); text = "testing"; ck_assert_int_eq(0, elm_code_text_leading_whitespace_length(text, strlen(text))); @@ -109,6 +123,7 @@ START_TEST (elm_code_text_leading_whitespace_test) text = " \t mix"; ck_assert_int_eq(3, elm_code_text_leading_whitespace_length(text, strlen(text))); + elm_shutdown(); } END_TEST @@ -116,6 +131,7 @@ START_TEST (elm_code_text_trailing_whitespace_test) { const char *text; + elm_init(1, NULL); text = "testing"; ck_assert_int_eq(0, elm_code_text_trailing_whitespace_length(text, strlen(text))); @@ -127,6 +143,7 @@ START_TEST (elm_code_text_trailing_whitespace_test) text = "mix \t "; ck_assert_int_eq(3, elm_code_text_trailing_whitespace_length(text, strlen(text))); + elm_shutdown(); } END_TEST @@ -134,6 +151,7 @@ START_TEST (elm_code_text_is_whitespace_test) { const char *text; + elm_init(1, NULL); text = " "; ck_assert_int_eq(1, elm_code_text_is_whitespace(text, strlen(text))); @@ -142,6 +160,7 @@ START_TEST (elm_code_text_is_whitespace_test) text = " . "; ck_assert_int_eq(0, elm_code_text_is_whitespace(text, strlen(text))); + elm_shutdown(); } END_TEST diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c b/src/tests/elementary/elm_code_test_widget.c similarity index 93% rename from legacy/elm_code/src/tests/widget/elm_code_test_widget.c rename to src/tests/elementary/elm_code_test_widget.c index 7f2303ff4d..660015363e 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget.c +++ b/src/tests/elementary/elm_code_test_widget.c @@ -1,10 +1,12 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "elementary_config.h" #endif -#include "elm_code_suite.h" +#define ELM_INTERNAL_API_ARGESFSDFEFC -#include "widget/elm_code_widget.c" +#include "elm_suite.h" +#include "Elementary.h" +#include "elm_code_widget.c" static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type, int id) { @@ -89,4 +91,3 @@ void elm_code_test_widget(TCase *tc) tcase_add_test(tc, elm_code_widget_construct); tcase_add_test(tc, elm_code_widget_construct_nocode); } - diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c b/src/tests/elementary/elm_code_test_widget_selection.c similarity index 98% rename from legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c rename to src/tests/elementary/elm_code_test_widget_selection.c index 9769f6bcd0..e181e6e14d 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget_selection.c +++ b/src/tests/elementary/elm_code_test_widget_selection.c @@ -1,12 +1,13 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "elementary_config.h" #endif -#include "elm_code_suite.h" +#define ELM_INTERNAL_API_ARGESFSDFEFC +#include "elm_suite.h" +#include "Elementary.h" #include "elm_code_widget_private.h" - -#include "widget/elm_code_widget_selection.h" +#include "elm_code_widget_selection.h" START_TEST (elm_code_test_widget_selection_set) { @@ -502,6 +503,7 @@ START_TEST (elm_code_test_widget_selection_select_line) selection = elm_code_widget_selection_text_get(widget); ck_assert_str_eq("line2", selection); free(selection); + elm_shutdown(); } END_TEST @@ -536,6 +538,7 @@ START_TEST (elm_code_test_widget_selection_select_word) selection = elm_code_widget_selection_text_get(widget); ck_assert_str_eq("stuff", selection); free(selection); + elm_shutdown(); } END_TEST @@ -574,6 +577,7 @@ START_TEST (elm_code_test_widget_selection_select_word_punctuation) selection = elm_code_widget_selection_text_get(widget); ck_assert_str_eq("mark", selection); free(selection); + elm_shutdown(); } END_TEST @@ -612,6 +616,7 @@ START_TEST (elm_code_test_widget_selection_select_word_symbols) selection = elm_code_widget_selection_text_get(widget); ck_assert_str_eq("braces", selection); free(selection); + elm_shutdown(); } END_TEST @@ -636,4 +641,3 @@ void elm_code_test_widget_selection(TCase *tc) tcase_add_test(tc, elm_code_test_widget_selection_select_word_punctuation); tcase_add_test(tc, elm_code_test_widget_selection_select_word_symbols); } - diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_text.c b/src/tests/elementary/elm_code_test_widget_text.c similarity index 92% rename from legacy/elm_code/src/tests/widget/elm_code_test_widget_text.c rename to src/tests/elementary/elm_code_test_widget_text.c index 86d4a33e51..e11ce6fad4 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget_text.c +++ b/src/tests/elementary/elm_code_test_widget_text.c @@ -1,8 +1,11 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "elementary_config.h" #endif -#include "elm_code_suite.h" +#define ELM_INTERNAL_API_ARGESFSDFEFC + +#include "elm_suite.h" +#include "Elementary.h" START_TEST (elm_code_test_widget_text_tab_width) { @@ -48,6 +51,7 @@ START_TEST (elm_code_test_widget_text_position) ck_assert_int_eq(2, elm_code_widget_line_text_position_for_column_get(widget, line, 9)); ck_assert_int_eq(1, elm_code_widget_line_text_position_for_column_get(widget, line, 7)); + elm_shutdown(); } END_TEST @@ -56,4 +60,3 @@ void elm_code_test_widget_text(TCase *tc) tcase_add_test(tc, elm_code_test_widget_text_tab_width); tcase_add_test(tc, elm_code_test_widget_text_position); } - diff --git a/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c b/src/tests/elementary/elm_code_test_widget_undo.c similarity index 97% rename from legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c rename to src/tests/elementary/elm_code_test_widget_undo.c index 0de2cb91a5..b07a294eb5 100644 --- a/legacy/elm_code/src/tests/widget/elm_code_test_widget_undo.c +++ b/src/tests/elementary/elm_code_test_widget_undo.c @@ -1,9 +1,11 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "elementary_config.h" #endif -#include "elm_code_suite.h" +#define ELM_INTERNAL_API_ARGESFSDFEFC +#include "elm_suite.h" +#include "Elementary.h" #include "elm_code_widget_private.h" START_TEST (elm_code_test_widget_undo_text_insert) @@ -161,4 +163,3 @@ void elm_code_test_widget_undo(TCase *tc) tcase_add_test(tc, elm_code_test_widget_undo_newline); tcase_add_test(tc, elm_code_test_widget_undo_delete); } - diff --git a/src/tests/elementary/elm_suite.c b/src/tests/elementary/elm_suite.c index 75facc6e37..a612e7edc3 100644 --- a/src/tests/elementary/elm_suite.c +++ b/src/tests/elementary/elm_suite.c @@ -71,6 +71,15 @@ static const Efl_Test_Case etc[] = { { "elm_slideshow", elm_test_slideshow}, { "elm_spinner", elm_test_spinner}, { "elm_plug", elm_test_plug}, + { "file_load", elm_code_file_test_load }, + { "file_memory", elm_code_file_test_memory }, + { "parse", elm_code_test_parse }, + { "text", elm_code_test_text }, + { "basic", elm_code_test_basic }, + { "widget", elm_code_test_widget }, + { "widget_text", elm_code_test_widget_text }, + { "widget_selection", elm_code_test_widget_selection }, + { "widget_undo", elm_code_test_widget_undo }, { NULL, NULL } }; diff --git a/src/tests/elementary/elm_suite.h b/src/tests/elementary/elm_suite.h index 1a191793bf..bf87d1b622 100644 --- a/src/tests/elementary/elm_suite.h +++ b/src/tests/elementary/elm_suite.h @@ -69,4 +69,15 @@ void elm_test_slideshow(TCase *tc); void elm_test_spinner(TCase *tc); void elm_test_plug(TCase *tc); +void elm_code_file_test_load(TCase *tc); +void elm_code_file_test_memory(TCase *tc); +void elm_code_test_basic(TCase *tc); +void elm_code_test_line(TCase *tc); +void elm_code_test_parse(TCase *tc); +void elm_code_test_text(TCase *tc); +void elm_code_test_widget(TCase *tc); +void elm_code_test_widget_text(TCase *tc); +void elm_code_test_widget_selection(TCase *tc); +void elm_code_test_widget_undo(TCase *tc); + #endif /* _ELM_SUITE_H */ diff --git a/src/tests/elementary/elm_test_helper.h b/src/tests/elementary/elm_test_helper.h index 0bfc5ca0e6..f0b44bb8ed 100644 --- a/src/tests/elementary/elm_test_helper.h +++ b/src/tests/elementary/elm_test_helper.h @@ -3,6 +3,19 @@ #include +#define ck_assert_strn_eq(s1, s2, len) \ + { \ + char expected[len+1], actual[len+1]; \ + \ + strncpy(expected, s1, len); \ + expected[len] = '\0'; \ + strncpy(actual, s2, len); \ + actual[len] = '\0'; \ + \ + ck_assert_str_eq(expected, actual); \ + } + + Eina_Bool elm_test_helper_wait_flag(double in, Eina_Bool *done); #endif /* _ELM_TEST_HELPER_H */ diff --git a/legacy/elm_code/src/tests/testdiff.diff b/src/tests/elementary/testdiff.diff similarity index 100% rename from legacy/elm_code/src/tests/testdiff.diff rename to src/tests/elementary/testdiff.diff diff --git a/legacy/elm_code/src/tests/testfile-windows.txt b/src/tests/elementary/testfile-windows.txt similarity index 100% rename from legacy/elm_code/src/tests/testfile-windows.txt rename to src/tests/elementary/testfile-windows.txt diff --git a/legacy/elm_code/src/tests/testfile-withblanks.txt b/src/tests/elementary/testfile-withblanks.txt similarity index 100% rename from legacy/elm_code/src/tests/testfile-withblanks.txt rename to src/tests/elementary/testfile-withblanks.txt diff --git a/legacy/elm_code/src/tests/testfile.txt b/src/tests/elementary/testfile.txt similarity index 100% rename from legacy/elm_code/src/tests/testfile.txt rename to src/tests/elementary/testfile.txt From efb9c26a1cb295f509fab398d6b0fe2f72c69b8f Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Fri, 3 Jun 2016 13:55:24 -0700 Subject: [PATCH 252/254] elementary: integrate elm_code theme. --- data/elementary/themes/Makefile.am | 1 + data/elementary/themes/default.edc | 1 + data/elementary/themes/edc/elm/code.edc | 16 +++++++++++++++ legacy/elm_code/data/Makefile.am | 4 ---- legacy/elm_code/data/themes/Makefile.am | 4 ---- .../elm_code/data/themes/default/Makefile.am | 20 ------------------- .../elm_code/data/themes/default/default.edc | 19 ------------------ 7 files changed, 18 insertions(+), 47 deletions(-) create mode 100644 data/elementary/themes/edc/elm/code.edc delete mode 100644 legacy/elm_code/data/Makefile.am delete mode 100644 legacy/elm_code/data/themes/Makefile.am delete mode 100644 legacy/elm_code/data/themes/default/Makefile.am delete mode 100644 legacy/elm_code/data/themes/default/default.edc diff --git a/data/elementary/themes/Makefile.am b/data/elementary/themes/Makefile.am index 40a2000050..19ff5e466a 100644 --- a/data/elementary/themes/Makefile.am +++ b/data/elementary/themes/Makefile.am @@ -95,6 +95,7 @@ elementary/themes/edc/elm/button.edc \ elementary/themes/edc/elm/calendar.edc \ elementary/themes/edc/elm/check.edc \ elementary/themes/edc/elm/clock.edc \ +elementary/themes/edc/elm/code.edc \ elementary/themes/edc/elm/colorsel.edc \ elementary/themes/edc/elm/colorclass.edc \ elementary/themes/edc/elm/conform.edc \ diff --git a/data/elementary/themes/default.edc b/data/elementary/themes/default.edc index cf88829c97..de83033134 100644 --- a/data/elementary/themes/default.edc +++ b/data/elementary/themes/default.edc @@ -72,6 +72,7 @@ collections { #include "edc/elm/gengrid.edc" #include "edc/elm/hover.edc" #include "edc/elm/cursor.edc" +#include "edc/elm/code.edc" // desktop in general #include "edc/wallpaper.edc" diff --git a/data/elementary/themes/edc/elm/code.edc b/data/elementary/themes/edc/elm/code.edc new file mode 100644 index 0000000000..3f371fac14 --- /dev/null +++ b/data/elementary/themes/edc/elm/code.edc @@ -0,0 +1,16 @@ +/* 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; + } + } + } + } +} diff --git a/legacy/elm_code/data/Makefile.am b/legacy/elm_code/data/Makefile.am deleted file mode 100644 index f67d4f3e7b..0000000000 --- a/legacy/elm_code/data/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -MAINTAINERCLEANFILES = Makefile.in - -SUBDIRS = themes - diff --git a/legacy/elm_code/data/themes/Makefile.am b/legacy/elm_code/data/themes/Makefile.am deleted file mode 100644 index 31a2b40dd3..0000000000 --- a/legacy/elm_code/data/themes/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -MAINTAINERCLEANFILES = Makefile.in - -SUBDIRS = default - diff --git a/legacy/elm_code/data/themes/default/Makefile.am b/legacy/elm_code/data/themes/default/Makefile.am deleted file mode 100644 index 46593bf159..0000000000 --- a/legacy/elm_code/data/themes/default/Makefile.am +++ /dev/null @@ -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 diff --git a/legacy/elm_code/data/themes/default/default.edc b/legacy/elm_code/data/themes/default/default.edc deleted file mode 100644 index dea7a81adb..0000000000 --- a/legacy/elm_code/data/themes/default/default.edc +++ /dev/null @@ -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; - } - } - } - } - } -} - From f3d5ae6ec25c71521a94475f4775e5614e0dba35 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Fri, 3 Jun 2016 14:04:36 -0700 Subject: [PATCH 253/254] elementary: make elm_code a BETA API. --- src/lib/elementary/elm_code.c | 2 +- src/lib/elementary/elm_code.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/elementary/elm_code.c b/src/lib/elementary/elm_code.c index ff26ea063e..612272eee3 100644 --- a/src/lib/elementary/elm_code.c +++ b/src/lib/elementary/elm_code.c @@ -1,4 +1,4 @@ -#ifdef HAVE_CONFIG +#ifdef HAVE_CONFIG_H # include "elementary_config.h" #endif diff --git a/src/lib/elementary/elm_code.h b/src/lib/elementary/elm_code.h index 046cb6e965..4e88fc3134 100644 --- a/src/lib/elementary/elm_code.h +++ b/src/lib/elementary/elm_code.h @@ -1,6 +1,8 @@ #ifndef ELM_CODE_H_ # define ELM_CODE_H_ +#ifdef EFL_BETA_API_SUPPORT + #include "elm_code_common.h" #include "elm_code_line.h" #include "elm_code_text.h" @@ -108,4 +110,6 @@ EAPI void elm_code_callback_fire(Elm_Code *code, const Eo_Event_Description *sig } #endif +#endif /* EFL_BETA_API_SUPPORT */ + #endif /* ELM_CODE_H_ */ From 412071497d507715387c19ea5e0aab4c4964b99f Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Fri, 3 Jun 2016 14:17:27 -0700 Subject: [PATCH 254/254] elementary: merge in elm_code example. --- legacy/elm_code/Makefile.am | 4 - legacy/elm_code/src/Makefile.am | 4 - legacy/elm_code/src/bin/Makefile.am | 20 ----- legacy/elm_code/src/lib/Makefile.am | 73 ------------------- legacy/elm_code/src/lib/widget/Makefile.am | 0 legacy/elm_code/src/tests/Makefile.am | 49 ------------- src/Makefile_Elementary.am | 18 ++++- src/bin/elementary/.gitignore | 1 + .../bin/elementary}/elm_code_test_main.c | 10 +-- .../bin/elementary}/elm_code_test_private.h | 0 10 files changed, 22 insertions(+), 157 deletions(-) delete mode 100644 legacy/elm_code/Makefile.am delete mode 100644 legacy/elm_code/src/Makefile.am delete mode 100644 legacy/elm_code/src/bin/Makefile.am delete mode 100644 legacy/elm_code/src/lib/Makefile.am delete mode 100644 legacy/elm_code/src/lib/widget/Makefile.am delete mode 100644 legacy/elm_code/src/tests/Makefile.am rename {legacy/elm_code/src/bin => src/bin/elementary}/elm_code_test_main.c (98%) rename {legacy/elm_code/src/bin => src/bin/elementary}/elm_code_test_private.h (100%) diff --git a/legacy/elm_code/Makefile.am b/legacy/elm_code/Makefile.am deleted file mode 100644 index b10ba50bda..0000000000 --- a/legacy/elm_code/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -MAINTAINERCLEANFILES = Makefile.in - -SUBDIRS = src data - diff --git a/legacy/elm_code/src/Makefile.am b/legacy/elm_code/src/Makefile.am deleted file mode 100644 index 15871c99eb..0000000000 --- a/legacy/elm_code/src/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -MAINTAINERCLEANFILES = Makefile.in - -SUBDIRS = lib bin tests - diff --git a/legacy/elm_code/src/bin/Makefile.am b/legacy/elm_code/src/bin/Makefile.am deleted file mode 100644 index 58105bcfc7..0000000000 --- a/legacy/elm_code/src/bin/Makefile.am +++ /dev/null @@ -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 diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am deleted file mode 100644 index 91bf637d34..0000000000 --- a/legacy/elm_code/src/lib/Makefile.am +++ /dev/null @@ -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) - diff --git a/legacy/elm_code/src/lib/widget/Makefile.am b/legacy/elm_code/src/lib/widget/Makefile.am deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/legacy/elm_code/src/tests/Makefile.am b/legacy/elm_code/src/tests/Makefile.am deleted file mode 100644 index 6150c6f6e0..0000000000 --- a/legacy/elm_code/src/tests/Makefile.am +++ /dev/null @@ -1,49 +0,0 @@ -MAINTAINERCLEANFILES = Makefile.in -CLEANFILES = check-results.xml - -if EFL_HAVE_TESTS - -check_PROGRAMS = elm_code_suite - -elm_code_suite_SOURCES = \ -elm_code_file_test_load.c \ -elm_code_file_test_memory.c \ -elm_code_test_basic.c \ -elm_code_test_line.c \ -elm_code_test_parse.c \ -elm_code_test_text.c \ -widget/elm_code_test_widget.c \ -widget/elm_code_test_widget_text.c \ -widget/elm_code_test_widget_selection.c \ -widget/elm_code_test_widget_undo.c \ -elm_code_suite.c - -elm_code_suite_CPPFLAGS = \ --DEFL_BETA_API_SUPPORT \ --DEFL_EO_API_SUPPORT \ --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)\" \ --DPACKAGE_TESTS_DIR=\"$(top_srcdir)/elm_code/src/tests/\" \ --DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/elm_code/src/tests/\" \ --DTESTS_DIR=\"$(abspath $(srcdir))/\" \ --DEFL_BETA_API_SUPPORT \ -@EFL_CFLAGS@ \ --DEFL_ELM_CODE_BUILD \ -@CHECK_CFLAGS@ - -elm_code_suite_LDADD = @EFL_LIBS@ @CHECK_LIBS@ $(top_builddir)/elm_code/src/lib/libelm_code.la -elm_code_suite_DEPENDENCIES = $(top_builddir)/elm_code/src/lib/libelm_code.la - -testdir = $(PACKAGE_TESTS_DIR) -test_DATA = \ -testfile.txt \ -testfile-windows.txt \ -testfile-withblanks.txt \ -testdiff.diff - -EXTRA_DIST = elm_code_suite.h $(test_DATA) - -endif diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am index c122a75bec..fa9bd84ca9 100644 --- a/src/Makefile_Elementary.am +++ b/src/Makefile_Elementary.am @@ -723,7 +723,8 @@ bin_PROGRAMS += \ bin/elementary/elementary_test \ bin/elementary/elementary_config \ bin/elementary/elementary_codegen \ -bin/elementary/elm_prefs_cc +bin/elementary/elm_prefs_cc \ +bin/elementary/elementary_code if BUILD_QUICKLAUNCH bin_PROGRAMS += \ @@ -861,6 +862,21 @@ bin_elementary_elementary_test_CPPFLAGS = \ -DPACKAGE_DATA_DIR=\"$(datadir)/elementary\" \ @ELEMENTARY_CFLAGS@ +bin_elementary_elementary_code_SOURCES = \ +bin/elementary/elm_code_test_main.c \ +bin/elementary/elm_code_test_private.h +bin_elementary_elementary_code_LDADD = @USE_ELEMENTARY_LIBS@ +bin_elementary_elementary_code_DEPENDENCIES = @USE_ELEMENTARY_INTERNAL_LIBS@ +bin_elementary_elementary_code_CPPFLAGS = \ +-I$(top_srcdir) \ +-I$(top_srcdir)/src/lib/elementary \ +-I$(top_builddir)/src/lib/elementary \ +-I$(top_srcdir)/src/bin/elementary \ +-DPACKAGE_BIN_DIR=\"$(bindir)\" \ +-DPACKAGE_LIB_DIR=\"$(libdir)\" \ +-DPACKAGE_DATA_DIR=\"$(datadir)/elementary\" \ +-DLOCALE_DIR=\"$(localedir)\" \ +@ELEMENTARY_CFLAGS@ bin_elementary_elementary_config_SOURCES = bin/elementary/config.c bin_elementary_elementary_config_LDADD = @USE_ELEMENTARY_LIBS@ diff --git a/src/bin/elementary/.gitignore b/src/bin/elementary/.gitignore index 5cbbb5c189..4f2e315ba3 100644 --- a/src/bin/elementary/.gitignore +++ b/src/bin/elementary/.gitignore @@ -5,3 +5,4 @@ /elementary_codegen /elementary_testql /elm_prefs_cc +/elementary_code diff --git a/legacy/elm_code/src/bin/elm_code_test_main.c b/src/bin/elementary/elm_code_test_main.c similarity index 98% rename from legacy/elm_code/src/bin/elm_code_test_main.c rename to src/bin/elementary/elm_code_test_main.c index b61484fdd9..80588ae159 100644 --- a/legacy/elm_code/src/bin/elm_code_test_main.c +++ b/src/bin/elementary/elm_code_test_main.c @@ -1,5 +1,5 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "elementary_config.h" #endif /* NOTE: Respecting header order is important for portability. @@ -13,8 +13,6 @@ #include #include -#include - #include "elm_code_test_private.h" #define COPYRIGHT "Copyright © 2014 andy and various contributors (see AUTHORS)." @@ -149,7 +147,7 @@ _elm_code_test_diff_inline_setup(Evas_Object *parent) evas_object_show(diff); elm_code_parser_standard_add(code, ELM_CODE_PARSER_STANDARD_DIFF); - elm_code_file_open(code, DATA_DIR "testdiff.diff"); + elm_code_file_open(code, PACKAGE_DATA_DIR "testdiff.diff"); return diff; } @@ -161,7 +159,7 @@ _elm_code_test_diff_setup(Evas_Object *parent) Elm_Code *code; code = elm_code_create(); - elm_code_file_open(code, DATA_DIR "testdiff.diff"); + elm_code_file_open(code, PACKAGE_DATA_DIR "testdiff.diff"); diff = elm_code_diff_widget_add(parent, code); return diff; @@ -403,7 +401,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) #if ENABLE_NLS setlocale(LC_ALL, ""); - bindtextdomain(PACKAGE, LOCALEDIR); + bindtextdomain(PACKAGE, LOCALE_DIR); bind_textdomain_codeset(PACKAGE, "UTF-8"); textdomain(PACKAGE); #endif diff --git a/legacy/elm_code/src/bin/elm_code_test_private.h b/src/bin/elementary/elm_code_test_private.h similarity index 100% rename from legacy/elm_code/src/bin/elm_code_test_private.h rename to src/bin/elementary/elm_code_test_private.h