Fixed some potential issues with getting the trash folder handle, and made some minor improvements to index class methods

This commit is contained in:
Veronica K. B. Olsen
2020-09-30 21:50:59 +02:00
parent d382e70d72
commit 6fc5dad938
3 changed files with 27 additions and 28 deletions
+18 -26
View File
@@ -279,8 +279,8 @@ class NWIndex():
if theItem.itemLayout == nwItemLayout.NO_LAYOUT:
logger.error("Not indexing no-layout item %s" % tHandle)
return False
if theRoot is None:
logger.error("Not indexing homeless item %s" % tHandle)
if theItem.parHandle is None:
logger.error("Not indexing orphaned item %s" % tHandle)
return False
# Run word counter for the whole text
@@ -288,7 +288,7 @@ class NWIndex():
self.textCounts[tHandle] = [cC, wC, pC]
# If the file is archived or trashed, we don't index the file itself
if theItem.parHandle == self.theProject.projTree.trashRoot():
if self.theProject.projTree.isTrashRoot(theItem.parHandle):
logger.error("Not indexing trash item %s" % tHandle)
return False
if theRoot.itemClass == nwItemClass.ARCHIVE:
@@ -459,16 +459,12 @@ class NWIndex():
"""Validate and save the information about a reference to a tag
in another file.
"""
isValid, theBits, thePos = self.scanThis(aLine)
isValid, theBits, _ = self.scanThis(aLine)
if not isValid or len(theBits) == 0:
return False
sTitle = "T%06d" % nTitle
if sTitle not in self.refIndex[tHandle]:
logger.error("Cannot save tags to file %s, no title %s" % (tHandle, sTitle))
return False
if theBits[0] != nwKeyWords.TAG_KEY:
if sTitle in self.refIndex[tHandle] and theBits[0] != nwKeyWords.TAG_KEY:
for aVal in theBits[1:]:
self.refIndex[tHandle][sTitle]["tags"].append([nLine, theBits[0], aVal])
@@ -574,15 +570,14 @@ class NWIndex():
"""
theStructure = []
for tItem in self.theProject.projTree:
if tItem is None:
continue
if not tItem.isExported and skipExcluded:
continue
tHandle = tItem.itemHandle
if tHandle not in self.novelIndex:
continue
for sTitle in sorted(self.novelIndex[tHandle].keys()):
theStructure.append("%s:%s" % (tHandle, sTitle))
if tItem is not None:
if not tItem.isExported and skipExcluded:
continue
tHandle = tItem.itemHandle
if tHandle not in self.novelIndex:
continue
for sTitle in sorted(self.novelIndex[tHandle].keys()):
theStructure.append("%s:%s" % (tHandle, sTitle))
return theStructure
@@ -624,14 +619,11 @@ class NWIndex():
if tHandle not in self.refIndex:
return theRefs
try:
for refTitle in self.refIndex[tHandle]:
for nLine, tKey, tTag in self.refIndex[tHandle][refTitle]["tags"]:
if sTitle is None or sTitle == refTitle:
theRefs[tKey].append(tTag)
except Exception as e:
logger.error("Failed to generate reference list")
logger.error(str(e))
for refTitle in self.refIndex[tHandle]:
theTags = self.refIndex[tHandle][refTitle].get("tags", None)
for aTag in theTags:
if len(aTag) == 3 and (sTitle is None or sTitle == refTitle):
theRefs[aTag[1]].append(aTag[2])
return theRefs
+7
View File
@@ -213,6 +213,13 @@ class NWTree():
return self._trashRoot
return None
def isTrashRoot(self, tHandle):
"""Check if a handle is the trash folder.
"""
if self._trashRoot is None:
return False
return tHandle == self._trashRoot
def archiveRoot(self):
"""Returns the handle of the archive folder, or None if there
isn't one.
+2 -2
View File
@@ -209,7 +209,7 @@ class GuiProjectTree(QTreeWidget):
)
return False
if pHandle == self.theProject.projTree.trashRoot():
if self.theProject.projTree.isTrashRoot(pHandle):
self.makeAlert(
"Cannot add new files or folders to the %s folder." % (
nwLabels.CLASS_NAME[nwItemClass.TRASH]
@@ -411,7 +411,7 @@ class GuiProjectTree(QTreeWidget):
return False
pHandle = nwItemS.parHandle
if pHandle is not None and pHandle == self.theProject.projTree.trashRoot():
if self.theProject.projTree.isTrashRoot(pHandle):
# If the file is in the trash folder already, as the
# user if they want to permanently delete the file.
doPermanent = False