annotate src/editors.c @ 1800:8ecd6eee4bc0

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