changeset: 6978:6551825f99fa
user:      Kevin McCarthy <ke...@8t8.us>
date:      Sun Mar 26 18:31:39 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/6551825f99fa

Add a menu stack to track current and past menus.

Change the pager to use a MENU, right now just to hold the refresh
state.

changeset: 6979:dbb9fbe9b3de
user:      Kevin McCarthy <ke...@8t8.us>
date:      Sun Mar 26 18:31:40 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/dbb9fbe9b3de

Change CurrentMenu to be controlled by the menu stack.

The pager menu is a bit tricky with respect to the menu->menu and
CurrentMenu, so add a few comments.

changeset: 6980:7cced4378ed5
user:      Kevin McCarthy <ke...@8t8.us>
date:      Sun Mar 26 18:31:41 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/7cced4378ed5

Set refresh when popping the menu stack.

This removes the need for the OPTNEEDREDRAW option and MAYBE_REDRAW
macro previously used to communicate back the need to refresh after
exiting a menu.

Remove the redraw parameter from ci_bounce_message() and
mix_make_chain() which served the same purpose.

changeset: 6981:cb57cd88846b
user:      Kevin McCarthy <ke...@8t8.us>
date:      Sun Mar 26 18:31:43 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/cb57cd88846b

Remove redraw parameter from crypt send_menus.

The parameter was used to notify the caller if the sign (a)s menu was
invoked, which displayed the key selection menu.  This is no longer
necessary with the menu stack pop operation.

changeset: 6982:4d06d85a4dd7
user:      Kevin McCarthy <ke...@8t8.us>
date:      Sun Mar 26 18:31:45 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/4d06d85a4dd7

Don't full redraw the index when handling a command from the pager.

This causes a noticable flicker when moving through messages from the pager.

diffs (truncated from 1552 to 950 lines):

diff -r b8519ee6bd74 -r 4d06d85a4dd7 addrbook.c
--- a/addrbook.c        Sun Mar 26 12:27:43 2017 -0700
+++ b/addrbook.c        Sun Mar 26 18:31:45 2017 -0700
@@ -145,15 +145,13 @@
     mutt_error _("You have no aliases!");
     return;
   }
-  
-  /* tell whoever called me to redraw the screen when I return */
-  set_option (OPTNEEDREDRAW);
-  
+
   menu = mutt_new_menu (MENU_ALIAS);
   menu->make_entry = alias_entry;
   menu->tag = alias_tag;
   menu->title = _("Aliases");
   menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_ALIAS, 
AliasHelp);
+  mutt_push_current_menu (menu);
 
 new_aliases:
 
@@ -237,6 +235,7 @@
     rfc822_write_address (buf, buflen, AliasTable[t]->addr, 1);
   }
 
+  mutt_pop_current_menu (menu);
   mutt_menuDestroy (&menu);
   FREE (&AliasTable);
   
diff -r b8519ee6bd74 -r 4d06d85a4dd7 browser.c
--- a/browser.c Sun Mar 26 12:27:43 2017 -0700
+++ b/browser.c Sun Mar 26 18:31:45 2017 -0700
@@ -611,7 +611,7 @@
   char helpstr[LONG_STRING];
   char title[STRING];
   struct browser_state state;
-  MUTTMENU *menu;
+  MUTTMENU *menu = NULL;
   struct stat st;
   int i, killPrefix = 0;
   int multiple = (flags & MUTT_SEL_MULTI)  ? 1 : 0;
@@ -722,6 +722,7 @@
 
   menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_FOLDER,
     FolderHelp);
+  mutt_push_current_menu (menu);
 
   init_menu (&state, menu, title, sizeof (title), buffy);
 
@@ -908,7 +909,6 @@
        }
 
        destroy_state (&state);
-       mutt_menuDestroy (&menu);
        goto bail;
 
       case OP_BROWSER_TELL:
@@ -954,7 +954,6 @@
          menu->current = 0; 
          menu->top = 0; 
          init_menu (&state, menu, title, sizeof (title), buffy);
-         MAYBE_REDRAW (menu->redraw);
        }
        /* else leave error on screen */
        break;
@@ -977,7 +976,6 @@
            menu->current = 0;
            menu->top = 0;
            init_menu (&state, menu, title, sizeof (title), buffy);
-           MAYBE_REDRAW (menu->redraw);
          }
        }
        break;
@@ -1015,7 +1013,6 @@
              state.entrylen--;
              mutt_message _("Mailbox deleted.");
              init_menu (&state, menu, title, sizeof (title), buffy);
-             MAYBE_REDRAW (menu->redraw);
            }
          }
          else
@@ -1080,7 +1077,6 @@
                  mutt_error _("Error scanning directory.");
                  if (examine_directory (menu, &state, LastDir, prefix) == -1)
                  {
-                   mutt_menuDestroy (&menu);
                    goto bail;
                  }
                }
@@ -1095,7 +1091,6 @@
              mutt_perror (buf);
          }
        }
-       MAYBE_REDRAW (menu->redraw);
        break;
        
       case OP_ENTER_MASK:
@@ -1151,7 +1146,6 @@
            else
            {
              mutt_error _("Error scanning directory.");
-             mutt_menuDestroy (&menu);
              goto bail;
            }
            killPrefix = 0;
@@ -1162,7 +1156,6 @@
            }
          }
        }
-       MAYBE_REDRAW (menu->redraw);
        break;
 
       case OP_SORT:
@@ -1246,10 +1239,8 @@
        {
          strfcpy (f, buf, flen);
          destroy_state (&state);
-         mutt_menuDestroy (&menu);
          goto bail;
        }
-       MAYBE_REDRAW (menu->redraw);
        break;
 
       case OP_BROWSER_VIEW_FILE:
@@ -1264,7 +1255,6 @@
        {
          strfcpy (f, state.entry[menu->current].name, flen);
          destroy_state (&state);
-         mutt_menuDestroy (&menu);
          goto bail;
        }
        else
@@ -1296,7 +1286,13 @@
   }
   
   bail:
-  
+
+  if (menu)
+  {
+    mutt_pop_current_menu (menu);
+    mutt_menuDestroy (&menu);
+  }
+
   if (!folder)
     strfcpy (LastDir, LastDirBackup, sizeof (LastDir));
   
diff -r b8519ee6bd74 -r 4d06d85a4dd7 commands.c
--- a/commands.c        Sun Mar 26 12:27:43 2017 -0700
+++ b/commands.c        Sun Mar 26 18:31:45 2017 -0700
@@ -238,7 +238,7 @@
   return rc;
 }
 
-void ci_bounce_message (HEADER *h, int *redraw)
+void ci_bounce_message (HEADER *h)
 {
   char prompt[SHORT_STRING];
   char scratch[SHORT_STRING];
@@ -276,13 +276,6 @@
     strfcpy(prompt, _("Bounce tagged messages to: "), sizeof(prompt));
   
   rc = mutt_get_field (prompt, buf, sizeof (buf), MUTT_ALIAS);
-
-  if (option (OPTNEEDREDRAW))
-  {
-    unset_option (OPTNEEDREDRAW);
-    *redraw = REDRAW_FULL;
-  }
-
   if (rc || !buf[0])
     return;
 
diff -r b8519ee6bd74 -r 4d06d85a4dd7 compose.c
--- a/compose.c Sun Mar 26 12:27:43 2017 -0700
+++ b/compose.c Sun Mar 26 18:31:45 2017 -0700
@@ -273,7 +273,7 @@
   NORMAL_COLOR;
 }
 
-static int edit_address_list (int line, ADDRESS **addr)
+static void edit_address_list (int line, ADDRESS **addr)
 {
   char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
   char *err = NULL;
@@ -287,12 +287,6 @@
     *addr = mutt_expand_aliases (*addr);
   }
 
-  if (option (OPTNEEDREDRAW))
-  {
-    unset_option (OPTNEEDREDRAW);
-    return (REDRAW_FULL);
-  }
-
   if (mutt_addrlist_to_intl (*addr, &err) != 0)
   {
     mutt_error (_("Warning: '%s' is a bad IDN."), err);
@@ -305,8 +299,6 @@
   rfc822_write_address (buf, sizeof (buf), *addr, 1);
   mutt_window_move (MuttIndexWindow, line, HDR_XOFFSET);
   mutt_paddstr (W, buf);
-  
-  return 0;
 }
 
 static int delete_attachment (MUTTMENU *menu, short *idxlen, int x)
@@ -516,6 +508,7 @@
   menu->tag = mutt_tag_attach;
   menu->data = idx;
   menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, 
ComposeHelp);
+  mutt_push_current_menu (menu);
 
   while (loop)
   {
@@ -527,11 +520,11 @@
        menu->pagelen = MuttIndexWindow->rows - HDR_ATTACH;
        break;
       case OP_COMPOSE_EDIT_FROM:
-       menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
+       edit_address_list (HDR_FROM, &msg->env->from);
         mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
        break;
       case OP_COMPOSE_EDIT_TO:
-       menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
+       edit_address_list (HDR_TO, &msg->env->to);
        if (option (OPTCRYPTOPPORTUNISTICENCRYPT))
        {
          crypt_opportunistic_encrypt (msg);
@@ -540,7 +533,7 @@
         mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
         break;
       case OP_COMPOSE_EDIT_BCC:
-       menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
+       edit_address_list (HDR_BCC, &msg->env->bcc);
        if (option (OPTCRYPTOPPORTUNISTICENCRYPT))
        {
          crypt_opportunistic_encrypt (msg);
@@ -549,7 +542,7 @@
         mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
        break;
       case OP_COMPOSE_EDIT_CC:
-       menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
+       edit_address_list (HDR_CC, &msg->env->cc);
        if (option (OPTCRYPTOPPORTUNISTICENCRYPT))
        {
          crypt_opportunistic_encrypt (msg);
@@ -574,7 +567,7 @@
         mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
         break;
       case OP_COMPOSE_EDIT_REPLY_TO:
-       menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
+       edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
         mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
        break;
       case OP_COMPOSE_EDIT_FCC:
@@ -587,7 +580,6 @@
          mutt_paddstr (W, fcc);
          fccSet = 1;
        }
-       MAYBE_REDRAW (menu->redraw);
         mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
         break;
       case OP_COMPOSE_EDIT_MESSAGE:
@@ -666,12 +658,6 @@
          FREE (&idx[idxlen]);
 
        menu->redraw |= REDRAW_STATUS;
-
-       if (option(OPTNEEDREDRAW))
-       {
-         menu->redraw = REDRAW_FULL;
-         unset_option(OPTNEEDREDRAW);
-       }
        
         mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
         break;
@@ -1163,7 +1149,6 @@
       case OP_SAVE:
        CHECK_COUNT;
        mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ?  
msg->content : idx[menu->current]->content, NULL, menu);
-       MAYBE_REDRAW (menu->redraw);
         /* no send2hook, since this doesn't modify the message */
        break;
 
@@ -1287,7 +1272,7 @@
           crypt_opportunistic_encrypt (msg);
           redraw_crypt_lines (msg);
        }
-       msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
+       msg->security = crypt_pgp_send_menu (msg);
        redraw_crypt_lines (msg);
         mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
         break;
@@ -1320,7 +1305,7 @@
           crypt_opportunistic_encrypt (msg);
           redraw_crypt_lines (msg);
        }
-       msg->security = crypt_smime_send_menu(msg, &menu->redraw);
+       msg->security = crypt_smime_send_menu(msg);
        redraw_crypt_lines (msg);
         mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
         break;
@@ -1329,7 +1314,7 @@
 #ifdef MIXMASTER
       case OP_COMPOSE_MIX:
       
-       mix_make_chain (&msg->chain, &menu->redraw);
+       mix_make_chain (&msg->chain);
         mutt_message_hook (NULL, msg, MUTT_SEND2HOOK);
         break;
 #endif
@@ -1348,6 +1333,7 @@
     }
   }
 
+  mutt_pop_current_menu (menu);
   mutt_menuDestroy (&menu);
 
   if (idxlen)
diff -r b8519ee6bd74 -r 4d06d85a4dd7 crypt-gpgme.c
--- a/crypt-gpgme.c     Sun Mar 26 12:27:43 2017 -0700
+++ b/crypt-gpgme.c     Sun Mar 26 18:31:45 2017 -0700
@@ -4031,6 +4031,7 @@
   menu->make_entry = crypt_entry;
   menu->help = helpstr;
   menu->data = key_table;
+  mutt_push_current_menu (menu);
 
   {
     const char *ts;
@@ -4139,10 +4140,9 @@
         }
     }
   
+  mutt_pop_current_menu (menu);
   mutt_menuDestroy (&menu);
   FREE (&key_table);
-
-  set_option (OPTNEEDREDRAW);
   
   return k;
 }
@@ -4701,7 +4701,7 @@
   init_smime ();
 }
 
-static int gpgme_send_menu (HEADER *msg, int *redraw, int is_smime)
+static int gpgme_send_menu (HEADER *msg, int is_smime)
 {
   crypt_key_t *p;
   char input_signas[SHORT_STRING];
@@ -4806,7 +4806,6 @@
 
         msg->security |= SIGN;
       }
-      *redraw = REDRAW_FULL;
       break;
 
     case 'b': /* (b)oth */
@@ -4853,14 +4852,14 @@
   return (msg->security);
 }
 
-int pgp_gpgme_send_menu (HEADER *msg, int *redraw)
+int pgp_gpgme_send_menu (HEADER *msg)
 {
-  return gpgme_send_menu (msg, redraw, 0);
+  return gpgme_send_menu (msg, 0);
 }
 
-int smime_gpgme_send_menu (HEADER *msg, int *redraw)
+int smime_gpgme_send_menu (HEADER *msg)
 {
-  return gpgme_send_menu (msg, redraw, 1);
+  return gpgme_send_menu (msg, 1);
 }
 
 static int verify_sender (HEADER *h, gpgme_protocol_t protocol)
diff -r b8519ee6bd74 -r 4d06d85a4dd7 crypt-gpgme.h
--- a/crypt-gpgme.h     Sun Mar 26 12:27:43 2017 -0700
+++ b/crypt-gpgme.h     Sun Mar 26 18:31:45 2017 -0700
@@ -48,8 +48,8 @@
 int pgp_gpgme_verify_one (BODY *sigbdy, STATE *s, const char *tempfile);
 int smime_gpgme_verify_one (BODY *sigbdy, STATE *s, const char *tempfile);
 
-int pgp_gpgme_send_menu (HEADER *msg, int *redraw);
-int smime_gpgme_send_menu (HEADER *msg, int *redraw);
+int pgp_gpgme_send_menu (HEADER *msg);
+int smime_gpgme_send_menu (HEADER *msg);
 
 int smime_gpgme_verify_sender (HEADER *h);
 
diff -r b8519ee6bd74 -r 4d06d85a4dd7 crypt-mod-pgp-classic.c
--- a/crypt-mod-pgp-classic.c   Sun Mar 26 12:27:43 2017 -0700
+++ b/crypt-mod-pgp-classic.c   Sun Mar 26 18:31:45 2017 -0700
@@ -61,9 +61,9 @@
   return pgp_verify_one (sigbdy, s, tempf);
 }
 
-static int crypt_mod_pgp_send_menu (HEADER *msg, int *redraw)
+static int crypt_mod_pgp_send_menu (HEADER *msg)
 {
-  return pgp_send_menu (msg, redraw);
+  return pgp_send_menu (msg);
 }
 
 static BODY *crypt_mod_pgp_encrypt_message (BODY *a, char *keylist, int sign)
diff -r b8519ee6bd74 -r 4d06d85a4dd7 crypt-mod-pgp-gpgme.c
--- a/crypt-mod-pgp-gpgme.c     Sun Mar 26 12:27:43 2017 -0700
+++ b/crypt-mod-pgp-gpgme.c     Sun Mar 26 18:31:45 2017 -0700
@@ -85,9 +85,9 @@
   return pgp_gpgme_verify_one (sigbdy, s, tempf);
 }
 
-static int crypt_mod_pgp_send_menu (HEADER *msg, int *redraw)
+static int crypt_mod_pgp_send_menu (HEADER *msg)
 {
-  return pgp_gpgme_send_menu (msg, redraw);
+  return pgp_gpgme_send_menu (msg);
 }
 
 static BODY *crypt_mod_pgp_encrypt_message (BODY *a, char *keylist, int sign)
diff -r b8519ee6bd74 -r 4d06d85a4dd7 crypt-mod-smime-classic.c
--- a/crypt-mod-smime-classic.c Sun Mar 26 12:27:43 2017 -0700
+++ b/crypt-mod-smime-classic.c Sun Mar 26 18:31:45 2017 -0700
@@ -61,9 +61,9 @@
   return smime_verify_one (sigbdy, s, tempf);
 }
 
-static int crypt_mod_smime_send_menu (HEADER *msg, int *redraw)
+static int crypt_mod_smime_send_menu (HEADER *msg)
 {
-  return smime_send_menu (msg, redraw);
+  return smime_send_menu (msg);
 }
 
 static void crypt_mod_smime_getkeys (ENVELOPE *env)
diff -r b8519ee6bd74 -r 4d06d85a4dd7 crypt-mod-smime-gpgme.c
--- a/crypt-mod-smime-gpgme.c   Sun Mar 26 12:27:43 2017 -0700
+++ b/crypt-mod-smime-gpgme.c   Sun Mar 26 18:31:45 2017 -0700
@@ -70,9 +70,9 @@
   return smime_gpgme_verify_one (sigbdy, s, tempf);
 }
 
-static int crypt_mod_smime_send_menu (HEADER *msg, int *redraw)
+static int crypt_mod_smime_send_menu (HEADER *msg)
 {
-  return smime_gpgme_send_menu (msg, redraw);
+  return smime_gpgme_send_menu (msg);
 }
 
 static BODY *crypt_mod_smime_build_smime_entity (BODY *a, char *certlist)
diff -r b8519ee6bd74 -r 4d06d85a4dd7 crypt-mod.h
--- a/crypt-mod.h       Sun Mar 26 12:27:43 2017 -0700
+++ b/crypt-mod.h       Sun Mar 26 18:31:45 2017 -0700
@@ -53,7 +53,7 @@
 typedef void (*crypt_func_pgp_extract_keys_from_attachment_list_t) 
                                            (FILE *fp, int tag, BODY *top);
 
-typedef int (*crypt_func_send_menu_t) (HEADER *msg, int *redraw);
+typedef int (*crypt_func_send_menu_t) (HEADER *msg);
 
  /* (SMIME) */
 typedef void (*crypt_func_smime_getkeys_t) (ENVELOPE *env);
diff -r b8519ee6bd74 -r 4d06d85a4dd7 cryptglue.c
--- a/cryptglue.c       Sun Mar 26 12:27:43 2017 -0700
+++ b/cryptglue.c       Sun Mar 26 18:31:45 2017 -0700
@@ -246,10 +246,10 @@
 }
 
 
-int crypt_pgp_send_menu (HEADER *msg, int *redraw)
+int crypt_pgp_send_menu (HEADER *msg)
 {
   if (CRYPT_MOD_CALL_CHECK (PGP, send_menu))
-    return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw);
+    return (CRYPT_MOD_CALL (PGP, send_menu)) (msg);
 
   return 0;
 }
@@ -380,10 +380,10 @@
   return -1;
 }
 
-int crypt_smime_send_menu (HEADER *msg, int *redraw)
+int crypt_smime_send_menu (HEADER *msg)
 {
   if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu))
-    return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw);
+    return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg);
 
   return 0;
 }
diff -r b8519ee6bd74 -r 4d06d85a4dd7 curs_lib.c
--- a/curs_lib.c        Sun Mar 26 12:27:43 2017 -0700
+++ b/curs_lib.c        Sun Mar 26 18:31:45 2017 -0700
@@ -94,7 +94,7 @@
 {
   keypad (stdscr, TRUE);
   clearok (stdscr, TRUE);
-  set_option (OPTNEEDREDRAW);
+  mutt_set_current_menu_redraw ();
 }
 
 event_t mutt_getch (void)
@@ -769,7 +769,6 @@
     if (_mutt_get_field (pc, buf, blen, (buffy ? MUTT_EFILE : MUTT_FILE) | 
MUTT_CLEAR, multiple, files, numfiles)
        != 0)
       buf[0] = 0;
-    MAYBE_REDRAW (*redraw);
     FREE (&pc);
   }
 
diff -r b8519ee6bd74 -r 4d06d85a4dd7 curs_main.c
--- a/curs_main.c       Sun Mar 26 12:27:43 2017 -0700
+++ b/curs_main.c       Sun Mar 26 18:31:45 2017 -0700
@@ -519,6 +519,7 @@
   menu->color = index_color;
   menu->current = ci_first_message ();
   menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN, 
IndexHelp);
+  mutt_push_current_menu (menu);
 
   if (!attach_msg)
     mutt_buffy_check(1); /* force the buffy check after we enter the folder */
@@ -612,14 +613,14 @@
     if (op != -1)
       mutt_curs_set (0);
 
-    if (menu->redraw & REDRAW_FULL)
-    {
-      menu_redraw_full (menu);
-      mutt_show_error ();
-    }
-
     if (menu->menu == MENU_MAIN)
     {
+      if (menu->redraw & REDRAW_FULL)
+      {
+        menu_redraw_full (menu);
+        mutt_show_error ();
+      }
+
 #ifdef USE_SIDEBAR
       if (menu->redraw & REDRAW_SIDEBAR || SidebarNeedsRedraw)
       {
@@ -1270,12 +1271,14 @@
 
         mutt_sleep (0);
 
-       /* Set CurrentMenu to MENU_MAIN before executing any folder
-        * hooks so that all the index menu functions are available to
-        * the exec command.
-        */
-
-       CurrentMenu = MENU_MAIN;
+        /* Note that menu->menu may be MENU_PAGER if the change folder
+         * operation originated from the pager.
+         *
+         * However, exec commands currently use CurrentMenu to determine what
+         * functions are available, which is automatically set by the
+         * mutt_push/pop_current_menu() functions.  If that changes, the menu
+         * would need to be reset here, and the pager cleanup code after the
+         * switch statement would need to be run. */
        mutt_folder_hook (buf);
 
        if ((Context = mx_open_mailbox (buf,
@@ -1322,12 +1325,21 @@
 
        if (option (OPTPGPAUTODEC) && (tag || !(CURHDR->security & 
PGP_TRADITIONAL_CHECKED)))
          mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
-       if ((op = mutt_display_message (CURHDR)) == -1)
+
+        /* If we are returning to the pager via an index menu redirection, we
+         * need to reset the menu->menu.  Otherwise mutt_pop_current_menu() 
will
+         * set CurrentMenu incorrectly when we return back to the index menu. 
*/
+        menu->menu = MENU_MAIN;
+
+        if ((op = mutt_display_message (CURHDR)) == -1)
        {
          unset_option (OPTNEEDRESORT);
          break;
        }
 
+        /* This is used to redirect a single operation back here afterwards.  
If
+         * mutt_display_message() returns 0, then the menu and pager state will
+         * be cleaned up after this switch statement. */
        menu->menu = MENU_PAGER;
        menu->oldcurrent = menu->current;
        continue;
@@ -1948,20 +1960,18 @@
        CHECK_ATTACH;
        CHECK_MSGCOUNT;
         CHECK_VISIBLE;
-       ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
+       ci_bounce_message (tag ? NULL : CURHDR);
        break;
 
       case OP_CREATE_ALIAS:
 
         mutt_create_alias (Context && Context->vcount ? CURHDR->env : NULL, 
NULL);
-       MAYBE_REDRAW (menu->redraw);
         menu->redraw |= REDRAW_CURRENT;
        break;
 
       case OP_QUERY:
        CHECK_ATTACH;
        mutt_query_menu (NULL, 0);
-       MAYBE_REDRAW (menu->redraw);
        break;
 
       case OP_PURGE_MESSAGE:
@@ -2041,7 +2051,6 @@
 
       case OP_ENTER_COMMAND:
 
-       CurrentMenu = MENU_MAIN;
        mutt_enter_command ();
        mutt_check_rescore (Context);
        if (option (OPTFORCEREDRAWINDEX))
@@ -2181,7 +2190,6 @@
        }
 #endif
 
-       MAYBE_REDRAW (menu->redraw);
        break;
 
       case OP_PRINT:
@@ -2310,7 +2318,6 @@
       case OP_SHELL_ESCAPE:
 
        mutt_shell_escape ();
-       MAYBE_REDRAW (menu->redraw);
        break;
 
       case OP_TAG_THREAD:
@@ -2446,14 +2453,12 @@
       mutt_clear_pager_position ();
       menu->menu = MENU_MAIN;
       menu->redraw = REDRAW_FULL;
-#if 0
-      set_option (OPTWEED); /* turn header weeding back on. */
-#endif
     }
 
     if (done) break;
   }
 
+  mutt_pop_current_menu (menu);
   mutt_menuDestroy (&menu);
   return (close);
 }
diff -r b8519ee6bd74 -r 4d06d85a4dd7 enter.c
--- a/enter.c   Sun Mar 26 12:27:43 2017 -0700
+++ b/enter.c   Sun Mar 26 18:31:45 2017 -0700
@@ -532,7 +532,6 @@
                !memcmp (tempbuf, state->wbuf + i, (state->lastchar - i) * 
sizeof (wchar_t)))
            {
              mutt_select_file (buf, buflen, (flags & MUTT_EFILE) ? 
MUTT_SEL_FOLDER : 0);
-             set_option (OPTNEEDREDRAW);
              if (*buf)
                replace_part (state, i, buf);
              rv = 1; 
@@ -643,7 +642,6 @@
              _mutt_select_file (buf, buflen, 
                                 ((flags & MUTT_EFILE) ? MUTT_SEL_FOLDER : 0) | 
(multiple ? MUTT_SEL_MULTI : 0), 
                                 files, numfiles);
-             set_option (OPTNEEDREDRAW);
              if (*buf)
              {
                mutt_pretty_mailbox (buf, buflen);
diff -r b8519ee6bd74 -r 4d06d85a4dd7 menu.c
--- a/menu.c    Sun Mar 26 12:27:43 2017 -0700
+++ b/menu.c    Sun Mar 26 18:31:45 2017 -0700
@@ -30,6 +30,11 @@
 
 char* SearchBuffers[MENU_MAX];
 
+/* These are used to track the active menus, for redraw operations. */
+static size_t MenuStackCount = 0;
+static size_t MenuStackLen = 0;
+static MUTTMENU **MenuStack = NULL;
+
 static void print_enriched_string (int attr, unsigned char *s, int do_color)
 {
   wchar_t wc;
@@ -389,7 +394,7 @@
     if (menu->top != 0) 
     {
       menu->top = 0;
-      set_option (OPTNEEDREDRAW);
+      menu->redraw |= REDRAW_INDEX;
     }
   }
   else 
@@ -709,6 +714,7 @@
   p->messagewin = MuttMessageWindow;
   p->color = default_color;
   p->search = menu_search_generic;
+
   return (p);
 }
 
@@ -727,6 +733,57 @@
   FREE (p);            /* __FREE_CHECKED__ */
 }
 
+static MUTTMENU *get_current_menu (void)
+{
+  return MenuStackCount ? MenuStack[MenuStackCount - 1] : NULL;
+}
+
+void mutt_push_current_menu (MUTTMENU *menu)
+{
+  if (MenuStackCount >= MenuStackLen)
+  {
+    MenuStackLen += 5;
+    safe_realloc (&MenuStack, MenuStackLen * sizeof(MUTTMENU *));
+  }
+
+  MenuStack[MenuStackCount++] = menu;
+  CurrentMenu = menu->menu;
+}
+
+void mutt_pop_current_menu (MUTTMENU *menu)
+{
+  MUTTMENU *prev_menu;
+
+  if (!MenuStackCount ||
+      (MenuStack[MenuStackCount - 1] != menu))
+  {
+    dprint (1, (debugfile, "mutt_pop_current_menu() called with inactive 
menu\n"));
+    return;
+  }
+
+  MenuStackCount--;
+  prev_menu = get_current_menu ();
+  if (prev_menu)
+  {
+    CurrentMenu = prev_menu->menu;
+    prev_menu->redraw = REDRAW_FULL;
+  }
+  else
+  {
+    CurrentMenu = MENU_MAIN;
+  }
+}
+
+void mutt_set_current_menu_redraw (void)
+{
+  MUTTMENU *current_menu;
+
+  current_menu = get_current_menu ();
+  if (current_menu)
+    current_menu->redraw = REDRAW_FULL;
+}
+
+
 #define MUTT_SEARCH_UP   1
 #define MUTT_SEARCH_DOWN 2
 
@@ -1030,7 +1087,6 @@
        break;
 
       case OP_ENTER_COMMAND:
-       CurrentMenu = menu->menu;
        mutt_enter_command ();
        if (option (OPTFORCEREDRAWINDEX))
        {
@@ -1070,7 +1126,6 @@
 
       case OP_SHELL_ESCAPE:
        mutt_shell_escape ();
-       MAYBE_REDRAW (menu->redraw);
        break;
 
       case OP_WHAT_KEY:
diff -r b8519ee6bd74 -r 4d06d85a4dd7 mutt.h
--- a/mutt.h    Sun Mar 26 12:27:43 2017 -0700
+++ b/mutt.h    Sun Mar 26 18:31:45 2017 -0700
@@ -523,7 +523,6 @@
   OPTFORCEREFRESH,     /* (pseudo) refresh even during macros */
   OPTLOCALES,          /* (pseudo) set if user has valid locale definition */
   OPTNOCURSES,         /* (pseudo) when sending in batch mode */
-  OPTNEEDREDRAW,       /* (pseudo) to notify caller of a submenu */
   OPTSEARCHREVERSE,    /* (pseudo) used by ci_search_command */
   OPTMSGERR,           /* (pseudo) used by mutt_error/mutt_message */
   OPTSEARCHINVALID,    /* (pseudo) used to invalidate the search pat */
diff -r b8519ee6bd74 -r 4d06d85a4dd7 mutt_crypt.h
--- a/mutt_crypt.h      Sun Mar 26 12:27:43 2017 -0700
+++ b/mutt_crypt.h      Sun Mar 26 18:31:45 2017 -0700
@@ -239,7 +239,7 @@
 /* Invoke the PGP command to import a key. */
 void crypt_pgp_invoke_import (const char *fname);
 
-int crypt_pgp_send_menu (HEADER *msg, int *redraw);
+int crypt_pgp_send_menu (HEADER *msg);
 
 /* fixme: needs documentation */
 int crypt_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf);
@@ -289,7 +289,7 @@
 /* Add a certificate and update index file (externally). */
 void crypt_smime_invoke_import (char *infile, char *mailbox);
 
-int crypt_smime_send_menu (HEADER *msg, int *redraw);
+int crypt_smime_send_menu (HEADER *msg);
 
 void crypt_smime_set_sender (const char *sender);
 
diff -r b8519ee6bd74 -r 4d06d85a4dd7 mutt_curses.h
--- a/mutt_curses.h     Sun Mar 26 12:27:43 2017 -0700
+++ b/mutt_curses.h     Sun Mar 26 18:31:45 2017 -0700
@@ -232,8 +232,6 @@
 /* reset the color to the normal terminal color as defined by 'color normal 
...' */
 #define NORMAL_COLOR SETCOLOR(MT_COLOR_NORMAL)
 
-#define MAYBE_REDRAW(x) if (option (OPTNEEDREDRAW)) { unset_option 
(OPTNEEDREDRAW); x = REDRAW_FULL; }
-
 /* ----------------------------------------------------------------------------
  * These are here to avoid compiler warnings with -Wall under SunOS 4.1.x
  */
diff -r b8519ee6bd74 -r 4d06d85a4dd7 mutt_menu.h
--- a/mutt_menu.h       Sun Mar 26 12:27:43 2017 -0700
+++ b/mutt_menu.h       Sun Mar 26 18:31:45 2017 -0700
@@ -120,6 +120,9 @@
 
 MUTTMENU *mutt_new_menu (int);
 void mutt_menuDestroy (MUTTMENU **);
+void mutt_push_current_menu (MUTTMENU *);
+void mutt_pop_current_menu (MUTTMENU *);
+void mutt_set_current_menu_redraw ();
 int mutt_menuLoop (MUTTMENU *);
 
 /* used in both the index and pager index to make an entry. */
diff -r b8519ee6bd74 -r 4d06d85a4dd7 mutt_ssl.c
--- a/mutt_ssl.c        Sun Mar 26 12:27:43 2017 -0700
+++ b/mutt_ssl.c        Sun Mar 26 18:31:45 2017 -0700
@@ -1170,6 +1170,8 @@
   FILE *fp;
   int allow_skip = 0;
 
+  mutt_push_current_menu (menu);
+
   menu->max = mutt_array_size (part) * 2 + 10;
   menu->dialog = (char **) safe_calloc (1, menu->max * sizeof (char *));
   for (i = 0; i < menu->max; i++)
@@ -1302,8 +1304,8 @@
     }
   }
   unset_option(OPTIGNOREMACROEVENTS);
+  mutt_pop_current_menu (menu);
   mutt_menuDestroy (&menu);
-  set_option (OPTNEEDREDRAW);
   dprint (2, (debugfile, "ssl interactive_check_cert: done=%d\n", done));
   return (done == 2);
 }
diff -r b8519ee6bd74 -r 4d06d85a4dd7 mutt_ssl_gnutls.c
--- a/mutt_ssl_gnutls.c Sun Mar 26 12:27:43 2017 -0700
+++ b/mutt_ssl_gnutls.c Sun Mar 26 18:31:45 2017 -0700
@@ -862,6 +862,7 @@
   menu->dialog = (char **) safe_calloc (1, menu->max * sizeof (char *));
   for (i = 0; i < menu->max; i++)
     menu->dialog[i] = (char *) safe_calloc (1, SHORT_STRING * sizeof (char));
+  mutt_push_current_menu (menu);
 
   row = 0;
   strfcpy (menu->dialog[row], _("This certificate belongs to:"), SHORT_STRING);
@@ -1065,6 +1066,7 @@
     }
   }
   unset_option (OPTIGNOREMACROEVENTS);
+  mutt_pop_current_menu (menu);
   mutt_menuDestroy (&menu);
   gnutls_x509_crt_deinit (cert);
 
diff -r b8519ee6bd74 -r 4d06d85a4dd7 pager.c
--- a/pager.c   Sun Mar 26 12:27:43 2017 -0700
+++ b/pager.c   Sun Mar 26 18:31:45 2017 -0700
@@ -1595,7 +1595,6 @@
   int i, j, ch = 0, rc = -1, hideQuoted = 0, q_level = 0, force_redraw = 0;
   int lines = 0, curline = 0, topline = 0, oldtopline = 0, err, first = 1;
   int r = -1, wrapped = 0, searchctx = 0;
-  int redraw = REDRAW_FULL;
   FILE *fp = NULL;
   LOFF_T last_pos = 0, last_offset = 0;
   int old_smart_wrap, old_markers;
@@ -1609,6 +1608,7 @@
   mutt_window_t *pager_status_window = NULL;
   mutt_window_t *pager_window = NULL;
 
+  MUTTMENU *pager_menu = NULL;
   MUTTMENU *index = NULL;              /* the Pager Index (PI) */
   int indexlen = PagerIndexLines;      /* indexlen not always == PIL */
   int indicator = indexlen / 3;        /* the indicator line of the PI */
@@ -1669,11 +1669,14 @@
   pager_status_window = safe_calloc (sizeof (mutt_window_t), 1);
   pager_window        = safe_calloc (sizeof (mutt_window_t), 1);
 
+  pager_menu = mutt_new_menu (MENU_PAGER);
+  mutt_push_current_menu (pager_menu);
+
   while (ch != -1)
   {
     mutt_curs_set (0);
 
-    if (redraw & REDRAW_FULL)
+    if (pager_menu->redraw & REDRAW_FULL)
     {
 #if ! (defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM))
       mutt_reflow_windows ();
@@ -1740,7 +1743,7 @@
          SearchBack = Resize->SearchBack;
        }
        lines = Resize->line;
-       redraw |= REDRAW_SIGWINCH;
+       pager_menu->redraw |= REDRAW_SIGWINCH;
 
        FREE (&Resize);
       }
@@ -1775,14 +1778,14 @@
        menu_redraw_index(index);
       }
 
-      redraw |= REDRAW_BODY | REDRAW_INDEX | REDRAW_STATUS;
+      pager_menu->redraw |= REDRAW_BODY | REDRAW_INDEX | REDRAW_STATUS;
 #ifdef USE_SIDEBAR
-      redraw |= REDRAW_SIDEBAR;
+      pager_menu->redraw |= REDRAW_SIDEBAR;
 #endif
       mutt_show_error ();
     }
 
-    if (redraw & REDRAW_SIGWINCH)
+    if (pager_menu->redraw & REDRAW_SIGWINCH)
     {
       i = -1;
       j = -1;
@@ -1798,14 +1801,14 @@
     }
 
 #ifdef USE_SIDEBAR
-    if ((redraw & REDRAW_SIDEBAR) || SidebarNeedsRedraw)
+    if ((pager_menu->redraw & REDRAW_SIDEBAR) || SidebarNeedsRedraw)
     {
       SidebarNeedsRedraw = 0;
       mutt_sb_draw ();
     }
 #endif
 
-    if ((redraw & REDRAW_BODY) || topline != oldtopline)

Reply via email to