]> granicus.if.org Git - neomutt/commitdiff
Change CurrentMenu to be controlled by the menu stack.
authorKevin McCarthy <kevin@8t8.us>
Mon, 27 Mar 2017 01:31:40 +0000 (18:31 -0700)
committerRichard Russon <rich@flatcap.org>
Sat, 1 Apr 2017 11:21:56 +0000 (12:21 +0100)
The pager menu is a bit tricky with respect to the menu->menu and
CurrentMenu, so add a few comments.

curs_main.c
menu.c
pager.c

index 9758c753d6dd97d372d8b1d631aab8efef8797f7..7f9846c7fc960348a5e5d0514f9678e9c1d01901 100644 (file)
@@ -459,12 +459,14 @@ static int main_change_folder(MUTTMENU *menu, int op, char *buf, size_t bufsz,
 
   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,
@@ -2077,12 +2079,21 @@ int mutt_index_menu (void)
        if (option (OPTPGPAUTODEC) && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
          mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
        int index_hint = Context->hdrs[Context->v2r[menu->current]]->index;
-       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;
        if (Context)
@@ -2777,7 +2788,6 @@ int mutt_index_menu (void)
 
       case OP_ENTER_COMMAND:
 
-       CurrentMenu = MENU_MAIN;
        mutt_enter_command ();
        mutt_check_rescore (Context);
        if (option (OPTFORCEREDRAWINDEX))
diff --git a/menu.c b/menu.c
index f0e8f0b672ff32f1ddb70c23a57d71c37f13d7af..dc49d739eecaa8157b90ec2de260d9101b09004e 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -807,6 +807,7 @@ void mutt_push_current_menu (MUTTMENU *menu)
   }
 
   MenuStack[MenuStackCount++] = menu;
+  CurrentMenu = menu->menu;
 }
 
 void mutt_pop_current_menu (MUTTMENU *menu)
@@ -819,6 +820,14 @@ void mutt_pop_current_menu (MUTTMENU *menu)
   }
 
   MenuStackCount--;
+  if (MenuStackCount)
+  {
+    CurrentMenu = MenuStack[MenuStackCount - 1]->menu;
+  }
+  else
+  {
+    CurrentMenu = MENU_MAIN;
+  }
 }
 
 
@@ -1134,7 +1143,6 @@ int mutt_menu_loop (MUTTMENU *menu)
        break;
 
       case OP_ENTER_COMMAND:
-       CurrentMenu = menu->menu;
        mutt_enter_command ();
        if (option (OPTFORCEREDRAWINDEX))
        {
diff --git a/pager.c b/pager.c
index b06bd9d31b6205e24d1c0b0ea5a9640ecb254c27..ccd905594672bbadb2c52f1f4dca008660d2377f 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -2681,7 +2681,6 @@ search_next:
        old_markers = option (OPTMARKERS);
        old_PagerIndexLines = PagerIndexLines;
 
-       CurrentMenu = MENU_PAGER;
        mutt_enter_command ();
 
        if (option (OPTNEEDRESORT))