The deleted and outtake files are now properly handled by the index

This commit is contained in:
Veronica K. B. Olsen
2020-08-16 16:51:07 +02:00
parent e0a824cfb6
commit 65131e87c7
2 changed files with 47 additions and 10 deletions
+23
View File
@@ -34,6 +34,7 @@ from time import time
from nw.constants import ( from nw.constants import (
nwFiles, nwKeyWords, nwItemType, nwItemClass, nwItemLayout, nwAlert nwFiles, nwKeyWords, nwItemType, nwItemClass, nwItemLayout, nwAlert
) )
from nw.core.document import NWDoc
from nw.core.tools import countWords from nw.core.tools import countWords
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -106,6 +107,8 @@ class NWIndex():
def deleteHandle(self, tHandle): def deleteHandle(self, tHandle):
"""Delete all entries of a given document handle. """Delete all entries of a given document handle.
""" """
logger.debug("Removing item %s from the index" % tHandle)
delTags = [] delTags = []
for tTag in self.tagIndex: for tTag in self.tagIndex:
if self.tagIndex[tTag][1] == tHandle: if self.tagIndex[tTag][1] == tHandle:
@@ -121,6 +124,26 @@ class NWIndex():
return return
def reIndexHandle(self, tHandle):
"""Put a file back into the index. This is used when files are
moved from the archive or trash folders back into the active
project.
"""
logger.debug("Re-indexing item %s" % tHandle)
tItem = self.theProject.projTree[tHandle]
if tItem is None:
return False
if tItem.itemType != nwItemType.FILE:
return False
theDoc = NWDoc(self.theProject, self.theParent)
theText = theDoc.openDocument(tHandle, showStatus=False)
if theText:
self.scanText(tHandle, theText)
return True
## ##
# Load and Save Index to/from File # Load and Save Index to/from File
## ##
+24 -10
View File
@@ -663,25 +663,30 @@ class GuiProjectTree(QTreeWidget):
self.makeAlert("The item cannot be moved to that location.", nwAlert.ERROR) self.makeAlert("The item cannot be moved to that location.", nwAlert.ERROR)
return return
wCount = int(sItem.text(self.C_COUNT)) wCount = int(sItem.text(self.C_COUNT))
isSame = snItem.itemClass == dnItem.itemClass isSame = snItem.itemClass == dnItem.itemClass
isNone = snItem.itemClass == nwItemClass.NO_CLASS isNone = snItem.itemClass == nwItemClass.NO_CLASS
isNote = snItem.itemLayout == nwItemLayout.NOTE isNote = snItem.itemLayout == nwItemLayout.NOTE
onFile = dnItem.itemType == nwItemType.FILE onFile = dnItem.itemType == nwItemType.FILE
isRoot = snItem.itemType == nwItemType.ROOT isRoot = snItem.itemType == nwItemType.ROOT
isArch = snItem.itemClass == nwItemClass.ARCHIVE onFree = dnItem.itemClass == nwItemClass.ARCHIVE
isArch |= dnItem.itemClass == nwItemClass.ARCHIVE onFree |= dnItem.itemClass == nwItemClass.TRASH
isOnTop = self.dropIndicatorPosition() == QAbstractItemView.OnItem isOnTop = self.dropIndicatorPosition() == QAbstractItemView.OnItem
if (isSame or isNone or isNote or isArch) and not (onFile and isOnTop) and not isRoot: if (isSame or isNone or isNote or onFree) and not (onFile and isOnTop) and not isRoot:
logger.debug("Drag'n'drop of item %s accepted" % sHandle) logger.debug("Drag'n'drop of item %s accepted" % sHandle)
self.propagateCount(sHandle, 0) self.propagateCount(sHandle, 0)
QTreeWidget.dropEvent(self, theEvent) QTreeWidget.dropEvent(self, theEvent)
# Handle orphaned files differently than tracked files
if isNone: if isNone:
self._moveOrphanedItem(sHandle, dHandle) self._moveOrphanedItem(sHandle, dHandle)
self._cleanOrphanedRoot() self._cleanOrphanedRoot()
else: else:
self._updateItemParent(sHandle) self._updateItemParent(sHandle)
if not isSame and not isArch:
# If the item does not have the same class as the target,
# and the target is not a free root folder, update its class
if not isSame and not onFree:
logger.debug("Item %s class has been changed from %s to %s" % ( logger.debug("Item %s class has been changed from %s to %s" % (
sHandle, sHandle,
snItem.itemClass.name, snItem.itemClass.name,
@@ -689,7 +694,16 @@ class GuiProjectTree(QTreeWidget):
)) ))
snItem.setClass(dnItem.itemClass) snItem.setClass(dnItem.itemClass)
self.setTreeItemValues(sHandle) self.setTreeItemValues(sHandle)
self.propagateCount(sHandle, wCount) self.propagateCount(sHandle, wCount)
# The items dropped into archive or trash should be removed
# from the project index
if onFree:
self.theParent.theIndex.deleteHandle(sHandle)
else:
self.theParent.theIndex.reIndexHandle(sHandle)
else: else:
logger.debug("Drag'n'drop of item %s not accepted" % sHandle) logger.debug("Drag'n'drop of item %s not accepted" % sHandle)
self.makeAlert("The item cannot be moved to that location.", nwAlert.ERROR) self.makeAlert("The item cannot be moved to that location.", nwAlert.ERROR)