]> granicus.if.org Git - mutt/commitdiff
Threading updates, from Daniel Eisenbud.
authorThomas Roessler <roessler@does-not-exist.org>
Thu, 13 Dec 2001 12:10:59 +0000 (12:10 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Thu, 13 Dec 2001 12:10:59 +0000 (12:10 +0000)
menu.c
mutt.h
sort.c
thread.c

diff --git a/menu.c b/menu.c
index 70cfd780d25c78d86c0d910d992fe8f7a471455f..82b85fabe30b5a9d26c4720c0178a056535b521a 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -88,6 +88,22 @@ static void print_enriched_string (int attr, unsigned char *s, int do_color)
            else
              addch (ACS_VLINE);
            break;
+         case M_TREE_TTEE:
+           if (option (OPTASCIICHARS))
+             addch ('-');
+           else if (Charset_is_utf8)
+             addstr ("\342\224\200"); /* FIXME: this is WACS_HLINE but should be WACS_TTEE */
+           else
+             addch (ACS_TTEE);
+           break;
+         case M_TREE_BTEE:
+           if (option (OPTASCIICHARS))
+             addch ('-');
+           else if (Charset_is_utf8)
+             addstr ("\342\224\200"); /* FIXME: this is WACS_HLINE but should be WACS_BTEE */
+           else
+             addch (ACS_BTEE);
+           break;
          case M_TREE_SPACE:
            addch (' ');
            break;
@@ -100,12 +116,12 @@ static void print_enriched_string (int attr, unsigned char *s, int do_color)
          case M_TREE_HIDDEN:
            addch ('&');
            break;
-         case M_TREE_MISSING:
-           addch ('?');
-           break;
          case M_TREE_EQUALS:
            addch ('=');
            break;
+         case M_TREE_MISSING:
+           addch ('?');
+           break;
        }
        s++, n--;
       }
diff --git a/mutt.h b/mutt.h
index 9e5ea13362f1ad4b97eb9120bd075a5847b41a2b..4e642891b62653f4cbdef511ad552e085e7bc71f 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -154,9 +154,11 @@ typedef enum
 #define M_TREE_RARROW          7
 #define M_TREE_STAR            8
 #define M_TREE_HIDDEN          9
-#define M_TREE_MISSING         10
-#define M_TREE_EQUALS          11
-#define M_TREE_MAX             12
+#define M_TREE_EQUALS          10
+#define M_TREE_TTEE            11
+#define M_TREE_BTEE            12
+#define M_TREE_MISSING         13
+#define M_TREE_MAX             14
 
 #define M_THREAD_COLLAPSE      (1<<0)
 #define M_THREAD_UNCOLLAPSE    (1<<1)
diff --git a/sort.c b/sort.c
index 4043b0b789432e8e7002e5f86e37210ae84eb3c1..20757f8cf98c2fd3fea04c702dea69e8486ccf86 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -181,6 +181,7 @@ void mutt_sort_headers (CONTEXT *ctx, int init)
   THREAD *thread, *top;
   sort_t *sortfunc;
   
+  init = 1; /* XXX temporary bug workaround (hopefully!) */
   unset_option (OPTNEEDRESORT);
 
   if (!ctx)
index 1f48ef70a05eb73d009792f0a3bdcc1454532082..2fb314a6feb281ce5e401e43c06d80e08bd598f2 100644 (file)
--- a/thread.c
+++ b/thread.c
@@ -114,7 +114,6 @@ static int is_next_displayed (CONTEXT *ctx, THREAD *tree)
   return (0);
 }
 
-
 /* Since the graphics characters have a value >255, I have to resort to
  * using escape sequences to pass the information to print_enriched_string().
  * These are the macros M_TREE_* defined in mutt.h.
@@ -126,15 +125,24 @@ static int is_next_displayed (CONTEXT *ctx, THREAD *tree)
 void mutt_linearize_tree (CONTEXT *ctx, int linearize)
 {
   char *pfx = NULL, *mypfx = NULL, *arrow = NULL, *myarrow = NULL;
-  char corner = Sort & SORT_REVERSE ? M_TREE_ULCORNER : M_TREE_LLCORNER;
+  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 nextdisp = 0, visible;
+  int nextdisp = 0, visible, pseudo = 0;
   THREAD *tree = ctx->tree;
   HEADER **array = ctx->hdrs + (Sort & SORT_REVERSE ? ctx->msgcount - 1 : 0);
   HEADER *hdr;
 
-  FOREVER
+  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 (hdr)
@@ -147,33 +155,27 @@ void mutt_linearize_tree (CONTEXT *ctx, int linearize)
     else
       visible = 0;
 
-    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));
-
     if (depth)
     {
       myarrow = arrow + (depth - start_depth - (start_depth ? 0 : 1)) * 2;
-      nextdisp = is_next_displayed (ctx, tree);
       
       if (depth && start_depth == depth)
        myarrow[0] = nextdisp ? M_TREE_LTEE : corner;
+      else if (tree->parent->message)
+       myarrow[0] = M_TREE_HIDDEN;
+      else if (option (OPTHIDEMISSING))
+       myarrow[0] = nextdisp ? vtee : M_TREE_HLINE;
       else
-       myarrow[0] = tree->parent->message ? M_TREE_HIDDEN : M_TREE_MISSING;
-      myarrow[1] = (tree->fake_thread ?  M_TREE_STAR
-                   : (tree->duplicate_thread ? M_TREE_EQUALS : M_TREE_HLINE));
+       myarrow[0] = M_TREE_MISSING;
+      myarrow[1] = pseudo ?  M_TREE_STAR
+                   : (tree->duplicate_thread ? M_TREE_EQUALS : M_TREE_HLINE);
+      pseudo = 0;
+
       if (visible)
       {
        myarrow[2] = M_TREE_RARROW;
        myarrow[3] = 0;
-      }
 
-      if (visible)
-      {
        hdr->tree = safe_malloc ((2 + depth * 2) * sizeof (char));
        if (start_depth > 1)
        {
@@ -192,43 +194,62 @@ void mutt_linearize_tree (CONTEXT *ctx, int linearize)
       array += Sort & SORT_REVERSE ? -1 : 1;
     }
 
-    if (tree->child)
+    if (tree->child && depth)
     {
-      if (depth)
-      {
-       mypfx = pfx + (depth - 1) * 2;
-       mypfx[0] = nextdisp ? M_TREE_VLINE : M_TREE_SPACE;
-       mypfx[1] = M_TREE_SPACE;
-      }
-      if (depth || !option (OPTHIDEMISSING)
-         || tree->message || tree->child->next)
-       depth++;
-      if (visible)
-        start_depth = depth;
-      tree = tree->child;
-      hdr = tree->message;
+      mypfx = pfx + (depth - 1) * 2;
+      mypfx[0] = nextdisp ? M_TREE_VLINE : M_TREE_SPACE;
+      mypfx[1] = M_TREE_SPACE;
     }
-    else
+
+    nextdisp = 0;
+
+    do
     {
-      while (!tree->next && tree->parent)
+      if (tree->child)
       {
-       if (hdr && VISIBLE (hdr, ctx))
-         start_depth = depth;
-       tree = tree->parent;
+       if (hdr || !option (OPTHIDEMISSING) || tree->child->next)
+       {
+         depth++;
+         if (visible)
+           start_depth = depth;
+       }
+
+       tree = tree->child;
+       if (tree->fake_thread)
+         pseudo = 1;
+       if (!nextdisp)
+         nextdisp = is_next_displayed (ctx, tree);
        hdr = tree->message;
-       if (depth)
+      }
+      else
+      {
+       while (!tree->next && tree->parent)
        {
-         if (start_depth == depth)
-           start_depth--;
-         depth--;
+         if (hdr && VISIBLE (hdr, ctx))
+           start_depth = depth;
+
+         tree = tree->parent;
+         hdr = tree->message;
+
+         if (hdr || !option (OPTHIDEMISSING) || tree->child->next)
+         {
+           if (start_depth == depth)
+             start_depth--;
+           depth--;
+         }
        }
+
+       if (hdr && VISIBLE (hdr, ctx))
+         start_depth = depth;
+       tree = tree->next;
+       if (!tree)
+         break;
+       if (!nextdisp)
+         nextdisp = is_next_displayed (ctx, tree);
+       hdr = tree->message;
       }
-      if (hdr && VISIBLE (hdr, ctx))
-       start_depth = depth;
-      tree = tree->next;
-      if (!tree)
-       break;
     }
+    while (!(hdr || !option (OPTHIDEMISSING) || tree->child->next));
   }
 
   safe_free ((void **) &pfx);
@@ -857,7 +878,7 @@ void mutt_sort_threads (CONTEXT *ctx, int init)
   mutt_linearize_tree (ctx, 1);
 }
 
-static HEADER *find_virtual (THREAD *cur)
+static HEADER *find_virtual (THREAD *cur, int reverse)
 {
   THREAD *top;
 
@@ -868,24 +889,32 @@ static HEADER *find_virtual (THREAD *cur)
   if ((cur = cur->child) == NULL)
     return (NULL);
 
+  while (reverse && cur->next)
+    cur = cur->next;
+
   FOREVER
   {
     if (cur->message && cur->message->virtual >= 0)
       return (cur->message);
 
     if (cur->child)
+    {
       cur = cur->child;
-    else if (cur->next)
-      cur = cur->next;
+
+      while (reverse && cur->next)
+       cur = cur->next;
+    }
+    else if (reverse ? cur->prev : cur->next)
+      cur = reverse ? cur->prev : cur->next;
     else
     {
-      while (!cur->next)
+      while (!(reverse ? cur->prev : cur->next))
       {
        cur = cur->parent;
        if (cur == top)
          return (NULL);
       }
-      cur = cur->next;
+      cur = reverse ? cur->prev : cur->next;
     }
     /* not reached */
   }
@@ -930,7 +959,7 @@ int _mutt_aside_thread (HEADER *hdr, short dir, short subthreads)
       cur = cur->next;
       if (!cur)
        return (-1);
-      tmp = find_virtual (cur);
+      tmp = find_virtual (cur, 0);
     } while (!tmp);
   }
   else
@@ -940,7 +969,7 @@ int _mutt_aside_thread (HEADER *hdr, short dir, short subthreads)
       cur = cur->prev;
       if (!cur)
        return (-1);
-      tmp = find_virtual (cur);
+      tmp = find_virtual (cur, 1);
     } while (!tmp);
   }
 
@@ -1050,7 +1079,7 @@ int _mutt_traverse_thread (CONTEXT *ctx, HEADER *cur, int flag)
     }
   }
 
-  if ((thread = thread->child) == NULL)
+  if (thread == top && (thread = thread->child) == NULL)
   {
     /* return value depends on action requested */
     if (flag & (M_THREAD_COLLAPSE | M_THREAD_UNCOLLAPSE))