Some minor cleanup and fixes

This commit is contained in:
Veronica K. B. Olsen
2020-12-21 11:03:47 +01:00
parent dc16077205
commit 4509545214
3 changed files with 53 additions and 42 deletions
+16 -1
View File
@@ -1317,10 +1317,12 @@ class NWProject():
# Handle orphans
aDoc = NWDoc(self, self.theParent)
nOrph = 0
noWhere = False
for oHandle in orphanFiles:
# Look for meta data
oName = ""
oParent = None
oClass = None
oLayout = None
if aDoc.openDocument(oHandle, showStatus=False, isOrphan=True) is not None:
@@ -1332,16 +1334,23 @@ class NWProject():
nOrph += 1
oName = "Recovered File %d" % nOrph
# Recover file meta data
if oClass is None:
oClass = nwItemClass.NOVEL
if oLayout is None:
oLayout = nwItemLayout.NOTE
if oParent is None or not self.projTree.isValid(oParent):
if oParent is None or not self.projTree.handleExists(oParent):
oParent = self.projTree.findRoot(oClass)
if oParent is None:
oParent = self.projTree.findRoot(nwItemClass.NOVEL)
# If the file still has no parent item, skip it
if oParent is None:
noWhere = True
continue
orphItem = NWItem(self)
orphItem.setName(oName)
orphItem.setType(nwItemType.FILE)
@@ -1349,6 +1358,12 @@ class NWProject():
orphItem.setLayout(oLayout)
self.projTree.append(oHandle, oParent, orphItem)
if noWhere:
self.makeAlert((
"One or more orphaned files could not be added back into the "
"project. Make sure at least a Novel root folder exists."
), nwAlert.WARN)
return True
def _appendSessionStats(self):