From ad2288e2fce5292a042dbc04d851401f2c5adebb Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 24 Jun 2025 16:05:59 +0200 Subject: [PATCH] Add tag value for novel docs in Outline and Novel View (#2428) --- novelwriter/core/index.py | 14 ++++++++------ novelwriter/core/indexdata.py | 4 +++- novelwriter/gui/noveltree.py | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/novelwriter/core/index.py b/novelwriter/core/index.py index d8e9c8e4..07933690 100644 --- a/novelwriter/core/index.py +++ b/novelwriter/core/index.py @@ -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 diff --git a/novelwriter/core/indexdata.py b/novelwriter/core/indexdata.py index 070558ce..4ddad943 100644 --- a/novelwriter/core/indexdata.py +++ b/novelwriter/core/indexdata.py @@ -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]: diff --git a/novelwriter/gui/noveltree.py b/novelwriter/gui/noveltree.py index 752c6d39..86913b61 100644 --- a/novelwriter/gui/noveltree.py +++ b/novelwriter/gui/noveltree.py @@ -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)