Merge pull request #335 from vkbo/word_counts

Word Counts
This commit is contained in:
Veronica K. Berglyd Olsen
2020-06-22 19:34:52 +02:00
committed by GitHub
+10 -6
View File
@@ -367,6 +367,7 @@ class GuiProjectTree(QTreeWidget):
if nwItemS is None: if nwItemS is None:
return False return False
wCount = int(trItemS.text(self.C_COUNT))
if nwItemS.itemType == nwItemType.FILE: if nwItemS.itemType == nwItemType.FILE:
logger.debug("User requested file %s moved to trash" % tHandle) logger.debug("User requested file %s moved to trash" % tHandle)
trItemP = trItemS.parent() trItemP = trItemS.parent()
@@ -393,6 +394,7 @@ class GuiProjectTree(QTreeWidget):
if doPermanent: if doPermanent:
logger.debug("Permanently deleting file with handle %s" % tHandle) logger.debug("Permanently deleting file with handle %s" % tHandle)
self.propagateCount(tHandle, 0)
tIndex = trItemP.indexOfChild(trItemS) tIndex = trItemP.indexOfChild(trItemS)
trItemC = trItemP.takeChild(tIndex) trItemC = trItemP.takeChild(tIndex)
@@ -422,10 +424,12 @@ class GuiProjectTree(QTreeWidget):
if pHandle is None: if pHandle is None:
logger.warning("File has no parent item") logger.warning("File has no parent item")
self.propagateCount(tHandle, 0)
tIndex = trItemP.indexOfChild(trItemS) tIndex = trItemP.indexOfChild(trItemS)
trItemC = trItemP.takeChild(tIndex) trItemC = trItemP.takeChild(tIndex)
trItemT.addChild(trItemC) trItemT.addChild(trItemC)
nwItemS.setParent(self.theProject.projTree.trashRoot()) nwItemS.setParent(self.theProject.projTree.trashRoot())
self.propagateCount(tHandle, wCount)
self._setTreeChanged(True) self._setTreeChanged(True)
self.theParent.theIndex.deleteHandle(tHandle) self.theParent.theIndex.deleteHandle(tHandle)
@@ -520,7 +524,7 @@ class GuiProjectTree(QTreeWidget):
relevant values in the project and on the status bar. This call relevant values in the project and on the status bar. This call
is a fast way of getting this number, and depends on the is a fast way of getting this number, and depends on the
propagateCount function being called when it should to maintain propagateCount function being called when it should to maintain
the correct count. the correct count. Orphan folder is not included in the total.
""" """
nWords = 0 nWords = 0
for n in range(self.topLevelItemCount()): for n in range(self.topLevelItemCount()):
@@ -629,6 +633,7 @@ class GuiProjectTree(QTreeWidget):
logger.error("Invalid drop index") logger.error("Invalid drop index")
return return
sItem = self._getTreeItem(sHandle)
dItem = self.itemFromIndex(dIndex) dItem = self.itemFromIndex(dIndex)
dHandle = dItem.data(self.C_NAME, Qt.UserRole) dHandle = dItem.data(self.C_NAME, Qt.UserRole)
snItem = self.theProject.projTree[sHandle] snItem = self.theProject.projTree[sHandle]
@@ -637,6 +642,7 @@ 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))
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
@@ -646,6 +652,7 @@ class GuiProjectTree(QTreeWidget):
isOnTop = self.dropIndicatorPosition() == QAbstractItemView.OnItem isOnTop = self.dropIndicatorPosition() == QAbstractItemView.OnItem
if (isSame or isNone or isNote) and not (onFile and isOnTop) and not isRoot: if (isSame or isNone or isNote) 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)
QTreeWidget.dropEvent(self, theEvent) QTreeWidget.dropEvent(self, theEvent)
if isNone: if isNone:
self._moveOrphanedItem(sHandle, dHandle) self._moveOrphanedItem(sHandle, dHandle)
@@ -660,6 +667,7 @@ class GuiProjectTree(QTreeWidget):
)) ))
snItem.setClass(dnItem.itemClass) snItem.setClass(dnItem.itemClass)
self.setTreeItemValues(sHandle) self.setTreeItemValues(sHandle)
self.propagateCount(sHandle, wCount)
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)
@@ -794,8 +802,7 @@ class GuiProjectTree(QTreeWidget):
def _updateItemParent(self, tHandle): def _updateItemParent(self, tHandle):
"""Update the parent handle of an item so that the information """Update the parent handle of an item so that the information
in the project is consistent with the treeView. Also move the in the project is consistent with the treeView.
word count over to the new parent tree.
""" """
trItemS = self._getTreeItem(tHandle) trItemS = self._getTreeItem(tHandle)
nwItemS = self.theProject.projTree[tHandle] nwItemS = self.theProject.projTree[tHandle]
@@ -805,10 +812,7 @@ class GuiProjectTree(QTreeWidget):
return False return False
pHandle = trItemP.data(self.C_NAME, Qt.UserRole) pHandle = trItemP.data(self.C_NAME, Qt.UserRole)
wC = int(trItemS.text(self.C_COUNT))
self.propagateCount(tHandle, -wC)
nwItemS.setParent(pHandle) nwItemS.setParent(pHandle)
self.propagateCount(tHandle, wC)
self.setTreeItemValues(tHandle) self.setTreeItemValues(tHandle)
self._setTreeChanged(True) self._setTreeChanged(True)