comparison src/editors.c @ 1400:67573155210c

Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
author zas_
date Sun, 08 Mar 2009 15:30:15 +0000
parents 7dfa34e4de15
children 611c25ef73f4
comparison
equal deleted inserted replaced
1399:7dfa34e4de15 1400:67573155210c
828 gboolean ok; 828 gboolean ok;
829 829
830 ed->pid = -1; 830 ed->pid = -1;
831 ed->flags = editor->flags | editor_command_parse(editor, list, &command); 831 ed->flags = editor->flags | editor_command_parse(editor, list, &command);
832 832
833 ok = !(ed->flags & EDITOR_ERROR_MASK); 833 ok = !EDITOR_ERRORS(ed->flags);
834 834
835 if (ok) 835 if (ok)
836 { 836 {
837 ok = (options->shell.path && *options->shell.path); 837 ok = (options->shell.path && *options->shell.path);
838 if (!ok) log_printf("ERROR: empty shell command\n"); 838 if (!ok) log_printf("ERROR: empty shell command\n");
922 } 922 }
923 } 923 }
924 924
925 g_free(command); 925 g_free(command);
926 926
927 return ed->flags & EDITOR_ERROR_MASK; 927 return EDITOR_ERRORS(ed->flags);
928 } 928 }
929 929
930 static gint editor_command_next_start(EditorData *ed) 930 static gint editor_command_next_start(EditorData *ed)
931 { 931 {
932 if (ed->vd) editor_verbose_window_fill(ed->vd, "\n", 1); 932 if (ed->vd) editor_verbose_window_fill(ed->vd, "\n", 1);
993 cont = ed->callback(NULL, ed->flags, ed->list, ed->data); 993 cont = ed->callback(NULL, ed->flags, ed->list, ed->data);
994 filelist_free(ed->list); 994 filelist_free(ed->list);
995 ed->list = NULL; 995 ed->list = NULL;
996 } 996 }
997 997
998 if (cont == EDITOR_CB_SUSPEND) 998 switch (cont)
999 return ed->flags & EDITOR_ERROR_MASK; 999 {
1000 else if (cont == EDITOR_CB_SKIP) 1000 case EDITOR_CB_SUSPEND:
1001 return editor_command_done(ed); 1001 return EDITOR_ERRORS(ed->flags);
1002 else 1002 case EDITOR_CB_SKIP:
1003 return editor_command_next_start(ed); 1003 return editor_command_done(ed);
1004 }
1005
1006 return editor_command_next_start(ed);
1004 } 1007 }
1005 1008
1006 static gint editor_command_done(EditorData *ed) 1009 static gint editor_command_done(EditorData *ed)
1007 { 1010 {
1008 gint flags; 1011 gint flags;
1032 ed->list = NULL; 1035 ed->list = NULL;
1033 } 1036 }
1034 1037
1035 ed->count = 0; 1038 ed->count = 0;
1036 1039
1037 flags = ed->flags & EDITOR_ERROR_MASK; 1040 flags = EDITOR_ERRORS(ed->flags);
1038 1041
1039 if (!ed->vd) editor_data_free(ed); 1042 if (!ed->vd) editor_data_free(ed);
1040 1043
1041 return flags; 1044 return flags;
1042 } 1045 }
1054 static gint editor_command_start(const EditorDescription *editor, const gchar *text, GList *list, EditorCallback cb, gpointer data) 1057 static gint editor_command_start(const EditorDescription *editor, const gchar *text, GList *list, EditorCallback cb, gpointer data)
1055 { 1058 {
1056 EditorData *ed; 1059 EditorData *ed;
1057 gint flags = editor->flags; 1060 gint flags = editor->flags;
1058 1061
1059 if (flags & EDITOR_ERROR_MASK) return flags & EDITOR_ERROR_MASK; 1062 if (EDITOR_ERRORS(flags)) return EDITOR_ERRORS(flags);
1060 1063
1061 ed = g_new0(EditorData, 1); 1064 ed = g_new0(EditorData, 1);
1062 ed->list = filelist_copy(list); 1065 ed->list = filelist_copy(list);
1063 ed->flags = flags; 1066 ed->flags = flags;
1064 ed->editor = editor; 1067 ed->editor = editor;
1072 if (flags & EDITOR_VERBOSE) 1075 if (flags & EDITOR_VERBOSE)
1073 editor_verbose_window(ed, text); 1076 editor_verbose_window(ed, text);
1074 1077
1075 editor_command_next_start(ed); 1078 editor_command_next_start(ed);
1076 /* errors from editor_command_next_start will be handled via callback */ 1079 /* errors from editor_command_next_start will be handled via callback */
1077 return flags & EDITOR_ERROR_MASK; 1080 return EDITOR_ERRORS(flags);
1078 } 1081 }
1079 1082
1080 gboolean is_valid_editor_command(const gchar *key) 1083 gboolean is_valid_editor_command(const gchar *key)
1081 { 1084 {
1082 if (!key) return FALSE; 1085 if (!key) return FALSE;
1094 if (!list) return FALSE; 1097 if (!list) return FALSE;
1095 if (!editor) return FALSE; 1098 if (!editor) return FALSE;
1096 1099
1097 error = editor_command_start(editor, editor->name, list, cb, data); 1100 error = editor_command_start(editor, editor->name, list, cb, data);
1098 1101
1099 if (error & EDITOR_ERROR_MASK) 1102 if (EDITOR_ERRORS(error))
1100 { 1103 {
1101 gchar *text = g_strdup_printf(_("%s\n\"%s\""), editor_get_error_str(error), editor->file); 1104 gchar *text = g_strdup_printf(_("%s\n\"%s\""), editor_get_error_str(error), editor->file);
1102 1105
1103 file_util_warning_dialog(_("Invalid editor command"), text, GTK_STOCK_DIALOG_ERROR, NULL); 1106 file_util_warning_dialog(_("Invalid editor command"), text, GTK_STOCK_DIALOG_ERROR, NULL);
1104 g_free(text); 1107 g_free(text);