Orphaned files are now put back in the tree, or rejected if nowhere to put them

This commit is contained in:
Veronica K. B. Olsen
2020-12-21 01:28:19 +01:00
parent 1ea12fedb9
commit 6a188a5906
3 changed files with 24 additions and 9 deletions
+13 -6
View File
@@ -1324,23 +1324,30 @@ class NWProject():
oClass = None oClass = None
oLayout = None oLayout = None
if aDoc.openDocument(oHandle, showStatus=False, isOrphan=True) is not None: if aDoc.openDocument(oHandle, showStatus=False, isOrphan=True) is not None:
oName, _, oClass, oLayout = aDoc.getMeta() oName, oParent, oClass, oLayout = aDoc.getMeta()
if oName == "": if oName:
oName = "Recovered: %s" % oName.lstrip("Recovered: ")
else:
nOrph += 1 nOrph += 1
oName = "Orphaned File %d" % nOrph oName = "Recovered File %d" % nOrph
if oClass is None: if oClass is None:
oClass = nwItemClass.NO_CLASS oClass = nwItemClass.NOVEL
if oLayout is None: if oLayout is None:
oLayout = nwItemLayout.NO_LAYOUT oLayout = nwItemLayout.NOTE
if oParent is None or not self.projTree.isValid(oParent):
oParent = self.projTree.findRoot(oClass)
if oParent is None:
oParent = self.projTree.findRoot(nwItemClass.NOVEL)
orphItem = NWItem(self) orphItem = NWItem(self)
orphItem.setName(oName) orphItem.setName(oName)
orphItem.setType(nwItemType.FILE) orphItem.setType(nwItemType.FILE)
orphItem.setClass(oClass) orphItem.setClass(oClass)
orphItem.setLayout(oLayout) orphItem.setLayout(oLayout)
self.projTree.append(oHandle, None, orphItem) self.projTree.append(oHandle, oParent, orphItem)
return True return True
+5
View File
@@ -294,6 +294,11 @@ class NWTree():
tTree.append(tHandle) tTree.append(tHandle)
return tTree return tTree
def isValid(self, tHandle):
"""Check if a handle exists in the project.
"""
return tHandle in self._treeOrder
## ##
# Setters # Setters
## ##
+6 -3
View File
@@ -851,7 +851,6 @@ class GuiProjectTree(QTreeWidget):
newItem.setData(self.C_NAME, Qt.UserRole, tHandle) newItem.setData(self.C_NAME, Qt.UserRole, tHandle)
newItem.setData(self.C_COUNT, Qt.UserRole, 0) newItem.setData(self.C_COUNT, Qt.UserRole, 0)
self.theMap[tHandle] = newItem
if pHandle is None: if pHandle is None:
if nwItem.itemType == nwItemType.ROOT: if nwItem.itemType == nwItemType.ROOT:
self.addTopLevelItem(newItem) self.addTopLevelItem(newItem)
@@ -859,8 +858,11 @@ class GuiProjectTree(QTreeWidget):
elif nwItem.itemType == nwItemType.TRASH: elif nwItem.itemType == nwItemType.TRASH:
self.addTopLevelItem(newItem) self.addTopLevelItem(newItem)
else: else:
self._addOrphanedRoot() self.makeAlert(
self.orphRoot.addChild(newItem) "There is nowhere to add file with name '%s'" % nwItem.itemName, nwAlert.ERROR
)
# self._addOrphanedRoot()
# self.orphRoot.addChild(newItem)
else: else:
byIndex = -1 byIndex = -1
if nHandle is not None and nHandle in self.theMap: if nHandle is not None and nHandle in self.theMap:
@@ -874,6 +876,7 @@ class GuiProjectTree(QTreeWidget):
self.theMap[pHandle].addChild(newItem) self.theMap[pHandle].addChild(newItem)
self.propagateCount(tHandle, nwItem.wordCount) self.propagateCount(tHandle, nwItem.wordCount)
self.theMap[tHandle] = newItem
self.setTreeItemValues(tHandle) self.setTreeItemValues(tHandle)
newItem.setExpanded(nwItem.isExpanded) newItem.setExpanded(nwItem.isExpanded)