diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2007-06-18 13:37:57 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2007-06-18 13:37:57 +0000 |
commit | 46e186fa61acac1cdf02db597b0cac05de189cfa (patch) | |
tree | 5ab46c45aac79b727f8cc197f1c3f447489a503e /apps/plugins/text_editor.c | |
parent | 06797c2c7fd2643343f3209e9f9c940565fe6f1b (diff) | |
download | rockbox-46e186fa61acac1cdf02db597b0cac05de189cfa.tar.gz rockbox-46e186fa61acac1cdf02db597b0cac05de189cfa.zip |
extend the text editor plugin to be able to modify the .colors file
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13665 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/text_editor.c')
-rw-r--r-- | apps/plugins/text_editor.c | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c index 523cbad30c..943596905c 100644 --- a/apps/plugins/text_editor.c +++ b/apps/plugins/text_editor.c | |||
@@ -283,6 +283,39 @@ int do_item_menu(int cur_sel, char* copy_buffer) | |||
283 | menu_exit(m); | 283 | menu_exit(m); |
284 | return ret; | 284 | return ret; |
285 | } | 285 | } |
286 | |||
287 | #ifdef HAVE_LCD_COLOR | ||
288 | /* in misc.h but no need to polute the api */ | ||
289 | #define toupper(c) (((c >= 'a') && (c <= 'z'))?c+'A':c) | ||
290 | #define isxdigit(c) ((c>='a' && c<= 'f') || (c>='A' && c<= 'F') \ | ||
291 | || (c>='0' && c<= '9')) | ||
292 | #define hex2dec(c) (((c) >= '0' && ((c) <= '9')) ? (toupper(c)) - '0' : \ | ||
293 | (toupper(c)) - 'A' + 10) | ||
294 | int hex_to_rgb(const char* hex) | ||
295 | { int ok = 1; | ||
296 | int i; | ||
297 | int red, green, blue; | ||
298 | |||
299 | if (rb->strlen(hex) == 6) { | ||
300 | for (i=0; i < 6; i++ ) { | ||
301 | if (!isxdigit(hex[i])) { | ||
302 | ok=0; | ||
303 | break; | ||
304 | } | ||
305 | } | ||
306 | |||
307 | if (ok) { | ||
308 | red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]); | ||
309 | green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]); | ||
310 | blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]); | ||
311 | return LCD_RGBPACK(red,green,blue); | ||
312 | } | ||
313 | } | ||
314 | |||
315 | return 0; | ||
316 | } | ||
317 | #endif /* HAVE_LCD_COLOR */ | ||
318 | |||
286 | /* this is the plugin entry point */ | 319 | /* this is the plugin entry point */ |
287 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | 320 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
288 | { | 321 | { |
@@ -296,6 +329,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
296 | int cur_sel=0; | 329 | int cur_sel=0; |
297 | static char copy_buffer[MAX_LINE_LEN]; | 330 | static char copy_buffer[MAX_LINE_LEN]; |
298 | bool prev_show_statusbar; | 331 | bool prev_show_statusbar; |
332 | #ifdef HAVE_LCD_COLOR | ||
333 | bool edit_icons_file = false; | ||
334 | #endif | ||
299 | 335 | ||
300 | rb = api; | 336 | rb = api; |
301 | 337 | ||
@@ -308,6 +344,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
308 | #endif | 344 | #endif |
309 | if (parameter) | 345 | if (parameter) |
310 | { | 346 | { |
347 | #ifdef HAVE_LCD_COLOR | ||
348 | char *c = NULL; | ||
349 | #endif | ||
311 | rb->strcpy(filename,(char*)parameter); | 350 | rb->strcpy(filename,(char*)parameter); |
312 | if (!get_eol_string(filename)) | 351 | if (!get_eol_string(filename)) |
313 | { | 352 | { |
@@ -319,6 +358,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
319 | rb->splash(HZ*2,"Couldnt open file: %s",(char*)parameter); | 358 | rb->splash(HZ*2,"Couldnt open file: %s",(char*)parameter); |
320 | return PLUGIN_ERROR; | 359 | return PLUGIN_ERROR; |
321 | } | 360 | } |
361 | #ifdef HAVE_LCD_COLOR | ||
362 | c = rb->strchr(filename, '.'); | ||
363 | if (c && rb->strcmp(c, ".icons")) | ||
364 | edit_icons_file = true; | ||
365 | #endif | ||
322 | /* read in the file */ | 366 | /* read in the file */ |
323 | while (rb->read_line(fd,temp_line,MAX_LINE_LEN)) | 367 | while (rb->read_line(fd,temp_line,MAX_LINE_LEN)) |
324 | { | 368 | { |
@@ -353,9 +397,50 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
353 | { | 397 | { |
354 | case ACTION_STD_OK: | 398 | case ACTION_STD_OK: |
355 | { | 399 | { |
400 | bool edit_text = true; | ||
401 | #ifdef HAVE_LCD_COLOR | ||
402 | int color; | ||
403 | #endif | ||
356 | if (line_count) | 404 | if (line_count) |
357 | rb->strcpy(temp_line,&buffer[do_action(ACTION_GET,0,cur_sel)]); | 405 | rb->strcpy(temp_line,&buffer[do_action(ACTION_GET,0,cur_sel)]); |
358 | if (!rb->kbd_input(temp_line,MAX_LINE_LEN)) | 406 | #ifdef HAVE_LCD_COLOR |
407 | if (edit_icons_file) | ||
408 | { | ||
409 | char *name = temp_line, *value = NULL; | ||
410 | char extension[MAX_LINE_LEN]; | ||
411 | rb->settings_parseline(temp_line, &name, &value); | ||
412 | if (line_count) | ||
413 | { | ||
414 | MENUITEM_STRINGLIST(menu, "Edit What?", NULL, | ||
415 | "Extension", "Color",); | ||
416 | switch (rb->do_menu(&menu, NULL)) | ||
417 | { | ||
418 | case 0: | ||
419 | edit_text = true; | ||
420 | break; | ||
421 | case 1: | ||
422 | edit_text = false; | ||
423 | if (value) | ||
424 | color = hex_to_rgb(value); | ||
425 | else color = 0; | ||
426 | rb->strcpy(extension, name); | ||
427 | rb->set_color(rb->screens[SCREEN_MAIN], name, &color, -1); | ||
428 | rb->snprintf(temp_line, MAX_LINE_LEN, "%s: %02X%02X%02X", | ||
429 | extension, RGB_UNPACK_RED(color), | ||
430 | RGB_UNPACK_GREEN(color), | ||
431 | RGB_UNPACK_BLUE(color)); | ||
432 | if (line_count) | ||
433 | { | ||
434 | do_action(ACTION_UPDATE,temp_line,cur_sel); | ||
435 | } | ||
436 | else do_action(ACTION_INSERT,temp_line,cur_sel); | ||
437 | changed = true; | ||
438 | break; | ||
439 | } | ||
440 | } | ||
441 | } | ||
442 | #endif | ||
443 | if (edit_text &&!rb->kbd_input(temp_line,MAX_LINE_LEN)) | ||
359 | { | 444 | { |
360 | if (line_count) | 445 | if (line_count) |
361 | { | 446 | { |