Fix partitioning problems in tag browser with fields that have no name, such as identifiers and formats

This commit is contained in:
Kovid Goyal 2012-06-03 16:42:48 +05:30
commit f90809eaf1

View File

@ -418,8 +418,11 @@ class TagsModel(QAbstractItemModel): # {{{
chardict[c][1] = idx
# sort the ranges to facilitate detecting overlap
if len(chardict) == 1 and ' ' in chardict:
# The category could not be partitioned.
collapse_model = 'disable'
else:
ranges = sorted([(v[0], v[1], c) for c,v in chardict.items()])
# Create a list of 'first letters' to use for each item in
# the category. The list is generated using the ranges. Overlaps
# are filled with the character that first occurs.
@ -448,13 +451,19 @@ class TagsModel(QAbstractItemModel): # {{{
else:
d['last'] = data[key][cat_len-1]
name = eval_formatter.safe_format(collapse_template,
d, 'TAG_VIEW', None)
d, '##TAG_VIEW##', None)
if name.startswith('##TAG_VIEW##'):
# Formatter threw an exception. Don't create subnode
node_parent = category
else:
sub_cat = self.create_node(parent=category, data = name,
tooltip = None, temporary=True,
category_icon = category_node.icon,
category_key=category_node.category_key,
icon_map=self.icon_state_map)
sub_cat.tag.is_searchable = False
sub_cat.is_gst = is_gst
node_parent = sub_cat
else: # by 'first letter'
cl = cl_list[idx]
if cl != collapse_letter: