Move the numeric_collation tweak to global preferences with the UI in Preferences / Behaviour. I didn't put it in db.prefs because I didn't want to create a linkage between icu.py and the database.

This commit is contained in:
Charles Haley 2021-10-25 16:53:30 +01:00
parent 1518344dd8
commit 689a280a2c
6 changed files with 37 additions and 11 deletions

View File

@ -541,13 +541,6 @@ preselect_first_completion = False
# 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
# numeric_collation = True note that doing so will cause problems with text
# that starts with numbers and is a little slower.
numeric_collation = False
#: Sort the list of libraries alphabetically
# The list of libraries in the Copy to library and Quick switch menus are
# normally sorted by most used. However, if there are more than a certain

View File

@ -11,7 +11,7 @@ from functools import partial
from polyglot.builtins import iteritems, native_string_type
from calibre.ebooks.metadata import author_to_author_sort
from calibre.utils.config_base import tweaks
from calibre.utils.config_base import tweaks, prefs
from calibre.utils.icu import sort_key, collation_order
CATEGORY_SORTS = ('name', 'popularity', 'rating') # This has to be a tuple not a set
@ -115,7 +115,7 @@ def clean_user_categories(dbcache):
return new_cats
numeric_collation = tweaks['numeric_collation']
numeric_collation = prefs['numeric_collation']
def first_digit(x):

View File

@ -76,6 +76,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
signal.connect(self.internally_viewed_formats_changed)
r('bools_are_tristate', db.prefs, restart_required=True)
r('numeric_collation', prefs, restart_required=True)
r = self.register
choices = [(_('Default'), 'default'), (_('Compact Metadata'), 'alt1'),
(_('All on 1 tab'), 'alt2')]

View File

@ -208,6 +208,20 @@ If not checked, the values can be Yes or No.</string>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="opt_numeric_collation">
<property name="text">
<string>Recognize numbers inside text when sorting (needs restart)</string>
</property>
<property name="toolTip">
<string>&lt;p&gt;Setting this means that when sorting on text fields
like title the text "Book 2" will sort before the text "Book 100".
Note that setting this can cause problems with text that starts
with numbers and is a little slower. This setting is per user, not
per library.&lt;/p&gt;</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="opt_delete_news_from_library_on_upload">
<property name="text">
<string>&amp;Delete news from library when it is automatically sent to reader</string>

View File

@ -542,6 +542,12 @@ def create_global_prefs(conf_obj=None):
'on case-sensitive searching'))
c.add_opt('case_sensitive', default=False, help=_(
'Make searches case-sensitive'))
c.add_opt('numeric_collation', default=False,
help=_('Recognize numbers inside text when sorting. Setting this '
'means that when sorting on text fields like title the text "Book 2"'
'will sort before the text "Book 100". Note that setting this '
'can cause problems with text that starts with numbers and is '
'a little slower.'))
c.add_opt('migrated', default=False, help='For Internal use. Don\'t modify.')
return c
@ -650,6 +656,18 @@ def read_tweaks():
tweaks = read_tweaks()
def migrate_tweaks_to_prefs():
# This must happen after the tweaks are loaded
# Migrate the numeric_collation tweak
if 'numeric_collation' in tweaks:
prefs['numeric_collation'] = tweaks.get('numeric_collation', False)
tweaks.pop('numeric_collation')
write_custom_tweaks(tweaks)
migrate_tweaks_to_prefs()
def reset_tweaks_to_default():
default_tweaks = exec_tweaks(default_tweaks_raw())
tweaks.clear()

View File

@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
import codecs
import sys
from calibre.utils.config_base import tweaks
from calibre.utils.config_base import tweaks, prefs
from calibre_extensions import icu as _icu
from polyglot.builtins import cmp
@ -87,7 +87,7 @@ def sort_collator():
if _sort_collator is None:
_sort_collator = collator().clone()
_sort_collator.strength = _icu.UCOL_SECONDARY
_sort_collator.numeric = tweaks['numeric_collation']
_sort_collator.numeric = prefs['numeric_collation']
return _sort_collator