diff --git a/src/calibre/gui2/complete2.py b/src/calibre/gui2/complete2.py index afac58d160..c16557707f 100644 --- a/src/calibre/gui2/complete2.py +++ b/src/calibre/gui2/complete2.py @@ -320,6 +320,9 @@ class LineEdit(QLineEdit, LineEditECM): self.no_popup = False # Interface {{{ + def set_sort_func(self, sort_func): + self.mcompleter.model().sort_func = sort_func + def update_items_cache(self, complete_items): self.all_items = complete_items @@ -457,6 +460,10 @@ class EditWithComplete(EnComboBox): self.installEventFilter(self) # Interface {{{ + + def set_sort_func(self, sort_func): + self.lineEdit().set_sort_func(sort_func) + def showPopup(self): orig = self.disable_popup self.disable_popup = False diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index b36cfeb063..6b87827d80 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -495,6 +495,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): def __init__(self, window, rows, model, tab, refresh_books): QDialog.__init__(self, window) self.setupUi(self) + self.series.set_sort_func(title_sort) self.model = model self.db = model.db self.refresh_book_list.setChecked(gprefs['refresh_book_list_on_bulk_edit']) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 7833543e15..4ce508361f 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -12,7 +12,7 @@ from qt.core import (Qt, QApplication, QStyle, QIcon, QDoubleSpinBox, QStyleOpt QAbstractTextDocumentLayout, QFont, QFontInfo, QDate, QDateTimeEdit, QDateTime, QEvent, QStyleOptionComboBox, QStyleOptionSpinBox, QLocale, QSize, QLineEdit, QDialog, QPalette) -from calibre.ebooks.metadata import rating_to_stars +from calibre.ebooks.metadata import rating_to_stars, title_sort from calibre.gui2 import UNDEFINED_QDATETIME, rating_font, gprefs from calibre.constants import iswindows from calibre.gui2.widgets import EnLineEdit @@ -286,6 +286,8 @@ class PubDateDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ class TextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ + use_title_sort = False + def __init__(self, parent): ''' Delegate for text data. If auto_complete_function needs to return a list @@ -301,7 +303,10 @@ class TextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ def createEditor(self, parent, option, index): if self.auto_complete_function: - editor = EditWithComplete(parent) + if self.use_title_sort: + editor = EditWithComplete(parent, sort_func=title_sort) + else: + editor = EditWithComplete(parent) editor.set_separator(None) editor.set_clear_button_enabled(False) complete_items = [i[1] for i in self.auto_complete_function()] @@ -326,6 +331,8 @@ class TextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ class SeriesDelegate(TextDelegate): # {{{ + use_title_sort = True + def initStyleOption(self, option, index): TextDelegate.initStyleOption(self, option, index) option.textElideMode = Qt.TextElideMode.ElideMiddle diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py index 93b0085d11..24091dfd9c 100644 --- a/src/calibre/gui2/metadata/basic_widgets.py +++ b/src/calibre/gui2/metadata/basic_widgets.py @@ -611,7 +611,7 @@ class SeriesEdit(EditWithComplete, ToMetadataMixin): data_changed = pyqtSignal() def __init__(self, parent): - EditWithComplete.__init__(self, parent) + EditWithComplete.__init__(self, parent, sort_func=title_sort) self.set_clear_button_enabled(False) self.set_separator(None) self.dialog = parent