]> granicus.if.org Git - neomutt/commitdiff
Fix sidebar "unsorted" order to match Buffy list order.
authorKevin McCarthy <kevin@8t8.us>
Sat, 2 Jul 2016 19:24:25 +0000 (12:24 -0700)
committerRichard Russon <rich@flatcap.org>
Sun, 3 Jul 2016 13:40:28 +0000 (14:40 +0100)
Since the previous commit decoupled the sidebar from the Buffy list,
we can now restore the order to match the buffy list when
sidebar_sort_method is set (back) to "unsorted".

sidebar.c

index adda9c9d309782a7c1d645c3e8531e897e05aa0f..ef01d57539b002d02d2187c8e82dafa7a61357bc 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -31,7 +31,7 @@
 /* Previous values for some sidebar config */
 static short  OldVisible;      /* sidebar_visible */
 static short  OldWidth;                /* sidebar_width */
-static short PreviousSort = -1;  /* sidebar_sort_method */
+static short PreviousSort = SORT_ORDER;  /* sidebar_sort_method */
 
 /**
  * struct sidebar_entry - Info about folders in the sidebar
@@ -324,7 +324,36 @@ static void update_entries_visibility (void)
 }
 
 /**
- * sort_entries - Sort an array of BUFFY pointers
+ * unsort_entries - Restore Entries array order to match Buffy list order
+ */
+static void unsort_entries (void)
+{
+  BUFFY *cur = Incoming;
+  int i = 0, j;
+  SBENTRY *tmp;
+
+  while (cur && (i < EntryCount))
+  {
+    j = i;
+    while ((j < EntryCount) &&
+           (Entries[j]->buffy != cur))
+      j++;
+    if (j < EntryCount)
+    {
+      if (j != i)
+      {
+        tmp = Entries[i];
+        Entries[i] = Entries[j];
+        Entries[j] = tmp;
+      }
+      i++;
+    }
+    cur = cur->next;
+  }
+}
+
+/**
+ * sort_entries - Sort Entries array.
  *
  * Sort the Entries array according to the current sort config
  * option "sidebar_sort_method". This calls qsort to do the work which calls our
@@ -342,6 +371,9 @@ static void sort_entries (void)
       (ssm == SORT_FLAGGED)   ||
       (ssm == SORT_PATH))
     qsort (Entries, EntryCount, sizeof (*Entries), cb_qsort_sbe);
+  else if ((ssm == SORT_ORDER) &&
+           (SidebarSortMethod != PreviousSort))
+    unsort_entries ();
 }
 
 /**