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.
This commit is contained in:
Kovid Goyal 2013-12-31 11:39:08 +05:30
parent 78911d6077
commit 84219dcf6b
2 changed files with 12 additions and 9 deletions

View File

@ -63,10 +63,8 @@ class SortByAction(InterfaceAction):
self._sactions = [] self._sactions = []
for name in sorted(name_map, key=sort_key): for name in sorted(name_map, key=sort_key):
key = name_map[name] key = name_map[name]
if key in {'title', 'series_sort', 'formats', 'path'}: if key in {'sort', 'series_sort', 'formats', 'path'}:
continue continue
if key == 'sort':
name = _('Title')
if key == 'ondevice' and self.gui.device_connected is None: if key == 'ondevice' and self.gui.device_connected is None:
continue continue
ascending = None ascending = None

View File

@ -474,7 +474,7 @@ class BooksView(QTableView): # {{{
state['last_modified_injected'] = True state['last_modified_injected'] = True
state['languages_injected'] = True state['languages_injected'] = True
state['sort_history'] = \ 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_positions'] = {}
state['column_sizes'] = {} state['column_sizes'] = {}
state['column_alignment'] = self._model.alignment_map 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): def cleanup_sort_history(self, sort_history, ignore_column_map=False):
history = [] history = []
for col, order in sort_history: for col, order in sort_history:
if not isinstance(order, bool): if not isinstance(order, bool):
continue continue
if col == 'date': col = {'date':'timestamp', 'sort':'title'}.get(col, col)
col = 'timestamp'
if ignore_column_map or col in self.column_map: if ignore_column_map or col in self.column_map:
if (not history or history[-1][0] != col): if (not history or history[-1][0] != col):
history.append([col, order]) history.append([col, order])
@ -512,6 +512,11 @@ class BooksView(QTableView): # {{{
def apply_sort_history(self, saved_history, max_sort_levels=3): def apply_sort_history(self, saved_history, max_sort_levels=3):
if not saved_history: if not saved_history:
return return
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( for col, order in reversed(self.cleanup_sort_history(
saved_history)[:max_sort_levels]): saved_history)[:max_sort_levels]):
self.sort_by_column_and_order(self.column_map.index(col), order) self.sort_by_column_and_order(self.column_map.index(col), order)