mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
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:
parent
a6ef8f7efd
commit
1a3ed93de4
@ -78,6 +78,19 @@ class TOC(object):
|
|||||||
for gc in child.iterdescendants():
|
for gc in child.iterdescendants():
|
||||||
yield gc
|
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
|
@property
|
||||||
def depth(self):
|
def depth(self):
|
||||||
"""The maximum depth of the navigation tree rooted at this node."""
|
"""The maximum depth of the navigation tree rooted at this node."""
|
||||||
|
@ -933,6 +933,7 @@ class TOCView(QWidget): # {{{
|
|||||||
if len(toc) == 0:
|
if len(toc) == 0:
|
||||||
return error_dialog(self, _('No items found'),
|
return error_dialog(self, _('No items found'),
|
||||||
_('No items were found that could be added to the Table of Contents.'), show=True)
|
_('No items were found that could be added to the Table of Contents.'), show=True)
|
||||||
|
toc.remove_duplicates()
|
||||||
self.insert_toc_fragment(toc)
|
self.insert_toc_fragment(toc)
|
||||||
|
|
||||||
def create_from_links(self):
|
def create_from_links(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user