diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py
index 1aa3796150..539cae1628 100644
--- a/resources/default_tweaks.py
+++ b/resources/default_tweaks.py
@@ -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
diff --git a/src/calibre/db/categories.py b/src/calibre/db/categories.py
index 552ec68523..67fb18b841 100644
--- a/src/calibre/db/categories.py
+++ b/src/calibre/db/categories.py
@@ -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):
diff --git a/src/calibre/gui2/preferences/behavior.py b/src/calibre/gui2/preferences/behavior.py
index 2c3caf0d4c..1cb9f19077 100644
--- a/src/calibre/gui2/preferences/behavior.py
+++ b/src/calibre/gui2/preferences/behavior.py
@@ -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')]
diff --git a/src/calibre/gui2/preferences/behavior.ui b/src/calibre/gui2/preferences/behavior.ui
index 925a602fc9..4b6b3dfe22 100644
--- a/src/calibre/gui2/preferences/behavior.ui
+++ b/src/calibre/gui2/preferences/behavior.ui
@@ -208,6 +208,20 @@ If not checked, the values can be Yes or No.
-
+
+
+ Recognize numbers inside text when sorting (needs restart)
+
+
+ <p>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.</p>
+
+
+
+ -
&Delete news from library when it is automatically sent to reader
diff --git a/src/calibre/utils/config_base.py b/src/calibre/utils/config_base.py
index 4e1bc6bd7c..f14407e971 100644
--- a/src/calibre/utils/config_base.py
+++ b/src/calibre/utils/config_base.py
@@ -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()
diff --git a/src/calibre/utils/icu.py b/src/calibre/utils/icu.py
index bf38ebd1ba..b35e5d0c4e 100644
--- a/src/calibre/utils/icu.py
+++ b/src/calibre/utils/icu.py
@@ -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