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