mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Change tag browser to handle multi-character "characters" that some languages use when doing first letter categorization.
This commit is contained in:
parent
c9e37072a9
commit
d5e7f83da4
@ -17,7 +17,7 @@ from PyQt4.Qt import (QAbstractItemModel, QIcon, QVariant, QFont, Qt,
|
|||||||
from calibre.gui2 import NONE, gprefs, config, error_dialog
|
from calibre.gui2 import NONE, gprefs, config, error_dialog
|
||||||
from calibre.library.database2 import Tag
|
from calibre.library.database2 import Tag
|
||||||
from calibre.utils.config import tweaks
|
from calibre.utils.config import tweaks
|
||||||
from calibre.utils.icu import sort_key, lower, strcmp, span_contractions
|
from calibre.utils.icu import sort_key, lower, strcmp, contractions
|
||||||
from calibre.library.field_metadata import TagsIcons, category_icon_map
|
from calibre.library.field_metadata import TagsIcons, category_icon_map
|
||||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
from calibre.utils.formatter import EvalFormatter
|
from calibre.utils.formatter import EvalFormatter
|
||||||
@ -259,6 +259,16 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
self.hidden_categories.add(cat)
|
self.hidden_categories.add(cat)
|
||||||
db.prefs.set('tag_browser_hidden_categories', list(self.hidden_categories))
|
db.prefs.set('tag_browser_hidden_categories', list(self.hidden_categories))
|
||||||
|
|
||||||
|
conts = contractions()
|
||||||
|
if len(conts) == 0:
|
||||||
|
self.do_contraction = False
|
||||||
|
else:
|
||||||
|
self.do_contraction = True
|
||||||
|
nconts = set()
|
||||||
|
for s in conts:
|
||||||
|
nconts.add(icu_upper(s))
|
||||||
|
self.contraction_set = frozenset(nconts)
|
||||||
|
|
||||||
self.db = db
|
self.db = db
|
||||||
self._run_rebuild()
|
self._run_rebuild()
|
||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
@ -379,10 +389,6 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
else:
|
else:
|
||||||
collapse_model = 'partition'
|
collapse_model = 'partition'
|
||||||
collapse_template = tweaks['categories_collapsed_popularity_template']
|
collapse_template = tweaks['categories_collapsed_popularity_template']
|
||||||
if True or get_lang() in self.langs_no_span_contractions:
|
|
||||||
use_span_contractions = False
|
|
||||||
else:
|
|
||||||
use_span_contractions = True
|
|
||||||
|
|
||||||
def get_name_components(name):
|
def get_name_components(name):
|
||||||
components = [t.strip() for t in name.split('.') if t.strip()]
|
components = [t.strip() for t in name.split('.') if t.strip()]
|
||||||
@ -423,15 +429,14 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
if not tag.sort:
|
if not tag.sort:
|
||||||
c = ' '
|
c = ' '
|
||||||
else:
|
else:
|
||||||
if not use_span_contractions:
|
if not self.do_contraction:
|
||||||
c = icu_upper(tag.sort)[0]
|
c = icu_upper(tag.sort)[0]
|
||||||
else:
|
else:
|
||||||
v = icu_upper(tag.sort)
|
v = icu_upper(tag.sort)
|
||||||
le = span_contractions(v)
|
c = v[0]
|
||||||
if le > 0:
|
for s in self.contraction_set:
|
||||||
c = v[:le]
|
if len(s) > len(c) and v.startswith(s):
|
||||||
else:
|
c = s
|
||||||
c = v[0]
|
|
||||||
if c not in chardict:
|
if c not in chardict:
|
||||||
chardict[c] = [idx, idx]
|
chardict[c] = [idx, idx]
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user