diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/text_editor.c | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c index c5515026dc..216fbc0117 100644 --- a/apps/plugins/text_editor.c +++ b/apps/plugins/text_editor.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include "lib/playback_control.h" | 22 | #include "lib/playback_control.h" |
23 | 23 | ||
24 | #if PLUGIN_BUFFER_SIZE > 0x45000 | 24 | #if PLUGIN_BUFFER_SIZE > 0x45000 |
25 | #define MAX_CHARS 0x40000 /* 128 kiB */ | 25 | #define MAX_CHARS 0x40000 /* 256 kiB */ |
26 | #else | 26 | #else |
27 | #define MAX_CHARS 0x6000 /* 24 kiB */ | 27 | #define MAX_CHARS 0x6000 /* 24 kiB */ |
28 | #endif | 28 | #endif |
@@ -58,7 +58,7 @@ int do_action(int action, char* str, int line) | |||
58 | 58 | ||
59 | int _do_action(int action, char* str, int line) | 59 | int _do_action(int action, char* str, int line) |
60 | { | 60 | { |
61 | int len; | 61 | int len, lennew; |
62 | int i=0,c=0; | 62 | int i=0,c=0; |
63 | if (line>=last_action_line) | 63 | if (line>=last_action_line) |
64 | { | 64 | { |
@@ -76,7 +76,7 @@ int _do_action(int action, char* str, int line) | |||
76 | len = rb->strlen(str)+1; | 76 | len = rb->strlen(str)+1; |
77 | if ( char_count+ len > MAX_CHARS ) | 77 | if ( char_count+ len > MAX_CHARS ) |
78 | return 0; | 78 | return 0; |
79 | rb->memmove(&buffer[c+len],&buffer[c],char_count); | 79 | rb->memmove(&buffer[c+len],&buffer[c],char_count-c); |
80 | rb->strcpy(&buffer[c],str); | 80 | rb->strcpy(&buffer[c],str); |
81 | char_count += len; | 81 | char_count += len; |
82 | line_count++; | 82 | line_count++; |
@@ -92,22 +92,27 @@ int _do_action(int action, char* str, int line) | |||
92 | if (line > line_count) | 92 | if (line > line_count) |
93 | return 0; | 93 | return 0; |
94 | len = rb->strlen(&buffer[c])+1; | 94 | len = rb->strlen(&buffer[c])+1; |
95 | rb->memmove(&buffer[c],&buffer[c+len],char_count-c-len); | ||
95 | char_count -= len; | 96 | char_count -= len; |
96 | rb->memmove(&buffer[c],&buffer[c+len],char_count); | ||
97 | line_count--; | 97 | line_count--; |
98 | break; | 98 | break; |
99 | case ACTION_UPDATE: | 99 | case ACTION_UPDATE: |
100 | if (line > line_count) | 100 | if (line > line_count) |
101 | return 0; | 101 | return 0; |
102 | len = rb->strlen(&buffer[c])+1; | 102 | len = rb->strlen(&buffer[c])+1; |
103 | rb->memmove(&buffer[c+rb->strlen(str)+1],&buffer[c+len],char_count); | 103 | lennew = rb->strlen(str)+1; |
104 | if ( char_count+ lennew-len > MAX_CHARS ) | ||
105 | return 0; | ||
106 | rb->memmove(&buffer[c+lennew],&buffer[c+len],char_count-c-len); | ||
104 | rb->strcpy(&buffer[c],str); | 107 | rb->strcpy(&buffer[c],str); |
105 | char_count += rb->strlen(str)+1-len; | 108 | char_count += lennew-len; |
106 | break; | 109 | break; |
107 | case ACTION_CONCAT: | 110 | case ACTION_CONCAT: |
108 | if (line > line_count) | 111 | if (line > line_count) |
109 | return 0; | 112 | return 0; |
110 | rb->memmove(&buffer[c-1],&buffer[c],char_count); | 113 | rb->memmove(&buffer[c-1],&buffer[c],char_count-c); |
114 | char_count--; | ||
115 | line_count--; | ||
111 | break; | 116 | break; |
112 | default: | 117 | default: |
113 | return 0; | 118 | return 0; |
@@ -264,7 +269,7 @@ int do_item_menu(int cur_sel, char* copy_buffer) | |||
264 | break; | 269 | break; |
265 | case 6: /* playback menu */ | 270 | case 6: /* playback menu */ |
266 | playback_control(NULL); | 271 | playback_control(NULL); |
267 | ret = MENU_RET_UPDATE; | 272 | ret = MENU_RET_NO_UPDATE; |
268 | break; | 273 | break; |
269 | default: | 274 | default: |
270 | ret = MENU_RET_NO_UPDATE; | 275 | ret = MENU_RET_NO_UPDATE; |
@@ -389,56 +394,57 @@ enum plugin_status plugin_start(const void* parameter) | |||
389 | { | 394 | { |
390 | case ACTION_STD_OK: | 395 | case ACTION_STD_OK: |
391 | { | 396 | { |
392 | bool edit_text = true; | ||
393 | #ifdef HAVE_LCD_COLOR | ||
394 | int color; | ||
395 | #endif | ||
396 | if (line_count) | 397 | if (line_count) |
397 | rb->strcpy(temp_line,&buffer[do_action(ACTION_GET,0,cur_sel)]); | 398 | rb->strcpy(temp_line,&buffer[do_action(ACTION_GET,0,cur_sel)]); |
398 | #ifdef HAVE_LCD_COLOR | 399 | #ifdef HAVE_LCD_COLOR |
399 | if (edit_colors_file) | 400 | if (edit_colors_file && line_count) |
400 | { | 401 | { |
401 | char *name = temp_line, *value = NULL; | 402 | char *name = temp_line, *value = NULL; |
402 | char extension[MAX_LINE_LEN]; | 403 | char extension[MAX_LINE_LEN]; |
404 | int color, old_color; | ||
405 | bool temp_changed; | ||
403 | rb->settings_parseline(temp_line, &name, &value); | 406 | rb->settings_parseline(temp_line, &name, &value); |
404 | if (line_count) | 407 | if (line_count) |
405 | { | 408 | { |
406 | MENUITEM_STRINGLIST(menu, "Edit What?", NULL, | 409 | MENUITEM_STRINGLIST(menu, "Edit What?", NULL, |
407 | "Extension", "Colour",); | 410 | "Extension", "Colour",); |
411 | rb->strcpy(extension, name); | ||
412 | if (value) | ||
413 | hex_to_rgb(value, &color); | ||
414 | else | ||
415 | color = 0; | ||
416 | |||
408 | switch (rb->do_menu(&menu, NULL, NULL, false)) | 417 | switch (rb->do_menu(&menu, NULL, NULL, false)) |
409 | { | 418 | { |
410 | case 0: | 419 | case 0: |
411 | edit_text = true; | 420 | temp_changed = !rb->kbd_input(extension,MAX_LINE_LEN); |
412 | break; | 421 | break; |
413 | case 1: | 422 | case 1: |
414 | edit_text = false; | 423 | old_color = color; |
415 | if (value) | ||
416 | hex_to_rgb(value, &color); | ||
417 | else color = 0; | ||
418 | rb->strcpy(extension, name); | ||
419 | rb->set_color(rb->screens[SCREEN_MAIN], name, &color, -1); | 424 | rb->set_color(rb->screens[SCREEN_MAIN], name, &color, -1); |
420 | rb->snprintf(temp_line, MAX_LINE_LEN, "%s: %02X%02X%02X", | 425 | temp_changed = (value == NULL) || (color != old_color); |
421 | extension, RGB_UNPACK_RED(color), | ||
422 | RGB_UNPACK_GREEN(color), | ||
423 | RGB_UNPACK_BLUE(color)); | ||
424 | if (line_count) | ||
425 | { | ||
426 | do_action(ACTION_UPDATE,temp_line,cur_sel); | ||
427 | } | ||
428 | else do_action(ACTION_INSERT,temp_line,cur_sel); | ||
429 | changed = true; | ||
430 | break; | 426 | break; |
431 | } | 427 | } |
428 | |||
429 | if (temp_changed) | ||
430 | { | ||
431 | rb->snprintf(temp_line, MAX_LINE_LEN, "%s: %02X%02X%02X", | ||
432 | extension, RGB_UNPACK_RED(color), | ||
433 | RGB_UNPACK_GREEN(color), | ||
434 | RGB_UNPACK_BLUE(color)); | ||
435 | do_action(ACTION_UPDATE, temp_line, cur_sel); | ||
436 | changed = true; | ||
437 | } | ||
432 | } | 438 | } |
433 | } | 439 | } |
440 | else | ||
434 | #endif | 441 | #endif |
435 | if (edit_text &&!rb->kbd_input(temp_line,MAX_LINE_LEN)) | 442 | if (!rb->kbd_input(temp_line,MAX_LINE_LEN)) |
436 | { | 443 | { |
437 | if (line_count) | 444 | if (line_count) |
438 | { | ||
439 | do_action(ACTION_UPDATE,temp_line,cur_sel); | 445 | do_action(ACTION_UPDATE,temp_line,cur_sel); |
440 | } | 446 | else |
441 | else do_action(ACTION_INSERT,temp_line,cur_sel); | 447 | do_action(ACTION_INSERT,temp_line,cur_sel); |
442 | changed = true; | 448 | changed = true; |
443 | } | 449 | } |
444 | } | 450 | } |