summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2016-06-11 11:59:34 +0100
committerAndy Williams <andy@andywilliams.me>2016-06-11 12:20:47 +0100
commit0b693bb6cac06353cff7705c1700e6ab88eadce5 (patch)
tree8e52a62aaea0f571f5865e00c16fc8d837b38ec6
parent191bc882d4b6d5fb85a640ef8cd558afd67062e9 (diff)
elementary: merge code test widgets to main test app
-rw-r--r--src/Makefile_Elementary.am20
-rw-r--r--src/bin/elementary/elm_code_test_main.c439
-rw-r--r--src/bin/elementary/elm_code_test_private.h6
-rw-r--r--src/bin/elementary/test.c15
-rw-r--r--src/bin/elementary/test_code.c297
5 files changed, 314 insertions, 463 deletions
diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am
index fee53728ab..dec763fe8f 100644
--- a/src/Makefile_Elementary.am
+++ b/src/Makefile_Elementary.am
@@ -727,8 +727,7 @@ bin_PROGRAMS += \
727bin/elementary/elementary_test \ 727bin/elementary/elementary_test \
728bin/elementary/elementary_config \ 728bin/elementary/elementary_config \
729bin/elementary/elementary_codegen \ 729bin/elementary/elementary_codegen \
730bin/elementary/elm_prefs_cc \ 730bin/elementary/elm_prefs_cc
731bin/elementary/elementary_code
732 731
733if BUILD_QUICKLAUNCH 732if BUILD_QUICKLAUNCH
734bin_PROGRAMS += \ 733bin_PROGRAMS += \
@@ -756,6 +755,7 @@ bin/elementary/test_calendar.c \
756bin/elementary/test_check.c \ 755bin/elementary/test_check.c \
757bin/elementary/test_clock.c \ 756bin/elementary/test_clock.c \
758bin/elementary/test_cnp.c \ 757bin/elementary/test_cnp.c \
758bin/elementary/test_code.c \
759bin/elementary/test_colorselector.c \ 759bin/elementary/test_colorselector.c \
760bin/elementary/test_colorclass.c \ 760bin/elementary/test_colorclass.c \
761bin/elementary/test_combobox.c \ 761bin/elementary/test_combobox.c \
@@ -868,22 +868,6 @@ bin_elementary_elementary_test_CPPFLAGS = \
868-DPACKAGE_DATA_DIR=\"$(datadir)/elementary\" \ 868-DPACKAGE_DATA_DIR=\"$(datadir)/elementary\" \
869@ELEMENTARY_CFLAGS@ 869@ELEMENTARY_CFLAGS@
870 870
871bin_elementary_elementary_code_SOURCES = \
872bin/elementary/elm_code_test_main.c \
873bin/elementary/elm_code_test_private.h
874bin_elementary_elementary_code_LDADD = @USE_ELEMENTARY_LIBS@
875bin_elementary_elementary_code_DEPENDENCIES = @USE_ELEMENTARY_INTERNAL_LIBS@
876bin_elementary_elementary_code_CPPFLAGS = \
877-I$(top_srcdir) \
878-I$(top_srcdir)/src/lib/elementary \
879-I$(top_builddir)/src/lib/elementary \
880-I$(top_srcdir)/src/bin/elementary \
881-DPACKAGE_BIN_DIR=\"$(bindir)\" \
882-DPACKAGE_LIB_DIR=\"$(libdir)\" \
883-DPACKAGE_DATA_DIR=\"$(datadir)/elementary\" \
884-DLOCALE_DIR=\"$(localedir)\" \
885@ELEMENTARY_CFLAGS@
886
887bin_elementary_elementary_config_SOURCES = bin/elementary/config.c 871bin_elementary_elementary_config_SOURCES = bin/elementary/config.c
888bin_elementary_elementary_config_LDADD = @USE_ELEMENTARY_LIBS@ 872bin_elementary_elementary_config_LDADD = @USE_ELEMENTARY_LIBS@
889bin_elementary_elementary_config_DEPENDENCIES = @USE_ELEMENTARY_INTERNAL_LIBS@ 873bin_elementary_elementary_config_DEPENDENCIES = @USE_ELEMENTARY_INTERNAL_LIBS@
diff --git a/src/bin/elementary/elm_code_test_main.c b/src/bin/elementary/elm_code_test_main.c
deleted file mode 100644
index 80588ae159..0000000000
--- a/src/bin/elementary/elm_code_test_main.c
+++ /dev/null
@@ -1,439 +0,0 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5/* NOTE: Respecting header order is important for portability.
6 * Always put system first, then EFL, then your public header,
7 * and finally your private one. */
8
9#if ENABLE_NLS
10# include <libintl.h>
11#endif
12
13#include <Ecore_Getopt.h>
14#include <Elementary.h>
15
16#include "elm_code_test_private.h"
17
18#define COPYRIGHT "Copyright © 2014 andy <andy@andywilliams.me> and various contributors (see AUTHORS)."
19
20static void
21_elm_code_test_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
22{
23 elm_exit();
24}
25
26static void _append_line(Elm_Code_File *file, const char *line)
27{
28 int length;
29
30 length = strlen(line);
31 elm_code_file_line_append(file, line, length, NULL);
32}
33
34static Eina_Bool
35_elm_code_test_line_clicked_cb(void *data EINA_UNUSED, const Eo_Event *event)
36{
37 Elm_Code_Line *line;
38
39 line = (Elm_Code_Line *)event->info;
40
41 printf("CLICKED line %d\n", line->number);
42 return EO_CALLBACK_CONTINUE;
43}
44
45static Eina_Bool
46_elm_code_test_line_done_cb(void *data EINA_UNUSED, const Eo_Event *event)
47{
48 Elm_Code_Line *line;
49
50 line = (Elm_Code_Line *)event->info;
51
52 if (line->number == 1)
53 elm_code_line_token_add(line, 17, 24, 1, ELM_CODE_TOKEN_TYPE_COMMENT);
54 else if (line->number == 4)
55 line->status = ELM_CODE_STATUS_TYPE_ERROR;
56
57 return EO_CALLBACK_STOP;
58}
59
60static Evas_Object *
61_elm_code_test_welcome_setup(Evas_Object *parent)
62{
63 Elm_Code *code;
64 Elm_Code_Widget *widget;
65
66 code = elm_code_create();
67 widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code));
68 elm_obj_code_widget_font_set(widget, NULL, 12);
69 eo_event_callback_add(widget, &ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_test_line_done_cb, NULL);
70 eo_event_callback_add(widget, ELM_OBJ_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code);
71
72 _append_line(code->file, "❤ Hello World, Elm Code! ❤");
73 _append_line(code->file, "");
74 _append_line(code->file, "This is a demo of elm_code's capabilities.");
75 _append_line(code->file, "⚑ *** Currently experimental ***");
76
77 evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
78 evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
79 evas_object_show(widget);
80
81 elm_code_widget_selection_start(widget, 1, 3);
82 elm_code_widget_selection_end(widget, 1, 13);
83
84 return widget;
85}
86
87static Evas_Object *
88_elm_code_test_editor_setup(Evas_Object *parent, Eina_Bool log)
89{
90 Elm_Code *code;
91 Elm_Code_Line *line;
92 Elm_Code_Widget *widget;
93
94 code = elm_code_create();
95 widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code));
96 elm_obj_code_widget_font_set(widget, NULL, 14);
97 elm_obj_code_widget_editable_set(widget, EINA_TRUE);
98 elm_obj_code_widget_show_whitespace_set(widget, EINA_TRUE);
99 elm_obj_code_widget_line_numbers_set(widget, EINA_TRUE);
100
101 if (!log)
102 {
103 _append_line(code->file, "Edit me :)");
104 _append_line(code->file, "");
105 _append_line(code->file, "");
106 _append_line(code->file, "...Please?");
107
108 line = elm_code_file_line_get(code->file, 1);
109 elm_code_line_token_add(line, 5, 6, 1, ELM_CODE_TOKEN_TYPE_COMMENT);
110 elm_code_callback_fire(code, &ELM_CODE_EVENT_LINE_LOAD_DONE, line);
111 }
112
113 evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
114 evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
115 evas_object_show(widget);
116
117 return widget;
118}
119
120static Evas_Object *
121_elm_code_test_mirror_setup(Elm_Code *code, char *font_name, Evas_Object *parent)
122{
123 Elm_Code_Widget *widget;
124
125 widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code));
126 elm_obj_code_widget_font_set(widget, font_name, 11);
127 elm_obj_code_widget_line_numbers_set(widget, EINA_TRUE);
128
129 evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
130 evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
131 evas_object_show(widget);
132
133 return widget;
134}
135
136static Evas_Object *
137_elm_code_test_diff_inline_setup(Evas_Object *parent)
138{
139 Evas_Object *diff;
140 Elm_Code *code;
141
142 code = elm_code_create();
143 diff = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code));
144
145 evas_object_size_hint_weight_set(diff, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
146 evas_object_size_hint_align_set(diff, EVAS_HINT_FILL, EVAS_HINT_FILL);
147 evas_object_show(diff);
148
149 elm_code_parser_standard_add(code, ELM_CODE_PARSER_STANDARD_DIFF);
150 elm_code_file_open(code, PACKAGE_DATA_DIR "testdiff.diff");
151
152 return diff;
153}
154
155static Evas_Object *
156_elm_code_test_diff_setup(Evas_Object *parent)
157{
158 Evas_Object *diff;
159 Elm_Code *code;
160
161 code = elm_code_create();
162 elm_code_file_open(code, PACKAGE_DATA_DIR "testdiff.diff");
163
164 diff = elm_code_diff_widget_add(parent, code);
165 return diff;
166}
167
168static Eina_Bool
169_elm_code_test_log_timer(void *data)
170{
171 Elm_Code *code = data;
172 static int line = 0;
173 char buf[250];
174
175 sprintf(buf, "line %d", ++line);
176 _append_line(code->file, buf);
177
178 return ECORE_CALLBACK_RENEW;
179}
180
181static void
182_elm_code_test_log_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
183{
184 static Ecore_Timer *t = NULL;
185
186 if (t)
187 {
188 elm_object_text_set(obj, "Start");
189 ecore_timer_del(t);
190 t = NULL;
191 return;
192 }
193
194 t = ecore_timer_add(0.05, _elm_code_test_log_timer, data);
195 elm_object_text_set(obj, "Stop");
196}
197
198static void
199_elm_code_test_welcome_editor_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
200{
201 Evas_Object *naviframe, *screen;
202
203 naviframe = (Evas_Object *)data;
204 screen = elm_box_add(naviframe);
205 evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
206 elm_box_pack_end(screen, _elm_code_test_editor_setup(screen, EINA_FALSE));
207 evas_object_show(screen);
208
209 elm_naviframe_item_push(naviframe, "Editor",
210 NULL, NULL, screen, NULL);
211}
212
213static void
214_elm_code_test_welcome_log_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
215{
216 Evas_Object *naviframe, *screen, *o, *code;
217
218 naviframe = (Evas_Object *)data;
219 screen = elm_box_add(naviframe);
220 evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
221
222 code = _elm_code_test_editor_setup(screen, EINA_TRUE);
223 elm_box_pack_end(screen, code);
224
225 o = elm_button_add(screen);
226 elm_object_text_set(o, "log");
227 evas_object_smart_callback_add(o, "clicked", _elm_code_test_log_clicked, elm_obj_code_widget_code_get(code));
228 elm_box_pack_end(screen, o);
229 evas_object_show(o);
230
231 evas_object_show(screen);
232
233 elm_naviframe_item_push(naviframe, "Editor",
234 NULL, NULL, screen, NULL);
235}
236
237static void
238_elm_code_test_welcome_mirror_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
239{
240 Elm_Code *code;
241 Evas_Object *naviframe, *screen, *widget;
242
243 naviframe = (Evas_Object *)data;
244 screen = elm_box_add(naviframe);
245 elm_box_homogeneous_set(screen, EINA_TRUE);
246 evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
247
248 widget = _elm_code_test_editor_setup(screen, EINA_FALSE);
249 code = elm_obj_code_widget_code_get(widget);
250 elm_box_pack_end(screen, widget);
251
252 elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, "Mono:style=Oblique", screen));
253 elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, "Nimbus Mono", screen));
254
255 evas_object_show(screen);
256 elm_naviframe_item_push(naviframe, "Mirrored editor",
257 NULL, NULL, screen, NULL);
258}
259
260static void
261_elm_code_test_welcome_diff_inline_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
262{
263 Evas_Object *naviframe, *screen;
264
265 naviframe = (Evas_Object *)data;
266 screen = elm_box_add(naviframe);
267 evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
268 elm_box_pack_end(screen, _elm_code_test_diff_inline_setup(screen));
269 evas_object_show(screen);
270
271 elm_naviframe_item_push(naviframe, "Diff widget (inline)",
272 NULL, NULL, screen, NULL);
273}
274
275static void
276_elm_code_test_welcome_diff_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
277{
278 Evas_Object *naviframe, *screen;
279
280 naviframe = (Evas_Object *)data;
281 screen = elm_box_add(naviframe);
282 evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
283 elm_box_pack_end(screen, _elm_code_test_diff_setup(screen));
284 evas_object_show(screen);
285
286 elm_naviframe_item_push(naviframe, "Diff widget (comparison)",
287 NULL, NULL, screen, NULL);
288}
289
290static Evas_Object *
291elm_code_test_win_setup(void)
292{
293 Evas_Object *win, *vbox, *text, *button, *naviframe;
294 Elm_Object_Item *item;
295
296 win = elm_win_util_standard_add("main", "Elm_Code Demo");
297 if (!win) return NULL;
298
299 naviframe = elm_naviframe_add(win);
300 evas_object_size_hint_weight_set(naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
301 elm_win_resize_object_add(win, naviframe);
302 evas_object_show(naviframe);
303
304 vbox = elm_box_add(win);
305 evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
306 evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
307 evas_object_show(vbox);
308
309 text = _elm_code_test_welcome_setup(vbox);
310 evas_object_size_hint_weight_set(text, EVAS_HINT_EXPAND, 0.5);
311 elm_box_pack_end(vbox, text);
312
313 button = elm_button_add(vbox);
314 elm_object_text_set(button, "Editor");
315 evas_object_size_hint_weight_set(button, 0.5, 0.25);
316 evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 1.0);
317 evas_object_smart_callback_add(button, "clicked",
318 _elm_code_test_welcome_editor_cb, naviframe);
319 elm_box_pack_end(vbox, button);
320 evas_object_show(button);
321
322 button = elm_button_add(vbox);
323 elm_object_text_set(button, "Log viewer");
324 evas_object_size_hint_weight_set(button, 0.5, 0.0);
325 evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 1.0);
326 evas_object_smart_callback_add(button, "clicked",
327 _elm_code_test_welcome_log_cb, naviframe);
328 elm_box_pack_end(vbox, button);
329 evas_object_show(button);
330
331 button = elm_button_add(vbox);
332 elm_object_text_set(button, "Mirrored editor");
333 evas_object_size_hint_weight_set(button, 0.5, 0.0);
334 evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 0.5);
335 evas_object_smart_callback_add(button, "clicked",
336 _elm_code_test_welcome_mirror_cb, naviframe);
337 elm_box_pack_end(vbox, button);
338 evas_object_show(button);
339
340 button = elm_button_add(vbox);
341 elm_object_text_set(button, "Diff (inline)");
342 evas_object_size_hint_weight_set(button, 0.5, 0.0);
343 evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 0.5);
344 evas_object_smart_callback_add(button, "clicked",
345 _elm_code_test_welcome_diff_inline_cb, naviframe);
346 elm_box_pack_end(vbox, button);
347 evas_object_show(button);
348
349 button = elm_button_add(vbox);
350 elm_object_text_set(button, "Diff (comparison)");
351 evas_object_size_hint_weight_set(button, 0.5, 0.25);
352 evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 0.0);
353 evas_object_smart_callback_add(button, "clicked",
354 _elm_code_test_welcome_diff_cb, naviframe);
355 elm_box_pack_end(vbox, button);
356 evas_object_show(button);
357
358 item = elm_naviframe_item_push(naviframe, "Choose Demo",
359 NULL, NULL,vbox, NULL);
360 elm_naviframe_item_title_enabled_set(item, EINA_FALSE, EINA_FALSE);
361 elm_win_resize_object_add(win, naviframe);
362
363 evas_object_smart_callback_add(win, "delete,request", _elm_code_test_win_del, NULL);
364 evas_object_resize(win, 400 * elm_config_scale_get(), 320 * elm_config_scale_get());
365 evas_object_show(win);
366
367 return win;
368}
369
370static const Ecore_Getopt optdesc = {
371 "elm_code_test",
372 "%prog [options]",
373 PACKAGE_VERSION,
374 COPYRIGHT,
375 "BSD with advertisement clause",
376 "An EFL elm_code_test program",
377 0,
378 {
379 ECORE_GETOPT_LICENSE('L', "license"),
380 ECORE_GETOPT_COPYRIGHT('C', "copyright"),
381 ECORE_GETOPT_VERSION('V', "version"),
382 ECORE_GETOPT_HELP('h', "help"),
383 ECORE_GETOPT_SENTINEL
384 }
385};
386
387EAPI_MAIN int
388elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
389{
390 Evas_Object *win;
391 int args;
392 Eina_Bool quit_option = EINA_FALSE;
393
394 Ecore_Getopt_Value values[] = {
395 ECORE_GETOPT_VALUE_BOOL(quit_option),
396 ECORE_GETOPT_VALUE_BOOL(quit_option),
397 ECORE_GETOPT_VALUE_BOOL(quit_option),
398 ECORE_GETOPT_VALUE_BOOL(quit_option),
399 ECORE_GETOPT_VALUE_NONE
400 };
401
402#if ENABLE_NLS
403 setlocale(LC_ALL, "");
404 bindtextdomain(PACKAGE, LOCALE_DIR);
405 bind_textdomain_codeset(PACKAGE, "UTF-8");
406 textdomain(PACKAGE);
407#endif
408
409 elm_code_init();
410
411 args = ecore_getopt_parse(&optdesc, values, argc, argv);
412 if (args < 0)
413 {
414 EINA_LOG_CRIT("Could not parse arguments.");
415 goto end;
416 }
417 else if (quit_option)
418 {
419 goto end;
420 }
421
422 /* tell elm about our app so it can figure out where to get files */
423 elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
424 elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR);
425 elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
426 elm_app_info_set(elm_main, "elm_code_test", "images/elm_code.png");
427
428 if (!(win = elm_code_test_win_setup()))
429 goto end;
430
431 elm_run();
432
433 end:
434 elm_code_shutdown();
435 elm_shutdown();
436
437 return 0;
438}
439ELM_MAIN()
diff --git a/src/bin/elementary/elm_code_test_private.h b/src/bin/elementary/elm_code_test_private.h
deleted file mode 100644
index 04fb817a02..0000000000
--- a/src/bin/elementary/elm_code_test_private.h
+++ /dev/null
@@ -1,6 +0,0 @@
1#ifndef ELM_CODE_TEST_PRIVATE_H_
2# define ELM_CODE_TEST_PRIVATE_H_
3
4// FIXME: put some private stuff related to your binary
5
6#endif
diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c
index b43fad940e..6dd37be640 100644
--- a/src/bin/elementary/test.c
+++ b/src/bin/elementary/test.c
@@ -279,6 +279,13 @@ void test_layout_disable(void *data, Evas_Object *obj, void *event_info);
279 279
280void test_colorclass(void *data, Evas_Object *obj, void *event_info); 280void test_colorclass(void *data, Evas_Object *obj, void *event_info);
281 281
282void test_code_welcome(void *data, Evas_Object *obj, void *event_info);
283void test_code_editor(void *data, Evas_Object *obj, void *event_info);
284void test_code_mirror(void *data, Evas_Object *obj, void *event_info);
285void test_code_log(void *data, Evas_Object *obj, void *event_info);
286void test_code_diff(void *data, Evas_Object *obj, void *event_info);
287void test_code_diff_inline(void *data, Evas_Object *obj, void *event_info);
288
282Evas_Object *win, *tbx; // TODO: refactoring 289Evas_Object *win, *tbx; // TODO: refactoring
283void *tt; 290void *tt;
284Eina_List *tests; 291Eina_List *tests;
@@ -625,6 +632,14 @@ add_tests:
625 ADD_TEST(NULL, "Entries", "Entry Emoticon", test_entry_emoticon); 632 ADD_TEST(NULL, "Entries", "Entry Emoticon", test_entry_emoticon);
626 633
627 //------------------------------// 634 //------------------------------//
635 ADD_TEST(NULL, "Advanced Entries", "Code Entry Markup", test_code_welcome);
636 ADD_TEST(NULL, "Advanced Entries", "Code Editor", test_code_editor);
637 ADD_TEST(NULL, "Advanced Entries", "Mirrored Editor", test_code_mirror);
638 ADD_TEST(NULL, "Advanced Entries", "Logger", test_code_log);
639 ADD_TEST(NULL, "Advanced Entries", "Diff Comparison", test_code_diff);
640 ADD_TEST(NULL, "Advanced Entries", "Diff Inline", test_code_diff_inline);
641
642 //------------------------------//
628 ADD_TEST(NULL, "Buttons", "Button", test_button); 643 ADD_TEST(NULL, "Buttons", "Button", test_button);
629 644
630 //------------------------------// 645 //------------------------------//
diff --git a/src/bin/elementary/test_code.c b/src/bin/elementary/test_code.c
new file mode 100644
index 0000000000..ed2d7ad765
--- /dev/null
+++ b/src/bin/elementary/test_code.c
@@ -0,0 +1,297 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4#include <Elementary.h>
5
6static Evas_Object *_test_code_win_create(const char *id, const char *name)
7{
8 Evas_Object *win;
9
10 win = elm_win_add(NULL, id, ELM_WIN_BASIC);
11 elm_win_title_set(win, name);
12 elm_win_autodel_set(win, EINA_TRUE);
13
14 evas_object_resize(win, 360 * elm_config_scale_get(), 220 * elm_config_scale_get());
15 return win;
16}
17
18static void _append_line(Elm_Code_File *file, const char *line)
19{
20 int length;
21
22 length = strlen(line);
23 elm_code_file_line_append(file, line, length, NULL);
24}
25
26static Eina_Bool
27_elm_code_test_line_clicked_cb(void *data EINA_UNUSED, const Eo_Event *event)
28{
29 Elm_Code_Line *line;
30
31 line = (Elm_Code_Line *)event->info;
32
33 printf("CLICKED line %d\n", line->number);
34 return EO_CALLBACK_CONTINUE;
35}
36
37static Eina_Bool
38_elm_code_test_line_done_cb(void *data EINA_UNUSED, const Eo_Event *event)
39{
40 Elm_Code_Line *line;
41
42 line = (Elm_Code_Line *)event->info;
43
44 if (line->number == 1)
45 elm_code_line_token_add(line, 17, 24, 1, ELM_CODE_TOKEN_TYPE_COMMENT);
46 else if (line->number == 4)
47 line->status = ELM_CODE_STATUS_TYPE_ERROR;
48
49 return EO_CALLBACK_STOP;
50}
51
52static Evas_Object *
53_elm_code_test_welcome_setup(Evas_Object *parent)
54{
55 Elm_Code *code;
56 Elm_Code_Widget *widget;
57
58 code = elm_code_create();
59 widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code));
60 elm_obj_code_widget_font_set(widget, NULL, 12);
61 eo_event_callback_add(widget, &ELM_CODE_EVENT_LINE_LOAD_DONE, _elm_code_test_line_done_cb, NULL);
62 eo_event_callback_add(widget, ELM_OBJ_CODE_WIDGET_EVENT_LINE_CLICKED, _elm_code_test_line_clicked_cb, code);
63
64 _append_line(code->file, "❤ Hello World, Elm Code! ❤");
65 _append_line(code->file, "");
66 _append_line(code->file, "This is a demo of elm_code's capabilities.");
67 _append_line(code->file, "⚑ *** Currently experimental ***");
68
69 evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
70 evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
71 evas_object_show(widget);
72
73 elm_code_widget_selection_start(widget, 1, 3);
74 elm_code_widget_selection_end(widget, 1, 13);
75
76 return widget;
77}
78
79static Evas_Object *
80_elm_code_test_editor_setup(Evas_Object *parent, Eina_Bool log)
81{
82 Elm_Code *code;
83 Elm_Code_Line *line;
84 Elm_Code_Widget *widget;
85
86 code = elm_code_create();
87 widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code));
88 elm_obj_code_widget_font_set(widget, NULL, 14);
89 elm_obj_code_widget_editable_set(widget, EINA_TRUE);
90 elm_obj_code_widget_show_whitespace_set(widget, EINA_TRUE);
91 elm_obj_code_widget_line_numbers_set(widget, EINA_TRUE);
92
93 if (!log)
94 {
95 _append_line(code->file, "Edit me :)");
96 _append_line(code->file, "");
97 _append_line(code->file, "");
98 _append_line(code->file, "...Please?");
99
100 line = elm_code_file_line_get(code->file, 1);
101 elm_code_line_token_add(line, 5, 6, 1, ELM_CODE_TOKEN_TYPE_COMMENT);
102 elm_code_callback_fire(code, &ELM_CODE_EVENT_LINE_LOAD_DONE, line);
103 }
104
105 evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
106 evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
107 evas_object_show(widget);
108
109 return widget;
110}
111
112static Evas_Object *
113_elm_code_test_mirror_setup(Elm_Code *code, char *font_name, Evas_Object *parent)
114{
115 Elm_Code_Widget *widget;
116
117 widget = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code));
118 elm_obj_code_widget_font_set(widget, font_name, 11);
119 elm_obj_code_widget_line_numbers_set(widget, EINA_TRUE);
120
121 evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
122 evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
123 evas_object_show(widget);
124
125 return widget;
126}
127
128static Evas_Object *
129_elm_code_test_diff_inline_setup(Evas_Object *parent)
130{
131 Evas_Object *diff;
132 Elm_Code *code;
133
134 code = elm_code_create();
135 diff = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, code));
136
137 evas_object_size_hint_weight_set(diff, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
138 evas_object_size_hint_align_set(diff, EVAS_HINT_FILL, EVAS_HINT_FILL);
139 evas_object_show(diff);
140
141 elm_code_parser_standard_add(code, ELM_CODE_PARSER_STANDARD_DIFF);
142 elm_code_file_open(code, PACKAGE_DATA_DIR "testdiff.diff");
143
144 return diff;
145}
146
147static Evas_Object *
148_elm_code_test_diff_setup(Evas_Object *parent)
149{
150 Evas_Object *diff;
151 Elm_Code *code;
152
153 code = elm_code_create();
154 elm_code_file_open(code, PACKAGE_DATA_DIR "testdiff.diff");
155
156 diff = elm_code_diff_widget_add(parent, code);
157 return diff;
158}
159
160static Eina_Bool
161_elm_code_test_log_timer(void *data)
162{
163 Elm_Code *code = data;
164 static int line = 0;
165 char buf[250];
166
167 sprintf(buf, "line %d", ++line);
168 _append_line(code->file, buf);
169
170 return ECORE_CALLBACK_RENEW;
171}
172
173static void
174_elm_code_test_log_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
175{
176 static Ecore_Timer *t = NULL;
177
178 if (t)
179 {
180 elm_object_text_set(obj, "Start");
181 ecore_timer_del(t);
182 t = NULL;
183 return;
184 }
185
186 t = ecore_timer_add(0.05, _elm_code_test_log_timer, data);
187 elm_object_text_set(obj, "Stop");
188}
189
190void
191test_code_editor(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
192{
193 Evas_Object *win, *screen;
194
195 win = _test_code_win_create("code-editor", "Code Editor");
196 screen = elm_box_add(win);
197 evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
198 elm_box_pack_end(screen, _elm_code_test_editor_setup(screen, EINA_FALSE));
199 elm_win_resize_object_add(win, screen);
200 evas_object_show(screen);
201
202 evas_object_show(win);
203}
204
205void
206test_code_log(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
207{
208 Evas_Object *win, *screen, *o, *code;
209
210 win = _test_code_win_create("code-log", "Code Log");
211 screen = elm_box_add(win);
212 evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
213
214 code = _elm_code_test_editor_setup(screen, EINA_TRUE);
215 elm_box_pack_end(screen, code);
216
217 o = elm_button_add(screen);
218 elm_object_text_set(o, "log");
219 evas_object_smart_callback_add(o, "clicked", _elm_code_test_log_clicked, elm_obj_code_widget_code_get(code));
220 elm_box_pack_end(screen, o);
221 evas_object_show(o);
222
223 elm_win_resize_object_add(win, screen);
224 evas_object_show(screen);
225
226 evas_object_show(win);
227}
228
229void
230test_code_mirror(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
231{
232 Elm_Code *code;
233 Evas_Object *win, *screen, *widget;
234
235 win = _test_code_win_create("code-mirror", "Code Mirror");
236 screen = elm_box_add(win);
237 elm_box_homogeneous_set(screen, EINA_TRUE);
238 evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
239
240 widget = _elm_code_test_editor_setup(screen, EINA_FALSE);
241 code = elm_obj_code_widget_code_get(widget);
242 elm_box_pack_end(screen, widget);
243
244 elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, "Mono:style=Oblique", screen));
245 elm_box_pack_end(screen, _elm_code_test_mirror_setup(code, "Nimbus Mono", screen));
246
247 elm_win_resize_object_add(win, screen);
248 evas_object_show(screen);
249
250 evas_object_show(win);
251}
252
253void
254test_code_diff_inline(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
255{
256 Evas_Object *win, *screen;
257
258 win = _test_code_win_create("code-diff-inline", "Code Diff Inline");
259 screen = elm_box_add(win);
260 evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
261 elm_box_pack_end(screen, _elm_code_test_diff_inline_setup(screen));
262 elm_win_resize_object_add(win, screen);
263 evas_object_show(screen);
264
265 evas_object_show(win);
266}
267
268void
269test_code_diff(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
270{
271 Evas_Object *win, *screen;
272
273 win = _test_code_win_create("code-diff", "Code Diff");
274 screen = elm_box_add(win);
275 evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
276 elm_box_pack_end(screen, _elm_code_test_diff_setup(screen));
277 elm_win_resize_object_add(win, screen);
278 evas_object_show(screen);
279
280 evas_object_show(win);
281}
282
283void
284test_code_welcome(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
285{
286 Evas_Object *win, *screen;
287
288 win = _test_code_win_create("code-welcome", "Code Welcome");
289 screen = elm_box_add(win);
290 evas_object_size_hint_weight_set(screen, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
291 elm_box_pack_end(screen, _elm_code_test_welcome_setup(screen));
292 elm_win_resize_object_add(win, screen);
293 evas_object_show(screen);
294
295 evas_object_show(win);
296}
297