static char *tsl = "\033]0;";
static char *fsl = "\007";
+/**
+ * collapse/uncollapse all threads
+ * @param menu current menu
+ * @param toggle toggle collapsed state
+ *
+ * This function is called by the OP_MAIN_COLLAPSE_ALL command and on folder
+ * enter if the OPTCOLLAPSEALL option is set. In the first case, the @toggle
+ * parameter is 1 to actually toggle collapsed/uncollapsed state on all
+ * threads. In the second case, the @toggle parameter is 0, actually turning
+ * this function into a one-way collapse.
+ */
+static void collapse_all(MUTTMENU *menu, int toggle)
+{
+ HEADER *h, *base;
+ THREAD *thread, *top;
+ int final;
+
+ /* Figure out what the current message would be after folding / unfolding,
+ * so that we can restore the cursor in a sane way afterwards. */
+ if (CURHDR->collapsed && toggle)
+ final = mutt_uncollapse_thread (Context, CURHDR);
+ else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
+ final = mutt_collapse_thread (Context, CURHDR);
+ else
+ final = CURHDR->virtual;
+
+ base = Context->hdrs[Context->v2r[final]];
+
+ /* Iterate all threads, perform collapse/uncollapse as needed */
+ top = Context->tree;
+ Context->collapsed = toggle ? !Context->collapsed : 1;
+ while ((thread = top) != NULL)
+ {
+ while (!thread->message)
+ thread = thread->child;
+ h = thread->message;
+
+ if (h->collapsed != Context->collapsed)
+ {
+ if (h->collapsed)
+ mutt_uncollapse_thread (Context, h);
+ else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
+ mutt_collapse_thread (Context, h);
+ }
+ top = top->next;
+ }
+
+ /* Restore the cursor */
+ mutt_set_virtual (Context);
+ int j;
+ for (j = 0; j < Context->vcount; j++)
+ {
+ if (Context->hdrs[Context->v2r[j]]->index == base->index)
+ {
+ menu->current = j;
+ break;
+ }
+ }
+
+ menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
+}
+
/* terminal status capability check. terminfo must have been initialized. */
short mutt_ts_capability(void)
{
else
menu->current = 0;
+ if (((Sort & SORT_MASK) == SORT_THREADS) && option (OPTCOLLAPSEALL))
+ collapse_all (menu, 0);
+
#ifdef USE_SIDEBAR
mutt_sb_set_open_buffy ();
#endif
if (!attach_msg)
mutt_buffy_check(1); /* force the buffy check after we enter the folder */
+ if (((Sort & SORT_MASK) == SORT_THREADS) && option (OPTCOLLAPSEALL))
+ {
+ collapse_all (menu, 0);
+ menu->redraw = REDRAW_FULL;
+ }
+
FOREVER
{
tag = 0; /* clear the tag-prefix */
if ((Sort & SORT_MASK) != SORT_THREADS)
{
- mutt_error _("Threading is not enabled.");
- break;
- }
-
- {
- HEADER *h, *base;
- THREAD *thread, *top;
- int final;
-
- if (CURHDR->collapsed)
- final = mutt_uncollapse_thread (Context, CURHDR);
- else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
- final = mutt_collapse_thread (Context, CURHDR);
- else
- final = CURHDR->virtual;
-
- base = Context->hdrs[Context->v2r[final]];
-
- top = Context->tree;
- Context->collapsed = !Context->collapsed;
- while ((thread = top) != NULL)
- {
- while (!thread->message)
- thread = thread->child;
- h = thread->message;
-
- if (h->collapsed != Context->collapsed)
- {
- if (h->collapsed)
- mutt_uncollapse_thread (Context, h);
- else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
- mutt_collapse_thread (Context, h);
- }
- top = top->next;
- }
-
- mutt_set_virtual (Context);
- for (j = 0; j < Context->vcount; j++)
- {
- if (Context->hdrs[Context->v2r[j]]->index == base->index)
- {
- menu->current = j;
- break;
- }
- }
-
- menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
- }
+ mutt_error _("Threading is not enabled.");
+ break;
+ }
+ collapse_all (menu, 1);
break;
/* --------------------------------------------------------------------