From: Kevin McCarthy Date: Mon, 27 Mar 2017 01:31:40 +0000 (-0700) Subject: Change CurrentMenu to be controlled by the menu stack. X-Git-Tag: neomutt-20170414~18^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f6fb63f276f2cc53568c8bee70840def4ad2fc0d;p=neomutt 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. --- diff --git a/curs_main.c b/curs_main.c index 9758c753d..7f9846c7f 100644 --- a/curs_main.c +++ b/curs_main.c @@ -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 f0e8f0b67..dc49d739e 100644 --- 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 b06bd9d31..ccd905594 100644 --- 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))