Orphaned files are now put back in the tree, or rejected if nowhere to put them
This commit is contained in:
+13
-6
@@ -1324,23 +1324,30 @@ class NWProject():
|
||||
oClass = None
|
||||
oLayout = 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
|
||||
oName = "Orphaned File %d" % nOrph
|
||||
oName = "Recovered File %d" % nOrph
|
||||
|
||||
if oClass is None:
|
||||
oClass = nwItemClass.NO_CLASS
|
||||
oClass = nwItemClass.NOVEL
|
||||
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.setName(oName)
|
||||
orphItem.setType(nwItemType.FILE)
|
||||
orphItem.setClass(oClass)
|
||||
orphItem.setLayout(oLayout)
|
||||
self.projTree.append(oHandle, None, orphItem)
|
||||
self.projTree.append(oHandle, oParent, orphItem)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -294,6 +294,11 @@ class NWTree():
|
||||
tTree.append(tHandle)
|
||||
return tTree
|
||||
|
||||
def isValid(self, tHandle):
|
||||
"""Check if a handle exists in the project.
|
||||
"""
|
||||
return tHandle in self._treeOrder
|
||||
|
||||
##
|
||||
# Setters
|
||||
##
|
||||
|
||||
+6
-3
@@ -851,7 +851,6 @@ class GuiProjectTree(QTreeWidget):
|
||||
newItem.setData(self.C_NAME, Qt.UserRole, tHandle)
|
||||
newItem.setData(self.C_COUNT, Qt.UserRole, 0)
|
||||
|
||||
self.theMap[tHandle] = newItem
|
||||
if pHandle is None:
|
||||
if nwItem.itemType == nwItemType.ROOT:
|
||||
self.addTopLevelItem(newItem)
|
||||
@@ -859,8 +858,11 @@ class GuiProjectTree(QTreeWidget):
|
||||
elif nwItem.itemType == nwItemType.TRASH:
|
||||
self.addTopLevelItem(newItem)
|
||||
else:
|
||||
self._addOrphanedRoot()
|
||||
self.orphRoot.addChild(newItem)
|
||||
self.makeAlert(
|
||||
"There is nowhere to add file with name '%s'" % nwItem.itemName, nwAlert.ERROR
|
||||
)
|
||||
# self._addOrphanedRoot()
|
||||
# self.orphRoot.addChild(newItem)
|
||||
else:
|
||||
byIndex = -1
|
||||
if nHandle is not None and nHandle in self.theMap:
|
||||
@@ -874,6 +876,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
self.theMap[pHandle].addChild(newItem)
|
||||
self.propagateCount(tHandle, nwItem.wordCount)
|
||||
|
||||
self.theMap[tHandle] = newItem
|
||||
self.setTreeItemValues(tHandle)
|
||||
newItem.setExpanded(nwItem.isExpanded)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user