From ca74e005ef5ef2d96fad405b4ba21e905724ed2c Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Mon, 9 Sep 2024 16:46:27 +0200
Subject: [PATCH] browser.py: Minor fix and optimization in .update_gallery.

---
 browser.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/browser.py b/browser.py
index b1bcc3a..33791a6 100755
--- a/browser.py
+++ b/browser.py
@@ -262,6 +262,8 @@ class MainWindow(Gtk.Window):
                     return True
                 if a_cmp is None:
                     return False
+                elif b_cmp is None:
+                    return True
                 return a_cmp > b_cmp
 
         def init_gallery_slot(file_item):
@@ -276,9 +278,10 @@ class MainWindow(Gtk.Window):
             slot.append(slot.content)
             return slot
 
-        self.gallery.bind_model(self.gallery_selection, init_gallery_slot)
+        self.gallery.bind_model(None, lambda _: Gtk.Box())
         if sort:
             self.gallery_store.sort(sorter)
+        self.gallery.bind_model(self.gallery_selection, init_gallery_slot)
         to_select = self.gallery.get_child_at_index(0)
         if suggested_selection:
             i = 0
-- 
2.30.2