From: Kevin McCarthy Date: Wed, 5 Apr 2017 23:09:34 +0000 (-0700) Subject: Separate out the compose menu redrawing. (see #3877) X-Git-Tag: neomutt-20170414^2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=265c3ca80480230558dbbaa9ad24f6b2f7034ba8;p=neomutt Separate out the compose menu redrawing. (see #3877) Add a custom_menu_redraw to the menu and change menu_redraw() to call that instead if set. --- diff --git a/compose.c b/compose.c index 235bf1d06..7363f2be3 100644 --- a/compose.c +++ b/compose.c @@ -468,6 +468,54 @@ static void compose_status_line (char *buf, size_t buflen, size_t col, int cols, (unsigned long) menu, 0); } +typedef struct +{ + HEADER *msg; + char *fcc; +} compose_redraw_data_t; + +static void compose_menu_redraw (MUTTMENU *menu) +{ + char buf[LONG_STRING]; + compose_redraw_data_t *rd = menu->redraw_data; + + if (!rd) + return; + + if (menu->redraw & REDRAW_FULL) + { + menu_redraw_full (menu); + + draw_envelope (rd->msg, rd->fcc); + menu->offset = HDR_ATTACH; + menu->pagelen = MuttIndexWindow->rows - HDR_ATTACH; + } + + menu_check_recenter (menu); + + if (menu->redraw & REDRAW_STATUS) + { + compose_status_line (buf, sizeof (buf), 0, MuttStatusWindow->cols, menu, NONULL(ComposeFormat)); + mutt_window_move (MuttStatusWindow, 0, 0); + SETCOLOR (MT_COLOR_STATUS); + mutt_paddstr (MuttStatusWindow->cols, buf); + NORMAL_COLOR; + menu->redraw &= ~REDRAW_STATUS; + } + +#ifdef USE_SIDEBAR + if (menu->redraw & REDRAW_SIDEBAR) + menu_redraw_sidebar (menu); +#endif + + if (menu->redraw & REDRAW_INDEX) + menu_redraw_index (menu); + else if (menu->redraw & (REDRAW_MOTION | REDRAW_MOTION_RESYNCH)) + menu_redraw_motion (menu); + else if (menu->redraw == REDRAW_CURRENT) + menu_redraw_current (menu); +} + /* return values: * @@ -497,6 +545,10 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ /* Sort, SortAux could be changed in mutt_index_menu() */ int oldSort, oldSortAux; struct stat st; + compose_redraw_data_t rd; + + rd.msg = msg; + rd.fcc = fcc; mutt_attach_init (msg->content); idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1); @@ -508,17 +560,14 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ menu->tag = mutt_tag_attach; menu->data = idx; menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp); + menu->custom_menu_redraw = compose_menu_redraw; + menu->redraw_data = &rd; mutt_push_current_menu (menu); while (loop) { switch (op = mutt_menuLoop (menu)) { - case OP_REDRAW: - draw_envelope (msg, fcc); - menu->offset = HDR_ATTACH; - menu->pagelen = MuttIndexWindow->rows - HDR_ATTACH; - break; case OP_COMPOSE_EDIT_FROM: edit_address_list (HDR_FROM, &msg->env->from); mutt_message_hook (NULL, msg, MUTT_SEND2HOOK); @@ -1320,17 +1369,6 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ #endif } - - /* Draw formatted compose status line */ - if (menu->redraw & REDRAW_STATUS) - { - compose_status_line (buf, sizeof (buf), 0, MuttStatusWindow->cols, menu, NONULL(ComposeFormat)); - mutt_window_move (MuttStatusWindow, 0, 0); - SETCOLOR (MT_COLOR_STATUS); - mutt_paddstr (MuttStatusWindow->cols, buf); - NORMAL_COLOR; - menu->redraw &= ~REDRAW_STATUS; - } } mutt_pop_current_menu (menu); diff --git a/menu.c b/menu.c index 1b2d4facd..3874faa49 100644 --- a/menu.c +++ b/menu.c @@ -926,6 +926,12 @@ static int menu_dialog_dokey (MUTTMENU *menu, int *ip) int menu_redraw (MUTTMENU *menu) { + if (menu->custom_menu_redraw) + { + menu->custom_menu_redraw (menu); + return OP_NULL; + } + /* See if all or part of the screen needs to be updated. */ if (menu->redraw & REDRAW_FULL) { diff --git a/mutt_menu.h b/mutt_menu.h index 061b8dd2e..e39c3ea01 100644 --- a/mutt_menu.h +++ b/mutt_menu.h @@ -75,6 +75,10 @@ typedef struct menu_t int (*tag) (struct menu_t *, int i, int m); + /* these are used for custom redrawing callbacks */ + void (*custom_menu_redraw) (struct menu_t *); + void *redraw_data; + /* color pair to be used for the requested element * (default function returns ColorDefs[MT_COLOR_NORMAL]) */