diff --git a/nw/core/index.py b/nw/core/index.py index d1bc7449..6ace8988 100644 --- a/nw/core/index.py +++ b/nw/core/index.py @@ -611,6 +611,14 @@ class NWIndex(): return theRefs + def getNovelData(self, tHandle, sTitle): + """Return the novel data of a given handle and title. + """ + if tHandle in self.novelIndex: + if sTitle in self.novelIndex[tHandle]: + return self.novelIndex[tHandle][sTitle] + return None + def getBackReferenceList(self, tHandle): """Build a list of files referring back to our file, specified by tHandle. diff --git a/nw/gui/outlinedetails.py b/nw/gui/outlinedetails.py index c4e54f16..5e1d1105 100644 --- a/nw/gui/outlinedetails.py +++ b/nw/gui/outlinedetails.py @@ -271,11 +271,10 @@ class GuiOutlineDetails(QScrollArea): """Update the content of the tree with the given handle and line number pointing to a header. """ - try: - nwItem = self.theProject.projTree[tHandle] - novIdx = self.theIndex.novelIndex[tHandle][sTitle] - theRefs = self.theIndex.getReferences(tHandle, sTitle) - except Exception: + nwItem = self.theProject.projTree[tHandle] + novIdx = self.theIndex.getNovelData(tHandle, sTitle) + theRefs = self.theIndex.getReferences(tHandle, sTitle) + if nwItem is None or novIdx is None or theRefs == {}: return False if novIdx["level"] in self.LVL_MAP: diff --git a/tests/test_core_index.py b/tests/test_core_index.py index d08cbd49..cbb8ff8b 100644 --- a/tests/test_core_index.py +++ b/tests/test_core_index.py @@ -218,7 +218,7 @@ def testCoreIndex_CheckThese(nwMinimal, dummyGUI): "@pov: Jane" )) assert theIndex.tagIndex == {"Jane": [2, cHandle, "CHARACTER", "T000001"]} - assert theIndex.novelIndex[nHandle]["T000001"]["title"] == "Hello World!" + assert theIndex.getNovelData(nHandle, "T000001")["title"] == "Hello World!" assert theIndex.novelChangedSince(0) assert theIndex.notesChangedSince(0) @@ -294,7 +294,7 @@ def testCoreIndex_ScanText(nwMinimal, dummyGUI): "Well, not really.\n" )) assert str(theIndex.tagIndex) == "{'Jane': [2, '%s', 'CHARACTER', 'T000001']}" % cHandle - assert theIndex.novelIndex[nHandle]["T000001"]["title"] == "Hello World!" + assert theIndex.getNovelData(nHandle, "T000001")["title"] == "Hello World!" # Check that title sections are indexed properly assert theIndex.scanText(nHandle, ( @@ -427,6 +427,9 @@ def testCoreIndex_ExtractData(nwMinimal, dummyGUI): nHandle = theProject.newFile("Hello", nwItemClass.NOVEL, "a508bb932959c") cHandle = theProject.newFile("Jane", nwItemClass.CHARACTER, "afb3043c7b2b3") + assert theIndex.getNovelData("", "") is None + assert theIndex.getNovelData("a508bb932959c", "") is None + assert theIndex.scanText(cHandle, ( "# Jane Smith\n" "@tag: Jane\n"