Fix auto-complete bug and outline export bug (#2343)
This commit is contained in:
@@ -131,6 +131,12 @@ class Index:
|
||||
self._novelExtra = extra
|
||||
return
|
||||
|
||||
def setItemClass(self, tHandle: str, itemClass: nwItemClass) -> None:
|
||||
"""Update the class for all tags of a handle."""
|
||||
logger.info("Updating class for '%s'", tHandle)
|
||||
self._tagsIndex.updateClass(tHandle, itemClass.name)
|
||||
return
|
||||
|
||||
##
|
||||
# Public Methods
|
||||
##
|
||||
@@ -854,6 +860,15 @@ class TagsIndex:
|
||||
x.get("name", "") for x in self._tags.values() if x.get("class", "") == className
|
||||
]
|
||||
|
||||
def updateClass(self, tHandle: str, className: str) -> None:
|
||||
"""Update the class name of an item. This must be called when a
|
||||
document moves to another class.
|
||||
"""
|
||||
for entry in self._tags.values():
|
||||
if entry.get("handle") == tHandle:
|
||||
entry["class"] = className
|
||||
return
|
||||
|
||||
##
|
||||
# Pack/Unpack
|
||||
##
|
||||
|
||||
@@ -435,7 +435,11 @@ class NWItem:
|
||||
"""
|
||||
if self._parent is not None:
|
||||
# Only update for child items
|
||||
self.setClass(itemClass)
|
||||
if itemClass != self._class:
|
||||
self.setClass(itemClass)
|
||||
if self._type == nwItemType.FILE:
|
||||
# Notify the index of the class change
|
||||
self._project.index.setItemClass(self._handle, itemClass)
|
||||
|
||||
if self._layout == nwItemLayout.NO_LAYOUT:
|
||||
# If no layout is set, pick one
|
||||
|
||||
@@ -784,7 +784,8 @@ class GuiOutlineTree(QTreeWidget):
|
||||
):
|
||||
if novIdx.level != "H0" and (nwItem := SHARED.project.tree[tHandle]):
|
||||
refs = SHARED.project.index.getReferences(tHandle, sTitle)
|
||||
story = {k: v for k, v in novIdx.comments.items() if k in sMatch}.values()
|
||||
comments = dict(novIdx.comments.items())
|
||||
story = [comments.get(k, "") for k in sMatch]
|
||||
data.append([
|
||||
novIdx.level,
|
||||
novIdx.title,
|
||||
|
||||
@@ -1049,6 +1049,12 @@ def testCoreIndex_TagsIndex():
|
||||
assert tagsIndex.tagClass("Tag3") == nwItemClass.PLOT.name
|
||||
assert tagsIndex.tagClass("Tag4") is None
|
||||
|
||||
# Change class of item
|
||||
tagsIndex.updateClass("0000000000003", nwItemClass.WORLD.name)
|
||||
assert tagsIndex.tagClass("Tag3") == nwItemClass.WORLD.name
|
||||
tagsIndex.updateClass("0000000000003", nwItemClass.PLOT.name)
|
||||
assert tagsIndex.tagClass("Tag3") == nwItemClass.PLOT.name
|
||||
|
||||
# Pack Data
|
||||
assert tagsIndex.packData() == content
|
||||
|
||||
|
||||
Reference in New Issue
Block a user