Improve editors a bit:
authorLaurent Monin <geeqie@norz.org>
Fri, 16 May 2008 08:37:07 +0000 (08:37 +0000)
committerLaurent Monin <geeqie@norz.org>
Fri, 16 May 2008 08:37:07 +0000 (08:37 +0000)
- 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

README
src/editors.c

diff --git a/README b/README
index 32a8082..ac02d86 100644 (file)
--- a/README
+++ b/README
@@ -392,8 +392,7 @@ geeqie-devel@lists.sourceforge.net
 
     %f  Replaced with list of selected files, may occur once.
     %p  Command is run once for each selected file, may occur multiple times.
-   none When neither %f or %p exist, list of files is appended to command.
-
+   
  Use of the following to display output window for the command:
 
     %v  Display result of command in output window, must occur as first two
@@ -406,6 +405,10 @@ geeqie-devel@lists.sourceforge.net
     %w  Prevent full screen from deactivating when command is executed,
         must occur as the first two characters.
 
+    %%  This will be replaced by one '%'. This is the way to escape '%'.
+
+    %d  This only makes sense for external commands like copy or move as this
+        is replaced by the destination.
 
 ======== Overlay Info                                        [section:overlay]
 
index 5a90598..d71f177 100644 (file)
 #include "main.h"
 #include "editors.h"
 
+#include "debug.h"
+#include "filedata.h"
+#include "filefilter.h"
 #include "utilops.h"
 #include "ui_fileops.h"
 #include "ui_spinner.h"
 #include "ui_utildlg.h"
 
-#include "filedata.h"
-#include "filefilter.h"
-
 #include <errno.h>
 
 
@@ -392,7 +392,9 @@ gint editor_command_parse(const gchar *template, GList *list, gchar **output)
                flags |= EDITOR_ERROR_EMPTY;
                goto err;
                }
-
+       
+       /* skip leading whitespaces if any */
+       while (g_ascii_isspace(*p)) p++;
 
        /* global flags */
        while (*p == '%')
@@ -411,9 +413,15 @@ gint editor_command_parse(const gchar *template, GList *list, gchar **output)
                                flags |= EDITOR_VERBOSE_MULTI;
                                p++;
                                break;
+                       default:
+                               flags |= EDITOR_ERROR_SYNTAX;
+                               goto err;
                        }
                }
 
+       /* skip whitespaces if any */
+       while (g_ascii_isspace(*p)) p++;
+
        /* command */
 
        while (*p)
@@ -450,6 +458,7 @@ gint editor_command_parse(const gchar *template, GList *list, gchar **output)
                                {
                                case 'd':
                                        flags |= EDITOR_DEST;
+                                       /* fall through */
                                case 'p':
                                        flags |= EDITOR_FOR_EACH;
                                        if (flags & EDITOR_SINGLE_COMMAND)
@@ -465,7 +474,9 @@ gint editor_command_parse(const gchar *template, GList *list, gchar **output)
                                                        flags |= EDITOR_ERROR_NO_FILE;
                                                        goto err;
                                                        }
-                                               pathl = editor_command_path_parse((FileData *)list->data, (*p == 'd') ? PATH_DEST : PATH_FILE, extensions);
+                                               pathl = editor_command_path_parse((FileData *)list->data,
+                                                                                 (flags & EDITOR_DEST) ? PATH_DEST : PATH_FILE,
+                                                                                 extensions);
                                                if (!pathl)
                                                        {
                                                        flags |= EDITOR_ERROR_NO_FILE;
@@ -515,6 +526,10 @@ gint editor_command_parse(const gchar *template, GList *list, gchar **output)
                                                        }
                                                }
                                        break;
+                               case '%':
+                                       /* %% = % escaping */
+                                       if (output) result = g_string_append_c(result, *p);
+                                       break;
                                default:
                                        flags |= EDITOR_ERROR_SYNTAX;
                                        goto err;
@@ -798,6 +813,16 @@ gint start_editor_from_filelist_full(gint n, GList *list, EditorCallback cb, gpo
        command = g_locale_from_utf8(options->editor_command[n], -1, NULL, NULL, NULL);
        error = editor_command_start(command, options->editor_name[n], list, cb, data);
        g_free(command);
+
+       if (n < GQ_EDITOR_GENERIC_SLOTS && (error & EDITOR_ERROR_SYNTAX))
+               {
+               gchar *text = g_strdup_printf(_("Syntax error in the editor template \"%s\":\n%s"),
+                                             options->editor_name[n], options->editor_command[n]);
+               
+               file_util_warning_dialog(_("Invalid editor command"), text, GTK_STOCK_DIALOG_ERROR, NULL);
+               g_free(text);
+               }
+
        return error;
 }