From d5e7f83da4297f69094438d6fd515166aaeffe94 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 5 Jul 2012 17:44:36 +0200 Subject: [PATCH] Change tag browser to handle multi-character "characters" that some languages use when doing first letter categorization. --- src/calibre/gui2/tag_browser/model.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/calibre/gui2/tag_browser/model.py b/src/calibre/gui2/tag_browser/model.py index 5b3996ac76..0bc602622c 100644 --- a/src/calibre/gui2/tag_browser/model.py +++ b/src/calibre/gui2/tag_browser/model.py @@ -17,7 +17,7 @@ from PyQt4.Qt import (QAbstractItemModel, QIcon, QVariant, QFont, Qt, from calibre.gui2 import NONE, gprefs, config, error_dialog from calibre.library.database2 import Tag 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.gui2.dialogs.confirm_delete import confirm from calibre.utils.formatter import EvalFormatter @@ -259,6 +259,16 @@ class TagsModel(QAbstractItemModel): # {{{ self.hidden_categories.add(cat) 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._run_rebuild() self.endResetModel() @@ -379,10 +389,6 @@ class TagsModel(QAbstractItemModel): # {{{ else: collapse_model = 'partition' 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): components = [t.strip() for t in name.split('.') if t.strip()] @@ -423,15 +429,14 @@ class TagsModel(QAbstractItemModel): # {{{ if not tag.sort: c = ' ' else: - if not use_span_contractions: + if not self.do_contraction: c = icu_upper(tag.sort)[0] else: v = icu_upper(tag.sort) - le = span_contractions(v) - if le > 0: - c = v[:le] - else: - c = v[0] + c = v[0] + for s in self.contraction_set: + if len(s) > len(c) and v.startswith(s): + c = s if c not in chardict: chardict[c] = [idx, idx] else: