diff --git a/nw/gui/elements/outline.py b/nw/gui/elements/outline.py index 75e4f396..33fd5469 100644 --- a/nw/gui/elements/outline.py +++ b/nw/gui/elements/outline.py @@ -118,28 +118,24 @@ class GuiProjectOutline(QWidget): if tHandle not in self.theIndex.novelIndex: continue - nwItem = self.theProject.getItem(tHandle) - if nwItem.itemLayout == nwItemLayout.NOTE: - continue - - for tEntry in self.theIndex.novelIndex[tHandle]: - - nTitle = str(tEntry[0]) - tTitle = tEntry[2] - tLevel = str(tEntry[1]) + for sTitle in self.theIndex.novelIndex[tHandle]: + + nwItem = self.theProject.getItem(tHandle) + tTitle = self.theIndex.novelIndex[tHandle][sTitle][1] + tLevel = self.theIndex.novelIndex[tHandle][sTitle][0] tLabel = nwItem.itemName - tItem = self._createTreeItem(tHandle, nTitle, tTitle, tLevel, tLabel) + tItem = self._createTreeItem(tHandle, sTitle, tTitle, tLevel, tLabel) - if tEntry[1] == 1: + if tLevel == "H1": currTitle = tItem self.mainTree.addTopLevelItem(tItem) - elif tEntry[1] == 2: + elif tLevel == "H2": if currTitle is None: self.mainTree.addTopLevelItem(tItem) else: currTitle.addChild(tItem) currChapter = tItem - elif tEntry[1] == 3: + elif tLevel == "H3": if currChapter is None: if currTitle is None: self.mainTree.addTopLevelItem(tItem) @@ -148,7 +144,7 @@ class GuiProjectOutline(QWidget): else: currChapter.addChild(tItem) currScene = tItem - elif tEntry[1] == 4: + elif tLevel == "H4": if currScene is None: if currChapter is None: if currTitle is None: @@ -168,15 +164,15 @@ class GuiProjectOutline(QWidget): # Internal Functions ## - def _createTreeItem(self, tHandle, nTitle, tTitle, tLevel, tLabel): + def _createTreeItem(self, tHandle, sTitle, tTitle, tLevel, tLabel): newItem = QTreeWidgetItem() newItem.setText(self.I_TITLE, tTitle) newItem.setText(self.I_LEVEL, tLevel) newItem.setText(self.I_LABEL, tLabel) - newItem.setText(self.I_LINE, nTitle) + newItem.setText(self.I_LINE, sTitle) - cC, wC, pC = self.theIndex.getCounts(tHandle, nTitle) + cC, wC, pC = self.theIndex.getCounts(tHandle, sTitle) newItem.setText(self.I_CCOUNT, str(cC)) newItem.setText(self.I_WCOUNT, str(wC)) newItem.setText(self.I_PCOUNT, str(pC)) @@ -192,7 +188,7 @@ class GuiProjectOutline(QWidget): objectList = [] entityList = [] customList = [] - for tKey, tTag in self.theIndex.getReferences(tHandle, nTitle): + for tKey, tTag in self.theIndex.getReferences(tHandle, sTitle): if tKey == nwKeyWords.POV_KEY: povList.append(tTag) elif tKey == nwKeyWords.CHAR_KEY: diff --git a/nw/project/index.py b/nw/project/index.py index f0e93fbc..ef4f7abf 100644 --- a/nw/project/index.py +++ b/nw/project/index.py @@ -37,14 +37,14 @@ class NWIndex(): nwKeyWords.CUSTOM_KEY ] TAG_CLASS = { - nwKeyWords.CHAR_KEY : [nwItemClass.CHARACTER, 1], - nwKeyWords.POV_KEY : [nwItemClass.CHARACTER, 2], - nwKeyWords.PLOT_KEY : [nwItemClass.PLOT, 1], - nwKeyWords.TIME_KEY : [nwItemClass.TIMELINE, 1], - nwKeyWords.WORLD_KEY : [nwItemClass.WORLD, 1], - nwKeyWords.OBJECT_KEY : [nwItemClass.OBJECT, 1], - nwKeyWords.ENTITY_KEY : [nwItemClass.ENTITY, 1], - nwKeyWords.CUSTOM_KEY : [nwItemClass.CUSTOM, 1], + nwKeyWords.CHAR_KEY : nwItemClass.CHARACTER, + nwKeyWords.POV_KEY : nwItemClass.CHARACTER, + nwKeyWords.PLOT_KEY : nwItemClass.PLOT, + nwKeyWords.TIME_KEY : nwItemClass.TIMELINE, + nwKeyWords.WORLD_KEY : nwItemClass.WORLD, + nwKeyWords.OBJECT_KEY : nwItemClass.OBJECT, + nwKeyWords.ENTITY_KEY : nwItemClass.ENTITY, + nwKeyWords.CUSTOM_KEY : nwItemClass.CUSTOM, } def __init__(self, theProject, theParent): @@ -211,18 +211,19 @@ class NWIndex(): self.indexBroken = True for tHandle in self.refIndex: - for tEntry in self.refIndex[tHandle]: - if len(tEntry) != 4: - self.indexBroken = True + for sTitle in self.refIndex[tHandle]: + for tEntry in self.refIndex[tHandle][sTitle]: + if len(tEntry) != 3: + self.indexBroken = True for tHandle in self.novelIndex: - for tEntry in self.novelIndex[tHandle]: - if len(tEntry) != 4: + for sLine in self.novelIndex[tHandle]: + if len(self.novelIndex[tHandle][sLine]) != 3: self.indexBroken = True for tHandle in self.noteIndex: - for tEntry in self.noteIndex[tHandle]: - if len(tEntry) != 4: + for sLine in self.noteIndex[tHandle]: + if len(self.noteIndex[tHandle][sLine]) != 3: self.indexBroken = True for tHandle in self.fileCounts: @@ -240,7 +241,7 @@ class NWIndex(): if self.indexBroken: self.clearIndex() self.theParent.makeAlert( - "The project index loaded from cache contains errors. Triggering Rebuild Index.", + "The index loaded from project cache contains errors. Rebuilding index.", nwAlert.WARN ) @@ -273,12 +274,12 @@ class NWIndex(): logger.debug("Indexing item with handle %s" % tHandle) # Check file type, and reset its old index - self.refIndex[tHandle] = [] + self.refIndex[tHandle] = {} if itemLayout == nwItemLayout.NOTE: - self.noteIndex[tHandle] = [] + self.noteIndex[tHandle] = {} isNovel = False else: - self.novelIndex[tHandle] = [] + self.novelIndex[tHandle] = {} isNovel = True # Also clear references to file in tag index @@ -309,7 +310,7 @@ class NWIndex(): if nTitle > 0: lastText = "\n".join(theLines[nTitle-1:nLine-1]) cC, wC, pC = countWords(lastText) - theCounts[str(nTitle)] = [cC, wC, pC] + theCounts["T%d" % nTitle] = [cC, wC, pC] nTitle = nLine elif aLine.startswith(r"@"): @@ -317,14 +318,14 @@ class NWIndex(): self.indexTag(tHandle, aLine, nLine, itemClass) elif aLine.startswith(r"%synopsis:"): - theSynopsis[str(nTitle)] = aLine[10:].strip() + theSynopsis["T%d" % nTitle] = aLine[10:].strip() # Count words for remaining text after last heading if nTitle > 0: lastText = "\n".join(theLines[nTitle-1:]) cC, wC, pC = countWords(lastText) - theCounts[str(nTitle)] = [cC, wC, pC] - + theCounts["T%d" % nTitle] = [cC, wC, pC] + if theSynopsis: self.textSynopsis[tHandle] = theSynopsis if theCounts: @@ -342,27 +343,30 @@ class NWIndex(): """ if aLine.startswith("# "): - hDepth = 1 + hDepth = "H1" hText = aLine[2:].strip() elif aLine.startswith("## "): - hDepth = 2 + hDepth = "H2" hText = aLine[3:].strip() elif aLine.startswith("### "): - hDepth = 3 + hDepth = "H3" hText = aLine[4:].strip() elif aLine.startswith("#### "): - hDepth = 4 + hDepth = "H4" hText = aLine[5:].strip() else: return False + sTitle = "T%d" % nLine + self.refIndex[tHandle][sTitle] = [] + if hText != "": if isNovel: if tHandle in self.novelIndex: - self.novelIndex[tHandle].append([nLine, hDepth, hText, itemLayout.name]) + self.novelIndex[tHandle][sTitle] = [hDepth, hText, itemLayout.name] else: if tHandle in self.noteIndex: - self.noteIndex[tHandle].append([nLine, hDepth, hText, itemLayout.name]) + self.noteIndex[tHandle][sTitle] = [hDepth, hText, itemLayout.name] return True @@ -375,9 +379,11 @@ class NWIndex(): if not isValid or len(theBits) == 0: return False + sTitle = "T%d" % nTitle + if theBits[0] != nwKeyWords.TAG_KEY: for aVal in theBits[1:]: - self.refIndex[tHandle].append([nLine, theBits[0], aVal, nTitle]) + self.refIndex[tHandle][sTitle].append([nLine, theBits[0], aVal]) return True @@ -470,7 +476,7 @@ class NWIndex(): # If we're still here, we better check that the references exist for n in range(1,nBits): if theBits[n] in self.tagIndex: - isGood[n] = self.TAG_CLASS[theBits[0]][0].name == self.tagIndex[theBits[n]][2] + isGood[n] = self.TAG_CLASS[theBits[0]].name == self.tagIndex[theBits[n]][2] return isGood @@ -510,9 +516,10 @@ class NWIndex(): if tHandle not in self.refIndex: return theRefs - for nLine, tKey, tTag, nTitle in self.refIndex[tHandle]: - if tTitle is None or tTitle == str(nTitle): - theRefs.append((tKey, tTag)) + for sTitle in self.refIndex[tHandle]: + for nLine, tKey, tTag in self.refIndex[tHandle][sTitle]: + if tTitle is None or tTitle == sTitle: + theRefs.append((tKey, tTag)) return theRefs @@ -535,9 +542,10 @@ class NWIndex(): if theTag is not None: for tHandle in self.refIndex: - for nLine, tKey, tTag, nTitle in self.refIndex[tHandle]: - if tTag == theTag: - theRefs[tHandle] = nLine + for sTitle in self.refIndex[tHandle]: + for nLine, tKey, tTag in self.refIndex[tHandle][sTitle]: + if tTag == theTag: + theRefs[tHandle] = nLine return theRefs