[geary/mjog/account-command-stacks: 18/25] Require MainWindow::select_folder to declare mode of interaction



commit 09fde274d3e39abe3dac0f47c6f77ffe7a2f2f4d
Author: Michael Gratton <mike vee net>
Date:   Sun Nov 3 07:05:18 2019 +1100

    Require MainWindow::select_folder to declare mode of interaction
    
    By determining if selecting a folder is interactive or not, the
    MainWindow can avoid enabling auto-marking of unread email.

 src/client/application/application-controller.vala |  2 +-
 src/client/application/geary-application.vala      |  4 +--
 src/client/components/main-window.vala             | 37 ++++++++++++++++------
 .../conversation-viewer/conversation-list-box.vala |  7 ++--
 .../conversation-viewer/conversation-viewer.vala   |  5 +--
 5 files changed, 39 insertions(+), 16 deletions(-)
---
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index fec08470..2127abe7 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -321,7 +321,7 @@ public class Application.Controller : Geary.BaseObject {
         this.application.engine.account_available.disconnect(on_account_available);
 
         // Release folder and conversations in the main window
-        yield this.main_window.select_folder(null);
+        yield this.main_window.select_folder(null, false);
 
         // hide window while shutting down, as this can take a few
         // seconds under certain conditions
diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala
index 7859a615..76d34e15 100644
--- a/src/client/application/geary-application.vala
+++ b/src/client/application/geary-application.vala
@@ -535,12 +535,12 @@ public class GearyApplication : Gtk.Application {
     public async void show_email(Geary.Folder? folder,
                                  Geary.EmailIdentifier id) {
         yield this.present();
-        yield this.controller.main_window.show_email(folder, id);
+        yield this.controller.main_window.show_email(folder, id, true);
     }
 
     public async void show_folder(Geary.Folder? folder) {
         yield this.present();
-        yield this.controller.main_window.select_folder(folder);
+        yield this.controller.main_window.select_folder(folder, true);
     }
 
     public async void show_inspector() {
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index a8afb549..1a7cc5d7 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -209,6 +209,10 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
 
     private Application.Controller.AccountContext? context = null;
 
+    // Determines if the conversation viewer should autoselect on next
+    // load
+    private bool previous_selection_was_interactive = false;
+
     // Caches the last non-search folder so it can be re-selected on
     // the search folder closing
     private Geary.Folder? previous_non_search_folder = null;
@@ -349,8 +353,15 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
         update_infobar_frame();
     }
 
-    /** Selects and open the given folder. */
-    public async void select_folder(Geary.Folder? to_select) {
+    /**
+     * Selects and open the given folder.
+     *
+     * If is_interactive is true, the selection is treated as being
+     * caused directly by human request (e.g. clicking on a folder in
+     * the folder list), as opposed to some side effect.
+     */
+    public async void select_folder(Geary.Folder? to_select,
+                                    bool is_interactive) {
         if (this.selected_folder != to_select) {
             // Cancel any existing folder loading
             this.folder_open.cancel();
@@ -404,6 +415,7 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
                 !this.is_shift_down && this.selected_folder_supports_trash
             );
             this.conversation_viewer.show_loading();
+            this.previous_selection_was_interactive = is_interactive;
 
             debug("Folder selected: %s",
                   (to_select != null) ? to_select.to_string() : "(null)");
@@ -455,8 +467,10 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
     }
 
     /** Selects the given account, folder and email. */
-    public async void show_email(Geary.Folder folder, Geary.EmailIdentifier id) {
-        yield select_folder(folder);
+    public async void show_email(Geary.Folder folder,
+                                 Geary.EmailIdentifier id,
+                                 bool is_interactive) {
+        yield select_folder(folder, is_interactive);
         Geary.App.Conversation? conversation =
             this.conversations.get_by_email_identifier(id);
         if (conversation != null) {
@@ -483,7 +497,7 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
         // XXX do other things like select the first/next most highest
         // account's inbox?
         this.search_bar.set_search_text(""); // Reset search.
-        this.select_folder.begin(null);
+        this.select_folder.begin(null, false);
     }
 
     /** Displays a composer addressed to a specific email address. */
@@ -532,7 +546,7 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
         return closed;
     }
 
-    public void search(string text) {
+    public void search(string text, bool is_interactive) {
         Geary.SearchFolder? search_folder = null;
         if (this.selected_account != null) {
             search_folder = this.selected_account.get_special_folder(
@@ -547,7 +561,9 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
         if (Geary.String.is_empty_or_whitespace(text)) {
             if (this.previous_non_search_folder != null &&
                 this.selected_folder is Geary.SearchFolder) {
-                this.select_folder.begin(this.previous_non_search_folder);
+                this.select_folder.begin(
+                    this.previous_non_search_folder, is_interactive
+                );
             }
             this.folder_list.remove_search();
             if (search_folder !=  null) {
@@ -1067,6 +1083,7 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
                         convo,
                         context.emails,
                         context.contacts,
+                        this.previous_selection_was_interactive,
                         (obj, ret) => {
                             try {
                                 this.conversation_viewer.load_conversation.end(ret);
@@ -1088,6 +1105,8 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
                 break;
             }
         }
+
+        this.previous_selection_was_interactive = true;
     }
 
     private void on_conversation_count_changed() {
@@ -1477,11 +1496,11 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
     }
 
     private void on_folder_selected(Geary.Folder? folder) {
-        this.select_folder.begin(folder);
+        this.select_folder.begin(folder, true);
     }
 
     private void do_search(string text) {
-        search(text);
+        search(text, true);
     }
 
     private void on_visible_conversations_changed(Gee.Set<Geary.App.Conversation> visible) {
diff --git a/src/client/conversation-viewer/conversation-list-box.vala 
b/src/client/conversation-viewer/conversation-list-box.vala
index 52ca7abf..7c56823c 100644
--- a/src/client/conversation-viewer/conversation-list-box.vala
+++ b/src/client/conversation-viewer/conversation-list-box.vala
@@ -651,7 +651,8 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
         base.destroy();
     }
 
-    public async void load_conversation(Geary.SearchQuery? query)
+    public async void load_conversation(Geary.SearchQuery? query,
+                                        bool start_mark_timer)
         throws GLib.Error {
         set_sort_func(null);
 
@@ -702,7 +703,9 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
             query, uninteresting, post_interesting
         );
 
-        this.mark_read_timer.start();
+        if (start_mark_timer) {
+            this.mark_read_timer.start();
+        }
     }
 
     /** Cancels loading the current conversation, if still in progress */
diff --git a/src/client/conversation-viewer/conversation-viewer.vala 
b/src/client/conversation-viewer/conversation-viewer.vala
index 02af3646..078086fe 100644
--- a/src/client/conversation-viewer/conversation-viewer.vala
+++ b/src/client/conversation-viewer/conversation-viewer.vala
@@ -233,7 +233,8 @@ public class ConversationViewer : Gtk.Stack, Geary.BaseInterface {
      */
     public async void load_conversation(Geary.App.Conversation conversation,
                                         Geary.App.EmailStore emails,
-                                        Application.ContactStore contacts)
+                                        Application.ContactStore contacts,
+                                        bool start_mark_timer)
         throws GLib.Error {
         remove_current_list();
 
@@ -280,7 +281,7 @@ public class ConversationViewer : Gtk.Stack, Geary.BaseInterface {
             }
         }
 
-        yield new_list.load_conversation(query);
+        yield new_list.load_conversation(query, start_mark_timer);
     }
 
     // Add a new conversation list to the UI


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