Add outline navigation to viewer

This commit is contained in:
Veronica Berglyd Olsen
2024-03-17 14:04:11 +01:00
parent ca3337914c
commit add499af89
3 changed files with 70 additions and 20 deletions
+9 -6
View File
@@ -519,11 +519,16 @@ class NWIndex:
def getItemHeading(self, tHandle: str, sTitle: str) -> IndexHeading | None:
"""Get the heading entry for a specific item and heading."""
tItem = self._itemIndex[tHandle]
if isinstance(tItem, IndexItem):
if tItem := self._itemIndex[tHandle]:
return tItem[sTitle]
return None
def iterItemHeadings(self, tHandle: str) -> Iterator[str, IndexHeading]:
"""Get all headings for a specific item."""
if tItem := self._itemIndex[tHandle]:
yield from tItem.items()
return []
def novelStructure(
self, rootHandle: str | None = None, activeOnly: bool = True
) -> Iterator[tuple[str, str, str, IndexHeading]]:
@@ -900,13 +905,11 @@ class ItemIndex:
if rHandle is None:
for sTitle in self._items[tHandle].headings():
hItem = self._items[tHandle][sTitle]
if hItem:
if hItem := self._items[tHandle][sTitle]:
yield tHandle, sTitle, hItem
elif tItem.itemRoot == rHandle:
for sTitle in self._items[tHandle].headings():
hItem = self._items[tHandle][sTitle]
if hItem:
if hItem := self._items[tHandle][sTitle]:
yield tHandle, sTitle, hItem
return