diff --git a/novelwriter/core/item.py b/novelwriter/core/item.py index 0aed8991..e23b4fb9 100644 --- a/novelwriter/core/item.py +++ b/novelwriter/core/item.py @@ -408,6 +408,8 @@ class NWItem(): self._type = value elif isItemType(value): self._type = nwItemType[value] + elif value == "TRASH": + self._type = nwItemType.ROOT else: logger.error("Unrecognised item type '%s'", value) self._type = nwItemType.NO_TYPE diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index 0d24d74c..26efb323 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -158,7 +158,7 @@ class NWProject(): if trashHandle is None: newItem = NWItem(self) newItem.setName(trConst(nwLabels.CLASS_NAME[nwItemClass.TRASH])) - newItem.setType(nwItemType.TRASH) + newItem.setType(nwItemType.ROOT) newItem.setClass(nwItemClass.TRASH) self.projTree.append(None, None, newItem) self.projTree.updateItemData(newItem.itemHandle) diff --git a/novelwriter/core/tree.py b/novelwriter/core/tree.py index a158c37a..eb349bf8 100644 --- a/novelwriter/core/tree.py +++ b/novelwriter/core/tree.py @@ -100,14 +100,13 @@ class NWTree(): if nwItem.itemClass == nwItemClass.ARCHIVE: logger.verbose("Item '%s' is the archive folder", str(tHandle)) self._archRoot = tHandle - - if nwItem.itemType == nwItemType.TRASH: - if self._trashRoot is None: - logger.verbose("Item '%s' is the trash folder", str(tHandle)) - self._trashRoot = tHandle - else: - logger.error("Only one trash folder allowed") - return False + elif nwItem.itemClass == nwItemClass.TRASH: + if self._trashRoot is None: + logger.verbose("Item '%s' is the trash folder", str(tHandle)) + self._trashRoot = tHandle + else: + logger.error("Only one trash folder allowed") + return False self._projTree[tHandle] = nwItem self._treeOrder.append(tHandle) diff --git a/novelwriter/enum.py b/novelwriter/enum.py index 3360d8c5..56340541 100644 --- a/novelwriter/enum.py +++ b/novelwriter/enum.py @@ -32,7 +32,6 @@ class nwItemType(Enum): ROOT = 1 FOLDER = 2 FILE = 3 - TRASH = 4 # END Enum nwItemType diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index 39445dee..7f5dc6f3 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -762,31 +762,18 @@ class GuiProjectTree(QTreeWidget): drop is allowed or not. Disallowed drops are cancelled. """ sHandle = self.getSelectedHandle() - dIndex = self.indexAt(theEvent.pos()) - if sHandle is None or not dIndex.isValid(): + if sHandle is None: logger.error("Invalid drag and drop event") return - sItem = self._getTreeItem(sHandle) - dItem = self.itemFromIndex(dIndex) - dHandle = dItem.data(self.C_NAME, Qt.UserRole) - snItem = self.theProject.projTree[sHandle] - dnItem = self.theProject.projTree[dHandle] - - if snItem.itemType == nwItemType.ROOT or dnItem is None: - logger.debug("Drag'n'drop of item '%s' not accepted", sHandle) - theEvent.ignore() - self.theParent.makeAlert(self.tr( - "The item cannot be moved to that location." - ), nwAlert.ERROR) - return - logger.debug("Drag'n'drop of item '%s' accepted", sHandle) self.propagateCount(sHandle, 0) QTreeWidget.dropEvent(self, theEvent) self._postItemMove(sHandle) + # Record undo information + sItem = self._getTreeItem(sHandle) pItem = sItem.parent() pIndex = 0 if pItem is not None: @@ -895,8 +882,7 @@ class GuiProjectTree(QTreeWidget): self._treeMap[tHandle] = newItem if pHandle is None: if nwItem.itemType == nwItemType.ROOT: - self.addTopLevelItem(newItem) - elif nwItem.itemType == nwItemType.TRASH: + newItem.setFlags(newItem.flags() ^ Qt.ItemIsDragEnabled) self.addTopLevelItem(newItem) else: self.theParent.makeAlert(self.tr( diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py index 3c180b50..19fe823a 100644 --- a/novelwriter/gui/theme.py +++ b/novelwriter/gui/theme.py @@ -639,9 +639,6 @@ class GuiIcons: iconName = "proj_scene" elif tLayout == nwItemLayout.NOTE: iconName = "proj_note" - elif tType == nwItemType.TRASH: - iconName = nwLabels.CLASS_ICON[tClass] - if iconName is None: return QIcon() diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index 6bb6fdd4..b2ac1c0e 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,13 +1,13 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 1308 + 1309 201 - 65350 + 65353 False @@ -141,7 +141,7 @@ Old File - + Trash