Skip to content

Commit

Permalink
Fix sort restoring on fields not present as columns not working
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kovidgoyal committed Dec 31, 2013
1 parent 78911d6 commit 84219dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/calibre/gui2/actions/sort.py
Expand Up @@ -63,10 +63,8 @@ def get_name(k):
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
Expand Down
17 changes: 11 additions & 6 deletions src/calibre/gui2/library/views.py
Expand Up @@ -474,7 +474,7 @@ def get_state(self):
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
Expand All @@ -499,11 +499,11 @@ def save_state(self):

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])
Expand All @@ -512,9 +512,14 @@ def cleanup_sort_history(self, sort_history, ignore_column_map=False):
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
Expand Down

0 comments on commit 84219dc

Please sign in to comment.