Add an option to control how completion works when editing authors/tags/series/etc.

By default, when completing items, calibre will show you all the
candidates that start with the text you have already typed. You can
instead have it show all candidates that contain the text you have
already typed. To do this, go to Preferences->Tweaks->Completion mode.
For example, if you type asi it will now match both Asimov and Quasimodo,
whereas the default behavior would match only Asimov. Fixes #1264304 [[Enhancement] search within string when tagging](https://bugs.launchpad.net/calibre/+bug/1264304)
This commit is contained in:
Kovid Goyal 2014-01-02 10:24:32 +05:30
parent 8e6ee68bd8
commit bea02304ee
3 changed files with 17 additions and 3 deletions

View File

@ -523,6 +523,14 @@ default_tweak_format = None
# your library and your personal editing style.
preselect_first_completion = False
#: Completion mode when editing authors/tags/series/etc.
# By default, when completing items, calibre will show you all the candidates
# that start with the text you have already typed. You can instead have it show
# all candidates that contain the text you have already typed. To do this, set
# completion_mode to 'contains'. For example, if you type asi it will match both
# Asimov and Quasimodo, whereas the default behavior would match only Asimov.
completion_mode = 'prefix'
#: Recognize numbers inside text when sorting
# This means that when sorting on text fields like title the text "Book 2"
# will sort before the text "Book 100". If you want this behavior, set

View File

@ -14,11 +14,14 @@ from PyQt4.Qt import (QLineEdit, QAbstractListModel, Qt, pyqtSignal, QObject,
QApplication, QListView, QPoint, QModelIndex, QFont, QFontInfo)
from calibre.constants import isosx, get_osx_version
from calibre.utils.icu import sort_key, primary_startswith
from calibre.utils.icu import sort_key, primary_startswith, primary_icu_find
from calibre.gui2 import NONE
from calibre.gui2.widgets import EnComboBox, LineEditECM
from calibre.utils.config import tweaks
def containsq(x, prefix):
return primary_icu_find(prefix, x)[0] != -1
class CompleteModel(QAbstractListModel): # {{{
def __init__(self, parent=None):
@ -45,8 +48,8 @@ class CompleteModel(QAbstractListModel): # {{{
return
subset = prefix.startswith(old_prefix)
universe = self.current_items if subset else self.all_items
self.current_items = tuple(x for x in universe if primary_startswith(x,
prefix))
func = primary_startswith if tweaks['completion_mode'] == 'prefix' else containsq
self.current_items = tuple(x for x in universe if func(x, prefix))
self.reset()
def rowCount(self, *args):

View File

@ -247,6 +247,9 @@ def primary_find(pat, src):
if _icu_not_ok:
from calibre.utils.filenames import ascii_text
return py_find(ascii_text(pat), ascii_text(src))
return primary_icu_find(pat, src)
def primary_icu_find(pat, src):
try:
return icu_find(_primary_collator, pat, src)
except AttributeError: