This commit is contained in:
Kovid Goyal 2022-02-07 13:16:53 +05:30
commit a467d5ef07
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 26 additions and 5 deletions

View File

@ -38,11 +38,9 @@ series_index_auto_increment = 'next'
use_series_auto_increment_tweak_when_importing = False
#: Add separator after completing an author name
# Should the completion separator be append
# to the end of the completed text to
# automatically begin a new completion operation
# for authors.
# Can be either True or False
# Set this if the completion separator should be appended to the end of the
# completed text to automatically begin a new completion operation for authors.
# It can be either True or False
authors_completer_append_separator = False
#: Author sort name algorithm
@ -502,7 +500,14 @@ default_tweak_format = None
# completions you will now have to press Tab to select one before pressing
# Enter. Which technique you prefer will depend on the state of metadata in
# your library and your personal editing style.
#
# If preselect_first_completion is False and you want Tab to accept what you
# typed instead of the first completion then set tab_accepts_uncompleted_text
# to True. If you do this then to select from the completions you must press
# the Down or Up arrow keys. The tweak tab_accepts_uncompleted_text is ignored
# if preselect_first_completion is True
preselect_first_completion = False
tab_accepts_uncompleted_text = False
#: Completion mode when editing authors/tags/series/etc.
# By default, when completing items, calibre will show you all the candidates

View File

@ -82,6 +82,7 @@ class CompleteModel(QAbstractListModel): # {{{
class Completer(QListView): # {{{
item_selected = pyqtSignal(object)
apply_current_text = pyqtSignal()
relayout_needed = pyqtSignal()
def __init__(self, completer_widget, max_visible_items=7, sort_func=sort_key, strip_completion_entries=True):
@ -101,6 +102,8 @@ class Completer(QListView): # {{{
self.pressed.connect(self.item_chosen)
self.installEventFilter(self)
self.setFocusPolicy(Qt.FocusPolicy.NoFocus)
self.tab_accepts_uncompleted_text = (tweaks['tab_accepts_uncompleted_text'] and
not tweaks['preselect_first_completion'])
def hide(self):
self.setCurrentIndex(QModelIndex())
@ -232,6 +235,9 @@ class Completer(QListView): # {{{
if idx.isValid():
self.item_chosen(idx)
self.hide()
elif self.tab_accepts_uncompleted_text:
self.hide()
self.apply_current_text.emit()
elif self.model().rowCount() > 0:
self.next_match()
e.accept()
@ -306,6 +312,8 @@ class LineEdit(QLineEdit, LineEditECM):
self.mcompleter = Completer(completer_widget, sort_func=sort_func, strip_completion_entries=strip_completion_entries)
self.mcompleter.item_selected.connect(self.completion_selected,
type=Qt.ConnectionType.QueuedConnection)
self.mcompleter.apply_current_text.connect(self.apply_current_text,
type=Qt.ConnectionType.QueuedConnection)
self.mcompleter.relayout_needed.connect(self.relayout)
self.mcompleter.setFocusProxy(completer_widget)
self.textEdited.connect(self.text_edited)
@ -425,6 +433,14 @@ class LineEdit(QLineEdit, LineEditECM):
self.setCursorPosition(len(before_text))
self.item_selected.emit(text)
def apply_current_text(self):
if self.sep is not None:
txt = str(self.text())
sep_pos = txt.rfind(self.sep)
if sep_pos:
ntxt = txt[sep_pos+1:].strip()
self.completion_selected(ntxt)
class EditWithComplete(EnComboBox):