[seahorse] sidebar: Properly invalidate headers



commit a5488e2358043be1cf6d623401c42a04df38ebab
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Tue Jun 16 19:29:04 2020 +0200

    sidebar: Properly invalidate headers
    
    On each time we called `update_places()`, we added each place in a
    sorted fashion, and then _sorted it again_. This was done because we
    were otherwise showing double headers. Even more, the internal
    implementation of `ListStore.sort()` emits a signal that all elements
    have been removed and re-added, which meant that the Sidebar cleared its
    selection, triggering some other unwanted and unnecessary callbacks as
    well.
    
    In any case, this can be easily solved by calling
    `Gtk.ListBox.invalidate_headers()`, which is exactly meant for this kind
    of use case.

 src/sidebar.vala | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)
---
diff --git a/src/sidebar.vala b/src/sidebar.vala
index e6bf6c2f..461e3547 100644
--- a/src/sidebar.vala
+++ b/src/sidebar.vala
@@ -109,13 +109,14 @@ public class Seahorse.Sidebar : Gtk.ListBox {
     private void place_header_cb(Gtk.ListBoxRow row, Gtk.ListBoxRow? before) {
         Seahorse.Place place = ((SidebarItem) row).place;
 
-        // We don't need a title iff
-        // * there is no previous row
-        // * the previous row is in the same category
+        // We need a title iff
+        // the previous row exists, and it's part of the same category
         if (before != null) {
             Seahorse.Place before_place = ((SidebarItem) before).place;
-            if (place.category == before_place.category)
+            if (place.category == before_place.category) {
+                row.set_header(null);
                 return;
+            }
         }
 
         var label = new Gtk.Label(place.category.to_string());
@@ -170,17 +171,9 @@ public class Seahorse.Sidebar : Gtk.ListBox {
         foreach (Backend backend in this.backends)
             update_backend(backend);
 
-        this.store.sort(compare_places);
-
-        // Restore selection -- this got cleared by the call to sort()
-        Gtk.ListBoxRow? new_row = null;
-        foreach (var row in this.get_children()) {
-            if (((SidebarItem)row).place == place) {
-                new_row = (Gtk.ListBoxRow) row;
-                break;
-            }
-        }
-        select_row(new_row ?? get_row_at_index(0));
+        // Needed when you have multiple keyrings (this can lead
+        // to multiple 'Password' titles).
+        invalidate_headers();
     }
 
     private void update_backend(Backend? backend) {


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