[balsa] balsa-index: Ensure visible in an idle handler



commit ca15524706e40e8eee7763e9fc699478fa8a0c61
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Aug 21 15:04:31 2020 -0400

    balsa-index: Ensure visible in an idle handler
    
    Ensure that a message is visible in a low-priority idle handler. On
    switching the notebook page, this allows any required sorting to be
    scheduled, and we can then reschedule the handler until the sorting is
    completed.
    
    * src/balsa-index.c
      (bndx_ensure_visible_idle): the handler;
      (balsa_index_ensure_visible): schedule it.

 ChangeLog         |  7 +++++++
 src/balsa-index.c | 33 ++++++++++++++++++++++++---------
 2 files changed, 31 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index cbfbc74d3..497cd47f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-08-21  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       balsa-index: Ensure visible in a low-priority idle callback
+
+       * src/balsa-index.c (bndx_ensure_visible_idle): the callback;
+       (balsa_index_ensure_visible): schedule it.
+
 2020-08-20  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Fix some more mailbox-opening issues
diff --git a/src/balsa-index.c b/src/balsa-index.c
index ee64d9ec9..9fcd7504e 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -2724,23 +2724,28 @@ balsa_index_pipe(BalsaIndex * index)
  * filter, even though the view does contain messages.  We prefer to
  * scroll to either the current message. If this one is unavailable -
  * to the last message in the view, if any. */
-void
-balsa_index_ensure_visible(BalsaIndex * index)
+static gboolean
+bndx_ensure_visible_idle(gpointer user_data)
 {
-    GtkTreeView *tree_view = GTK_TREE_VIEW(index);
-    GdkRectangle rect;
+    BalsaIndex *bindex = user_data;
+    GtkTreeView *tree_view = GTK_TREE_VIEW(bindex);
+    GtkTreeModel *model;
     GtkTreePath *path = NULL;
 
-    if (!gtk_widget_get_window(GTK_WIDGET(tree_view)))
-        return;
+    model = gtk_tree_view_get_model(tree_view);
+
+    if (libbalsa_mailbox_get_has_sort_pending(LIBBALSA_MAILBOX(model)))
+        return G_SOURCE_CONTINUE;
 
-    if (!bndx_find_current_msgno(index, &path, NULL)) {
+    if (!bndx_find_current_msgno(bindex, &path, NULL)) {
         /* Current message not displayed, make sure that something
            else is... */
         /* Was the cursor set? */
         gtk_tree_view_get_cursor(tree_view, &path, NULL);
         if (path == NULL) {
             /* No */
+            GdkRectangle rect;
+
             gtk_tree_view_get_visible_rect(tree_view, &rect);
             gtk_tree_view_convert_tree_to_widget_coords(tree_view,
                                                         rect.x, rect.y,
@@ -2753,10 +2758,8 @@ balsa_index_ensure_visible(BalsaIndex * index)
                 path = NULL;
             } else {
                 /* Scroll to the last message. */
-                GtkTreeModel *model;
                 gint n_children;
 
-                model = gtk_tree_view_get_model(tree_view);
                 n_children = gtk_tree_model_iter_n_children(model, NULL);
 
                 if (n_children > 0)
@@ -2769,6 +2772,18 @@ balsa_index_ensure_visible(BalsaIndex * index)
         gtk_tree_view_scroll_to_cell(tree_view, path, NULL, FALSE, 0, 0);
         gtk_tree_path_free(path);
     }
+
+    g_object_unref(bindex);
+
+    return G_SOURCE_REMOVE;
+}
+
+void
+balsa_index_ensure_visible(BalsaIndex * bindex)
+{
+    g_return_if_fail(BALSA_IS_INDEX(bindex));
+
+    g_idle_add_full(G_PRIORITY_LOW, bndx_ensure_visible_idle, g_object_ref(bindex), NULL);
 }
 
 void


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