annotate src/editors.c @ 911:8adf248bf5c9

fixed stop button in editor dialog
author nadvornik
date Tue, 22 Jul 2008 17:57:22 +0000
parents ff51413f098d
children 978f52f8a79d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
196
f6e307c7bad6 rename GQview -> Geeqie over the code
nadvornik
parents: 190
diff changeset
2 * Geeqie
123
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
3 * (C) 2006 John Ellis
475
48c8e49b571c updated copyright in source files
nadvornik
parents: 444
diff changeset
4 * Copyright (C) 2008 The Geeqie Team
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 261
diff changeset
14 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15 #include "editors.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16
669
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
17 #include "filedata.h"
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
18 #include "filefilter.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include "utilops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21 #include "ui_spinner.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22 #include "ui_utildlg.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24 #include <errno.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27 #define EDITOR_WINDOW_WIDTH 500
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
28 #define EDITOR_WINDOW_HEIGHT 300
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
29
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32 typedef struct _EditorVerboseData EditorVerboseData;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 struct _EditorVerboseData {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34 GenericDialog *gd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 GtkWidget *button_close;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36 GtkWidget *button_stop;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37 GtkWidget *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38 GtkWidget *progress;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39 GtkWidget *spinner;
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
40 };
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
41
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
42 typedef struct _EditorData EditorData;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
43 struct _EditorData {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
44 gint flags;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
45 GPid pid;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
46 gchar *command_template;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
47 GList *list;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 gint count;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 gint total;
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
50 gboolean stopping;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
51 EditorVerboseData *vd;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
52 EditorCallback callback;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
53 gpointer data;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56
730
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
57 static Editor editor_slot_defaults[GQ_EDITOR_SLOTS] = {
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
58 { N_("The Gimp"), "gimp-remote %{.cr2;.crw;.nef;.raw;*}f" },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
59 { N_("XV"), "xv %f" },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
60 { N_("Xpaint"), "xpaint %f" },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
61 { N_("UFraw"), "ufraw %{.cr2;.crw;.nef;.raw}p" },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
62 { N_("Add XMP sidecar"), "%vFILE=%{.cr2;.crw;.nef;.raw}p;XMP=`echo \"$FILE\"|sed -e 's|\\.[^.]*$|.xmp|'`; exiftool -tagsfromfile \"$FILE\" \"$XMP\"" },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
63 { NULL, NULL },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
64 { NULL, NULL },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
65 { NULL, NULL },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
66 { N_("Rotate jpeg clockwise"), "%vif jpegtran -rotate 90 -copy all -outfile %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p; then mv %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p;else rm %{.jpg;.jpeg}p_tmp;fi" },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
67 { N_("Rotate jpeg counterclockwise"), "%vif jpegtran -rotate 270 -copy all -outfile %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p; then mv %{.jpg;.jpeg}p_tmp %{.jpg;.jpeg}p;else rm %{.jpg;.jpeg}p_tmp;fi" },
134
9009856628f7 started implementation of external commands; external Delete should work
nadvornik
parents: 123
diff changeset
68 /* special slots */
136
18c2a29e681c more external commands
nadvornik
parents: 135
diff changeset
69 #if 1
18c2a29e681c more external commands
nadvornik
parents: 135
diff changeset
70 /* for testing */
730
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
71 { N_("External Copy command"), "%vset -x;cp %p %d" },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
72 { N_("External Move command"), "%vset -x;mv %p %d" },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
73 { N_("External Rename command"), "%vset -x;mv %p %d" },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
74 { N_("External Delete command"), NULL },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
75 { N_("External New Folder command"), NULL },
136
18c2a29e681c more external commands
nadvornik
parents: 135
diff changeset
76 #else
730
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
77 { N_("External Copy command"), NULL },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
78 { N_("External Move command"), NULL },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
79 { N_("External Rename command"), NULL },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
80 { N_("External Delete command"), NULL },
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
81 { N_("External New Folder command"), NULL },
136
18c2a29e681c more external commands
nadvornik
parents: 135
diff changeset
82 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
85 static void editor_verbose_window_progress(EditorData *ed, const gchar *text);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
86 static gint editor_command_next_start(EditorData *ed);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
87 static gint editor_command_next_finish(EditorData *ed, gint status);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
88 static gint editor_command_done(EditorData *ed);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92 * external editor routines
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95
768
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
96 void editor_set_name(gint n, gchar *name)
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
97 {
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
98 if (n < 0 || n >= GQ_EDITOR_SLOTS) return;
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
99
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
100 g_free(options->editor[n].name);
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
101
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
102 options->editor[n].name = name ? utf8_validate_or_convert(name) : NULL;
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
103 }
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
104
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
105 void editor_set_command(gint n, gchar *command)
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
106 {
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
107 if (n < 0 || n >= GQ_EDITOR_SLOTS) return;
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
108
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
109 g_free(options->editor[n].command);
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
110 options->editor[n].command = command ? utf8_validate_or_convert(command) : NULL;
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
111 }
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
112
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 void editor_reset_defaults(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 gint i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116
283
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
117 for (i = 0; i < GQ_EDITOR_SLOTS; i++)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 {
768
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
119 editor_set_name(i, _(editor_slot_defaults[i].name));
ff51413f098d Use functions to set editors name and command and ensure they are
zas_
parents: 766
diff changeset
120 editor_set_command(i, _(editor_slot_defaults[i].command));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
124 static void editor_verbose_data_free(EditorData *ed)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
125 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
126 if (!ed->vd) return;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
127 g_free(ed->vd);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
128 ed->vd = NULL;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
129 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
130
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
131 static void editor_data_free(EditorData *ed)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
132 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
133 editor_verbose_data_free(ed);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
134 g_free(ed->command_template);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
135 g_free(ed);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
136 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
137
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138 static void editor_verbose_window_close(GenericDialog *gd, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
140 EditorData *ed = data;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142 generic_dialog_close(gd);
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
143 editor_verbose_data_free(ed);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
144 if (ed->pid == -1) editor_data_free(ed); /* the process has already terminated */
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147 static void editor_verbose_window_stop(GenericDialog *gd, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
149 EditorData *ed = data;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
150 ed->stopping = TRUE;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
151 ed->count = 0;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
152 editor_verbose_window_progress(ed, _("stopping..."));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 static void editor_verbose_window_enable_close(EditorVerboseData *vd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157 vd->gd->cancel_cb = editor_verbose_window_close;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159 spinner_set_interval(vd->spinner, -1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160 gtk_widget_set_sensitive(vd->button_stop, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
161 gtk_widget_set_sensitive(vd->button_close, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
164 static EditorVerboseData *editor_verbose_window(EditorData *ed, const gchar *text)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166 EditorVerboseData *vd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167 GtkWidget *scrolled;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 GtkWidget *hbox;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171 vd = g_new0(EditorVerboseData, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172
254
9faf34f047b1 Make the wmclass value unique among the code by defining
zas_
parents: 238
diff changeset
173 vd->gd = file_util_gen_dlg(_("Edit command results"), GQ_WMCLASS, "editor_results",
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174 NULL, FALSE,
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
175 NULL, ed);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176 buf = g_strdup_printf(_("Output of %s"), text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177 generic_dialog_add_message(vd->gd, NULL, buf, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179 vd->button_stop = generic_dialog_add_button(vd->gd, GTK_STOCK_STOP, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 editor_verbose_window_stop, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 gtk_widget_set_sensitive(vd->button_stop, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 vd->button_close = generic_dialog_add_button(vd->gd, GTK_STOCK_CLOSE, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 editor_verbose_window_close, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 gtk_widget_set_sensitive(vd->button_close, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 scrolled = gtk_scrolled_window_new(NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 gtk_box_pack_start(GTK_BOX(vd->gd->vbox), scrolled, TRUE, TRUE, 5);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 gtk_widget_show(scrolled);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 vd->text = gtk_text_view_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194 gtk_text_view_set_editable(GTK_TEXT_VIEW(vd->text), FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 gtk_widget_set_size_request(vd->text, EDITOR_WINDOW_WIDTH, EDITOR_WINDOW_HEIGHT);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 gtk_container_add(GTK_CONTAINER(scrolled), vd->text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 gtk_widget_show(vd->text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 hbox = gtk_hbox_new(FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200 gtk_box_pack_start(GTK_BOX(vd->gd->vbox), hbox, FALSE, FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 gtk_widget_show(hbox);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
203 vd->progress = gtk_progress_bar_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(vd->progress), 0.0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205 gtk_box_pack_start(GTK_BOX(hbox), vd->progress, TRUE, TRUE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
206 gtk_widget_show(vd->progress);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
207
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208 vd->spinner = spinner_new(NULL, SPINNER_SPEED);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209 gtk_box_pack_start(GTK_BOX(hbox), vd->spinner, FALSE, FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
210 gtk_widget_show(vd->spinner);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
211
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212 gtk_widget_show(vd->gd->dialog);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
214 ed->vd = vd;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 return vd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 static void editor_verbose_window_fill(EditorVerboseData *vd, gchar *text, gint len)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220 GtkTextBuffer *buffer;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 GtkTextIter iter;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(vd->text));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224 gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 gtk_text_buffer_insert(buffer, &iter, text, len);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
228 static void editor_verbose_window_progress(EditorData *ed, const gchar *text)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
230 if (!ed->vd) return;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
231
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
232 if (ed->total)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
234 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ed->vd->progress), (double)ed->count / ed->total);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
237 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ed->vd->progress), (text) ? text : "");
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 static gboolean editor_verbose_io_cb(GIOChannel *source, GIOCondition condition, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
242 EditorData *ed = data;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243 gchar buf[512];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244 gsize count;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
246 if (condition & G_IO_IN)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
248 while (g_io_channel_read_chars(source, buf, sizeof(buf), &count, NULL) == G_IO_STATUS_NORMAL)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
249 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
250 if (!g_utf8_validate(buf, count, NULL))
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
252 gchar *utf8;
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
253
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
254 utf8 = g_locale_to_utf8(buf, count, NULL, NULL, NULL);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
255 if (utf8)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
257 editor_verbose_window_fill(ed->vd, utf8, -1);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
258 g_free(utf8);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
260 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
261 {
288
d1f74154463e Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents: 283
diff changeset
262 editor_verbose_window_fill(ed->vd, "Error converting text to valid utf8\n", -1);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 }
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
265 else
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
266 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
267 editor_verbose_window_fill(ed->vd, buf, count);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
268 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
269 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
270 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
271
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
272 if (condition & (G_IO_ERR | G_IO_HUP))
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
273 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
274 g_io_channel_shutdown(source, TRUE, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
275 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
279 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
281 typedef enum {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
282 PATH_FILE,
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
283 PATH_DEST
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
284 } PathType;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
285
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
286
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
287 static gchar *editor_command_path_parse(const FileData *fd, PathType type, const gchar *extensions)
123
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
288 {
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
289 GString *string;
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
290 gchar *pathl;
147
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
291 const gchar *p = NULL;
123
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
292
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
293 string = g_string_new("");
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
294
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
295 if (type == PATH_FILE)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
296 {
147
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
297 GList *ext_list = filter_to_list(extensions);
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
298 GList *work = ext_list;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
299
147
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
300 if (!work)
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
301 p = fd->path;
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
302 else
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
303 {
516
b7e99bfeadc9 Convert the minority of while() to while ().
zas_
parents: 475
diff changeset
304 while (work)
147
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
305 {
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
306 GList *work2;
147
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
307 gchar *ext = work->data;
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
308 work = work->next;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
309
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
310 if (strcmp(ext, "*") == 0 ||
147
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
311 strcasecmp(ext, fd->extension) == 0)
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
312 {
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
313 p = fd->path;
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
314 break;
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
315 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
316
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
317 work2 = fd->sidecar_files;
516
b7e99bfeadc9 Convert the minority of while() to while ().
zas_
parents: 475
diff changeset
318 while (work2)
147
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
319 {
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
320 FileData *sfd = work2->data;
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
321 work2 = work2->next;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
322
147
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
323 if (strcasecmp(ext, sfd->extension) == 0)
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
324 {
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
325 p = sfd->path;
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
326 break;
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
327 }
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
328 }
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
329 if (p) break;
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
330 }
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
331 string_list_free(ext_list);
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
332 if (!p) return NULL;
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
333 }
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
334 }
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
335 else if (type == PATH_DEST)
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
336 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
337 if (fd->change && fd->change->dest)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
338 p = fd->change->dest;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
339 else
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
340 p = "";
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
341 }
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
342
123
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
343 while (*p != '\0')
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
344 {
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
345 /* must escape \, ", `, and $ to avoid problems,
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
346 * we assume system shell supports bash-like escaping
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
347 */
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
348 if (strchr("\\\"`$", *p) != NULL)
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
349 {
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
350 string = g_string_append_c(string, '\\');
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
351 }
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
352 string = g_string_append_c(string, *p);
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
353 p++;
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
354 }
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
355
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
356 pathl = path_from_utf8(string->str);
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
357 g_string_free(string, TRUE);
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
358
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
359 return pathl;
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
360 }
3602a4aa7c71 Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 60
diff changeset
361
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364 * The supported macros for editor commands:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
365 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 * %f first occurence replaced by quoted sequence of filenames, command is run once.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
367 * only one occurence of this macro is supported.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368 * ([ls %f] results in [ls "file1" "file2" ... "lastfile"])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369 * %p command is run for each filename in turn, each instance replaced with single filename.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370 * multiple occurences of this macro is supported for complex shell commands.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 * This macro will BLOCK THE APPLICATION until it completes, since command is run once
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372 * for every file in syncronous order. To avoid blocking add the %v macro, below.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 * ([ls %p] results in [ls "file1"], [ls "file2"] ... [ls "lastfile"])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 * none if no macro is supplied, the result is equivalent to "command %f"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 * ([ls] results in [ls "file1" "file2" ... "lastfile"])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377 * Only one of the macros %f or %p may be used in a given commmand.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378 *
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
379 * %v must be the first two characters[1] in a command, causes a window to display
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 * showing the output of the command(s).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381 * %V same as %v except in the case of %p only displays a window for multiple files,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 * operating on a single file is suppresses the output dialog.
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
383 *
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
384 * %w must be first two characters in a command, presence will disable full screen
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
385 * from exiting upon invocation.
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
386 *
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
387 *
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
388 * [1] Note: %v,%V may also be preceded by "%w".
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389 */
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
390
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
391
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
392 gint editor_command_parse(const gchar *template, GList *list, gchar **output)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
394 gint flags = 0;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
395 const gchar *p = template;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
396 GString *result = NULL;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
397 gchar *extensions = NULL;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
398
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
399 if (output)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
400 result = g_string_new("");
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
401
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
402 if (!template || template[0] == '\0')
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
403 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
404 flags |= EDITOR_ERROR_EMPTY;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
405 goto err;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
406 }
669
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
407
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
408 /* skip leading whitespaces if any */
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
409 while (g_ascii_isspace(*p)) p++;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
410
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
411 /* global flags */
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
412 while (*p == '%')
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
413 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
414 switch (*++p)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
415 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
416 case 'w':
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
417 flags |= EDITOR_KEEP_FS;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
418 p++;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
419 break;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
420 case 'v':
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
421 flags |= EDITOR_VERBOSE;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
422 p++;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
423 break;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
424 case 'V':
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
425 flags |= EDITOR_VERBOSE_MULTI;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
426 p++;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
427 break;
669
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
428 default:
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
429 flags |= EDITOR_ERROR_SYNTAX;
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
430 goto err;
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
431 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
432 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
433
669
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
434 /* skip whitespaces if any */
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
435 while (g_ascii_isspace(*p)) p++;
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
436
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
437 /* command */
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
438
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
439 while (*p)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
440 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
441 if (*p != '%')
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
442 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
443 if (output) result = g_string_append_c(result, *p);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
444 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
445 else /* *p == '%' */
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
446 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
447 extensions = NULL;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
448 gchar *pathl = NULL;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
450 p++;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
451
147
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
452 /* for example "%f" or "%{.crw;.raw;.cr2}f" */
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
453 if (*p == '{')
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
454 {
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
455 gchar *end;
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
456
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
457 p++;
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
458 end = strchr(p, '}');
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
459 if (!end)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
460 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
461 flags |= EDITOR_ERROR_SYNTAX;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
462 goto err;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
463 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
464
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
465 extensions = g_strndup(p, end - p);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
466 p = end + 1;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
467 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
468
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
469 switch (*p)
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
470 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
471 case 'd':
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
472 flags |= EDITOR_DEST;
669
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
473 /* fall through */
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
474 case 'p':
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
475 flags |= EDITOR_FOR_EACH;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
476 if (flags & EDITOR_SINGLE_COMMAND)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
477 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
478 flags |= EDITOR_ERROR_INCOMPATIBLE;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
479 goto err;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
480 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
481 if (output)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
482 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
483 /* use the first file from the list */
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
484 if (!list || !list->data)
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
485 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
486 flags |= EDITOR_ERROR_NO_FILE;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
487 goto err;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
488 }
669
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
489 pathl = editor_command_path_parse((FileData *)list->data,
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
490 (flags & EDITOR_DEST) ? PATH_DEST : PATH_FILE,
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
491 extensions);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
492 if (!pathl)
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
493 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
494 flags |= EDITOR_ERROR_NO_FILE;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
495 goto err;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
496 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
497 result = g_string_append_c(result, '"');
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
498 result = g_string_append(result, pathl);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
499 g_free(pathl);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
500 result = g_string_append_c(result, '"');
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
501 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
502 break;
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
503
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
504 case 'f':
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
505 flags |= EDITOR_SINGLE_COMMAND;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
506 if (flags & (EDITOR_FOR_EACH | EDITOR_DEST))
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
507 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
508 flags |= EDITOR_ERROR_INCOMPATIBLE;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
509 goto err;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
510 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
511
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
512 if (output)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
513 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
514 /* use whole list */
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
515 GList *work = list;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
516 gboolean ok = FALSE;
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
517
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
518 while (work)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
519 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
520 FileData *fd = work->data;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
521 pathl = editor_command_path_parse(fd, PATH_FILE, extensions);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
522
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
523 if (pathl)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
524 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
525 ok = TRUE;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
526 if (work != list) g_string_append_c(result, ' ');
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
527 result = g_string_append_c(result, '"');
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
528 result = g_string_append(result, pathl);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
529 g_free(pathl);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
530 result = g_string_append_c(result, '"');
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
531 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
532 work = work->next;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
533 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
534 if (!ok)
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
535 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
536 flags |= EDITOR_ERROR_NO_FILE;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
537 goto err;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
538 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
539 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
540 break;
669
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
541 case '%':
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
542 /* %% = % escaping */
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
543 if (output) result = g_string_append_c(result, *p);
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
544 break;
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
545 default:
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
546 flags |= EDITOR_ERROR_SYNTAX;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
547 goto err;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
548 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
549 if (extensions) g_free(extensions);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
550 extensions = NULL;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
551 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
552 p++;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
555 if (output) *output = g_string_free(result, FALSE);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
556 return flags;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
557
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
558
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
559 err:
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
560 if (output)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
562 g_string_free(result, TRUE);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
563 *output = NULL;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
564 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
565 if (extensions) g_free(extensions);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
566 return flags;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
567 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
568
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
569 static void editor_child_exit_cb (GPid pid, gint status, gpointer data)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
570 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
571 EditorData *ed = data;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
572 g_spawn_close_pid(pid);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
573 ed->pid = -1;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
574
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
575 editor_command_next_finish(ed, status);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
576 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
577
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
578
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
579 static gint editor_command_one(const gchar *template, GList *list, EditorData *ed)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
580 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
581 gchar *command;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
582 FileData *fd = list->data;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
583 GPid pid;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
584 gint standard_output;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
585 gint standard_error;
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
586 gboolean ok;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
587
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
588 ed->pid = -1;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
589 ed->flags = editor_command_parse(template, list, &command);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
590
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
591 ok = !(ed->flags & EDITOR_ERROR_MASK);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
592
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
593 if (ok)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
594 {
737
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
595 ok = (options->shell.path && *options->shell.path);
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
596 if (!ok) log_printf("ERROR: empty shell command\n");
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
597
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
598 if (ok)
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
599 {
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
600 ok = (access(options->shell.path, X_OK) == 0);
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
601 if (!ok) log_printf("ERROR: cannot execute shell command '%s'\n", options->shell.path);
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
602 }
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
603
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
604 if (!ok) ed->flags |= EDITOR_ERROR_CANT_EXEC;
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
605 }
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
606
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
607 if (ok)
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
608 {
443
e7361d06d83a editor_command_one(): tidy up.
zas_
parents: 442
diff changeset
609 gchar *working_directory;
e7361d06d83a editor_command_one(): tidy up.
zas_
parents: 442
diff changeset
610 gchar *args[4];
737
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
611 guint n = 0;
443
e7361d06d83a editor_command_one(): tidy up.
zas_
parents: 442
diff changeset
612
e7361d06d83a editor_command_one(): tidy up.
zas_
parents: 442
diff changeset
613 working_directory = remove_level_from_path(fd->path);
737
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
614 args[n++] = options->shell.path;
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
615 if (options->shell.options && *options->shell.options)
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
616 args[n++] = options->shell.options;
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
617 args[n++] = command;
8a8873e7a552 Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents: 731
diff changeset
618 args[n] = NULL;
443
e7361d06d83a editor_command_one(): tidy up.
zas_
parents: 442
diff changeset
619
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
620 ok = g_spawn_async_with_pipes(working_directory, args, NULL,
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
621 G_SPAWN_DO_NOT_REAP_CHILD, /* GSpawnFlags */
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
622 NULL, NULL,
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
623 &pid,
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
624 NULL,
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
625 ed->vd ? &standard_output : NULL,
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
626 ed->vd ? &standard_error : NULL,
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
627 NULL);
443
e7361d06d83a editor_command_one(): tidy up.
zas_
parents: 442
diff changeset
628
e7361d06d83a editor_command_one(): tidy up.
zas_
parents: 442
diff changeset
629 g_free(working_directory);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
630
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
631 if (!ok) ed->flags |= EDITOR_ERROR_CANT_EXEC;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
632 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
633
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
634 if (ok)
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
635 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
636 g_child_watch_add(pid, editor_child_exit_cb, ed);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
637 ed->pid = pid;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
638 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
639
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
640 if (ed->vd)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
641 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
642 if (!ok)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
644 gchar *buf;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
645
147
b2266996fa83 added possibility to specify prefered file type for external commands
nadvornik
parents: 140
diff changeset
646 buf = g_strdup_printf(_("Failed to run command:\n%s\n"), template);
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
647 editor_verbose_window_fill(ed->vd, buf, strlen(buf));
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
648 g_free(buf);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
649
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
650 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
651 else
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
652 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
653 GIOChannel *channel_output;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
654 GIOChannel *channel_error;
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
655
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
656 channel_output = g_io_channel_unix_new(standard_output);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
657 g_io_channel_set_flags(channel_output, G_IO_FLAG_NONBLOCK, NULL);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
658
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
659 g_io_add_watch_full(channel_output, G_PRIORITY_HIGH, G_IO_IN | G_IO_ERR | G_IO_HUP,
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
660 editor_verbose_io_cb, ed, NULL);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
661 g_io_channel_unref(channel_output);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
662
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
663 channel_error = g_io_channel_unix_new(standard_error);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
664 g_io_channel_set_flags(channel_error, G_IO_FLAG_NONBLOCK, NULL);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
665
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
666 g_io_add_watch_full(channel_error, G_PRIORITY_HIGH, G_IO_IN | G_IO_ERR | G_IO_HUP,
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
667 editor_verbose_io_cb, ed, NULL);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
668 g_io_channel_unref(channel_error);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
669 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
670 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
671
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
672 g_free(command);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
673
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
674 return ed->flags & EDITOR_ERROR_MASK;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
675 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
676
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
677 static gint editor_command_next_start(EditorData *ed)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
678 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
679 if (ed->vd) editor_verbose_window_fill(ed->vd, "\n", 1);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
680
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
681 if (ed->list && ed->count < ed->total)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
682 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
683 FileData *fd;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
684 gint error;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
685
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
686 fd = ed->list->data;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
687
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
688 if (ed->vd)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
689 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
690 editor_verbose_window_progress(ed, (ed->flags & EDITOR_FOR_EACH) ? fd->path : _("running..."));
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
691 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
692 ed->count++;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
693
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
694 error = editor_command_one(ed->command_template, ed->list, ed);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
695 if (!error && ed->vd)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
696 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
697 gtk_widget_set_sensitive(ed->vd->button_stop, (ed->list != NULL) );
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
698 if (ed->flags & EDITOR_FOR_EACH)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
699 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
700 editor_verbose_window_fill(ed->vd, fd->path, strlen(fd->path));
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
701 editor_verbose_window_fill(ed->vd, "\n", 1);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
702 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
703 }
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
704
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
705 if (!error)
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
706 return 0;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
707 else
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
708 /* command was not started, call the finish immediately */
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
709 return editor_command_next_finish(ed, 0);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
710 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
711
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
712 /* everything is done */
237
404629011caa Add missing return at the end of editor_command_next_start().
zas_
parents: 196
diff changeset
713 return editor_command_done(ed);
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
714 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
715
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
716 static gint editor_command_next_finish(EditorData *ed, gint status)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
717 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
718 gint cont = ed->stopping ? EDITOR_CB_SKIP : EDITOR_CB_CONTINUE;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
719
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
720 if (status)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
721 ed->flags |= EDITOR_ERROR_STATUS;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
722
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
723 if (ed->flags & EDITOR_FOR_EACH)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
724 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
725 /* handle the first element from the list */
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
726 GList *fd_element = ed->list;
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
727
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
728 ed->list = g_list_remove_link(ed->list, fd_element);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
729 if (ed->callback)
911
8adf248bf5c9 fixed stop button in editor dialog
nadvornik
parents: 768
diff changeset
730 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
731 cont = ed->callback(ed->list ? ed : NULL, ed->flags, fd_element, ed->data);
911
8adf248bf5c9 fixed stop button in editor dialog
nadvornik
parents: 768
diff changeset
732 if (ed->stopping && cont == EDITOR_CB_CONTINUE) cont = EDITOR_CB_SKIP;
8adf248bf5c9 fixed stop button in editor dialog
nadvornik
parents: 768
diff changeset
733 }
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
734 filelist_free(fd_element);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
735 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
737 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
738 /* handle whole list */
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
739 if (ed->callback)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
740 cont = ed->callback(NULL, ed->flags, ed->list, ed->data);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
741 filelist_free(ed->list);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
742 ed->list = NULL;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
743 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
744
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
745 if (cont == EDITOR_CB_SUSPEND)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
746 return ed->flags & EDITOR_ERROR_MASK;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
747 else if (cont == EDITOR_CB_SKIP)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
748 return editor_command_done(ed);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
749 else
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
750 return editor_command_next_start(ed);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
751 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
752
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
753 static gint editor_command_done(EditorData *ed)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
754 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
755 gint flags;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
756
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
757 if (ed->vd)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
758 {
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
759 const gchar *text;
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
760
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
761 if (ed->count == ed->total)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
762 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
763 text = _("done");
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
764 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
765 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
766 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
767 text = _("stopped by user");
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
768 }
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
769 editor_verbose_window_progress(ed, text);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
770 editor_verbose_window_enable_close(ed->vd);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
771 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
772
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
773 /* free the not-handled items */
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
774 if (ed->list)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
775 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
776 ed->flags |= EDITOR_ERROR_SKIPPED;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
777 if (ed->callback) ed->callback(NULL, ed->flags, ed->list, ed->data);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
778 filelist_free(ed->list);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
779 ed->list = NULL;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
780 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
781
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
782 ed->count = 0;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
783
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
784 flags = ed->flags & EDITOR_ERROR_MASK;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
785
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
786 if (!ed->vd) editor_data_free(ed);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
787
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
788 return flags;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
789 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
790
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
791 void editor_resume(gpointer ed)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
792 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
793 editor_command_next_start(ed);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
794 }
443
e7361d06d83a editor_command_one(): tidy up.
zas_
parents: 442
diff changeset
795
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
796 void editor_skip(gpointer ed)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
797 {
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
798 editor_command_done(ed);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
799 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
800
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
801 static gint editor_command_start(const gchar *template, const gchar *text, GList *list, EditorCallback cb, gpointer data)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
802 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
803 EditorData *ed;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
804 gint flags = editor_command_parse(template, NULL, NULL);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
805
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
806 if (flags & EDITOR_ERROR_MASK) return flags & EDITOR_ERROR_MASK;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
807
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
808 ed = g_new0(EditorData, 1);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
809 ed->list = filelist_copy(list);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
810 ed->flags = flags;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
811 ed->command_template = g_strdup(template);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
812 ed->total = (flags & EDITOR_SINGLE_COMMAND) ? 1 : g_list_length(list);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
813 ed->count = 0;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
814 ed->stopping = FALSE;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
815 ed->callback = cb;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
816 ed->data = data;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
817
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
818 if ((flags & EDITOR_VERBOSE_MULTI) && list && list->next)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
819 flags |= EDITOR_VERBOSE;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
820
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
821 if (flags & EDITOR_VERBOSE)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
822 editor_verbose_window(ed, text);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
823
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 440
diff changeset
824 editor_command_next_start(ed);
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
825 /* errors from editor_command_next_start will be handled via callback */
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
826 return flags & EDITOR_ERROR_MASK;
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
827 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
828
766
7148e125bf23 Check for existing editor command using is_valid_editor_command().
zas_
parents: 753
diff changeset
829 gboolean is_valid_editor_command(gint n)
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
830 {
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
831 return (n >= 0 && n < GQ_EDITOR_SLOTS
730
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
832 && options->editor[n].command
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
833 && strlen(options->editor[n].command) > 0);
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
834 }
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
835
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
836 gint start_editor_from_filelist_full(gint n, GList *list, EditorCallback cb, gpointer data)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
837 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
838 gchar *command;
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
839 gint error;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
840
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
841 if (!list) return FALSE;
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
842 if (!is_valid_editor_command(n)) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
843
730
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
844 command = g_locale_from_utf8(options->editor[n].command, -1, NULL, NULL, NULL);
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
845 error = editor_command_start(command, options->editor[n].name, list, cb, data);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
846 g_free(command);
669
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
847
670
a484500de88d Improve editor commands error display:
zas_
parents: 669
diff changeset
848 if (n < GQ_EDITOR_GENERIC_SLOTS && (error & EDITOR_ERROR_MASK))
669
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
849 {
670
a484500de88d Improve editor commands error display:
zas_
parents: 669
diff changeset
850 gchar *text = g_strdup_printf(_("%s\n#%d \"%s\":\n%s"), editor_get_error_str(error), n+1,
730
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
851 options->editor[n].name, options->editor[n].command);
669
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
852
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
853 file_util_warning_dialog(_("Invalid editor command"), text, GTK_STOCK_DIALOG_ERROR, NULL);
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
854 g_free(text);
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
855 }
dd5d7fe9458f Improve editors a bit:
zas_
parents: 586
diff changeset
856
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
857 return error;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
858 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
859
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
860 gint start_editor_from_filelist(gint n, GList *list)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
861 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
862 return start_editor_from_filelist_full(n, list, NULL, NULL);
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
863 }
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
864
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
865 gint start_editor_from_file_full(gint n, FileData *fd, EditorCallback cb, gpointer data)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
866 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
867 GList *list;
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
868 gint error;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
869
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
870 if (!fd) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
871
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 136
diff changeset
872 list = g_list_append(NULL, fd);
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
873 error = start_editor_from_filelist_full(n, list, cb, data);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
874 g_list_free(list);
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
875 return error;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
876 }
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
877
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
878 gint start_editor_from_file(gint n, FileData *fd)
136
18c2a29e681c more external commands
nadvornik
parents: 135
diff changeset
879 {
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
880 return start_editor_from_file_full(n, fd, NULL, NULL);
136
18c2a29e681c more external commands
nadvornik
parents: 135
diff changeset
881 }
18c2a29e681c more external commands
nadvornik
parents: 135
diff changeset
882
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
883 gint editor_window_flag_set(gint n)
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
884 {
444
452b7ffeb7ad Minor cleanup and code redundancy reduction.
zas_
parents: 443
diff changeset
885 if (!is_valid_editor_command(n)) return TRUE;
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
886
730
2d8a8e892b5e Use a struct to handle editor's properties.
zas_
parents: 671
diff changeset
887 return (editor_command_parse(options->editor[n].command, NULL, NULL) & EDITOR_KEEP_FS);
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
888 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
889
753
477f48ba28d8 rewritten utilops.h:
nadvornik
parents: 737
diff changeset
890 gint editor_is_filter(gint n)
477f48ba28d8 rewritten utilops.h:
nadvornik
parents: 737
diff changeset
891 {
477f48ba28d8 rewritten utilops.h:
nadvornik
parents: 737
diff changeset
892 if (!is_valid_editor_command(n)) return FALSE;
477f48ba28d8 rewritten utilops.h:
nadvornik
parents: 737
diff changeset
893
477f48ba28d8 rewritten utilops.h:
nadvornik
parents: 737
diff changeset
894 return (editor_command_parse(options->editor[n].command, NULL, NULL) & EDITOR_DEST);
477f48ba28d8 rewritten utilops.h:
nadvornik
parents: 737
diff changeset
895 }
477f48ba28d8 rewritten utilops.h:
nadvornik
parents: 737
diff changeset
896
140
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
897 const gchar *editor_get_error_str(gint flags)
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
898 {
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
899 if (flags & EDITOR_ERROR_EMPTY) return _("Editor template is empty.");
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
900 if (flags & EDITOR_ERROR_SYNTAX) return _("Editor template has incorrect syntax.");
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
901 if (flags & EDITOR_ERROR_INCOMPATIBLE) return _("Editor template uses incompatible macros.");
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
902 if (flags & EDITOR_ERROR_NO_FILE) return _("Can't find matching file type.");
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
903 if (flags & EDITOR_ERROR_CANT_EXEC) return _("Can't execute external editor.");
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
904 if (flags & EDITOR_ERROR_STATUS) return _("External editor returned error status.");
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
905 if (flags & EDITOR_ERROR_SKIPPED) return _("File was skipped.");
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
906 return _("Unknown error.");
e57b0207e180 editors.c was almost completely rewritten:
nadvornik
parents: 138
diff changeset
907 }
731
fa8f7d7396cf Introduce an helper function that returns the name of an editor.
zas_
parents: 730
diff changeset
908
fa8f7d7396cf Introduce an helper function that returns the name of an editor.
zas_
parents: 730
diff changeset
909 const gchar *editor_get_name(gint n)
fa8f7d7396cf Introduce an helper function that returns the name of an editor.
zas_
parents: 730
diff changeset
910 {
fa8f7d7396cf Introduce an helper function that returns the name of an editor.
zas_
parents: 730
diff changeset
911 if (!is_valid_editor_command(n)) return NULL;
fa8f7d7396cf Introduce an helper function that returns the name of an editor.
zas_
parents: 730
diff changeset
912
fa8f7d7396cf Introduce an helper function that returns the name of an editor.
zas_
parents: 730
diff changeset
913 if (options->editor[n].name && strlen(options->editor[n].name) > 0)
fa8f7d7396cf Introduce an helper function that returns the name of an editor.
zas_
parents: 730
diff changeset
914 return options->editor[n].name;
fa8f7d7396cf Introduce an helper function that returns the name of an editor.
zas_
parents: 730
diff changeset
915
fa8f7d7396cf Introduce an helper function that returns the name of an editor.
zas_
parents: 730
diff changeset
916 return _("(unknown)");
fa8f7d7396cf Introduce an helper function that returns the name of an editor.
zas_
parents: 730
diff changeset
917 }