Add tag value for novel docs in Outline and Novel View (#2428)

This commit is contained in:
Veronica Berglyd Olsen
2025-06-24 16:05:59 +02:00
parent 4b5f3c8af8
commit ad2288e2fc
3 changed files with 12 additions and 7 deletions
+8 -6
View File
@@ -708,17 +708,19 @@ class Index:
return 0, 0, 0
def getReferences(self, tHandle: str, sTitle: str | None = None) -> dict[str, list[str]]:
"""Extract all references made in a file, and optionally title
section.
"""Extract all tags and references made in a file, and
optionally title section.
"""
tRefs = {x: [] for x in nwKeyWords.VALID_KEYS}
refs = {x: [] for x in nwKeyWords.VALID_KEYS}
for rTitle, hItem in self._itemIndex.iterItemHeaders(tHandle):
if sTitle is None or sTitle == rTitle:
for aTag, refTypes in hItem.references.items():
for refType in refTypes:
if refType in tRefs:
tRefs[refType].append(self._tagsIndex.tagName(aTag))
return tRefs
if refType in refs:
refs[refType].append(self._tagsIndex.tagName(aTag))
if tag := hItem.tag:
refs[nwKeyWords.TAG_KEY] = [self._tagsIndex.tagName(tag)]
return refs
def getReferenceForHeader(self, tHandle: str, nHead: int, keyClass: str) -> list[str]:
"""Get the display names for a tags class for insertion into a
+3 -1
View File
@@ -342,12 +342,14 @@ class IndexHeading:
##
def getReferences(self) -> dict[str, list[str]]:
"""Extract all references for this heading."""
"""Extract all tags and 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 and (name := self._cache.tags.tagName(tag)):
refs[keyword].append(name)
if tag := self._tag:
refs[nwKeyWords.TAG_KEY] = [self._cache.tags.tagName(tag)]
return refs
def getReferencesByKeyword(self, keyword: str) -> list[str]:
+1
View File
@@ -593,6 +593,7 @@ class GuiNovelTree(NTreeView):
lines = []
if head := SHARED.project.index.getItemHeading(tHandle, sTitle):
tags = head.getReferences()
appendTags(tags, nwKeyWords.TAG_KEY, lines)
appendTags(tags, nwKeyWords.POV_KEY, lines)
appendTags(tags, nwKeyWords.FOCUS_KEY, lines)
appendTags(tags, nwKeyWords.CHAR_KEY, lines)