[geary/mjog/folder-order] FolderList.AccountBranch: Fix ordering of special-use folders
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/folder-order] FolderList.AccountBranch: Fix ordering of special-use folders
- Date: Thu, 23 Apr 2020 01:45:59 +0000 (UTC)
commit 9e0acad23d069cd86f5cdc823ae6f3a0c50e2941
Author: Michael Gratton <mike vee net>
Date: Thu Apr 23 11:42:53 2020 +1000
FolderList.AccountBranch: Fix ordering of special-use folders
Don't rely on the special-use enum ordinal, there's no reason to
expect the engine lists uses in an order people would file helpful.
.../folder-list/folder-list-account-branch.vala | 41 ++++++++++++++++++++--
1 file changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/src/client/folder-list/folder-list-account-branch.vala
b/src/client/folder-list/folder-list-account-branch.vala
index 2f94952f..3d17f6e1 100644
--- a/src/client/folder-list/folder-list-account-branch.vala
+++ b/src/client/folder-list/folder-list-account-branch.vala
@@ -6,6 +6,26 @@
// A branch that holds all the folders for a particular account.
public class FolderList.AccountBranch : Sidebar.Branch {
+
+ // Defines the ordering that special-use folders appear in the
+ // folder list
+ private const Geary.Folder.SpecialUse[] SPECIAL_USE_ORDERING = {
+ INBOX,
+ SEARCH,
+ FLAGGED,
+ IMPORTANT,
+ DRAFTS,
+ CUSTOM,
+ NONE,
+ OUTBOX,
+ SENT,
+ ARCHIVE,
+ ALL_MAIL,
+ TRASH,
+ JUNK
+ };
+
+
public Geary.Account account { get; private set; }
public SpecialGrouping user_folder_group { get; private set; }
public Gee.HashMap<Geary.FolderPath, FolderEntry> folder_entries { get; private set; }
@@ -61,8 +81,25 @@ public class FolderList.AccountBranch : Sidebar.Branch {
Geary.Folder.SpecialUse type_a = entry_a.folder.used_as;
Geary.Folder.SpecialUse type_b = entry_b.folder.used_as;
- // Special folders are ordered by their enum value.
- return (int) type_a - (int) type_b;
+ if (type_a == type_b) return 0;
+ if (type_a == INBOX) return -1;
+ if (type_b == INBOX) return 1;
+
+ int ordering_a = 0;
+ for (; ordering_a < SPECIAL_USE_ORDERING.length; ordering_a++) {
+ if (type_a == SPECIAL_USE_ORDERING[ordering_a]) {
+ break;
+ }
+ }
+ int ordering_b = 0;
+ for (; ordering_b < SPECIAL_USE_ORDERING.length; ordering_b++) {
+ if (type_b == SPECIAL_USE_ORDERING[ordering_b]) {
+ break;
+ }
+ }
+
+ if (ordering_a == ordering_b) return normal_folder_comparator(a, b);
+ return ordering_a - ordering_b;
}
private static int normal_folder_comparator(Sidebar.Entry a, Sidebar.Entry b) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]