]> granicus.if.org Git - mutt/commitdiff
$narrow_tree; fater redrawing when changing tree options. From
authorThomas Roessler <roessler@does-not-exist.org>
Thu, 28 Feb 2002 08:23:59 +0000 (08:23 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Thu, 28 Feb 2002 08:23:59 +0000 (08:23 +0000)
Daniel Eisenbud.

curs_main.c
init.c
init.h
mutt.h
thread.c

index ca908c5a4ecafdc8564b76934844d5989abcae66..c08bac3db70c5dbba60f905a16bab0583a7fce72 100644 (file)
@@ -454,6 +454,13 @@ int mutt_index_menu (void)
      */
     if (option (OPTNEEDRESORT) && Context && Context->msgcount)
       resort_index (menu);
+    
+    if (option (OPTREDRAWTREE) && Context && Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
+    {
+      mutt_draw_tree (Context);
+      menu->redraw |= REDRAW_STATUS;
+      unset_option (OPTREDRAWTREE);
+    }
 
     if (Context && !attach_msg)
     {
diff --git a/init.c b/init.c
index 2c3dd53f70843fc09563dd12f51657e35ee61bdf..268c685c0b1434dd7bb637a53b4c2c0560410371 100644 (file)
--- a/init.c
+++ b/init.c
@@ -780,6 +780,8 @@ static void mutt_restore_default (struct option_t *p)
     set_option (OPTNEEDRESORT);
   if (p->flags & R_RESORT_INIT)
     set_option (OPTRESORTINIT);
+  if (p->flags & R_TREE)
+    set_option (OPTREDRAWTREE);
 }
 
 static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
@@ -1228,6 +1230,8 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
       set_option (OPTNEEDRESORT);
     if (MuttVars[idx].flags & R_RESORT_INIT)
       set_option (OPTRESORTINIT);
+    if (MuttVars[idx].flags & R_TREE)
+      set_option (OPTREDRAWTREE);
   }
   return (r);
 }
diff --git a/init.h b/init.h
index 754318696c0a9b434506f021729f69e8bda4a97f..9794150b8bc21e064189c5d4135c4ccc6c23b2e0 100644 (file)
--- a/init.h
+++ b/init.h
@@ -58,6 +58,7 @@
 #define R_RESORT       (1<<2)  /* resort the mailbox */
 #define R_RESORT_SUB   (1<<3)  /* resort subthreads */
 #define R_RESORT_INIT  (1<<4)  /* resort from scratch */
+#define R_TREE         (1<<5)  /* redraw the thread tree */
 #define R_BOTH         (R_INDEX | R_PAGER)
 #define R_RESORT_BOTH  (R_RESORT | R_RESORT_SUB)
 
@@ -663,26 +664,26 @@ struct option_t MuttVars[] = {
   ** affect the generation of Message-IDs, and it will not lead to the 
   ** cut-off of first-level domains.
   */
-  { "hide_limited",    DT_BOOL, R_RESORT|R_INDEX, OPTHIDELIMITED, 0 },
+  { "hide_limited",    DT_BOOL, R_TREE|R_INDEX, OPTHIDELIMITED, 0 },
   /*
   ** .pp
   ** When set, mutt will not show the presence of missing messages in the
   ** thread tree.
   */
-  { "hide_missing",    DT_BOOL, R_RESORT|R_INDEX, OPTHIDEMISSING, 1 },
+  { "hide_missing",    DT_BOOL, R_TREE|R_INDEX, OPTHIDEMISSING, 1 },
   /*
   ** .pp
   ** When set, mutt will not show the presence of messages that are hidden
   ** by limiting, in the thread tree.
   */
-  { "hide_top_limited",        DT_BOOL, R_RESORT|R_INDEX, OPTHIDETOPLIMITED, 0 },
+  { "hide_top_limited",        DT_BOOL, R_TREE|R_INDEX, OPTHIDETOPLIMITED, 0 },
   /*
   ** .pp
   ** When set, mutt will not show the presence of missing messages at the
   ** top of threads in the thread tree.  Note that when $$hide_limited is
   ** set, this option will have no effect.
   */
-  { "hide_top_missing",        DT_BOOL, R_RESORT|R_INDEX, OPTHIDETOPMISSING, 1 },
+  { "hide_top_missing",        DT_BOOL, R_TREE|R_INDEX, OPTHIDETOPMISSING, 1 },
   /*
   ** .pp
   ** When set, mutt will not show the presence of messages that are hidden
@@ -1118,6 +1119,12 @@ struct option_t MuttVars[] = {
   { "msg_format",      DT_SYN,  R_NONE, UL "message_format", 0 },
   /*
   */
+  { "narrow_tree",     DT_BOOL, R_TREE|R_INDEX, OPTNARROWTREE, 0 },
+  /*
+  ** .pp
+  ** This variable, when set, makes the thread tree narrower, allowing
+  ** deeper threads to fit on the screen.
+  */
   { "pager",           DT_PATH, R_NONE, UL &Pager, UL "builtin" },
   /*
   ** .pp
diff --git a/mutt.h b/mutt.h
index b380b3e575b3158312702f66eda1cfb239d2bcd2..6a34feb84dd4895a0c721a0523cbe43863064292 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -372,6 +372,7 @@ enum
   OPTMETOO,
   OPTMHPURGE,
   OPTMIMEFORWDECODE,
+  OPTNARROWTREE,
   OPTPAGERSTOP,
   OPTPIPEDECODE,
   OPTPIPESPLIT,
@@ -467,6 +468,7 @@ enum
                         *          external program.
                         */
   OPTMENUCALLER,       /* (pseudo) tell menu to give caller a take */
+  OPTREDRAWTREE,       /* (pseudo) redraw the thread tree */
 #ifdef HAVE_PGP
   OPTPGPCHECKTRUST,    /* (pseudo) used by pgp_select_key () */
   OPTDONTHANDLEPGPKEYS,        /* (pseudo) used to extract PGP keys */
index 7e0ced860e5378a22fda88f1b8b12a4db69ceb94..af36fb3ec285928f40ab4654d0cdb0c7d07fb0be 100644 (file)
--- a/thread.c
+++ b/thread.c
@@ -115,18 +115,23 @@ static void linearize_tree (CONTEXT *ctx)
  * skip parts of the tree in mutt_draw_tree() if we've decided here that we
  * don't care about them any more.
  */
-static void calculate_visibility (CONTEXT *ctx)
+static void calculate_visibility (CONTEXT *ctx, int *max_depth)
 {
   THREAD *tmp, *tree = ctx->tree;
   int hide_top_missing = option (OPTHIDETOPMISSING) && !option (OPTHIDEMISSING);
   int hide_top_limited = option (OPTHIDETOPLIMITED) && !option (OPTHIDELIMITED);
+  int depth = 0;
 
   /* we walk each level backwards to make it easier to compute next_subtree_visible */
   while (tree->next)
     tree = tree->next;
+  *max_depth = 0;
 
   FOREVER
   {
+    if (depth > *max_depth)
+      *max_depth = depth;
+
     tree->subtree_visible = 0;
     if (tree->message)
     {
@@ -163,6 +168,7 @@ static void calculate_visibility (CONTEXT *ctx)
                                                || tree->next->subtree_visible);
     if (tree->child)
     {
+      depth++;
       tree = tree->child;
       while (tree->next)
        tree = tree->next;
@@ -172,7 +178,10 @@ static void calculate_visibility (CONTEXT *ctx)
     else
     {
       while (tree && !tree->prev)
+      {
+       depth--;
        tree = tree->parent;
+      }
       if (!tree)
        break;
       else
@@ -216,29 +225,23 @@ static void calculate_visibility (CONTEXT *ctx)
  */
 void mutt_draw_tree (CONTEXT *ctx)
 {
-  char *pfx = NULL, *mypfx = NULL, *arrow = NULL, *myarrow = NULL;
+  char *pfx = NULL, *mypfx = NULL, *arrow = NULL, *myarrow = NULL, *new_tree;
   char corner = (Sort & SORT_REVERSE) ? M_TREE_ULCORNER : M_TREE_LLCORNER;
   char vtee = (Sort & SORT_REVERSE) ? M_TREE_BTEE : M_TREE_TTEE;
-  int depth = 0, start_depth = 0, max_depth = 0, max_width = 0;
+  int depth = 0, start_depth = 0, max_depth = 0, width = option (OPTNARROWTREE) ? 1 : 2;
   THREAD *nextdisp = NULL, *pseudo = NULL, *parent = NULL, *tree = ctx->tree;
-  HEADER *hdr;
 
   /* Do the visibility calculations and free the old thread chars.
    * From now on we can simply ignore invisible subtrees
    */
-  calculate_visibility (ctx);
+  calculate_visibility (ctx, &max_depth);
+  pfx = safe_malloc (width * max_depth + 2);
+  arrow = safe_malloc (width * max_depth + 2);
   while (tree)
   {
-    if (depth >= max_depth)
-      safe_realloc ((void **) &pfx,
-                   (max_depth += 32) * 2 * sizeof (char));
-    if (depth - start_depth >= max_width)
-      safe_realloc ((void **) &arrow,
-                   (max_width += 16) * 2 * sizeof (char));
-    hdr = tree->message;
     if (depth)
     {
-      myarrow = arrow + (depth - start_depth - (start_depth ? 0 : 1)) * 2;
+      myarrow = arrow + (depth - start_depth - (start_depth ? 0 : 1)) * width;
       if (depth && start_depth == depth)
        myarrow[0] = nextdisp ? M_TREE_LTEE : corner;
       else if (parent->message && !option (OPTHIDELIMITED))
@@ -247,28 +250,31 @@ void mutt_draw_tree (CONTEXT *ctx)
        myarrow[0] = M_TREE_MISSING;
       else
        myarrow[0] = vtee;
-      myarrow[1] = pseudo ?  M_TREE_STAR
-                   : (tree->duplicate_thread ? M_TREE_EQUALS : M_TREE_HLINE);
+      if (width == 2)
+       myarrow[1] = pseudo ?  M_TREE_STAR
+                            : (tree->duplicate_thread ? M_TREE_EQUALS : M_TREE_HLINE);
       if (tree->visible)
       {
-       myarrow[2] = M_TREE_RARROW;
-       myarrow[3] = 0;
-       hdr->tree = safe_malloc ((2 + depth * 2) * sizeof (char));
+       myarrow[width] = M_TREE_RARROW;
+       myarrow[width + 1] = 0;
+       new_tree = safe_malloc ((2 + depth * width));
        if (start_depth > 1)
        {
-         strncpy (hdr->tree, pfx, (start_depth - 1) * 2);
-         strfcpy (hdr->tree + (start_depth - 1) * 2,
-                  arrow, (2 + depth - start_depth) * 2);
+         strncpy (new_tree, pfx, (start_depth - 1) * width);
+         strfcpy (new_tree + (start_depth - 1) * width,
+                  arrow, (1 + depth - start_depth) * width + 2);
        }
        else
-         strfcpy (hdr->tree, arrow, 2 + depth * 2);
+         strfcpy (new_tree, arrow, 2 + depth * width);
+       tree->message->tree = new_tree;
       }
     }
     if (tree->child && depth)
     {
-      mypfx = pfx + (depth - 1) * 2;
+      mypfx = pfx + (depth - 1) * width;
       mypfx[0] = nextdisp ? M_TREE_VLINE : M_TREE_SPACE;
-      mypfx[1] = M_TREE_SPACE;
+      if (width == 2)
+       mypfx[1] = M_TREE_SPACE;
     }
     parent = tree;
     nextdisp = NULL;
@@ -317,7 +323,6 @@ void mutt_draw_tree (CONTEXT *ctx)
        if (!tree)
          break;
       }
-      hdr = tree->message;
       if (!pseudo && tree->fake_thread)
        pseudo = tree;
       if (!nextdisp && tree->next_subtree_visible)