Use lowest level ToC section in highlights panel

Matches search panel
This commit is contained in:
Kovid Goyal 2020-09-05 06:33:51 +05:30
parent 7dbefdf117
commit 80de18c2b6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 13 additions and 4 deletions

View File

@ -77,13 +77,21 @@ class Highlights(QTreeWidget):
self.uuid_map = {}
highlights = (h for h in highlights if not h.get('removed') and h.get('highlighted_text'))
section_map = defaultdict(list)
section_tt_map = {}
for h in self.sorted_highlights(highlights):
sec = h.get('top_level_section_title') or _('Unknown')
tsec = h.get('top_level_section_title')
lsec = h.get('lowest_level_section_title')
sec = lsec or tsec or _('Unknown')
if sec != tsec:
section_tt_map[sec] = tsec
section_map[sec].append(h)
for secnum, (sec, items) in enumerate(section_map.items()):
section = QTreeWidgetItem([sec], 1)
section.setFlags(Qt.ItemIsEnabled)
section.setFont(0, self.section_font)
tt = section_tt_map.get(sec)
if tt:
section.setToolTip(0, _('Top level section in Table of Contents:') + '\n' + tt)
self.addTopLevelItem(section)
section.setExpanded(True)
for itemnum, h in enumerate(items):

View File

@ -468,9 +468,10 @@ class Results(QTreeWidget): # {{{
lines = []
for i, node in enumerate(toc_nodes):
lines.append('\xa0\xa0' * i + '' + (node.get('title') or _('Unknown')))
tt = ngettext('Table of Contents section:', 'Table of Contents sections:', len(lines))
tt += '\n' + '\n'.join(lines)
section.setToolTip(0, tt)
if lines:
tt = ngettext('Table of Contents section:', 'Table of Contents sections:', len(lines))
tt += '\n' + '\n'.join(lines)
section.setToolTip(0, tt)
self.section_map[section_key] = section
self.addTopLevelItem(section)
section.setExpanded(True)