Mercurial > geeqie
annotate src/editors.c @ 1752:843c4eb46e09
fixed incorrect translation
author | nadvornik |
---|---|
date | Sun, 13 Sep 2009 21:03:17 +0000 |
parents | a0e47436b552 |
children | ebfb5af3f5de |
rev | line source |
---|---|
9 | 1 /* |
196 | 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 |
1284 | 4 * Copyright (C) 2008 - 2009 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
281 | 14 #include "main.h" |
9 | 15 #include "editors.h" |
16 | |
669 | 17 #include "filedata.h" |
18 #include "filefilter.h" | |
1022
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
1000
diff
changeset
|
19 #include "misc.h" |
1736 | 20 #include "pixbuf_util.h" |
9 | 21 #include "ui_fileops.h" |
22 #include "ui_spinner.h" | |
23 #include "ui_utildlg.h" | |
1022
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
1000
diff
changeset
|
24 #include "utilops.h" |
9 | 25 |
26 #include <errno.h> | |
27 | |
28 | |
29 #define EDITOR_WINDOW_WIDTH 500 | |
30 #define EDITOR_WINDOW_HEIGHT 300 | |
31 | |
32 | |
33 | |
34 typedef struct _EditorVerboseData EditorVerboseData; | |
35 struct _EditorVerboseData { | |
36 GenericDialog *gd; | |
37 GtkWidget *button_close; | |
38 GtkWidget *button_stop; | |
39 GtkWidget *text; | |
40 GtkWidget *progress; | |
41 GtkWidget *spinner; | |
140 | 42 }; |
43 | |
44 typedef struct _EditorData EditorData; | |
45 struct _EditorData { | |
1405 | 46 EditorFlags flags; |
140 | 47 GPid pid; |
48 GList *list; | |
9 | 49 gint count; |
50 gint total; | |
140 | 51 gboolean stopping; |
52 EditorVerboseData *vd; | |
53 EditorCallback callback; | |
54 gpointer data; | |
1272 | 55 const EditorDescription *editor; |
1652
58a5d1e01e33
run external commands from current directory even with no files
nadvornik
parents:
1618
diff
changeset
|
56 gchar *working_directory; /* fallback if no files are given (editor_no_param) */ |
9 | 57 }; |
58 | |
59 | |
140 | 60 static void editor_verbose_window_progress(EditorData *ed, const gchar *text); |
1405 | 61 static EditorFlags editor_command_next_start(EditorData *ed); |
62 static EditorFlags editor_command_next_finish(EditorData *ed, gint status); | |
63 static EditorFlags editor_command_done(EditorData *ed); | |
9 | 64 |
65 /* | |
66 *----------------------------------------------------------------------------- | |
67 * external editor routines | |
68 *----------------------------------------------------------------------------- | |
69 */ | |
70 | |
1272 | 71 GHashTable *editors = NULL; |
1479 | 72 GtkListStore *desktop_file_list; |
1736 | 73 gboolean editors_finished = FALSE; |
1272 | 74 |
75 #ifdef G_KEY_FILE_DESKTOP_GROUP | |
76 #define DESKTOP_GROUP G_KEY_FILE_DESKTOP_GROUP | |
77 #else | |
78 #define DESKTOP_GROUP "Desktop Entry" | |
79 #endif | |
80 | |
81 void editor_description_free(EditorDescription *editor) | |
768
ff51413f098d
Use functions to set editors name and command and ensure they are
zas_
parents:
766
diff
changeset
|
82 { |
1272 | 83 if (!editor) return; |
84 | |
85 g_free(editor->key); | |
86 g_free(editor->name); | |
1278
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
87 g_free(editor->icon); |
1272 | 88 g_free(editor->exec); |
89 g_free(editor->menu_path); | |
90 g_free(editor->hotkey); | |
1468 | 91 g_free(editor->comment); |
1272 | 92 string_list_free(editor->ext_list); |
93 g_free(editor->file); | |
94 g_free(editor); | |
95 } | |
768
ff51413f098d
Use functions to set editors name and command and ensure they are
zas_
parents:
766
diff
changeset
|
96 |
1272 | 97 static GList *editor_mime_types_to_extensions(gchar **mime_types) |
98 { | |
99 /* FIXME: this should be rewritten to use the shared mime database, as soon as we switch to gio */ | |
768
ff51413f098d
Use functions to set editors name and command and ensure they are
zas_
parents:
766
diff
changeset
|
100 |
1272 | 101 static const gchar *conv_table[][2] = { |
1486 | 102 {"application/x-ufraw", ".ufraw"}, |
1272 | 103 {"image/*", "*"}, |
104 {"image/bmp", ".bmp"}, | |
105 {"image/gif", ".gif"}, | |
106 {"image/jpeg", ".jpeg;.jpg"}, | |
107 {"image/jpg", ".jpg;.jpeg"}, | |
108 {"image/pcx", ".pcx"}, | |
109 {"image/png", ".png"}, | |
110 {"image/svg", ".svg"}, | |
111 {"image/svg+xml", ".svg"}, | |
112 {"image/svg+xml-compressed", ".svg"}, | |
113 {"image/tiff", ".tiff;.tif"}, | |
114 {"image/x-bmp", ".bmp"}, | |
115 {"image/x-canon-crw", ".crw"}, | |
116 {"image/x-cr2", ".cr2"}, | |
117 {"image/x-dcraw", "%raw"}, | |
118 {"image/x-ico", ".ico"}, | |
119 {"image/x-mrw", ".mrw"}, | |
120 {"image/x-MS-bmp", ".bmp"}, | |
121 {"image/x-nef", ".nef"}, | |
122 {"image/x-orf", ".orf"}, | |
123 {"image/x-pcx", ".pcx"}, | |
124 {"image/xpm", ".xpm"}, | |
125 {"image/x-png", ".png"}, | |
126 {"image/x-portable-anymap", ".pam"}, | |
127 {"image/x-portable-bitmap", ".pbm"}, | |
128 {"image/x-portable-graymap", ".pgm"}, | |
129 {"image/x-portable-pixmap", ".ppm"}, | |
130 {"image/x-psd", ".psd"}, | |
131 {"image/x-raf", ".raf"}, | |
132 {"image/x-sgi", ".sgi"}, | |
133 {"image/x-tga", ".tga"}, | |
134 {"image/x-xbitmap", ".xbm"}, | |
135 {"image/x-xcf", ".xcf"}, | |
136 {"image/x-xpixmap", ".xpm"}, | |
137 {"image/x-x3f", ".x3f"}, | |
138 {NULL, NULL}}; | |
139 | |
140 gint i, j; | |
141 GList *list = NULL; | |
142 | |
143 for (i = 0; mime_types[i]; i++) | |
144 for (j = 0; conv_table[j][0]; j++) | |
145 if (strcmp(mime_types[i], conv_table[j][0]) == 0) | |
146 list = g_list_concat(list, filter_to_list(conv_table[j][1])); | |
147 | |
148 return list; | |
768
ff51413f098d
Use functions to set editors name and command and ensure they are
zas_
parents:
766
diff
changeset
|
149 } |
ff51413f098d
Use functions to set editors name and command and ensure they are
zas_
parents:
766
diff
changeset
|
150 |
1736 | 151 gboolean editor_read_desktop_file(const gchar *path) |
768
ff51413f098d
Use functions to set editors name and command and ensure they are
zas_
parents:
766
diff
changeset
|
152 { |
1272 | 153 GKeyFile *key_file; |
154 EditorDescription *editor; | |
155 gchar *extensions; | |
1278
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
156 gchar *type; |
1272 | 157 const gchar *key = filename_from_path(path); |
158 gchar **categories, **only_show_in, **not_show_in; | |
1274 | 159 gchar *try_exec; |
1479 | 160 GtkTreeIter iter; |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
161 gboolean category_geeqie = FALSE; |
1272 | 162 |
163 if (g_hash_table_lookup(editors, key)) return FALSE; /* the file found earlier wins */ | |
164 | |
165 key_file = g_key_file_new(); | |
166 if (!g_key_file_load_from_file(key_file, path, 0, NULL)) | |
167 { | |
168 g_key_file_free(key_file); | |
169 return FALSE; | |
170 } | |
1278
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
171 |
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
172 type = g_key_file_get_string(key_file, DESKTOP_GROUP, "Type", NULL); |
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
173 if (!type || strcmp(type, "Application") != 0) |
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
174 { |
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
175 /* We only consider desktop entries of Application type */ |
1409 | 176 g_key_file_free(key_file); |
1463
25168240a247
added function to reload external editors at any time
nadvornik
parents:
1409
diff
changeset
|
177 g_free(type); |
1278
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
178 return FALSE; |
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
179 } |
1463
25168240a247
added function to reload external editors at any time
nadvornik
parents:
1409
diff
changeset
|
180 g_free(type); |
1272 | 181 |
1407
57421a728682
Revert changeset 1502. It brokes the spec: hidden desktop files from user directory should hide files from system directory with the same name.
zas_
parents:
1406
diff
changeset
|
182 editor = g_new0(EditorDescription, 1); |
57421a728682
Revert changeset 1502. It brokes the spec: hidden desktop files from user directory should hide files from system directory with the same name.
zas_
parents:
1406
diff
changeset
|
183 |
57421a728682
Revert changeset 1502. It brokes the spec: hidden desktop files from user directory should hide files from system directory with the same name.
zas_
parents:
1406
diff
changeset
|
184 editor->key = g_strdup(key); |
57421a728682
Revert changeset 1502. It brokes the spec: hidden desktop files from user directory should hide files from system directory with the same name.
zas_
parents:
1406
diff
changeset
|
185 editor->file = g_strdup(path); |
57421a728682
Revert changeset 1502. It brokes the spec: hidden desktop files from user directory should hide files from system directory with the same name.
zas_
parents:
1406
diff
changeset
|
186 |
57421a728682
Revert changeset 1502. It brokes the spec: hidden desktop files from user directory should hide files from system directory with the same name.
zas_
parents:
1406
diff
changeset
|
187 g_hash_table_insert(editors, editor->key, editor); |
57421a728682
Revert changeset 1502. It brokes the spec: hidden desktop files from user directory should hide files from system directory with the same name.
zas_
parents:
1406
diff
changeset
|
188 |
1278
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
189 if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "Hidden", NULL) |
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
190 || g_key_file_get_boolean(key_file, DESKTOP_GROUP, "NoDisplay", NULL)) |
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
191 { |
1407
57421a728682
Revert changeset 1502. It brokes the spec: hidden desktop files from user directory should hide files from system directory with the same name.
zas_
parents:
1406
diff
changeset
|
192 editor->hidden = TRUE; |
1278
c5852c543775
Add support for NoDisplay (entry is then hidden) and Type (only Application type is valid here) keys.
zas_
parents:
1276
diff
changeset
|
193 } |
1272 | 194 |
195 categories = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "Categories", NULL, NULL); | |
196 if (categories) | |
197 { | |
198 gboolean found = FALSE; | |
199 gint i; | |
200 for (i = 0; categories[i]; i++) | |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
201 { |
1272 | 202 /* IMHO "Graphics" is exactly the category that we are interested in, so this does not have to be configurable */ |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
203 if (strcmp(categories[i], "Graphics") == 0) |
1272 | 204 { |
205 found = TRUE; | |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
206 } |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
207 if (strcmp(categories[i], "X-Geeqie") == 0) |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
208 { |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
209 found = TRUE; |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
210 category_geeqie = TRUE; |
1272 | 211 break; |
212 } | |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
213 } |
1479 | 214 if (!found) editor->ignored = TRUE; |
1272 | 215 g_strfreev(categories); |
216 } | |
217 else | |
218 { | |
1479 | 219 editor->ignored = TRUE; |
1272 | 220 } |
221 | |
222 only_show_in = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "OnlyShowIn", NULL, NULL); | |
223 if (only_show_in) | |
224 { | |
225 gboolean found = FALSE; | |
226 gint i; | |
227 for (i = 0; only_show_in[i]; i++) | |
228 if (strcmp(only_show_in[i], "X-Geeqie") == 0) | |
229 { | |
230 found = TRUE; | |
231 break; | |
232 } | |
1479 | 233 if (!found) editor->ignored = TRUE; |
1272 | 234 g_strfreev(only_show_in); |
235 } | |
768
ff51413f098d
Use functions to set editors name and command and ensure they are
zas_
parents:
766
diff
changeset
|
236 |
1272 | 237 not_show_in = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "NotShowIn", NULL, NULL); |
238 if (not_show_in) | |
239 { | |
240 gboolean found = FALSE; | |
241 gint i; | |
242 for (i = 0; not_show_in[i]; i++) | |
243 if (strcmp(not_show_in[i], "X-Geeqie") == 0) | |
244 { | |
245 found = TRUE; | |
246 break; | |
247 } | |
1479 | 248 if (found) editor->ignored = TRUE; |
1272 | 249 g_strfreev(not_show_in); |
250 } | |
251 | |
1407
57421a728682
Revert changeset 1502. It brokes the spec: hidden desktop files from user directory should hide files from system directory with the same name.
zas_
parents:
1406
diff
changeset
|
252 |
1274 | 253 try_exec = g_key_file_get_string(key_file, DESKTOP_GROUP, "TryExec", NULL); |
1479 | 254 if (try_exec && !editor->hidden && !editor->ignored) |
1274 | 255 { |
256 gchar *try_exec_res = g_find_program_in_path(try_exec); | |
1407
57421a728682
Revert changeset 1502. It brokes the spec: hidden desktop files from user directory should hide files from system directory with the same name.
zas_
parents:
1406
diff
changeset
|
257 if (!try_exec_res) editor->hidden = TRUE; |
1274 | 258 g_free(try_exec_res); |
259 g_free(try_exec); | |
260 } | |
1479 | 261 |
262 if (editor->ignored) | |
1272 | 263 { |
1479 | 264 /* ignored editors will be deleted, no need to parse the rest */ |
1272 | 265 g_key_file_free(key_file); |
1407
57421a728682
Revert changeset 1502. It brokes the spec: hidden desktop files from user directory should hide files from system directory with the same name.
zas_
parents:
1406
diff
changeset
|
266 return TRUE; |
1272 | 267 } |
268 | |
269 editor->name = g_key_file_get_locale_string(key_file, DESKTOP_GROUP, "Name", NULL, NULL); | |
270 editor->icon = g_key_file_get_string(key_file, DESKTOP_GROUP, "Icon", NULL); | |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
271 |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
272 /* Icon key can be either a full path (absolute with file name extension) or an icon name (without extension) */ |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
273 if (editor->icon && !g_path_is_absolute(editor->icon)) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
274 { |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
275 gchar *ext = strrchr(editor->icon, '.'); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
276 |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
277 if (ext && strlen(ext) == 4 && |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
278 (!strcmp(ext, ".png") || !strcmp(ext, ".xpm") || !strcmp(ext, ".svg"))) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
279 { |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
280 log_printf(_("Desktop file '%s' should not include extension in Icon key: '%s'\n"), |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
281 editor->file, editor->icon); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
282 |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
283 // drop extension |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
284 *ext = '\0'; |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
285 } |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
286 } |
1736 | 287 if (editor->icon && !register_theme_icon_as_stock(editor->key, editor->icon)) |
288 { | |
289 g_free(editor->icon); | |
290 editor->icon = NULL; | |
291 } | |
1272 | 292 |
293 editor->exec = g_key_file_get_string(key_file, DESKTOP_GROUP, "Exec", NULL); | |
294 | |
295 editor->menu_path = g_key_file_get_string(key_file, DESKTOP_GROUP, "X-Geeqie-Menu-Path", NULL); | |
296 if (!editor->menu_path) editor->menu_path = g_strdup("EditMenu/ExternalMenu"); | |
297 | |
298 editor->hotkey = g_key_file_get_string(key_file, DESKTOP_GROUP, "X-Geeqie-Hotkey", NULL); | |
299 | |
1468 | 300 editor->comment = g_key_file_get_string(key_file, DESKTOP_GROUP, "Comment", NULL); |
301 | |
1272 | 302 extensions = g_key_file_get_string(key_file, DESKTOP_GROUP, "X-Geeqie-File-Extensions", NULL); |
303 if (extensions) | |
304 editor->ext_list = filter_to_list(extensions); | |
305 else | |
306 { | |
307 gchar **mime_types = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "MimeType", NULL, NULL); | |
308 if (mime_types) | |
309 { | |
310 editor->ext_list = editor_mime_types_to_extensions(mime_types); | |
311 g_strfreev(mime_types); | |
312 if (!editor->ext_list) editor->hidden = TRUE; | |
313 } | |
314 } | |
315 | |
316 if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Keep-Fullscreen", NULL)) editor->flags |= EDITOR_KEEP_FS; | |
317 if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Verbose", NULL)) editor->flags |= EDITOR_VERBOSE; | |
318 if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Verbose-Multi", NULL)) editor->flags |= EDITOR_VERBOSE_MULTI; | |
319 if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Filter", NULL)) editor->flags |= EDITOR_DEST; | |
320 if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "Terminal", NULL)) editor->flags |= EDITOR_TERMINAL; | |
321 | |
1742 | 322 editor->flags |= editor_command_parse(editor, NULL, FALSE, NULL); |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
323 |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
324 if ((editor->flags & EDITOR_NO_PARAM) && !category_geeqie) editor->hidden = TRUE; |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
325 |
1272 | 326 g_key_file_free(key_file); |
1479 | 327 |
328 if (editor->ignored) return TRUE; | |
329 | |
330 gtk_list_store_append(desktop_file_list, &iter); | |
331 gtk_list_store_set(desktop_file_list, &iter, | |
332 DESKTOP_FILE_COLUMN_KEY, key, | |
333 DESKTOP_FILE_COLUMN_NAME, editor->name, | |
334 DESKTOP_FILE_COLUMN_HIDDEN, editor->hidden, | |
335 DESKTOP_FILE_COLUMN_WRITABLE, access_file(path, W_OK), | |
336 DESKTOP_FILE_COLUMN_PATH, path, -1); | |
1272 | 337 |
338 return TRUE; | |
768
ff51413f098d
Use functions to set editors name and command and ensure they are
zas_
parents:
766
diff
changeset
|
339 } |
ff51413f098d
Use functions to set editors name and command and ensure they are
zas_
parents:
766
diff
changeset
|
340 |
1272 | 341 static gboolean editor_remove_desktop_file_cb(gpointer key, gpointer value, gpointer user_data) |
342 { | |
343 EditorDescription *editor = value; | |
1479 | 344 return editor->hidden || editor->ignored; |
1272 | 345 } |
346 | |
1736 | 347 void editor_table_finish(void) |
9 | 348 { |
1736 | 349 g_hash_table_foreach_remove(editors, editor_remove_desktop_file_cb, NULL); |
350 editors_finished = TRUE; | |
1272 | 351 } |
352 | |
1736 | 353 void editor_table_clear(void) |
1272 | 354 { |
1479 | 355 if (desktop_file_list) |
356 { | |
357 gtk_list_store_clear(desktop_file_list); | |
358 } | |
359 else | |
360 { | |
361 desktop_file_list = gtk_list_store_new(DESKTOP_FILE_COLUMN_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING); | |
362 } | |
1463
25168240a247
added function to reload external editors at any time
nadvornik
parents:
1409
diff
changeset
|
363 if (editors) |
1272 | 364 { |
1463
25168240a247
added function to reload external editors at any time
nadvornik
parents:
1409
diff
changeset
|
365 g_hash_table_destroy(editors); |
1272 | 366 } |
1463
25168240a247
added function to reload external editors at any time
nadvornik
parents:
1409
diff
changeset
|
367 editors = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)editor_description_free); |
1736 | 368 editors_finished = FALSE; |
369 } | |
9 | 370 |
1736 | 371 static GList *editor_add_desktop_dir(GList *list, const gchar *path) |
372 { | |
373 DIR *dp; | |
374 struct dirent *dir; | |
375 gchar *pathl; | |
376 | |
377 pathl = path_from_utf8(path); | |
378 dp = opendir(pathl); | |
379 g_free(pathl); | |
380 if (!dp) | |
381 { | |
382 /* dir not found */ | |
383 return list; | |
384 } | |
385 while ((dir = readdir(dp)) != NULL) | |
386 { | |
387 gchar *namel = dir->d_name; | |
388 | |
389 if (g_str_has_suffix(namel, ".desktop")) | |
390 { | |
391 gchar *name = path_to_utf8(namel); | |
392 gchar *dpath = g_build_filename(path, name, NULL); | |
393 list = g_list_prepend(list, dpath); | |
394 g_free(name); | |
395 } | |
396 } | |
397 closedir(dp); | |
398 return list; | |
399 } | |
400 | |
401 GList *editor_get_desktop_files(void) | |
402 { | |
403 gchar *path; | |
404 gchar *xdg_data_dirs; | |
405 gchar *all_dirs; | |
406 gchar **split_dirs; | |
407 gint i; | |
408 GList *list = NULL; | |
409 | |
1272 | 410 xdg_data_dirs = getenv("XDG_DATA_DIRS"); |
411 if (xdg_data_dirs && xdg_data_dirs[0]) | |
412 xdg_data_dirs = path_to_utf8(xdg_data_dirs); | |
413 else | |
414 xdg_data_dirs = g_strdup("/usr/share"); | |
415 | |
1274 | 416 all_dirs = g_strconcat(get_rc_dir(), ":", GQ_APP_DIR, ":", xdg_data_home_get(), ":", xdg_data_dirs, NULL); |
1272 | 417 |
418 g_free(xdg_data_dirs); | |
419 | |
420 split_dirs = g_strsplit(all_dirs, ":", 0); | |
421 | |
422 g_free(all_dirs); | |
423 | |
1736 | 424 for (i = 0; split_dirs[i]; i++); |
425 for (--i; i >= 0; i--) | |
9 | 426 { |
1272 | 427 path = g_build_filename(split_dirs[i], "applications", NULL); |
1736 | 428 list = editor_add_desktop_dir(list, path); |
1272 | 429 g_free(path); |
9 | 430 } |
1272 | 431 |
432 g_strfreev(split_dirs); | |
1746 | 433 return list; |
9 | 434 } |
435 | |
1272 | 436 static void editor_list_add_cb(gpointer key, gpointer value, gpointer data) |
437 { | |
438 GList **listp = data; | |
439 EditorDescription *editor = value; | |
440 | |
1402 | 441 /* do not show the special commands in any list, they are called explicitly */ |
1272 | 442 if (strcmp(editor->key, CMD_COPY) == 0 || |
443 strcmp(editor->key, CMD_MOVE) == 0 || | |
444 strcmp(editor->key, CMD_RENAME) == 0 || | |
445 strcmp(editor->key, CMD_DELETE) == 0 || | |
446 strcmp(editor->key, CMD_FOLDER) == 0) return; | |
447 | |
448 *listp = g_list_prepend(*listp, editor); | |
449 } | |
450 | |
1276
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
451 static gint editor_sort(gconstpointer a, gconstpointer b) |
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
452 { |
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
453 const EditorDescription *ea = a; |
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
454 const EditorDescription *eb = b; |
1402 | 455 gint ret; |
1276
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
456 |
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
457 ret = strcmp(ea->menu_path, eb->menu_path); |
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
458 if (ret != 0) return ret; |
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
459 |
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
460 return g_utf8_collate(ea->name, eb->name); |
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
461 } |
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
462 |
1272 | 463 GList *editor_list_get(void) |
464 { | |
465 GList *editors_list = NULL; | |
1736 | 466 |
467 if (!editors_finished) return NULL; | |
468 | |
1272 | 469 g_hash_table_foreach(editors, editor_list_add_cb, &editors_list); |
1276
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
470 editors_list = g_list_sort(editors_list, editor_sort); |
4177057ca11b
editor_list_get() now returns a sorted list, this way items appear in the same order in all menus.
zas_
parents:
1274
diff
changeset
|
471 |
1272 | 472 return editors_list; |
473 } | |
474 | |
475 /* ------------------------------ */ | |
476 | |
477 | |
140 | 478 static void editor_verbose_data_free(EditorData *ed) |
479 { | |
480 if (!ed->vd) return; | |
481 g_free(ed->vd); | |
482 ed->vd = NULL; | |
483 } | |
484 | |
485 static void editor_data_free(EditorData *ed) | |
486 { | |
487 editor_verbose_data_free(ed); | |
1652
58a5d1e01e33
run external commands from current directory even with no files
nadvornik
parents:
1618
diff
changeset
|
488 g_free(ed->working_directory); |
140 | 489 g_free(ed); |
490 } | |
491 | |
9 | 492 static void editor_verbose_window_close(GenericDialog *gd, gpointer data) |
493 { | |
140 | 494 EditorData *ed = data; |
9 | 495 |
496 generic_dialog_close(gd); | |
140 | 497 editor_verbose_data_free(ed); |
498 if (ed->pid == -1) editor_data_free(ed); /* the process has already terminated */ | |
9 | 499 } |
500 | |
501 static void editor_verbose_window_stop(GenericDialog *gd, gpointer data) | |
502 { | |
140 | 503 EditorData *ed = data; |
504 ed->stopping = TRUE; | |
505 ed->count = 0; | |
506 editor_verbose_window_progress(ed, _("stopping...")); | |
9 | 507 } |
508 | |
509 static void editor_verbose_window_enable_close(EditorVerboseData *vd) | |
510 { | |
511 vd->gd->cancel_cb = editor_verbose_window_close; | |
512 | |
513 spinner_set_interval(vd->spinner, -1); | |
514 gtk_widget_set_sensitive(vd->button_stop, FALSE); | |
515 gtk_widget_set_sensitive(vd->button_close, TRUE); | |
516 } | |
517 | |
140 | 518 static EditorVerboseData *editor_verbose_window(EditorData *ed, const gchar *text) |
9 | 519 { |
520 EditorVerboseData *vd; | |
521 GtkWidget *scrolled; | |
522 GtkWidget *hbox; | |
523 gchar *buf; | |
524 | |
525 vd = g_new0(EditorVerboseData, 1); | |
526 | |
1174
0bea79d87065
Drop useless wmclass stuff. Gtk will take care of it and as said in the documentation using gtk_window_set_wmclass() is sort of pointless.
zas_
parents:
1055
diff
changeset
|
527 vd->gd = file_util_gen_dlg(_("Edit command results"), "editor_results", |
9 | 528 NULL, FALSE, |
140 | 529 NULL, ed); |
9 | 530 buf = g_strdup_printf(_("Output of %s"), text); |
531 generic_dialog_add_message(vd->gd, NULL, buf, NULL); | |
532 g_free(buf); | |
533 vd->button_stop = generic_dialog_add_button(vd->gd, GTK_STOCK_STOP, NULL, | |
534 editor_verbose_window_stop, FALSE); | |
535 gtk_widget_set_sensitive(vd->button_stop, FALSE); | |
536 vd->button_close = generic_dialog_add_button(vd->gd, GTK_STOCK_CLOSE, NULL, | |
537 editor_verbose_window_close, TRUE); | |
538 gtk_widget_set_sensitive(vd->button_close, FALSE); | |
539 | |
540 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
541 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
542 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
543 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
544 gtk_box_pack_start(GTK_BOX(vd->gd->vbox), scrolled, TRUE, TRUE, 5); | |
545 gtk_widget_show(scrolled); | |
546 | |
547 vd->text = gtk_text_view_new(); | |
548 gtk_text_view_set_editable(GTK_TEXT_VIEW(vd->text), FALSE); | |
549 gtk_widget_set_size_request(vd->text, EDITOR_WINDOW_WIDTH, EDITOR_WINDOW_HEIGHT); | |
550 gtk_container_add(GTK_CONTAINER(scrolled), vd->text); | |
551 gtk_widget_show(vd->text); | |
552 | |
553 hbox = gtk_hbox_new(FALSE, 0); | |
554 gtk_box_pack_start(GTK_BOX(vd->gd->vbox), hbox, FALSE, FALSE, 0); | |
555 gtk_widget_show(hbox); | |
556 | |
557 vd->progress = gtk_progress_bar_new(); | |
558 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(vd->progress), 0.0); | |
559 gtk_box_pack_start(GTK_BOX(hbox), vd->progress, TRUE, TRUE, 0); | |
560 gtk_widget_show(vd->progress); | |
561 | |
562 vd->spinner = spinner_new(NULL, SPINNER_SPEED); | |
563 gtk_box_pack_start(GTK_BOX(hbox), vd->spinner, FALSE, FALSE, 0); | |
564 gtk_widget_show(vd->spinner); | |
442 | 565 |
9 | 566 gtk_widget_show(vd->gd->dialog); |
567 | |
140 | 568 ed->vd = vd; |
9 | 569 return vd; |
570 } | |
571 | |
572 static void editor_verbose_window_fill(EditorVerboseData *vd, gchar *text, gint len) | |
573 { | |
574 GtkTextBuffer *buffer; | |
575 GtkTextIter iter; | |
576 | |
577 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(vd->text)); | |
578 gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1); | |
579 gtk_text_buffer_insert(buffer, &iter, text, len); | |
580 } | |
581 | |
140 | 582 static void editor_verbose_window_progress(EditorData *ed, const gchar *text) |
9 | 583 { |
140 | 584 if (!ed->vd) return; |
585 | |
586 if (ed->total) | |
9 | 587 { |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
588 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ed->vd->progress), (gdouble)ed->count / ed->total); |
9 | 589 } |
590 | |
140 | 591 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ed->vd->progress), (text) ? text : ""); |
9 | 592 } |
593 | |
594 static gboolean editor_verbose_io_cb(GIOChannel *source, GIOCondition condition, gpointer data) | |
595 { | |
140 | 596 EditorData *ed = data; |
9 | 597 gchar buf[512]; |
598 gsize count; | |
599 | |
140 | 600 if (condition & G_IO_IN) |
9 | 601 { |
140 | 602 while (g_io_channel_read_chars(source, buf, sizeof(buf), &count, NULL) == G_IO_STATUS_NORMAL) |
603 { | |
604 if (!g_utf8_validate(buf, count, NULL)) | |
9 | 605 { |
140 | 606 gchar *utf8; |
444 | 607 |
140 | 608 utf8 = g_locale_to_utf8(buf, count, NULL, NULL, NULL); |
609 if (utf8) | |
9 | 610 { |
140 | 611 editor_verbose_window_fill(ed->vd, utf8, -1); |
612 g_free(utf8); | |
9 | 613 } |
614 else | |
615 { | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
616 editor_verbose_window_fill(ed->vd, "Error converting text to valid utf8\n", -1); |
9 | 617 } |
618 } | |
140 | 619 else |
620 { | |
621 editor_verbose_window_fill(ed->vd, buf, count); | |
622 } | |
623 } | |
9 | 624 } |
625 | |
140 | 626 if (condition & (G_IO_ERR | G_IO_HUP)) |
9 | 627 { |
140 | 628 g_io_channel_shutdown(source, TRUE, NULL); |
9 | 629 return FALSE; |
630 } | |
631 | |
632 return TRUE; | |
633 } | |
634 | |
138 | 635 typedef enum { |
636 PATH_FILE, | |
1272 | 637 PATH_FILE_URL, |
140 | 638 PATH_DEST |
138 | 639 } PathType; |
640 | |
641 | |
1742 | 642 static gchar *editor_command_path_parse(const FileData *fd, gboolean consider_sidecars, PathType type, const EditorDescription *editor) |
123
3602a4aa7c71
Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
643 { |
3602a4aa7c71
Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
644 GString *string; |
3602a4aa7c71
Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
645 gchar *pathl; |
1408 | 646 const gchar *p = NULL; |
123
3602a4aa7c71
Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
647 |
3602a4aa7c71
Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
648 string = g_string_new(""); |
442 | 649 |
1272 | 650 if (type == PATH_FILE || type == PATH_FILE_URL) |
138 | 651 { |
1272 | 652 GList *work = editor->ext_list; |
442 | 653 |
147
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
654 if (!work) |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
655 p = fd->path; |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
656 else |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
657 { |
516 | 658 while (work) |
147
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
659 { |
444 | 660 GList *work2; |
147
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
661 gchar *ext = work->data; |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
662 work = work->next; |
442 | 663 |
664 if (strcmp(ext, "*") == 0 || | |
1307 | 665 g_ascii_strcasecmp(ext, fd->extension) == 0) |
147
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
666 { |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
667 p = fd->path; |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
668 break; |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
669 } |
442 | 670 |
1742 | 671 work2 = consider_sidecars ? fd->sidecar_files : NULL; |
516 | 672 while (work2) |
147
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
673 { |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
674 FileData *sfd = work2->data; |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
675 work2 = work2->next; |
442 | 676 |
1307 | 677 if (g_ascii_strcasecmp(ext, sfd->extension) == 0) |
147
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
678 { |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
679 p = sfd->path; |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
680 break; |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
681 } |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
682 } |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
683 if (p) break; |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
684 } |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
685 if (!p) return NULL; |
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
140
diff
changeset
|
686 } |
138 | 687 } |
140 | 688 else if (type == PATH_DEST) |
138 | 689 { |
690 if (fd->change && fd->change->dest) | |
691 p = fd->change->dest; | |
692 else | |
693 p = ""; | |
694 } | |
444 | 695 |
1407
57421a728682
Revert changeset 1502. It brokes the spec: hidden desktop files from user directory should hide files from system directory with the same name.
zas_
parents:
1406
diff
changeset
|
696 g_assert(p); |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
697 string = g_string_append(string, p); |
123
3602a4aa7c71
Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
698 |
1272 | 699 if (type == PATH_FILE_URL) g_string_prepend(string, "file://"); |
123
3602a4aa7c71
Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
700 pathl = path_from_utf8(string->str); |
3602a4aa7c71
Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
701 g_string_free(string, TRUE); |
3602a4aa7c71
Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
702 |
1402 | 703 if (pathl && !pathl[0]) /* empty string case */ |
704 { | |
705 g_free(pathl); | |
706 pathl = NULL; | |
707 } | |
708 | |
123
3602a4aa7c71
Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
709 return pathl; |
3602a4aa7c71
Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
710 } |
3602a4aa7c71
Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
711 |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
712 static GString *append_quoted(GString *str, const char *s, gboolean single_quotes, gboolean double_quotes) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
713 { |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
714 const char *p; |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
715 |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
716 if (!single_quotes) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
717 { |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
718 if (!double_quotes) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
719 g_string_append_c(str, '\''); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
720 else |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
721 g_string_append(str, "\"'"); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
722 } |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
723 |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
724 for (p = s; *p != '\0'; p++) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
725 { |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
726 if (*p == '\'') |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
727 g_string_append(str, "'\\''"); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
728 else |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
729 g_string_append_c(str, *p); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
730 } |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
731 |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
732 if (!single_quotes) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
733 { |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
734 if (!double_quotes) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
735 g_string_append_c(str, '\''); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
736 else |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
737 g_string_append(str, "'\""); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
738 } |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
739 |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
740 return str; |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
741 } |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
742 |
9 | 743 |
1742 | 744 EditorFlags editor_command_parse(const EditorDescription *editor, GList *list, gboolean consider_sidecars, gchar **output) |
9 | 745 { |
1405 | 746 EditorFlags flags = 0; |
1272 | 747 const gchar *p; |
140 | 748 GString *result = NULL; |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
749 gboolean escape = FALSE; |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
750 gboolean single_quotes = FALSE; |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
751 gboolean double_quotes = FALSE; |
442 | 752 |
140 | 753 if (output) |
754 result = g_string_new(""); | |
755 | |
1272 | 756 if (editor->exec[0] == '\0') |
140 | 757 { |
758 flags |= EDITOR_ERROR_EMPTY; | |
759 goto err; | |
760 } | |
669 | 761 |
1272 | 762 p = editor->exec; |
669 | 763 /* skip leading whitespaces if any */ |
764 while (g_ascii_isspace(*p)) p++; | |
442 | 765 |
140 | 766 /* command */ |
442 | 767 |
140 | 768 while (*p) |
769 { | |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
770 if (escape) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
771 { |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
772 escape = FALSE; |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
773 if (output) result = g_string_append_c(result, *p); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
774 } |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
775 else if (*p == '\\') |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
776 { |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
777 if (!single_quotes) escape = TRUE; |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
778 if (output) result = g_string_append_c(result, *p); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
779 } |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
780 else if (*p == '\'') |
140 | 781 { |
782 if (output) result = g_string_append_c(result, *p); | |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
783 if (!single_quotes && !double_quotes) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
784 single_quotes = TRUE; |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
785 else if (single_quotes) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
786 single_quotes = FALSE; |
140 | 787 } |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
788 else if (*p == '"') |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
789 { |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
790 if (output) result = g_string_append_c(result, *p); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
791 if (!single_quotes && !double_quotes) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
792 double_quotes = TRUE; |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
793 else if (double_quotes) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
794 double_quotes = FALSE; |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
795 } |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
796 else if (*p == '%' && p[1]) |
140 | 797 { |
798 gchar *pathl = NULL; | |
9 | 799 |
140 | 800 p++; |
442 | 801 |
802 switch (*p) | |
140 | 803 { |
1272 | 804 case 'f': /* single file */ |
805 case 'u': /* single url */ | |
140 | 806 flags |= EDITOR_FOR_EACH; |
807 if (flags & EDITOR_SINGLE_COMMAND) | |
808 { | |
809 flags |= EDITOR_ERROR_INCOMPATIBLE; | |
810 goto err; | |
811 } | |
1399 | 812 if (list) |
1397
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1367
diff
changeset
|
813 { |
1399 | 814 /* use the first file from the list */ |
815 if (!list->data) | |
816 { | |
817 flags |= EDITOR_ERROR_NO_FILE; | |
818 goto err; | |
819 } | |
820 pathl = editor_command_path_parse((FileData *)list->data, | |
1742 | 821 consider_sidecars, |
1399 | 822 (*p == 'f') ? PATH_FILE : PATH_FILE_URL, |
823 editor); | |
824 if (!pathl) | |
825 { | |
826 flags |= EDITOR_ERROR_NO_FILE; | |
827 goto err; | |
828 } | |
829 if (output) | |
830 { | |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
831 result = append_quoted(result, pathl, single_quotes, double_quotes); |
1399 | 832 } |
833 g_free(pathl); | |
1397
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1367
diff
changeset
|
834 } |
442 | 835 break; |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
836 |
1272 | 837 case 'F': |
838 case 'U': | |
140 | 839 flags |= EDITOR_SINGLE_COMMAND; |
840 if (flags & (EDITOR_FOR_EACH | EDITOR_DEST)) | |
841 { | |
842 flags |= EDITOR_ERROR_INCOMPATIBLE; | |
843 goto err; | |
844 } | |
845 | |
1399 | 846 if (list) |
140 | 847 { |
848 /* use whole list */ | |
849 GList *work = list; | |
850 gboolean ok = FALSE; | |
444 | 851 |
140 | 852 while (work) |
853 { | |
854 FileData *fd = work->data; | |
1742 | 855 pathl = editor_command_path_parse(fd, consider_sidecars, (*p == 'F') ? PATH_FILE : PATH_FILE_URL, editor); |
140 | 856 if (pathl) |
857 { | |
858 ok = TRUE; | |
1397
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1367
diff
changeset
|
859 |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1367
diff
changeset
|
860 if (output) |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1367
diff
changeset
|
861 { |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1367
diff
changeset
|
862 ok = TRUE; |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1367
diff
changeset
|
863 if (work != list) g_string_append_c(result, ' '); |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
864 result = append_quoted(result, pathl, single_quotes, double_quotes); |
1397
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1367
diff
changeset
|
865 } |
140 | 866 g_free(pathl); |
867 } | |
868 work = work->next; | |
869 } | |
442 | 870 if (!ok) |
140 | 871 { |
872 flags |= EDITOR_ERROR_NO_FILE; | |
873 goto err; | |
874 } | |
875 } | |
442 | 876 break; |
1272 | 877 case 'i': |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
878 if (editor->icon && *editor->icon) |
1272 | 879 { |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
880 if (output) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
881 { |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
882 result = g_string_append(result, "--icon "); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
883 result = append_quoted(result, editor->icon, single_quotes, double_quotes); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
884 } |
1272 | 885 } |
886 break; | |
887 case 'c': | |
888 if (output) | |
889 { | |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
890 result = append_quoted(result, editor->name, single_quotes, double_quotes); |
1272 | 891 } |
892 break; | |
893 case 'k': | |
894 if (output) | |
895 { | |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
896 result = append_quoted(result, editor->file, single_quotes, double_quotes); |
1272 | 897 } |
898 break; | |
669 | 899 case '%': |
900 /* %% = % escaping */ | |
901 if (output) result = g_string_append_c(result, *p); | |
902 break; | |
1272 | 903 case 'd': |
904 case 'D': | |
905 case 'n': | |
906 case 'N': | |
907 case 'v': | |
908 case 'm': | |
909 /* deprecated according to spec, ignore */ | |
910 break; | |
140 | 911 default: |
912 flags |= EDITOR_ERROR_SYNTAX; | |
913 goto err; | |
914 } | |
915 } | |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
916 else |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
917 { |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
918 if (output) result = g_string_append_c(result, *p); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
919 } |
140 | 920 p++; |
9 | 921 } |
922 | |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
923 if (!(flags & (EDITOR_FOR_EACH | EDITOR_SINGLE_COMMAND))) flags |= EDITOR_NO_PARAM; |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
924 |
1478
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
925 if (output) |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
926 { |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
927 *output = g_string_free(result, FALSE); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
928 DEBUG_3("Editor cmd: %s", *output); |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
929 } |
3cc98d5c6907
Improve editors through .desktop files implementation:
zas_
parents:
1468
diff
changeset
|
930 |
140 | 931 return flags; |
932 | |
442 | 933 |
140 | 934 err: |
442 | 935 if (output) |
9 | 936 { |
140 | 937 g_string_free(result, TRUE); |
938 *output = NULL; | |
939 } | |
940 return flags; | |
941 } | |
942 | |
1272 | 943 |
1397
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1367
diff
changeset
|
944 static void editor_child_exit_cb(GPid pid, gint status, gpointer data) |
140 | 945 { |
946 EditorData *ed = data; | |
947 g_spawn_close_pid(pid); | |
948 ed->pid = -1; | |
442 | 949 |
140 | 950 editor_command_next_finish(ed, status); |
951 } | |
952 | |
953 | |
1405 | 954 static EditorFlags editor_command_one(const EditorDescription *editor, GList *list, EditorData *ed) |
140 | 955 { |
956 gchar *command; | |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
957 FileData *fd = (ed->flags & EDITOR_NO_PARAM) ? NULL : list->data;; |
140 | 958 GPid pid; |
442 | 959 gint standard_output; |
960 gint standard_error; | |
140 | 961 gboolean ok; |
962 | |
963 ed->pid = -1; | |
1405 | 964 ed->flags = editor->flags; |
1742 | 965 ed->flags |= editor_command_parse(editor, list, TRUE, &command); |
140 | 966 |
1400
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
967 ok = !EDITOR_ERRORS(ed->flags); |
140 | 968 |
969 if (ok) | |
970 { | |
737
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
971 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
|
972 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
|
973 |
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
974 if (ok) |
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
975 { |
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
976 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
|
977 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
|
978 } |
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
979 |
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
980 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
|
981 } |
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
982 |
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
983 if (ok) |
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
984 { |
443 | 985 gchar *working_directory; |
986 gchar *args[4]; | |
737
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
987 guint n = 0; |
443 | 988 |
1652
58a5d1e01e33
run external commands from current directory even with no files
nadvornik
parents:
1618
diff
changeset
|
989 working_directory = fd ? remove_level_from_path(fd->path) : g_strdup(ed->working_directory); |
737
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
990 args[n++] = options->shell.path; |
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
991 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
|
992 args[n++] = options->shell.options; |
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
993 args[n++] = command; |
8a8873e7a552
Make shell command and its option rc file options instead of hardcoded strings.
zas_
parents:
731
diff
changeset
|
994 args[n] = NULL; |
443 | 995 |
1272 | 996 if ((ed->flags & EDITOR_DEST) && fd->change && fd->change->dest) /* FIXME: error handling */ |
997 { | |
1402 | 998 g_setenv("GEEQIE_DESTINATION", fd->change->dest, TRUE); |
1272 | 999 } |
1000 else | |
1001 { | |
1402 | 1002 g_unsetenv("GEEQIE_DESTINATION"); |
1272 | 1003 } |
1004 | |
442 | 1005 ok = g_spawn_async_with_pipes(working_directory, args, NULL, |
140 | 1006 G_SPAWN_DO_NOT_REAP_CHILD, /* GSpawnFlags */ |
442 | 1007 NULL, NULL, |
1008 &pid, | |
1009 NULL, | |
1010 ed->vd ? &standard_output : NULL, | |
1011 ed->vd ? &standard_error : NULL, | |
140 | 1012 NULL); |
443 | 1013 |
1014 g_free(working_directory); | |
442 | 1015 |
140 | 1016 if (!ok) ed->flags |= EDITOR_ERROR_CANT_EXEC; |
1017 } | |
1018 | |
442 | 1019 if (ok) |
140 | 1020 { |
1021 g_child_watch_add(pid, editor_child_exit_cb, ed); | |
1022 ed->pid = pid; | |
1023 } | |
442 | 1024 |
140 | 1025 if (ed->vd) |
1026 { | |
1027 if (!ok) | |
9 | 1028 { |
140 | 1029 gchar *buf; |
1030 | |
1272 | 1031 buf = g_strdup_printf(_("Failed to run command:\n%s\n"), editor->file); |
140 | 1032 editor_verbose_window_fill(ed->vd, buf, strlen(buf)); |
1033 g_free(buf); | |
1034 | |
1035 } | |
442 | 1036 else |
140 | 1037 { |
1038 GIOChannel *channel_output; | |
1039 GIOChannel *channel_error; | |
444 | 1040 |
140 | 1041 channel_output = g_io_channel_unix_new(standard_output); |
1042 g_io_channel_set_flags(channel_output, G_IO_FLAG_NONBLOCK, NULL); | |
926 | 1043 g_io_channel_set_encoding(channel_output, NULL, NULL); |
140 | 1044 |
1045 g_io_add_watch_full(channel_output, G_PRIORITY_HIGH, G_IO_IN | G_IO_ERR | G_IO_HUP, | |
1046 editor_verbose_io_cb, ed, NULL); | |
1047 g_io_channel_unref(channel_output); | |
1048 | |
1049 channel_error = g_io_channel_unix_new(standard_error); | |
1050 g_io_channel_set_flags(channel_error, G_IO_FLAG_NONBLOCK, NULL); | |
926 | 1051 g_io_channel_set_encoding(channel_error, NULL, NULL); |
140 | 1052 |
1053 g_io_add_watch_full(channel_error, G_PRIORITY_HIGH, G_IO_IN | G_IO_ERR | G_IO_HUP, | |
1054 editor_verbose_io_cb, ed, NULL); | |
1055 g_io_channel_unref(channel_error); | |
1056 } | |
1057 } | |
442 | 1058 |
140 | 1059 g_free(command); |
1060 | |
1400
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1061 return EDITOR_ERRORS(ed->flags); |
140 | 1062 } |
1063 | |
1405 | 1064 static EditorFlags editor_command_next_start(EditorData *ed) |
140 | 1065 { |
1066 if (ed->vd) editor_verbose_window_fill(ed->vd, "\n", 1); | |
1067 | |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1068 if ((ed->list || (ed->flags & EDITOR_NO_PARAM)) && ed->count < ed->total) |
140 | 1069 { |
1070 FileData *fd; | |
1405 | 1071 EditorFlags error; |
140 | 1072 |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1073 fd = (ed->flags & EDITOR_NO_PARAM) ? NULL : ed->list->data; |
140 | 1074 |
1075 if (ed->vd) | |
1076 { | |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1077 if ((ed->flags & EDITOR_FOR_EACH) && fd) |
1402 | 1078 editor_verbose_window_progress(ed, fd->path); |
1079 else | |
1080 editor_verbose_window_progress(ed, _("running...")); | |
140 | 1081 } |
1082 ed->count++; | |
1083 | |
1272 | 1084 error = editor_command_one(ed->editor, ed->list, ed); |
140 | 1085 if (!error && ed->vd) |
1086 { | |
1087 gtk_widget_set_sensitive(ed->vd->button_stop, (ed->list != NULL) ); | |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1088 if ((ed->flags & EDITOR_FOR_EACH) && fd) |
9 | 1089 { |
140 | 1090 editor_verbose_window_fill(ed->vd, fd->path, strlen(fd->path)); |
1091 editor_verbose_window_fill(ed->vd, "\n", 1); | |
9 | 1092 } |
1093 } | |
140 | 1094 |
442 | 1095 if (!error) |
140 | 1096 return 0; |
1402 | 1097 |
1098 /* command was not started, call the finish immediately */ | |
1099 return editor_command_next_finish(ed, 0); | |
140 | 1100 } |
442 | 1101 |
140 | 1102 /* everything is done */ |
237
404629011caa
Add missing return at the end of editor_command_next_start().
zas_
parents:
196
diff
changeset
|
1103 return editor_command_done(ed); |
140 | 1104 } |
1105 | |
1405 | 1106 static EditorFlags editor_command_next_finish(EditorData *ed, gint status) |
140 | 1107 { |
1108 gint cont = ed->stopping ? EDITOR_CB_SKIP : EDITOR_CB_CONTINUE; | |
1109 | |
1110 if (status) | |
1111 ed->flags |= EDITOR_ERROR_STATUS; | |
1112 | |
1113 if (ed->flags & EDITOR_FOR_EACH) | |
1114 { | |
1115 /* handle the first element from the list */ | |
1116 GList *fd_element = ed->list; | |
444 | 1117 |
140 | 1118 ed->list = g_list_remove_link(ed->list, fd_element); |
1119 if (ed->callback) | |
911 | 1120 { |
140 | 1121 cont = ed->callback(ed->list ? ed : NULL, ed->flags, fd_element, ed->data); |
911 | 1122 if (ed->stopping && cont == EDITOR_CB_CONTINUE) cont = EDITOR_CB_SKIP; |
1123 } | |
140 | 1124 filelist_free(fd_element); |
9 | 1125 } |
1126 else | |
1127 { | |
140 | 1128 /* handle whole list */ |
1129 if (ed->callback) | |
1130 cont = ed->callback(NULL, ed->flags, ed->list, ed->data); | |
1131 filelist_free(ed->list); | |
1132 ed->list = NULL; | |
1133 } | |
9 | 1134 |
1400
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1135 switch (cont) |
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1136 { |
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1137 case EDITOR_CB_SUSPEND: |
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1138 return EDITOR_ERRORS(ed->flags); |
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1139 case EDITOR_CB_SKIP: |
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1140 return editor_command_done(ed); |
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1141 } |
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1142 |
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1143 return editor_command_next_start(ed); |
140 | 1144 } |
9 | 1145 |
1405 | 1146 static EditorFlags editor_command_done(EditorData *ed) |
140 | 1147 { |
1405 | 1148 EditorFlags flags; |
9 | 1149 |
140 | 1150 if (ed->vd) |
1151 { | |
1152 if (ed->count == ed->total) | |
9 | 1153 { |
1402 | 1154 editor_verbose_window_progress(ed, _("done")); |
9 | 1155 } |
1156 else | |
1157 { | |
1402 | 1158 editor_verbose_window_progress(ed, _("stopped by user")); |
9 | 1159 } |
140 | 1160 editor_verbose_window_enable_close(ed->vd); |
1161 } | |
1162 | |
1163 /* free the not-handled items */ | |
1164 if (ed->list) | |
1165 { | |
1166 ed->flags |= EDITOR_ERROR_SKIPPED; | |
1167 if (ed->callback) ed->callback(NULL, ed->flags, ed->list, ed->data); | |
1168 filelist_free(ed->list); | |
1169 ed->list = NULL; | |
1170 } | |
9 | 1171 |
140 | 1172 ed->count = 0; |
1173 | |
1400
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1174 flags = EDITOR_ERRORS(ed->flags); |
140 | 1175 |
1176 if (!ed->vd) editor_data_free(ed); | |
1177 | |
1178 return flags; | |
1179 } | |
1180 | |
1181 void editor_resume(gpointer ed) | |
1182 { | |
1183 editor_command_next_start(ed); | |
1184 } | |
443 | 1185 |
140 | 1186 void editor_skip(gpointer ed) |
1187 { | |
442 | 1188 editor_command_done(ed); |
9 | 1189 } |
1190 | |
1652
58a5d1e01e33
run external commands from current directory even with no files
nadvornik
parents:
1618
diff
changeset
|
1191 static EditorFlags editor_command_start(const EditorDescription *editor, const gchar *text, GList *list, const gchar *working_directory, EditorCallback cb, gpointer data) |
140 | 1192 { |
1193 EditorData *ed; | |
1405 | 1194 EditorFlags flags = editor->flags; |
442 | 1195 |
1400
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1196 if (EDITOR_ERRORS(flags)) return EDITOR_ERRORS(flags); |
140 | 1197 |
1198 ed = g_new0(EditorData, 1); | |
1199 ed->list = filelist_copy(list); | |
1200 ed->flags = flags; | |
1272 | 1201 ed->editor = editor; |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1202 ed->total = (flags & (EDITOR_SINGLE_COMMAND | EDITOR_NO_PARAM)) ? 1 : g_list_length(list); |
140 | 1203 ed->callback = cb; |
1652
58a5d1e01e33
run external commands from current directory even with no files
nadvornik
parents:
1618
diff
changeset
|
1204 ed->data = data; |
58a5d1e01e33
run external commands from current directory even with no files
nadvornik
parents:
1618
diff
changeset
|
1205 ed->working_directory = g_strdup(working_directory); |
442 | 1206 |
140 | 1207 if ((flags & EDITOR_VERBOSE_MULTI) && list && list->next) |
1208 flags |= EDITOR_VERBOSE; | |
442 | 1209 |
140 | 1210 if (flags & EDITOR_VERBOSE) |
1211 editor_verbose_window(ed, text); | |
442 | 1212 |
1213 editor_command_next_start(ed); | |
140 | 1214 /* errors from editor_command_next_start will be handled via callback */ |
1400
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1215 return EDITOR_ERRORS(flags); |
140 | 1216 } |
1217 | |
1272 | 1218 gboolean is_valid_editor_command(const gchar *key) |
444 | 1219 { |
1272 | 1220 if (!key) return FALSE; |
1221 return g_hash_table_lookup(editors, key) != NULL; | |
444 | 1222 } |
1223 | |
1652
58a5d1e01e33
run external commands from current directory even with no files
nadvornik
parents:
1618
diff
changeset
|
1224 EditorFlags start_editor_from_filelist_full(const gchar *key, GList *list, const gchar *working_directory, EditorCallback cb, gpointer data) |
9 | 1225 { |
1405 | 1226 EditorFlags error; |
1272 | 1227 EditorDescription *editor; |
1743 | 1228 if (!key) return EDITOR_ERROR_EMPTY; |
1272 | 1229 |
1230 editor = g_hash_table_lookup(editors, key); | |
9 | 1231 |
1743 | 1232 if (!editor) return EDITOR_ERROR_EMPTY; |
1233 if (!list && !(editor->flags & EDITOR_NO_PARAM)) return EDITOR_ERROR_NO_FILE; | |
1272 | 1234 |
1743 | 1235 error = editor_command_parse(editor, list, TRUE, NULL); |
1236 | |
1237 if (EDITOR_ERRORS(error)) return error; | |
1238 | |
1239 error |= editor_command_start(editor, editor->name, list, working_directory, cb, data); | |
9 | 1240 |
1400
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1399
diff
changeset
|
1241 if (EDITOR_ERRORS(error)) |
669 | 1242 { |
1272 | 1243 gchar *text = g_strdup_printf(_("%s\n\"%s\""), editor_get_error_str(error), editor->file); |
669 | 1244 |
1245 file_util_warning_dialog(_("Invalid editor command"), text, GTK_STOCK_DIALOG_ERROR, NULL); | |
1246 g_free(text); | |
1247 } | |
1248 | |
1743 | 1249 return EDITOR_ERRORS(error); |
9 | 1250 } |
1251 | |
1405 | 1252 EditorFlags start_editor_from_filelist(const gchar *key, GList *list) |
140 | 1253 { |
1652
58a5d1e01e33
run external commands from current directory even with no files
nadvornik
parents:
1618
diff
changeset
|
1254 return start_editor_from_filelist_full(key, list, NULL, NULL, NULL); |
140 | 1255 } |
1256 | |
1405 | 1257 EditorFlags start_editor_from_file_full(const gchar *key, FileData *fd, EditorCallback cb, gpointer data) |
9 | 1258 { |
1259 GList *list; | |
1405 | 1260 EditorFlags error; |
9 | 1261 |
138 | 1262 if (!fd) return FALSE; |
9 | 1263 |
138 | 1264 list = g_list_append(NULL, fd); |
1652
58a5d1e01e33
run external commands from current directory even with no files
nadvornik
parents:
1618
diff
changeset
|
1265 error = start_editor_from_filelist_full(key, list, NULL, cb, data); |
9 | 1266 g_list_free(list); |
140 | 1267 return error; |
9 | 1268 } |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1269 |
1405 | 1270 EditorFlags start_editor_from_file(const gchar *key, FileData *fd) |
136 | 1271 { |
1272 | 1272 return start_editor_from_file_full(key, fd, NULL, NULL); |
136 | 1273 } |
1274 | |
1652
58a5d1e01e33
run external commands from current directory even with no files
nadvornik
parents:
1618
diff
changeset
|
1275 EditorFlags start_editor(const gchar *key, const gchar *working_directory) |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1276 { |
1652
58a5d1e01e33
run external commands from current directory even with no files
nadvornik
parents:
1618
diff
changeset
|
1277 return start_editor_from_filelist_full(key, NULL, working_directory, NULL, NULL); |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1278 } |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1279 |
1405 | 1280 gboolean editor_window_flag_set(const gchar *key) |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1281 { |
1272 | 1282 EditorDescription *editor; |
1283 if (!key) return TRUE; | |
1284 | |
1285 editor = g_hash_table_lookup(editors, key); | |
1286 if (!editor) return TRUE; | |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1287 |
1405 | 1288 return !!(editor->flags & EDITOR_KEEP_FS); |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1289 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1290 |
1405 | 1291 gboolean editor_is_filter(const gchar *key) |
753 | 1292 { |
1272 | 1293 EditorDescription *editor; |
1294 if (!key) return TRUE; | |
1295 | |
1296 editor = g_hash_table_lookup(editors, key); | |
1297 if (!editor) return TRUE; | |
753 | 1298 |
1405 | 1299 return !!(editor->flags & EDITOR_DEST); |
753 | 1300 } |
1301 | |
1581
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1302 gboolean editor_no_param(const gchar *key) |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1303 { |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1304 EditorDescription *editor; |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1305 if (!key) return FALSE; |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1306 |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1307 editor = g_hash_table_lookup(editors, key); |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1308 if (!editor) return FALSE; |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1309 |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1310 return !!(editor->flags & EDITOR_NO_PARAM); |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1311 } |
c9c1a16ff8ae
allow external editors without parameters, as long as they are in
nadvornik
parents:
1486
diff
changeset
|
1312 |
1618
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1313 gboolean editor_blocks_file(const gchar *key) |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1314 { |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1315 EditorDescription *editor; |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1316 if (!key) return FALSE; |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1317 |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1318 editor = g_hash_table_lookup(editors, key); |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1319 if (!editor) return FALSE; |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1320 |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1321 /* Decide if the image file should be blocked during editor execution |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1322 Editors like gimp can be used long time after the original file was |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1323 saved, for editing unrelated files. |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1324 %f vs. %F seems to be a good heuristic to detect this kind of editors. |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1325 */ |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1326 |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1327 return !(editor->flags & EDITOR_SINGLE_COMMAND); |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1328 } |
552648eff4f2
do not block the files sent to external editors like gimp
nadvornik
parents:
1581
diff
changeset
|
1329 |
1405 | 1330 const gchar *editor_get_error_str(EditorFlags flags) |
140 | 1331 { |
1332 if (flags & EDITOR_ERROR_EMPTY) return _("Editor template is empty."); | |
1333 if (flags & EDITOR_ERROR_SYNTAX) return _("Editor template has incorrect syntax."); | |
1334 if (flags & EDITOR_ERROR_INCOMPATIBLE) return _("Editor template uses incompatible macros."); | |
1335 if (flags & EDITOR_ERROR_NO_FILE) return _("Can't find matching file type."); | |
1336 if (flags & EDITOR_ERROR_CANT_EXEC) return _("Can't execute external editor."); | |
1337 if (flags & EDITOR_ERROR_STATUS) return _("External editor returned error status."); | |
1338 if (flags & EDITOR_ERROR_SKIPPED) return _("File was skipped."); | |
1339 return _("Unknown error."); | |
1340 } | |
731
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
1341 |
1272 | 1342 const gchar *editor_get_name(const gchar *key) |
731
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
1343 { |
1272 | 1344 EditorDescription *editor = g_hash_table_lookup(editors, key); |
731
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
1345 |
1272 | 1346 if (!editor) return NULL; |
1347 | |
1348 return editor->name; | |
731
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
1349 } |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1022
diff
changeset
|
1350 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |