mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-07 09:01:38 -04:00
Edit Book: Update the Table of Contents view automatically when the ncx file is edited.
Also avoid unnecessary rebuilds of the Table of Contents view.
This commit is contained in:
parent
a480c5c5a0
commit
50812974e0
@ -186,9 +186,10 @@ def get_toc(container, verify_destinations=True):
|
||||
toc = find_existing_toc(container)
|
||||
if toc is None or not container.has_name(toc):
|
||||
ans = TOC()
|
||||
ans.lang = ans.uid = None
|
||||
ans.lang = ans.uid = ans.toc_file_name = None
|
||||
return ans
|
||||
ans = parse_ncx(container, toc)
|
||||
ans.toc_file_name = toc
|
||||
if verify_destinations:
|
||||
verify_toc_destinations(container, ans)
|
||||
return ans
|
||||
|
@ -1122,6 +1122,10 @@ class Boss(QObject):
|
||||
|
||||
def editor_data_changed(self, editor):
|
||||
self.gui.preview.start_refresh_timer()
|
||||
for name, ed in editors.iteritems():
|
||||
if ed is editor:
|
||||
self.gui.toc_view.start_refresh_timer(name)
|
||||
break
|
||||
|
||||
def editor_undo_redo_state_changed(self, *args):
|
||||
self.apply_current_editor_state()
|
||||
|
@ -118,7 +118,6 @@ class TOCViewer(QWidget):
|
||||
self.setLayout(l)
|
||||
l.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
self.is_visible = False
|
||||
self.view = QTreeWidget(self)
|
||||
self.delegate = Delegate(self.view)
|
||||
self.view.setItemDelegate(self.delegate)
|
||||
@ -136,9 +135,22 @@ class TOCViewer(QWidget):
|
||||
|
||||
self.refresh_action = QAction(QIcon(I('view-refresh.png')), _('&Refresh'), self)
|
||||
self.refresh_action.triggered.connect(self.refresh)
|
||||
self.refresh_timer = t = QTimer(self)
|
||||
t.setInterval(1000), t.setSingleShot(True)
|
||||
t.timeout.connect(self.auto_refresh)
|
||||
self.toc_name = None
|
||||
self.currently_editing = None
|
||||
|
||||
def start_refresh_timer(self, name):
|
||||
if self.isVisible() and self.toc_name == name:
|
||||
self.refresh_timer.start()
|
||||
|
||||
def auto_refresh(self):
|
||||
if self.isVisible():
|
||||
self.refresh()
|
||||
|
||||
def refresh(self):
|
||||
self.refresh_requested.emit() # Give boos a chance to commit dirty editors to the container
|
||||
self.refresh_requested.emit() # Give boss a chance to commit dirty editors to the container
|
||||
self.build()
|
||||
|
||||
def item_pressed(self, item):
|
||||
@ -176,6 +188,7 @@ class TOCViewer(QWidget):
|
||||
if c is None:
|
||||
return
|
||||
toc = get_toc(c, verify_destinations=False)
|
||||
self.toc_name = getattr(toc, 'toc_file_name', None)
|
||||
|
||||
def process_node(toc, parent):
|
||||
for child in toc:
|
||||
@ -191,12 +204,12 @@ class TOCViewer(QWidget):
|
||||
self.view.clear()
|
||||
process_node(toc, self.view.invisibleRootItem())
|
||||
|
||||
def visibility_changed(self, visible):
|
||||
self.is_visible = visible
|
||||
if visible:
|
||||
def showEvent(self, ev):
|
||||
if self.toc_name is None or not ev.spontaneous():
|
||||
self.build()
|
||||
return super(TOCViewer, self).showEvent(ev)
|
||||
|
||||
def update_if_visible(self):
|
||||
if self.is_visible:
|
||||
if self.isVisible():
|
||||
self.build()
|
||||
|
||||
|
@ -612,7 +612,6 @@ class Main(MainWindow):
|
||||
d.setWidget(self.toc_view)
|
||||
self.addDockWidget(Qt.LeftDockWidgetArea, d)
|
||||
d.close() # Hidden by default
|
||||
d.visibilityChanged.connect(self.toc_view.visibility_changed)
|
||||
|
||||
d = create(_('Checkpoints'), 'checkpoints')
|
||||
d.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea | Qt.BottomDockWidgetArea | Qt.TopDockWidgetArea)
|
||||
|
Loading…
x
Reference in New Issue
Block a user