From a552eb852c1d02cedb0c6517603ce44a219e3110 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Mon, 14 May 2007 21:23:21 +0200 Subject: [PATCH] much shorter. Signed-off-by: Pierre Habouzit --- flags.c | 93 +++++++++++++++++++--------------------------- lib-ui/curs_main.c | 3 +- 2 files changed, 39 insertions(+), 57 deletions(-) diff --git a/flags.c b/flags.c index fc3c4b4..c767ac6 100644 --- a/flags.c +++ b/flags.c @@ -318,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 (); + 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; + + mvprintw(LINES - 1, 0, "%s? (D/N/O/r/*/!): ", + bf ? _("Set flag") : _("Clear flag")); + clrtoeol(); + + c = mutt_getch().ch; + if (c == -1) { + CLEARLINE (LINES - 1); + return (-1); + } - 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; - - case '*': - flag = M_TAG; - break; - - 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; } diff --git a/lib-ui/curs_main.c b/lib-ui/curs_main.c index b094f23..0fa37cb 100644 --- a/lib-ui/curs_main.c +++ b/lib-ui/curs_main.c @@ -1742,8 +1742,7 @@ int mutt_index_menu (void) CHECK_VISIBLE; CHECK_READONLY; - if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == - 0) { + if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0) { menu->redraw = REDRAW_STATUS; if (tag) menu->redraw |= REDRAW_INDEX; -- 2.20.1