From c19c6246529a22d8937032981efe0e9ff32f6038 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 16 Aug 2020 21:17:58 +0200 Subject: [PATCH] Allow folders in Outtakes root folder as it seems to be working as intended with the current logic --- nw/gui/projtree.py | 51 +++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index ab2fe52b..6fadb199 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -59,6 +59,7 @@ class GuiProjectTree(QTreeWidget): self.theParent = theParent self.theTheme = theParent.theTheme self.theProject = theParent.theProject + self.theIndex = theParent.theIndex # Tree Settings self.theMap = None @@ -145,6 +146,9 @@ class GuiProjectTree(QTreeWidget): if not self.theParent.hasProject: return False + # The item needs to be assigned an item class, so one must be + # provided, or it must be possible to extract it from the parent + # item of the new item. if itemClass is None and pHandle is not None: pItem = self.theProject.projTree[pHandle] if pItem is not None: @@ -167,6 +171,7 @@ class GuiProjectTree(QTreeWidget): self.makeAlert("Failed to add new item.", nwAlert.BUG) return False + # Everything is fine, we have what we need, so we proceed logger.verbose("Adding new item of type %s and class %s to handle %s" % ( itemType.name, itemClass.name, str(pHandle)) ) @@ -182,7 +187,9 @@ class GuiProjectTree(QTreeWidget): # If still nothing, give up if pHandle is None: - logger.error("Did not find anywhere to add the item!") + self.makeAlert( + "Did not find anywhere to add the file or folder!", nwAlert.ERROR + ) return False # Now check if the selected item is a file, in which case @@ -207,14 +214,6 @@ class GuiProjectTree(QTreeWidget): ) return False - if pItem.itemClass == nwItemClass.ARCHIVE: - self.makeAlert( - "Cannot add new files or folders to the %s folder." % ( - nwLabels.CLASS_NAME[nwItemClass.ARCHIVE] - ), nwAlert.ERROR - ) - return False - # If we're still here, add the file or folder if itemType == nwItemType.FILE: tHandle = self.theProject.newFile("New File", itemClass, pHandle) @@ -226,7 +225,6 @@ class GuiProjectTree(QTreeWidget): # Add the new item to the tree self.revealTreeItem(tHandle, nHandle) - self.theParent.editItem() return True @@ -332,7 +330,9 @@ class GuiProjectTree(QTreeWidget): logger.debug("Emptying Trash folder") if trashHandle is None: - self.makeAlert("There is no Trash folder.", nwAlert.INFO) + self.makeAlert( + "There is currently no Trash folder in this project.", nwAlert.INFO + ) return False theTrash = self.getTreeFromHandle(trashHandle) @@ -341,13 +341,13 @@ class GuiProjectTree(QTreeWidget): nTrash = len(theTrash) if nTrash == 0: - self.makeAlert("The Trash folder is empty.", nwAlert.INFO) + self.makeAlert("The Trash folder is already empty.", nwAlert.INFO) return False msgBox = QMessageBox() msgRes = msgBox.question( self, "Empty Trash", "Permanently delete %d file%s from Trash?" % ( - nTrash, "s"*int(nTrash > 1) + nTrash, "s" if nTrash > 1 else "" ) ) if msgRes != QMessageBox.Yes: @@ -420,7 +420,7 @@ class GuiProjectTree(QTreeWidget): theDoc = NWDoc(self.theProject, self.theParent) theDoc.deleteDocument(tHandle) del self.theProject.projTree[tHandle] - self.theParent.theIndex.deleteHandle(tHandle) + self.theIndex.deleteHandle(tHandle) else: # The file is not already in the trash folder, so we @@ -448,7 +448,7 @@ class GuiProjectTree(QTreeWidget): self.propagateCount(tHandle, wCount) self._setTreeChanged(True) - self.theParent.theIndex.deleteHandle(tHandle) + self.theIndex.deleteHandle(tHandle) elif nwItemS.itemType == nwItemType.FOLDER: logger.debug("User requested folder %s deleted" % tHandle) @@ -461,7 +461,11 @@ class GuiProjectTree(QTreeWidget): trItemP.takeChild(tIndex) del self.theProject.projTree[tHandle] else: - self.makeAlert("Cannot delete folder. It is not empty.", nwAlert.ERROR) + self.makeAlert(( + "Cannot delete folder. It is not empty. " + "Recursive deletion is not supported. " + "Please delete the content first." + ), nwAlert.ERROR) return False elif nwItemS.itemType == nwItemType.ROOT: @@ -473,7 +477,11 @@ class GuiProjectTree(QTreeWidget): self.theParent.mainMenu.setAvailableRoot() self._setTreeChanged(True) else: - self.makeAlert("Cannot delete root folder. It is not empty.", nwAlert.ERROR) + self.makeAlert(( + "Cannot delete root folder. It is not empty. " + "Recursive deletion is not supported. " + "Please delete the content first." + ), nwAlert.ERROR) return False return True @@ -710,11 +718,12 @@ class GuiProjectTree(QTreeWidget): self.propagateCount(sHandle, wCount) # The items dropped into archive or trash should be removed - # from the project index + # from the project index, for all other items, we rescan the + # file to ensure the index is up to date. if onFree: - self.theParent.theIndex.deleteHandle(sHandle) + self.theIndex.deleteHandle(sHandle) else: - self.theParent.theIndex.reIndexHandle(sHandle) + self.theIndex.reIndexHandle(sHandle) else: logger.debug("Drag'n'drop of item %s not accepted" % sHandle) @@ -964,7 +973,7 @@ class GuiProjectTreeMenu(QMenu): showEdit = not isTrash and not isOrph showExport = isFile and not inTrash and not isOrph showNewFile = not isTrash and not inTrash and not isOrph and not isArch - showNewFolder = not isTrash and not inTrash and not isOrph and not isArch + showNewFolder = not isTrash and not inTrash and not isOrph showDelete = not isTrash showEmpty = isTrash