From 84219dcf6bc661c7e4698536a69a6a43385a9388 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 31 Dec 2013 11:39:08 +0530 Subject: [PATCH] Fix sort restoring on fields not present as columns not working Book list: Fix sorting on fields that are not viewable as columns not being restored on calibre restart. Also fix sorting on the Title field via the right click menu not being restored. --- src/calibre/gui2/actions/sort.py | 4 +--- src/calibre/gui2/library/views.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/actions/sort.py b/src/calibre/gui2/actions/sort.py index 3a4462511f..9a8f25a295 100644 --- a/src/calibre/gui2/actions/sort.py +++ b/src/calibre/gui2/actions/sort.py @@ -63,10 +63,8 @@ class SortByAction(InterfaceAction): self._sactions = [] for name in sorted(name_map, key=sort_key): key = name_map[name] - if key in {'title', 'series_sort', 'formats', 'path'}: + if key in {'sort', 'series_sort', 'formats', 'path'}: continue - if key == 'sort': - name = _('Title') if key == 'ondevice' and self.gui.device_connected is None: continue ascending = None diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 666f737f49..26da246299 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -474,7 +474,7 @@ class BooksView(QTableView): # {{{ state['last_modified_injected'] = True state['languages_injected'] = True state['sort_history'] = \ - self.cleanup_sort_history(self.model().sort_history) + self.cleanup_sort_history(self.model().sort_history, ignore_column_map=self.is_library_view) state['column_positions'] = {} state['column_sizes'] = {} state['column_alignment'] = self._model.alignment_map @@ -499,11 +499,11 @@ class BooksView(QTableView): # {{{ def cleanup_sort_history(self, sort_history, ignore_column_map=False): history = [] + for col, order in sort_history: if not isinstance(order, bool): continue - if col == 'date': - col = 'timestamp' + col = {'date':'timestamp', 'sort':'title'}.get(col, col) if ignore_column_map or col in self.column_map: if (not history or history[-1][0] != col): history.append([col, order]) @@ -512,9 +512,14 @@ class BooksView(QTableView): # {{{ def apply_sort_history(self, saved_history, max_sort_levels=3): if not saved_history: return - for col, order in reversed(self.cleanup_sort_history( - saved_history)[:max_sort_levels]): - self.sort_by_column_and_order(self.column_map.index(col), order) + if self.is_library_view: + for col, order in reversed(self.cleanup_sort_history( + saved_history, ignore_column_map=True)[:max_sort_levels]): + self.sort_by_named_field(col, order) + else: + for col, order in reversed(self.cleanup_sort_history( + saved_history)[:max_sort_levels]): + self.sort_by_column_and_order(self.column_map.index(col), order) def apply_state(self, state, max_sort_levels=3): h = self.column_header