mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Table of Contents Edit tool: When generating from XPath's add a checkbox to control if duplicate entries at the same level are added or not. Fixes #1790761 [Generate ToC from XPath](https://bugs.launchpad.net/calibre/+bug/1790761)
This commit is contained in:
parent
2fcf979b3c
commit
d07f070a66
@ -12,7 +12,7 @@ from threading import Thread
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from future_builtins import map
|
from future_builtins import map
|
||||||
|
|
||||||
from PyQt5.Qt import (QPushButton, QFrame, QMenu, QInputDialog,
|
from PyQt5.Qt import (QPushButton, QFrame, QMenu, QInputDialog, QCheckBox,
|
||||||
QDialog, QVBoxLayout, QDialogButtonBox, QSize, QStackedWidget, QWidget,
|
QDialog, QVBoxLayout, QDialogButtonBox, QSize, QStackedWidget, QWidget,
|
||||||
QLabel, Qt, pyqtSignal, QIcon, QTreeWidget, QGridLayout, QTreeWidgetItem,
|
QLabel, Qt, pyqtSignal, QIcon, QTreeWidget, QGridLayout, QTreeWidgetItem,
|
||||||
QToolButton, QItemSelectionModel, QCursor, QKeySequence, QSizePolicy)
|
QToolButton, QItemSelectionModel, QCursor, QKeySequence, QSizePolicy)
|
||||||
@ -60,6 +60,9 @@ class XPathDialog(QDialog): # {{{
|
|||||||
self.load_menu = QMenu(b)
|
self.load_menu = QMenu(b)
|
||||||
b.setMenu(self.load_menu)
|
b.setMenu(self.load_menu)
|
||||||
self.setup_load_button()
|
self.setup_load_button()
|
||||||
|
self.remove_duplicates_cb = QCheckBox(_('Do not add duplicate entries at the same level'))
|
||||||
|
self.remove_duplicates_cb.setChecked(self.prefs.get('xpath_toc_remove_duplicates', True))
|
||||||
|
l.addWidget(self.remove_duplicates_cb)
|
||||||
l.addStretch()
|
l.addStretch()
|
||||||
l.addWidget(bb)
|
l.addWidget(bb)
|
||||||
self.resize(self.sizeHint() + QSize(50, 75))
|
self.resize(self.sizeHint() + QSize(50, 75))
|
||||||
@ -115,6 +118,7 @@ class XPathDialog(QDialog): # {{{
|
|||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
if self.check():
|
if self.check():
|
||||||
|
self.prefs.set('xpath_toc_remove_duplicates', self.remove_duplicates_cb.isChecked())
|
||||||
super(XPathDialog, self).accept()
|
super(XPathDialog, self).accept()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -129,7 +133,7 @@ class ItemView(QFrame): # {{{
|
|||||||
delete_item = pyqtSignal()
|
delete_item = pyqtSignal()
|
||||||
flatten_item = pyqtSignal()
|
flatten_item = pyqtSignal()
|
||||||
go_to_root = pyqtSignal()
|
go_to_root = pyqtSignal()
|
||||||
create_from_xpath = pyqtSignal(object)
|
create_from_xpath = pyqtSignal(object, object)
|
||||||
create_from_links = pyqtSignal()
|
create_from_links = pyqtSignal()
|
||||||
create_from_files = pyqtSignal()
|
create_from_files = pyqtSignal()
|
||||||
flatten_toc = pyqtSignal()
|
flatten_toc = pyqtSignal()
|
||||||
@ -303,15 +307,15 @@ class ItemView(QFrame): # {{{
|
|||||||
l.addWidget(la, l.rowCount(), 0, 1, 2)
|
l.addWidget(la, l.rowCount(), 0, 1, 2)
|
||||||
|
|
||||||
def create_from_major_headings(self):
|
def create_from_major_headings(self):
|
||||||
self.create_from_xpath.emit(['//h:h%d'%i for i in xrange(1, 4)])
|
self.create_from_xpath.emit(['//h:h%d'%i for i in xrange(1, 4)], True)
|
||||||
|
|
||||||
def create_from_all_headings(self):
|
def create_from_all_headings(self):
|
||||||
self.create_from_xpath.emit(['//h:h%d'%i for i in xrange(1, 7)])
|
self.create_from_xpath.emit(['//h:h%d'%i for i in xrange(1, 7)], True)
|
||||||
|
|
||||||
def create_from_user_xpath(self):
|
def create_from_user_xpath(self):
|
||||||
d = XPathDialog(self, self.prefs)
|
d = XPathDialog(self, self.prefs)
|
||||||
if d.exec_() == d.Accepted and d.xpaths:
|
if d.exec_() == d.Accepted and d.xpaths:
|
||||||
self.create_from_xpath.emit(d.xpaths)
|
self.create_from_xpath.emit(d.xpaths, d.remove_duplicates_cb.isChecked())
|
||||||
|
|
||||||
def hide_azw3_warning(self):
|
def hide_azw3_warning(self):
|
||||||
self.w1.setVisible(False), self.w2.setVisible(False)
|
self.w1.setVisible(False), self.w2.setVisible(False)
|
||||||
@ -928,12 +932,14 @@ class TOCView(QWidget): # {{{
|
|||||||
process_node(self.root, toc, nodes)
|
process_node(self.root, toc, nodes)
|
||||||
self.highlight_item(nodes[0])
|
self.highlight_item(nodes[0])
|
||||||
|
|
||||||
def create_from_xpath(self, xpaths):
|
def create_from_xpath(self, xpaths, remove_duplicates=True):
|
||||||
toc = from_xpaths(self.ebook, xpaths)
|
toc = from_xpaths(self.ebook, xpaths)
|
||||||
|
print(1111111, remove_duplicates)
|
||||||
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()
|
if remove_duplicates:
|
||||||
|
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