[geary/mjog/account-command-stacks: 72/77] Application.Controller: Add convenience method



commit fa6008fb563290990fc2c12ca6b7ad6a4cbebb43
Author: Michael Gratton <mike vee net>
Date:   Tue Nov 5 08:23:00 2019 +1100

    Application.Controller: Add convenience method

 src/client/application/application-controller.vala | 29 +++++++++++-----------
 1 file changed, 15 insertions(+), 14 deletions(-)
---
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index 2127abe7..f2d036e1 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -1361,20 +1361,12 @@ public class Application.Controller : Geary.BaseObject {
                         // Select this inbox if there isn't an
                         // existing folder selected and it is the
                         // inbox for the first account
-                        if (!main_window.folder_list.is_any_selected()) {
-                            Geary.AccountInformation? first_account = null;
-                            foreach (Geary.AccountInformation info in this.accounts.keys) {
-                                if (first_account == null ||
-                                    info.ordinal < first_account.ordinal) {
-                                    first_account = info;
-                                }
-                            }
-                            if (folder.account.information == first_account) {
-                                // First we try to select the Inboxes branch inbox if
-                                // it's there, falling back to the main folder list.
-                                if (!main_window.folder_list.select_inbox(folder.account))
-                                    main_window.folder_list.select_folder(folder);
-                            }
+                        if (!this.main_window.folder_list.is_any_selected() &&
+                            folder.account.information == get_first_account()) {
+                            // First we try to select the Inboxes branch inbox if
+                            // it's there, falling back to the main folder list.
+                            if (!main_window.folder_list.select_inbox(folder.account))
+                                main_window.folder_list.select_folder(folder);
                         }
                     }
 
@@ -1695,6 +1687,15 @@ public class Application.Controller : Geary.BaseObject {
         return ret.size >= 1 ? ret : null;
     }
 
+    private Geary.AccountInformation? get_first_account() {
+        return this.accounts.keys.iterator().fold<Geary.AccountInformation?>(
+            (next, prev) => {
+                return prev == null || next.ordinal < prev.ordinal ? next : prev;
+            },
+            null
+        );
+    }
+
     private bool should_add_folder(Gee.Collection<Geary.Folder>? all,
                                    Geary.Folder folder) {
         // if folder is openable, add it


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]