Mercurial > geeqie
comparison src/editors.c @ 669:dd5d7fe9458f
Improve editors a bit:
- allow whitespaces before and after %v, %V, %w
- allow % escaping using %% (mandatory to use shell commands than contain % characters)
- display a dialog on execution if a syntax error is detected (only for generic editors)
- update README editors section
author | zas_ |
---|---|
date | Fri, 16 May 2008 08:37:07 +0000 |
parents | 905688aa2317 |
children | a484500de88d |
comparison
equal
deleted
inserted
replaced
668:a074514d418e | 669:dd5d7fe9458f |
---|---|
12 | 12 |
13 | 13 |
14 #include "main.h" | 14 #include "main.h" |
15 #include "editors.h" | 15 #include "editors.h" |
16 | 16 |
17 #include "debug.h" | |
18 #include "filedata.h" | |
19 #include "filefilter.h" | |
17 #include "utilops.h" | 20 #include "utilops.h" |
18 #include "ui_fileops.h" | 21 #include "ui_fileops.h" |
19 #include "ui_spinner.h" | 22 #include "ui_spinner.h" |
20 #include "ui_utildlg.h" | 23 #include "ui_utildlg.h" |
21 | |
22 #include "filedata.h" | |
23 #include "filefilter.h" | |
24 | 24 |
25 #include <errno.h> | 25 #include <errno.h> |
26 | 26 |
27 | 27 |
28 #define EDITOR_WINDOW_WIDTH 500 | 28 #define EDITOR_WINDOW_WIDTH 500 |
390 if (!template || template[0] == '\0') | 390 if (!template || template[0] == '\0') |
391 { | 391 { |
392 flags |= EDITOR_ERROR_EMPTY; | 392 flags |= EDITOR_ERROR_EMPTY; |
393 goto err; | 393 goto err; |
394 } | 394 } |
395 | 395 |
396 /* skip leading whitespaces if any */ | |
397 while (g_ascii_isspace(*p)) p++; | |
396 | 398 |
397 /* global flags */ | 399 /* global flags */ |
398 while (*p == '%') | 400 while (*p == '%') |
399 { | 401 { |
400 switch (*++p) | 402 switch (*++p) |
409 break; | 411 break; |
410 case 'V': | 412 case 'V': |
411 flags |= EDITOR_VERBOSE_MULTI; | 413 flags |= EDITOR_VERBOSE_MULTI; |
412 p++; | 414 p++; |
413 break; | 415 break; |
414 } | 416 default: |
415 } | 417 flags |= EDITOR_ERROR_SYNTAX; |
418 goto err; | |
419 } | |
420 } | |
421 | |
422 /* skip whitespaces if any */ | |
423 while (g_ascii_isspace(*p)) p++; | |
416 | 424 |
417 /* command */ | 425 /* command */ |
418 | 426 |
419 while (*p) | 427 while (*p) |
420 { | 428 { |
448 | 456 |
449 switch (*p) | 457 switch (*p) |
450 { | 458 { |
451 case 'd': | 459 case 'd': |
452 flags |= EDITOR_DEST; | 460 flags |= EDITOR_DEST; |
461 /* fall through */ | |
453 case 'p': | 462 case 'p': |
454 flags |= EDITOR_FOR_EACH; | 463 flags |= EDITOR_FOR_EACH; |
455 if (flags & EDITOR_SINGLE_COMMAND) | 464 if (flags & EDITOR_SINGLE_COMMAND) |
456 { | 465 { |
457 flags |= EDITOR_ERROR_INCOMPATIBLE; | 466 flags |= EDITOR_ERROR_INCOMPATIBLE; |
463 if (!list || !list->data) | 472 if (!list || !list->data) |
464 { | 473 { |
465 flags |= EDITOR_ERROR_NO_FILE; | 474 flags |= EDITOR_ERROR_NO_FILE; |
466 goto err; | 475 goto err; |
467 } | 476 } |
468 pathl = editor_command_path_parse((FileData *)list->data, (*p == 'd') ? PATH_DEST : PATH_FILE, extensions); | 477 pathl = editor_command_path_parse((FileData *)list->data, |
478 (flags & EDITOR_DEST) ? PATH_DEST : PATH_FILE, | |
479 extensions); | |
469 if (!pathl) | 480 if (!pathl) |
470 { | 481 { |
471 flags |= EDITOR_ERROR_NO_FILE; | 482 flags |= EDITOR_ERROR_NO_FILE; |
472 goto err; | 483 goto err; |
473 } | 484 } |
513 flags |= EDITOR_ERROR_NO_FILE; | 524 flags |= EDITOR_ERROR_NO_FILE; |
514 goto err; | 525 goto err; |
515 } | 526 } |
516 } | 527 } |
517 break; | 528 break; |
529 case '%': | |
530 /* %% = % escaping */ | |
531 if (output) result = g_string_append_c(result, *p); | |
532 break; | |
518 default: | 533 default: |
519 flags |= EDITOR_ERROR_SYNTAX; | 534 flags |= EDITOR_ERROR_SYNTAX; |
520 goto err; | 535 goto err; |
521 } | 536 } |
522 if (extensions) g_free(extensions); | 537 if (extensions) g_free(extensions); |
796 if (!is_valid_editor_command(n)) return FALSE; | 811 if (!is_valid_editor_command(n)) return FALSE; |
797 | 812 |
798 command = g_locale_from_utf8(options->editor_command[n], -1, NULL, NULL, NULL); | 813 command = g_locale_from_utf8(options->editor_command[n], -1, NULL, NULL, NULL); |
799 error = editor_command_start(command, options->editor_name[n], list, cb, data); | 814 error = editor_command_start(command, options->editor_name[n], list, cb, data); |
800 g_free(command); | 815 g_free(command); |
816 | |
817 if (n < GQ_EDITOR_GENERIC_SLOTS && (error & EDITOR_ERROR_SYNTAX)) | |
818 { | |
819 gchar *text = g_strdup_printf(_("Syntax error in the editor template \"%s\":\n%s"), | |
820 options->editor_name[n], options->editor_command[n]); | |
821 | |
822 file_util_warning_dialog(_("Invalid editor command"), text, GTK_STOCK_DIALOG_ERROR, NULL); | |
823 g_free(text); | |
824 } | |
825 | |
801 return error; | 826 return error; |
802 } | 827 } |
803 | 828 |
804 gint start_editor_from_filelist(gint n, GList *list) | 829 gint start_editor_from_filelist(gint n, GList *list) |
805 { | 830 { |