mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-08 22:33:42 +02:00
Add a tweak to change the behavior of the tab character in completing combo boxes
This commit is contained in:
parent
2adc821a67
commit
288a5f8593
2 changed files with 26 additions and 5 deletions
|
|
@ -38,11 +38,9 @@
|
|||
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 @@
|
|||
# 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
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ def index_for_prefix(self, prefix):
|
|||
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 @@ def __init__(self, completer_widget, max_visible_items=7, sort_func=sort_key, st
|
|||
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 @@ def eventFilter(self, obj, e):
|
|||
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 @@ def __init__(self, parent=None, completer_widget=None, sort_func=sort_key, strip
|
|||
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 @@ def completion_selected(self, text):
|
|||
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):
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue