Skip to content

Commit

Permalink
Improve editors a bit:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Laurent Monin committed May 16, 2008
1 parent 8cf9235 commit dbb4e40
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
7 changes: 5 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]

Expand Down
35 changes: 30 additions & 5 deletions src/editors.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
#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>


Expand Down Expand Up @@ -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 == '%')
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit dbb4e40

Please sign in to comment.