ToC Editor: When generating ToCs using headings/xpath ignore duplicate entries at the same level that have the same text. Fixes #1735799 [[Enhancement] Filter dupes in TOC editor](https://bugs.launchpad.net/calibre/+bug/1735799)

This commit is contained in:
Kovid Goyal 2018-08-22 13:30:17 +05:30
parent a6ef8f7efd
commit 1a3ed93de4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 14 additions and 0 deletions

View File

@ -78,6 +78,19 @@ class TOC(object):
for gc in child.iterdescendants():
yield gc
def remove_duplicates(self, only_text=True):
seen = set()
remove = []
for child in self:
key = child.title if only_text else (child.title, child.dest, (child.frag or None))
if key in seen:
remove.append(child)
else:
seen.add(key)
child.remove_duplicates()
for child in remove:
self.remove(child)
@property
def depth(self):
"""The maximum depth of the navigation tree rooted at this node."""

View File

@ -933,6 +933,7 @@ class TOCView(QWidget): # {{{
if len(toc) == 0:
return error_dialog(self, _('No items found'),
_('No items were found that could be added to the Table of Contents.'), show=True)
toc.remove_duplicates()
self.insert_toc_fragment(toc)
def create_from_links(self):