Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the...
authorLaurent Monin <geeqie@norz.org>
Sun, 8 Mar 2009 15:30:15 +0000 (15:30 +0000)
committerLaurent Monin <geeqie@norz.org>
Sun, 8 Mar 2009 15:30:15 +0000 (15:30 +0000)
src/editors.c
src/editors.h
src/menu.c
src/preferences.c
src/utilops.c

index aa15afb..c77e05b 100644 (file)
@@ -830,7 +830,7 @@ static gint editor_command_one(const EditorDescription *editor, GList *list, Edi
        ed->pid = -1;
        ed->flags = editor->flags | editor_command_parse(editor, list, &command);
 
-       ok = !(ed->flags & EDITOR_ERROR_MASK);
+       ok = !EDITOR_ERRORS(ed->flags);
 
        if (ok)
                {
@@ -924,7 +924,7 @@ static gint editor_command_one(const EditorDescription *editor, GList *list, Edi
 
        g_free(command);
 
-       return ed->flags & EDITOR_ERROR_MASK;
+       return EDITOR_ERRORS(ed->flags);
 }
 
 static gint editor_command_next_start(EditorData *ed)
@@ -995,12 +995,15 @@ static gint editor_command_next_finish(EditorData *ed, gint status)
                ed->list = NULL;
                }
 
-       if (cont == EDITOR_CB_SUSPEND)
-               return ed->flags & EDITOR_ERROR_MASK;
-       else if (cont == EDITOR_CB_SKIP)
-               return editor_command_done(ed);
-       else
-               return editor_command_next_start(ed);
+       switch (cont)
+               {
+               case EDITOR_CB_SUSPEND:
+                       return EDITOR_ERRORS(ed->flags);
+               case EDITOR_CB_SKIP:
+                       return editor_command_done(ed);
+               }
+       
+       return editor_command_next_start(ed);
 }
 
 static gint editor_command_done(EditorData *ed)
@@ -1034,7 +1037,7 @@ static gint editor_command_done(EditorData *ed)
 
        ed->count = 0;
 
-       flags = ed->flags & EDITOR_ERROR_MASK;
+       flags = EDITOR_ERRORS(ed->flags);
 
        if (!ed->vd) editor_data_free(ed);
 
@@ -1056,7 +1059,7 @@ static gint editor_command_start(const EditorDescription *editor, const gchar *t
        EditorData *ed;
        gint flags = editor->flags;
 
-       if (flags & EDITOR_ERROR_MASK) return flags & EDITOR_ERROR_MASK;
+       if (EDITOR_ERRORS(flags)) return EDITOR_ERRORS(flags);
 
        ed = g_new0(EditorData, 1);
        ed->list = filelist_copy(list);
@@ -1074,7 +1077,7 @@ static gint editor_command_start(const EditorDescription *editor, const gchar *t
 
        editor_command_next_start(ed);
        /* errors from editor_command_next_start will be handled via callback */
-       return flags & EDITOR_ERROR_MASK;
+       return EDITOR_ERRORS(flags);
 }
 
 gboolean is_valid_editor_command(const gchar *key)
@@ -1096,7 +1099,7 @@ gint start_editor_from_filelist_full(const gchar *key, GList *list, EditorCallba
 
        error = editor_command_start(editor, editor->name, list, cb, data);
 
-       if (error & EDITOR_ERROR_MASK)
+       if (EDITOR_ERRORS(error))
                {
                gchar *text = g_strdup_printf(_("%s\n\"%s\""), editor_get_error_str(error), editor->file);
                
index c474727..8f104bb 100644 (file)
@@ -34,6 +34,8 @@
 
 #define        EDITOR_ERROR_MASK         0xffff0000
 
+#define EDITOR_ERRORS(flags) ((flags) & EDITOR_ERROR_MASK)
+#define EDITOR_ERRORS_BUT_SKIPPED(flags) (((flags) & EDITOR_ERROR_MASK) && !((flags) & EDITOR_ERROR_SKIPPED))
 
 /* return values from callback function */
 enum {
index 13e9ea4..a028622 100644 (file)
@@ -76,12 +76,8 @@ static void add_edit_items(GtkWidget *menu, GCallback func, GList *fd_list)
                work = work->next;
                gboolean active = TRUE;
 
-               if (fd_list)
-                       {
-                       gint flags = editor_command_parse(editor, fd_list, NULL);
-                       if ((flags & EDITOR_ERROR_MASK) != 0)
-                               active = FALSE;
-                       }
+               if (fd_list && EDITOR_ERRORS(editor_command_parse(editor, fd_list, NULL)))
+                       active = FALSE;
 
                if (active)
                        {
index 0e94b07..cbbb05d 100644 (file)
@@ -201,7 +201,7 @@ static void config_parse_editor_entries(GtkWidget **editor_name_entry, GtkWidget
                        {
                        gint flags = editor_command_parse(buf, NULL, NULL);
                
-                       if (flags & EDITOR_ERROR_MASK)
+                       if (EDITOR_ERRORS(flags))
                                {
                                if (errmsg->str[0]) g_string_append(errmsg, "\n\n");
                                g_string_append_printf(errmsg, _("%s\n#%d \"%s\":\n%s"), editor_get_error_str(flags),
index e40e875..c93a547 100644 (file)
@@ -503,10 +503,11 @@ static void file_util_abort_cb(GenericDialog *gd, gpointer data)
 static gint file_util_perform_ci_cb(gpointer resume_data, gint flags, GList *list, gpointer data)
 {
        UtilityData *ud = data;
+       gint ret = EDITOR_CB_CONTINUE;
+
        ud->resume_data = resume_data;
        
-       gint ret = EDITOR_CB_CONTINUE;
-       if ((flags & EDITOR_ERROR_MASK) && !(flags & EDITOR_ERROR_SKIPPED))
+       if (EDITOR_ERRORS_BUT_SKIPPED(flags))
                {
                GString *msg = g_string_new(editor_get_error_str(flags));
                GenericDialog *d;
@@ -548,7 +549,7 @@ static gint file_util_perform_ci_cb(gpointer resume_data, gint flags, GList *lis
                FileData *fd = list->data;
                list = list->next;
 
-               if (!(flags & EDITOR_ERROR_MASK)) /* files were successfully deleted, call the maint functions */
+               if (!EDITOR_ERRORS(flags)) /* files were successfully deleted, call the maint functions */
                        {
                        if (ud->with_sidecars) 
                                file_data_sc_apply_ci(fd);
@@ -792,7 +793,7 @@ static void file_util_perform_ci_dir(UtilityData *ud, gboolean internal, gboolea
 static gint file_util_perform_ci_dir_cb(gpointer resume_data, gint flags, GList *list, gpointer data)
 {
        UtilityData *ud = data;
-       file_util_perform_ci_dir(ud, FALSE, !((flags & EDITOR_ERROR_MASK) && !(flags & EDITOR_ERROR_SKIPPED)));
+       file_util_perform_ci_dir(ud, FALSE, !EDITOR_ERRORS_BUT_SKIPPED(flags));
        return EDITOR_CB_CONTINUE; /* does not matter, there was just single directory */
 }