From: Christian Heller Date: Sat, 24 Aug 2024 06:47:09 +0000 (+0200) Subject: In Browser, also preserve sort order between reloads. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/todos?a=commitdiff_plain;h=94a137a6a56f972edd21016c6e691ab84b4ac779;p=stable_plom In Browser, also preserve sort order between reloads. --- 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)