mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Port get_toc_data() to RapydScript
This commit is contained in:
parent
98ceaecd52
commit
86a5bf6656
@ -28,6 +28,33 @@ add_extra_css(def():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_toc_data(book):
|
||||||
|
spine = book.manifest.spine
|
||||||
|
spine_toc_map = {name: v'[]' for name in spine}
|
||||||
|
parent_map = {}
|
||||||
|
toc_id_map = {}
|
||||||
|
|
||||||
|
def process_node(node):
|
||||||
|
toc_id_map[node.id] = node
|
||||||
|
items = spine_toc_map[node.dest]
|
||||||
|
if items:
|
||||||
|
items.push(node)
|
||||||
|
children = node.children
|
||||||
|
if children:
|
||||||
|
for child in children:
|
||||||
|
parent_map[child.id] = node
|
||||||
|
process_node(child)
|
||||||
|
|
||||||
|
toc = book.manifest.toc
|
||||||
|
if toc:
|
||||||
|
process_node(toc)
|
||||||
|
return {
|
||||||
|
'spine': spine, 'spine_toc_map': spine_toc_map,
|
||||||
|
'spine_idx_map': {name: idx for idx, name in enumerate(spine)},
|
||||||
|
'parent_map': parent_map, 'toc_id_map': toc_id_map
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class SearchOverlay:
|
class SearchOverlay:
|
||||||
|
|
||||||
def __init__(self, view):
|
def __init__(self, view):
|
||||||
@ -90,7 +117,11 @@ class SearchOverlay:
|
|||||||
def clear_caches(self, book):
|
def clear_caches(self, book):
|
||||||
if self._worker:
|
if self._worker:
|
||||||
book = book or current_book()
|
book = book or current_book()
|
||||||
data = {'book_hash': book.book_hash, 'stored_files': book.stored_files, 'spine': book.manifest.spine}
|
self.toc_data = get_toc_data(book)
|
||||||
|
data = {
|
||||||
|
'book_hash': book.book_hash, 'stored_files': book.stored_files, 'spine': book.manifest.spine,
|
||||||
|
'toc_data': self.toc_data
|
||||||
|
}
|
||||||
self.worker.postMessage({'type': 'clear_caches', 'book': data})
|
self.worker.postMessage({'type': 'clear_caches', 'book': data})
|
||||||
|
|
||||||
def onkeydown(self, event):
|
def onkeydown(self, event):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user