]> granicus.if.org Git - neomutt/commitdiff
Separate out the compose menu redrawing. (see #3877)
authorKevin McCarthy <kevin@8t8.us>
Wed, 5 Apr 2017 23:09:34 +0000 (16:09 -0700)
committerKevin McCarthy <kevin@8t8.us>
Wed, 5 Apr 2017 23:09:34 +0000 (16:09 -0700)
Add a custom_menu_redraw to the menu and change menu_redraw() to call
that instead if set.

compose.c
menu.c
mutt_menu.h

index 235bf1d0679ba1907bc7538f9310c36623818fdf..7363f2be3a441a167261b1285802aae02bd025f4 100644 (file)
--- 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 1b2d4facd432d7c6e5cb3f8970bbff3313c29c51..3874faa49749ef29d334c5de6e38a0dbca036b40 100644 (file)
--- 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)
   {
index 061b8dd2ea3043c28f8515e3aad2f3c5832d382f..e39c3ea0154b4bd5a32b1fe9abe6176e80528619 100644 (file)
@@ -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])
    */