X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=flags.c;h=137c78949e916dd0e5bd816e816e8f57b7229a65;hp=b206ae39f409f387637c272a552bb6ae1585f110;hb=1c62190597f45fd606cf680df3f6a099b9f7ec18;hpb=8e6b42b9b28f646a6764936d80bda04647d5b45f diff --git a/flags.c b/flags.c index b206ae3..137c789 100644 --- a/flags.c +++ b/flags.c @@ -7,28 +7,25 @@ * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif +#include + +#include +#include +#include +#include #include "mutt.h" -#include "mutt_curses.h" -#include "mutt_menu.h" #include "sort.h" -#include "mx.h" -#include "sidebar.h" -#ifdef USE_IMAP -#include "imap_private.h" -#endif +#include -#include "lib/intl.h" void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx) { int changed = h->changed; int deleted = ctx->deleted; int tagged = ctx->tagged; + int flagged = ctx->flagged; if (ctx->readonly && flag != M_TAG) return; /* don't modify anything if we are read-only */ @@ -44,7 +41,6 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx) h->deleted = 1; if (upd_ctx) ctx->deleted++; -#ifdef USE_IMAP /* deleted messages aren't treated as changed elsewhere so that the * purge-on-sync option works correctly. This isn't applicable here */ if (ctx && ctx->magic == M_IMAP) { @@ -52,7 +48,6 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx) if (upd_ctx) ctx->changed = 1; } -#endif } } else if (h->deleted) { @@ -63,14 +58,12 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx) ctx->appended--; } h->appended = 0; /* when undeleting, also reset the appended flag */ -#ifdef USE_IMAP /* see my comment above */ if (ctx->magic == M_IMAP) { h->changed = 1; if (upd_ctx) ctx->changed = 1; } -#endif /* * If the user undeletes a message which is marked as * "trash" in the maildir folder on disk, the folder has @@ -270,11 +263,10 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx) * search results so that any future search will match the current status * of this message and not what it was at the time it was last searched. */ - if (h->searched - && (changed != h->changed || deleted != ctx->deleted - || tagged != ctx->tagged)) + if (h->searched && (changed != h->changed || deleted != ctx->deleted || + tagged != ctx->tagged || flagged != ctx->flagged)) h->searched = 0; - sidebar_draw (0); + sidebar_draw (); } void mutt_tag_set_flag (int flag, int bf) @@ -306,7 +298,7 @@ int mutt_thread_set_flag (HEADER * hdr, int flag, int bf, int subthread) if ((cur = cur->child) == NULL) return (0); - FOREVER { + for (;;) { if (cur->message) mutt_set_flag (Context, cur->message, flag, bf); @@ -326,66 +318,49 @@ int mutt_thread_set_flag (HEADER * hdr, int flag, int bf, int subthread) /* not reached */ } -int mutt_change_flag (HEADER * h, int bf) +int mutt_change_flag(HEADER * h, int bf) { - int i, flag; - event_t event; - - mvprintw (LINES - 1, 0, "%s? (D/N/O/r/*/!): ", - bf ? _("Set flag") : _("Clear flag")); - clrtoeol (); - - event = mutt_getch (); - i = event.ch; - if (i == -1) { - CLEARLINE (LINES - 1); - return (-1); - } - - CLEARLINE (LINES - 1); - - switch (i) { - case 'd': - case 'D': - flag = M_DELETE; - break; - - case 'N': - case 'n': - flag = M_NEW; - break; - - case 'o': - case 'O': - if (h) - mutt_set_flag (Context, h, M_READ, !bf); - else - mutt_tag_set_flag (M_READ, !bf); - flag = M_OLD; - break; - - case 'r': - case 'R': - flag = M_REPLIED; - break; + static char const actions[] = { + ['d'] = M_DELETE, ['D'] = M_DELETE, + ['n'] = M_NEW, ['N'] = M_NEW, + ['o'] = M_OLD, ['O'] = M_OLD, + ['r'] = M_REPLIED, ['R'] = M_REPLIED, + ['*'] = M_TAG, + ['!'] = M_FLAG, + }; + + int c; + + mvwprintw(stdscr, LINES - 1, 0, "%s? (D/N/O/r/*/!): ", + bf ? _("Set flag") : _("Clear flag")); + wclrtoeol(stdscr); + + c = mutt_getch().ch; + if (c == -1) { + CLEARLINE(stdscr, LINES - 1); + return (-1); + } - case '*': - flag = M_TAG; - break; + CLEARLINE(stdscr, LINES - 1); - case '!': - flag = M_FLAG; - break; + if (c < 0 || c > countof(actions) || !actions[c]) { + BEEP(); + return -1; + } - default: - BEEP (); - return (-1); - } + if (actions[c] == M_OLD) { + if (h) { + mutt_set_flag(Context, h, M_READ, !bf); + } else { + mutt_tag_set_flag(M_READ, !bf); + } + } - if (h) - mutt_set_flag (Context, h, flag, bf); - else - mutt_tag_set_flag (flag, bf); + if (h) { + mutt_set_flag(Context, h, actions[c], bf); + } else { + mutt_tag_set_flag(actions[c], bf); + } - return 0; + return 0; }