[balsa] balsa-index: scroll to row in another idle handler



commit fe65a19ce2403d431f2611e61d217668ffa4760e
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Aug 22 13:28:44 2020 -0400

    balsa-index: scroll to row in another idle handler
    
    * src/balsa-index.c
      (bndx_scroll_to_row_idle): the handler;
      (bndx_scroll_to_row): helper to schedule it;
      (bndx_scroll_on_open_idle), (bndx_select_row), (bndx_ensure_visible_idle):
        use the helper;
      (bndx_destroy): remove the source, if necessary.

 ChangeLog         | 11 +++++++++++
 src/balsa-index.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 57 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 497cd47f0..0ceeb3445 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2020-08-22  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       balsa-index: scroll to row in another idle handler
+
+       * src/balsa-index.c
+         (bndx_scroll_to_row_idle): the handler;
+         (bndx_scroll_to_row): helper to schedule it;
+         (bndx_scroll_on_open_idle), (bndx_select_row), (bndx_ensure_visible_idle):
+           use the helper;
+         (bndx_destroy): remove the source, if necessary.
+
 2020-08-21  Peter Bloomfield  <pbloomfield bellsouth net>
 
        balsa-index: Ensure visible in a low-priority idle callback
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 05b010868..41fbdff28 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -174,6 +174,7 @@ struct _BalsaIndex {
     /* Idle handler ids */
     guint selection_changed_idle_id;
     guint mailbox_changed_idle_id;
+    guint scroll_to_row_idle_id;
 
     LibBalsaMailboxSearchIter *search_iter;
     BalsaIndexWidthPreference width_preference;
@@ -265,6 +266,11 @@ bndx_destroy(GObject * obj)
         bindex->mailbox_changed_idle_id = 0;
     }
 
+    if (bindex->scroll_to_row_idle_id != 0) {
+        g_source_remove(bindex->scroll_to_row_idle_id);
+        bindex->scroll_to_row_idle_id = 0;
+    }
+
     /* Clean up any other idle handler sources */
     while (g_source_remove_by_user_data(bindex))
         /* Nothing */ ;
@@ -848,6 +854,43 @@ balsa_index_new(void)
  * destroyed by now, of course.
  */
 
+static gboolean
+bndx_scroll_to_row_idle(gpointer user_data)
+{
+    BalsaIndex *bindex = user_data;
+    GtkTreeView *tree_view = GTK_TREE_VIEW(bindex);
+    GtkTreePath *path;
+
+    path = gtk_tree_row_reference_get_path(bindex->reference);
+    gtk_tree_row_reference_free(bindex->reference);
+    bindex->reference = NULL;
+
+    gtk_tree_view_scroll_to_cell(tree_view, path, NULL, FALSE, 0, 0);
+    gtk_tree_path_free(path);
+
+    bindex->scroll_to_row_idle_id = 0;
+
+    return G_SOURCE_REMOVE;
+}
+
+static void
+bndx_scroll_to_row(BalsaIndex *bindex, GtkTreePath *path)
+{
+    GtkTreeModel *model;
+
+    if (bindex->reference != NULL)
+        gtk_tree_row_reference_free(bindex->reference);
+
+    model = gtk_tree_view_get_model(GTK_TREE_VIEW(bindex));
+    bindex->reference = gtk_tree_row_reference_new(model, path);
+
+    if (bindex->scroll_to_row_idle_id == 0) {
+        bindex->scroll_to_row_idle_id =
+            g_idle_add_full(G_PRIORITY_LOW + 10, /* lower than low! */
+                            bndx_scroll_to_row_idle, bindex, NULL);
+    }
+}
+
 static gboolean
 bndx_scroll_on_open_idle(BalsaIndex *bindex)
 {
@@ -895,7 +938,7 @@ bndx_scroll_on_open_idle(BalsaIndex *bindex)
     }
 
     bndx_expand_to_row(bindex, path);
-    gtk_tree_view_scroll_to_cell(tree_view, path, NULL, FALSE, 0, 0);
+    bndx_scroll_to_row(bindex, path);
 
     view_on_open =
         g_object_get_data(G_OBJECT(mailbox), BALSA_INDEX_VIEW_ON_OPEN);
@@ -2228,7 +2271,7 @@ bndx_select_row(BalsaIndex * index, GtkTreePath * path)
     GtkTreeView *tree_view = GTK_TREE_VIEW(index);
 
     gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
-    gtk_tree_view_scroll_to_cell(tree_view, path, NULL, FALSE, 0, 0);
+    bndx_scroll_to_row(index, path);
 }
 
 /* Check that all parents are expanded. */
@@ -2769,7 +2812,7 @@ bndx_ensure_visible_idle(gpointer user_data)
     }
 
     if (path != NULL) {
-        gtk_tree_view_scroll_to_cell(tree_view, path, NULL, FALSE, 0, 0);
+        bndx_scroll_to_row(bindex, path);
         gtk_tree_path_free(path);
     }
 


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