Add back extra column content

This commit is contained in:
Veronica Berglyd Olsen
2025-03-23 16:41:40 +01:00
parent 9d63a018e8
commit 95d8e3ac98
7 changed files with 113 additions and 301 deletions
+36 -6
View File
@@ -36,6 +36,7 @@ from novelwriter.common import checkInt, isListInstance, isTitleTag
from novelwriter.constants import nwKeyWords, nwStyles
if TYPE_CHECKING: # pragma: no cover
from novelwriter.core.index import TagsIndex
from novelwriter.core.item import NWItem
logger = logging.getLogger(__name__)
@@ -56,12 +57,13 @@ class IndexNode:
must be reset each time the item is re-indexed.
"""
__slots__ = ("_handle", "_item", "_headings", "_count", "_notes")
__slots__ = ("_tags", "_handle", "_item", "_headings", "_notes", "_count")
def __init__(self, tHandle: str, nwItem: NWItem) -> None:
def __init__(self, tagsIndex: TagsIndex, tHandle: str, nwItem: NWItem) -> None:
self._tags = tagsIndex
self._handle = tHandle
self._item = nwItem
self._headings: dict[str, IndexHeading] = {TT_NONE: IndexHeading(TT_NONE)}
self._headings: dict[str, IndexHeading] = {TT_NONE: IndexHeading(self._tags, TT_NONE)}
self._notes: dict[str, set[str]] = {}
self._count = 0
return
@@ -179,7 +181,7 @@ class IndexNode:
"""Unpack an item entry from the data."""
for key, entry in data.items():
if isTitleTag(key):
heading = IndexHeading(key)
heading = IndexHeading(self._tags, key)
heading.unpackData(entry)
self.addHeading(heading)
elif key == "document":
@@ -202,9 +204,16 @@ class IndexHeading:
of all references made under the heading.
"""
__slots__ = ("_key", "_line", "_level", "_title", "_counts", "_tag", "_refs", "_comments")
__slots__ = (
"_tags", "_key", "_line", "_level", "_title",
"_counts", "_tag", "_refs", "_comments",
)
def __init__(self, key: str, line: int = 0, level: str = "H0", title: str = "") -> None:
def __init__(
self, tagsIndex: TagsIndex, key: str, line: int = 0,
level: str = "H0", title: str = "",
) -> None:
self._tags = tagsIndex
self._key = key
self._line = line
self._level = level
@@ -314,6 +323,27 @@ class IndexHeading:
self._refs[tag].add(keyword)
return
##
# Getters
##
def getReferences(self) -> dict[str, list[str]]:
"""Extract all references for this heading."""
refs = {x: [] for x in nwKeyWords.VALID_KEYS}
for tag, types in self._refs.items():
for keyword in types:
if keyword in refs:
refs[keyword].append(self._tags.tagName(tag))
return refs
def getReferencesByKeyword(self, keyword: str) -> list[str]:
"""Extract all references for this heading."""
refs = []
for tag, types in self._refs.items():
if keyword in types:
refs.append(self._tags.tagName(tag))
return refs
##
# Data Methods
##