From 94a137a6a56f972edd21016c6e691ab84b4ac779 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sat, 24 Aug 2024 08:47:09 +0200 Subject: [PATCH] In Browser, also preserve sort order between reloads. --- browser.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/browser.py b/browser.py index 651e1e5..fca3b81 100755 --- a/browser.py +++ b/browser.py @@ -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) -- 2.30.2