From 65131e87c7622805b48f6608be9f052275ca3359 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 16 Aug 2020 16:51:07 +0200 Subject: [PATCH] The deleted and outtake files are now properly handled by the index --- nw/core/index.py | 23 +++++++++++++++++++++++ nw/gui/projtree.py | 34 ++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/nw/core/index.py b/nw/core/index.py index c542a459..5b7cc05c 100644 --- a/nw/core/index.py +++ b/nw/core/index.py @@ -34,6 +34,7 @@ from time import time from nw.constants import ( nwFiles, nwKeyWords, nwItemType, nwItemClass, nwItemLayout, nwAlert ) +from nw.core.document import NWDoc from nw.core.tools import countWords logger = logging.getLogger(__name__) @@ -106,6 +107,8 @@ class NWIndex(): def deleteHandle(self, tHandle): """Delete all entries of a given document handle. """ + logger.debug("Removing item %s from the index" % tHandle) + delTags = [] for tTag in self.tagIndex: if self.tagIndex[tTag][1] == tHandle: @@ -121,6 +124,26 @@ class NWIndex(): 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 ## diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index 5fd83f5e..f80437ed 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -663,25 +663,30 @@ class GuiProjectTree(QTreeWidget): self.makeAlert("The item cannot be moved to that location.", nwAlert.ERROR) return - wCount = int(sItem.text(self.C_COUNT)) - isSame = snItem.itemClass == dnItem.itemClass - isNone = snItem.itemClass == nwItemClass.NO_CLASS - isNote = snItem.itemLayout == nwItemLayout.NOTE - onFile = dnItem.itemType == nwItemType.FILE - isRoot = snItem.itemType == nwItemType.ROOT - isArch = snItem.itemClass == nwItemClass.ARCHIVE - isArch |= dnItem.itemClass == nwItemClass.ARCHIVE + wCount = int(sItem.text(self.C_COUNT)) + isSame = snItem.itemClass == dnItem.itemClass + isNone = snItem.itemClass == nwItemClass.NO_CLASS + isNote = snItem.itemLayout == nwItemLayout.NOTE + onFile = dnItem.itemType == nwItemType.FILE + isRoot = snItem.itemType == nwItemType.ROOT + onFree = dnItem.itemClass == nwItemClass.ARCHIVE + onFree |= dnItem.itemClass == nwItemClass.TRASH 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) self.propagateCount(sHandle, 0) QTreeWidget.dropEvent(self, theEvent) + + # Handle orphaned files differently than tracked files if isNone: self._moveOrphanedItem(sHandle, dHandle) self._cleanOrphanedRoot() else: 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" % ( sHandle, snItem.itemClass.name, @@ -689,7 +694,16 @@ class GuiProjectTree(QTreeWidget): )) snItem.setClass(dnItem.itemClass) self.setTreeItemValues(sHandle) + 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: logger.debug("Drag'n'drop of item %s not accepted" % sHandle) self.makeAlert("The item cannot be moved to that location.", nwAlert.ERROR)