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^2~21 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8240fc8175ff88485e9b5cf7958c8e8bd2453655;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 b92ab6ede..cc7c1a952 100644 --- a/curs_main.c +++ b/curs_main.c @@ -1271,12 +1271,14 @@ int mutt_index_menu (void) 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, @@ -1323,12 +1325,21 @@ int mutt_index_menu (void) 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; @@ -2042,7 +2053,6 @@ int mutt_index_menu (void) case OP_ENTER_COMMAND: - CurrentMenu = MENU_MAIN; mutt_enter_command (); mutt_check_rescore (Context); if (option (OPTFORCEREDRAWINDEX)) @@ -2447,9 +2457,6 @@ int mutt_index_menu (void) 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; diff --git a/menu.c b/menu.c index 46debdb8b..891a580eb 100644 --- a/menu.c +++ b/menu.c @@ -742,6 +742,7 @@ void mutt_push_current_menu (MUTTMENU *menu) } MenuStack[MenuStackCount++] = menu; + CurrentMenu = menu->menu; } void mutt_pop_current_menu (MUTTMENU *menu) @@ -754,6 +755,14 @@ void mutt_pop_current_menu (MUTTMENU *menu) } MenuStackCount--; + if (MenuStackCount) + { + CurrentMenu = MenuStack[MenuStackCount - 1]->menu; + } + else + { + CurrentMenu = MENU_MAIN; + } } @@ -1060,7 +1069,6 @@ int mutt_menuLoop (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 0f434c0f3..bfbfc0239 100644 --- a/pager.c +++ b/pager.c @@ -2493,7 +2493,6 @@ search_next: old_markers = option (OPTMARKERS); old_PagerIndexLines = PagerIndexLines; - CurrentMenu = MENU_PAGER; mutt_enter_command (); if (option (OPTNEEDRESORT))