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