comparison src/editors.c @ 1652:58a5d1e01e33

run external commands from current directory even with no files
author nadvornik
date Fri, 19 Jun 2009 22:34:52 +0000
parents 552648eff4f2
children 8e64965c1d92
comparison
equal deleted inserted replaced
1651:8966e72ae99a 1652:58a5d1e01e33
50 gboolean stopping; 50 gboolean stopping;
51 EditorVerboseData *vd; 51 EditorVerboseData *vd;
52 EditorCallback callback; 52 EditorCallback callback;
53 gpointer data; 53 gpointer data;
54 const EditorDescription *editor; 54 const EditorDescription *editor;
55 gchar *working_directory; /* fallback if no files are given (editor_no_param) */
55 }; 56 };
56 57
57 58
58 static void editor_verbose_window_progress(EditorData *ed, const gchar *text); 59 static void editor_verbose_window_progress(EditorData *ed, const gchar *text);
59 static EditorFlags editor_command_next_start(EditorData *ed); 60 static EditorFlags editor_command_next_start(EditorData *ed);
462 } 463 }
463 464
464 static void editor_data_free(EditorData *ed) 465 static void editor_data_free(EditorData *ed)
465 { 466 {
466 editor_verbose_data_free(ed); 467 editor_verbose_data_free(ed);
468 g_free(ed->working_directory);
467 g_free(ed); 469 g_free(ed);
468 } 470 }
469 471
470 static void editor_verbose_window_close(GenericDialog *gd, gpointer data) 472 static void editor_verbose_window_close(GenericDialog *gd, gpointer data)
471 { 473 {
961 { 963 {
962 gchar *working_directory; 964 gchar *working_directory;
963 gchar *args[4]; 965 gchar *args[4];
964 guint n = 0; 966 guint n = 0;
965 967
966 working_directory = fd ? remove_level_from_path(fd->path) : NULL; 968 working_directory = fd ? remove_level_from_path(fd->path) : g_strdup(ed->working_directory);
967 args[n++] = options->shell.path; 969 args[n++] = options->shell.path;
968 if (options->shell.options && *options->shell.options) 970 if (options->shell.options && *options->shell.options)
969 args[n++] = options->shell.options; 971 args[n++] = options->shell.options;
970 args[n++] = command; 972 args[n++] = command;
971 args[n] = NULL; 973 args[n] = NULL;
1163 void editor_skip(gpointer ed) 1165 void editor_skip(gpointer ed)
1164 { 1166 {
1165 editor_command_done(ed); 1167 editor_command_done(ed);
1166 } 1168 }
1167 1169
1168 static EditorFlags editor_command_start(const EditorDescription *editor, const gchar *text, GList *list, EditorCallback cb, gpointer data) 1170 static EditorFlags editor_command_start(const EditorDescription *editor, const gchar *text, GList *list, const gchar *working_directory, EditorCallback cb, gpointer data)
1169 { 1171 {
1170 EditorData *ed; 1172 EditorData *ed;
1171 EditorFlags flags = editor->flags; 1173 EditorFlags flags = editor->flags;
1172 1174
1173 if (EDITOR_ERRORS(flags)) return EDITOR_ERRORS(flags); 1175 if (EDITOR_ERRORS(flags)) return EDITOR_ERRORS(flags);
1176 ed->list = filelist_copy(list); 1178 ed->list = filelist_copy(list);
1177 ed->flags = flags; 1179 ed->flags = flags;
1178 ed->editor = editor; 1180 ed->editor = editor;
1179 ed->total = (flags & (EDITOR_SINGLE_COMMAND | EDITOR_NO_PARAM)) ? 1 : g_list_length(list); 1181 ed->total = (flags & (EDITOR_SINGLE_COMMAND | EDITOR_NO_PARAM)) ? 1 : g_list_length(list);
1180 ed->callback = cb; 1182 ed->callback = cb;
1181 ed->data = data; 1183 ed->data = data;
1184 ed->working_directory = g_strdup(working_directory);
1182 1185
1183 if ((flags & EDITOR_VERBOSE_MULTI) && list && list->next) 1186 if ((flags & EDITOR_VERBOSE_MULTI) && list && list->next)
1184 flags |= EDITOR_VERBOSE; 1187 flags |= EDITOR_VERBOSE;
1185 1188
1186 if (flags & EDITOR_VERBOSE) 1189 if (flags & EDITOR_VERBOSE)
1195 { 1198 {
1196 if (!key) return FALSE; 1199 if (!key) return FALSE;
1197 return g_hash_table_lookup(editors, key) != NULL; 1200 return g_hash_table_lookup(editors, key) != NULL;
1198 } 1201 }
1199 1202
1200 EditorFlags start_editor_from_filelist_full(const gchar *key, GList *list, EditorCallback cb, gpointer data) 1203 EditorFlags start_editor_from_filelist_full(const gchar *key, GList *list, const gchar *working_directory, EditorCallback cb, gpointer data)
1201 { 1204 {
1202 EditorFlags error; 1205 EditorFlags error;
1203 EditorDescription *editor; 1206 EditorDescription *editor;
1204 if (!key) return FALSE; 1207 if (!key) return FALSE;
1205 1208
1206 editor = g_hash_table_lookup(editors, key); 1209 editor = g_hash_table_lookup(editors, key);
1207 1210
1208 if (!editor) return FALSE; 1211 if (!editor) return FALSE;
1209 if (!list && !(editor->flags & EDITOR_NO_PARAM)) return FALSE; 1212 if (!list && !(editor->flags & EDITOR_NO_PARAM)) return FALSE;
1210 1213
1211 error = editor_command_start(editor, editor->name, list, cb, data); 1214 error = editor_command_start(editor, editor->name, list, working_directory, cb, data);
1212 1215
1213 if (EDITOR_ERRORS(error)) 1216 if (EDITOR_ERRORS(error))
1214 { 1217 {
1215 gchar *text = g_strdup_printf(_("%s\n\"%s\""), editor_get_error_str(error), editor->file); 1218 gchar *text = g_strdup_printf(_("%s\n\"%s\""), editor_get_error_str(error), editor->file);
1216 1219
1221 return error; 1224 return error;
1222 } 1225 }
1223 1226
1224 EditorFlags start_editor_from_filelist(const gchar *key, GList *list) 1227 EditorFlags start_editor_from_filelist(const gchar *key, GList *list)
1225 { 1228 {
1226 return start_editor_from_filelist_full(key, list, NULL, NULL); 1229 return start_editor_from_filelist_full(key, list, NULL, NULL, NULL);
1227 } 1230 }
1228 1231
1229 EditorFlags start_editor_from_file_full(const gchar *key, FileData *fd, EditorCallback cb, gpointer data) 1232 EditorFlags start_editor_from_file_full(const gchar *key, FileData *fd, EditorCallback cb, gpointer data)
1230 { 1233 {
1231 GList *list; 1234 GList *list;
1232 EditorFlags error; 1235 EditorFlags error;
1233 1236
1234 if (!fd) return FALSE; 1237 if (!fd) return FALSE;
1235 1238
1236 list = g_list_append(NULL, fd); 1239 list = g_list_append(NULL, fd);
1237 error = start_editor_from_filelist_full(key, list, cb, data); 1240 error = start_editor_from_filelist_full(key, list, NULL, cb, data);
1238 g_list_free(list); 1241 g_list_free(list);
1239 return error; 1242 return error;
1240 } 1243 }
1241 1244
1242 EditorFlags start_editor_from_file(const gchar *key, FileData *fd) 1245 EditorFlags start_editor_from_file(const gchar *key, FileData *fd)
1243 { 1246 {
1244 return start_editor_from_file_full(key, fd, NULL, NULL); 1247 return start_editor_from_file_full(key, fd, NULL, NULL);
1245 } 1248 }
1246 1249
1247 EditorFlags start_editor(const gchar *key) 1250 EditorFlags start_editor(const gchar *key, const gchar *working_directory)
1248 { 1251 {
1249 return start_editor_from_filelist_full(key, NULL, NULL, NULL); 1252 return start_editor_from_filelist_full(key, NULL, working_directory, NULL, NULL);
1250 } 1253 }
1251 1254
1252 gboolean editor_window_flag_set(const gchar *key) 1255 gboolean editor_window_flag_set(const gchar *key)
1253 { 1256 {
1254 EditorDescription *editor; 1257 EditorDescription *editor;