From bfbc7f5d70f724010a9789ecefca6c1aa9f22962 Mon Sep 17 00:00:00 2001
From: Michael Gratton <mike@vee.net>
Date: Tue, 29 Sep 2020 23:01:38 +1000
Subject: [PATCH 033/124] client: Fix not all folders being displayed in
 additional main windows

Application.MainWindow: Sort folders already available in an account
by path so that FolderListTree is able to add them all successfully.

Application.FolderContext: Implement Gee.Comparable so instances can
be sorted.

Fixes #1004
---
 src/client/application/application-folder-context.vala | 7 ++++++-
 src/client/application/application-main-window.vala    | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/client/application/application-folder-context.vala b/src/client/application/application-folder-context.vala
index b85c901b..4ed47cf5 100644
--- a/src/client/application/application-folder-context.vala
+++ b/src/client/application/application-folder-context.vala
@@ -9,7 +9,8 @@
 /**
  * Collects application state related to a single folder.
  */
-public class Application.FolderContext : Geary.BaseObject {
+public class Application.FolderContext : Geary.BaseObject,
+    Gee.Comparable<FolderContext> {
 
 
     /** Specifies different kinds of displayable email counts. */
@@ -41,6 +42,10 @@ public class Application.FolderContext : Geary.BaseObject {
         update();
     }
 
+    public int compare_to(FolderContext other) {
+        return this.folder.path.compare_to(other.folder.path);
+    }
+
     private void update() {
         this.display_name = Util.I18n.to_folder_display_name(this.folder);
 
diff --git a/src/client/application/application-main-window.vala b/src/client/application/application-main-window.vala
index 73b50e33..47749019 100644
--- a/src/client/application/application-main-window.vala
+++ b/src/client/application/application-main-window.vala
@@ -1010,7 +1010,12 @@ public class Application.MainWindow :
             to_add.commands.undone.connect(on_command_undo);
             to_add.commands.redone.connect(on_command_redo);
 
-            add_folders(to_add.get_folders());
+            // Sort the folders so FolderListTree adds them all
+            // correctly
+            var added = new Gee.TreeSet<FolderContext>();
+            added.add_all(to_add.get_folders());
+
+            add_folders(added);
             this.accounts.add(to_add);
         }
     }
-- 
2.29.2

