mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add saved sorts to the "Sort by" action top-level menu
This commit is contained in:
parent
80c997b13e
commit
e1b00c6af5
@ -5,6 +5,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
from contextlib import suppress
|
||||
from functools import partial
|
||||
from qt.core import (
|
||||
QAbstractItemView, QAction, QDialog, QDialogButtonBox, QIcon, QListWidget,
|
||||
QListWidgetItem, QSize, Qt, QToolButton, QVBoxLayout, pyqtSignal,
|
||||
@ -82,6 +83,14 @@ class SortByAction(InterfaceAction):
|
||||
lv = self.gui.library_view
|
||||
m = lv.model()
|
||||
db = m.db
|
||||
|
||||
# Add saved sorts to the menu
|
||||
saved_sorts = db.new_api.pref('saved_multisort_specs', {})
|
||||
if saved_sorts:
|
||||
for name in sorted(saved_sorts.keys(), key=primary_sort_key):
|
||||
menu.addAction(name, partial(self.named_sort_selected, saved_sorts[name]))
|
||||
menu.addSeparator()
|
||||
|
||||
try:
|
||||
sort_col, order = m.sorted_on
|
||||
except TypeError:
|
||||
@ -144,6 +153,9 @@ class SortByAction(InterfaceAction):
|
||||
hidden.append(i.data(Qt.ItemDataRole.UserRole))
|
||||
db.new_api.set_pref(SORT_HIDDEN_PREF, tuple(hidden))
|
||||
|
||||
def named_sort_selected(self, sort_spec):
|
||||
self.gui.library_view.multisort(sort_spec)
|
||||
|
||||
def choose_multisort(self):
|
||||
from calibre.gui2.dialogs.multisort import ChooseMultiSort
|
||||
d = ChooseMultiSort(self.gui.current_db, parent=self.gui, is_device_connected=self.gui.device_connected)
|
||||
|
@ -583,6 +583,11 @@ class BooksModel(QAbstractTableModel): # {{{
|
||||
if not self.db:
|
||||
return
|
||||
self.db.multisort(self.sort_history[:tweaks['maximum_resort_levels']])
|
||||
if self.sort_history:
|
||||
# There are ways to get here that don't set sorted_on, e.g., the
|
||||
# sort_by action. I don't think sort_history can be empty, but it
|
||||
# doesn't hurt to check
|
||||
self.sorted_on = (self.sort_history[0])
|
||||
if reset:
|
||||
self.beginResetModel(), self.endResetModel()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user