home · contact · privacy
In Browser, also preserve sort order between reloads.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 24 Aug 2024 06:47:09 +0000 (08:47 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 24 Aug 2024 06:47:09 +0000 (08:47 +0200)
browser.py

index 651e1e5f8295e69ea80cfe291cb28215f1387c12..fca3b812e92be067e010b8ab1afd8ff54783ca56 100755 (executable)
@@ -108,15 +108,23 @@ class Window(Gtk.ApplicationWindow):
         self.props.child = box_outer
 
         self.item = None
+        self.sort_order = []
         self.reload_dir()
 
     def on_sort_select(self, button):
-        self.sort(button.props.label)
+        self.update_sort_order(button.props.label)
+        self.sort()
         self.sorter.props.label = f'SORT: {button.props.label}'
 
-    def sort(self, attr_name):
+    def update_sort_order(self, attr_name):
+        if attr_name in self.sort_order:
+            self.sort_order.remove(attr_name)
+        self.sort_order += [attr_name]
+
+    def sort(self):
         self.list_store.remove_all()
-        self.unsorted.sort(key=lambda i: getattr(i, attr_name))
+        for key in self.sort_order:
+            self.unsorted.sort(key=lambda i: getattr(i, key))
         for file_item in self.unsorted:
             self.list_store.append(file_item)
         if self.item:
@@ -180,7 +188,7 @@ class Window(Gtk.ApplicationWindow):
             for item in [item for item in self.unsorted if '' == item.model]:
                 item.set_metadata(et, cache)
         self.max_index = len(self.unsorted) - 1
-        self.sort('name')
+        self.sort()
         with open(CACHE_PATH, 'w', encoding='utf8') as f:
             json_dump(cache, f)