From 414f4d3a6e8a5d86042ce0be7a7158c5adbdb892 Mon Sep 17 00:00:00 2001
From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com>
Date: Mon, 21 Dec 2020 01:39:18 +0100
Subject: [PATCH] Remove code related to orphaned files
---
.../icons/typicons_colour_dark/icons.conf | 1 -
.../icons/typicons_colour_dark/warning.svg | 31 -------
.../icons/typicons_colour_light/icons.conf | 1 -
.../icons/typicons_colour_light/warning.svg | 31 -------
nw/assets/icons/typicons_grey_dark/icons.conf | 1 -
.../icons/typicons_grey_dark/warning.svg | 31 -------
.../icons/typicons_grey_light/icons.conf | 1 -
.../icons/typicons_grey_light/warning.svg | 31 -------
nw/gui/projtree.py | 82 +++----------------
nw/gui/theme.py | 1 -
tests/test_gui_projtree.py | 5 +-
11 files changed, 13 insertions(+), 203 deletions(-)
delete mode 100644 nw/assets/icons/typicons_colour_dark/warning.svg
delete mode 100644 nw/assets/icons/typicons_colour_light/warning.svg
delete mode 100644 nw/assets/icons/typicons_grey_dark/warning.svg
delete mode 100644 nw/assets/icons/typicons_grey_light/warning.svg
diff --git a/nw/assets/icons/typicons_colour_dark/icons.conf b/nw/assets/icons/typicons_colour_dark/icons.conf
index 927da636..d4671820 100644
--- a/nw/assets/icons/typicons_colour_dark/icons.conf
+++ b/nw/assets/icons/typicons_colour_dark/icons.conf
@@ -29,7 +29,6 @@ cls_archive = delete.svg
cls_trash = trash.svg
proj_document = document-text.svg
proj_folder = folder.svg
-proj_orphan = warning.svg
doc_h1 = heading1.svg
doc_h2 = heading2.svg
doc_h3 = heading3.svg
diff --git a/nw/assets/icons/typicons_colour_dark/warning.svg b/nw/assets/icons/typicons_colour_dark/warning.svg
deleted file mode 100644
index eef5a902..00000000
--- a/nw/assets/icons/typicons_colour_dark/warning.svg
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
diff --git a/nw/assets/icons/typicons_colour_light/icons.conf b/nw/assets/icons/typicons_colour_light/icons.conf
index 1a97029f..4f9ffb6c 100644
--- a/nw/assets/icons/typicons_colour_light/icons.conf
+++ b/nw/assets/icons/typicons_colour_light/icons.conf
@@ -29,7 +29,6 @@ cls_archive = delete.svg
cls_trash = trash.svg
proj_document = document-text.svg
proj_folder = folder.svg
-proj_orphan = warning.svg
doc_h1 = heading1.svg
doc_h2 = heading2.svg
doc_h3 = heading3.svg
diff --git a/nw/assets/icons/typicons_colour_light/warning.svg b/nw/assets/icons/typicons_colour_light/warning.svg
deleted file mode 100644
index ad55f227..00000000
--- a/nw/assets/icons/typicons_colour_light/warning.svg
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
diff --git a/nw/assets/icons/typicons_grey_dark/icons.conf b/nw/assets/icons/typicons_grey_dark/icons.conf
index f9c8c49d..7dae46e9 100644
--- a/nw/assets/icons/typicons_grey_dark/icons.conf
+++ b/nw/assets/icons/typicons_grey_dark/icons.conf
@@ -29,7 +29,6 @@ cls_archive = delete.svg
cls_trash = trash.svg
proj_document = document-text.svg
proj_folder = folder.svg
-proj_orphan = warning.svg
doc_h1 = heading1.svg
doc_h2 = heading2.svg
doc_h3 = heading3.svg
diff --git a/nw/assets/icons/typicons_grey_dark/warning.svg b/nw/assets/icons/typicons_grey_dark/warning.svg
deleted file mode 100644
index 3753c9f4..00000000
--- a/nw/assets/icons/typicons_grey_dark/warning.svg
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
diff --git a/nw/assets/icons/typicons_grey_light/icons.conf b/nw/assets/icons/typicons_grey_light/icons.conf
index 732486a5..f21000cb 100644
--- a/nw/assets/icons/typicons_grey_light/icons.conf
+++ b/nw/assets/icons/typicons_grey_light/icons.conf
@@ -29,7 +29,6 @@ cls_archive = delete.svg
cls_trash = trash.svg
proj_document = document-text.svg
proj_folder = folder.svg
-proj_orphan = warning.svg
doc_h1 = heading1.svg
doc_h2 = heading2.svg
doc_h3 = heading3.svg
diff --git a/nw/assets/icons/typicons_grey_light/warning.svg b/nw/assets/icons/typicons_grey_light/warning.svg
deleted file mode 100644
index 86f67929..00000000
--- a/nw/assets/icons/typicons_grey_light/warning.svg
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py
index 748d9ed8..28af1b0c 100644
--- a/nw/gui/projtree.py
+++ b/nw/gui/projtree.py
@@ -62,7 +62,6 @@ class GuiProjectTree(QTreeWidget):
# Tree Settings
self.theMap = None
- self.orphRoot = None
self.treeChanged = False
self.ctxMenu = GuiProjectTreeMenu(self)
@@ -149,7 +148,6 @@ class GuiProjectTree(QTreeWidget):
"""
self.clear()
self.theMap = {}
- self.orphRoot = None
return
def newTreeItem(self, itemType, itemClass):
@@ -270,6 +268,9 @@ class GuiProjectTree(QTreeWidget):
"""
nwItem = self.theProject.projTree[tHandle]
trItem = self._addTreeItem(nwItem, nHandle)
+ if trItem is None:
+ return False
+
pHandle = nwItem.itemParent
if pHandle is not None and pHandle in self.theMap:
self.theMap[pHandle].setExpanded(True)
@@ -326,8 +327,6 @@ class GuiProjectTree(QTreeWidget):
"""
theList = []
for i in range(self.topLevelItemCount()):
- if self.topLevelItem(i) == self.orphRoot:
- continue
theList = self._scanChildren(theList, self.topLevelItem(i), i)
logger.debug("Saving project tree item order")
self.theProject.setTreeOrder(theList)
@@ -603,13 +602,11 @@ class GuiProjectTree(QTreeWidget):
relevant values in the project and on the status bar. This call
is a fast way of getting this number, and depends on the
propagateCount function being called when it should to maintain
- the correct count. Orphan folder is not included in the total.
+ the correct count.
"""
nWords = 0
for n in range(self.topLevelItemCount()):
tItem = self.topLevelItem(n)
- if tItem == self.orphRoot:
- continue
nWords += int(tItem.data(self.C_COUNT, Qt.UserRole))
self.theProject.setProjectWordCount(nWords)
@@ -769,13 +766,7 @@ class GuiProjectTree(QTreeWidget):
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)
+ self._updateItemParent(sHandle)
# If the item does not have the same class as the target,
# and the target is not a free root folder, update its class
@@ -861,8 +852,7 @@ class GuiProjectTree(QTreeWidget):
self.makeAlert(
"There is nowhere to add file with name '%s'" % nwItem.itemName, nwAlert.ERROR
)
- # self._addOrphanedRoot()
- # self.orphRoot.addChild(newItem)
+ return None
else:
byIndex = -1
if nHandle is not None and nHandle in self.theMap:
@@ -906,39 +896,12 @@ class GuiProjectTree(QTreeWidget):
trItem = self._addTreeItem(
self.theProject.projTree[trashHandle]
)
- trItem.setExpanded(True)
- self._setTreeChanged(True)
+ if trItem is not None:
+ trItem.setExpanded(True)
+ self._setTreeChanged(True)
return trItem
- def _addOrphanedRoot(self):
- """Add the special Orphaned Files root item to hold non-root
- items with no parent set.
- """
- if self.orphRoot is None:
- newItem = QTreeWidgetItem([""]*4)
- newItem.setText(self.C_NAME, "Orphaned Files")
- newItem.setData(self.C_NAME, Qt.UserRole, None)
- newItem.setIcon(self.C_NAME, self.theTheme.getIcon("proj_orphan"))
- newItem.setText(self.C_COUNT, "")
- newItem.setData(self.C_COUNT, Qt.UserRole, 0)
- newItem.setText(self.C_EXPORT, "")
- newItem.setText(self.C_FLAGS, "")
- self.addTopLevelItem(newItem)
- self.orphRoot = newItem
- newItem.setExpanded(True)
-
- return
-
- def _cleanOrphanedRoot(self):
- """Remove the special Orphaned Files root folder if it is empty.
- """
- if self.orphRoot is not None:
- if self.orphRoot.childCount() == 0:
- self.takeTopLevelItem(self.indexOfTopLevelItem(self.orphRoot))
- self.orphRoot = None
- return
-
def _updateItemParent(self, tHandle):
"""Update the parent handle of an item so that the information
in the project is consistent with the treeView.
@@ -959,27 +922,6 @@ class GuiProjectTree(QTreeWidget):
return True
- def _moveOrphanedItem(self, tHandle, dHandle):
- """Move an Orphaned Item to a new dHandle parent item. This
- function will set all the missing meta data based on the meta
- data of the destination item.
- """
- trItemS = self._getTreeItem(tHandle)
- nwItemS = self.theProject.projTree[tHandle]
- nwItemD = self.theProject.projTree[dHandle]
- trItemP = trItemS.parent()
- nwItemS.setClass(nwItemD.itemClass)
- if trItemP is None:
- logger.error("Failed to find new parent item of %s" % tHandle)
- return False
-
- pHandle = trItemP.data(self.C_NAME, Qt.UserRole)
- nwItemS.setParent(pHandle)
- self.setTreeItemValues(tHandle)
- self._setTreeChanged(True)
-
- return True
-
def _setTreeChanged(self, theState):
"""Set the tree change flag, and propagate to the project.
"""
@@ -1055,12 +997,10 @@ class GuiProjectTreeMenu(QMenu):
inTrash = theItem.itemParent == trashHandle and trashHandle is not None
isTrash = theItem.itemHandle == trashHandle and trashHandle is not None
isFile = theItem.itemType == nwItemType.FILE
- isOrph = isFile and theItem.itemParent is None
- allowEdit = not (isTrash or isOrph)
- allowNew = not (isTrash or inTrash or isOrph)
+ allowNew = not (isTrash or inTrash)
- self.editItem.setVisible(allowEdit)
+ self.editItem.setVisible(not isTrash)
self.openItem.setVisible(isFile)
self.viewItem.setVisible(isFile)
self.toggleExp.setVisible(isFile)
diff --git a/nw/gui/theme.py b/nw/gui/theme.py
index c2b4b9fd..cd691aa2 100644
--- a/nw/gui/theme.py
+++ b/nw/gui/theme.py
@@ -524,7 +524,6 @@ class GuiIcons:
"cls_trash" : (QStyle.SP_DriveHDIcon, "drive-harddisk"),
"proj_document" : (QStyle.SP_FileIcon, "x-office-document"),
"proj_folder" : (QStyle.SP_DirIcon, "folder"),
- "proj_orphan" : (QStyle.SP_MessageBoxWarning, "dialog-warning"),
"proj_nwx" : (None, None),
"status_lang" : (None, None),
"status_time" : (None, None),
diff --git a/tests/test_gui_projtree.py b/tests/test_gui_projtree.py
index 94726348..a663b18a 100644
--- a/tests/test_gui_projtree.py
+++ b/tests/test_gui_projtree.py
@@ -127,11 +127,10 @@ def testGuiProjTree_Main(qtbot, monkeypatch, nwGUI, nwMinimal):
nwGUI.openProject(nwMinimal)
# Check that the orphaned file was found and added to the tree
- assert nwTree.orphRoot is not None
nwTree.flushTreeOrder()
- assert "1234567890abc" not in nwGUI.theProject.projTree._treeOrder
+ assert "1234567890abc" in nwGUI.theProject.projTree._treeOrder
orItem = nwTree._getTreeItem("1234567890abc")
- assert orItem.text(nwTree.C_NAME) == "Orphaned File 1"
+ assert orItem.text(nwTree.C_NAME) == "Recovered File 1"
# qtbot.stopForInteraction()