Block drag and drop for ROOT items on the widget level, and drop the TRASH item type

This commit is contained in:
Veronica Berglyd Olsen
2022-04-23 16:57:13 +02:00
parent d96c8ddf85
commit bd5a14b18e
7 changed files with 18 additions and 35 deletions
+2
View File
@@ -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
+1 -1
View File
@@ -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)
+7 -8
View File
@@ -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)
-1
View File
@@ -32,7 +32,6 @@ class nwItemType(Enum):
ROOT = 1
FOLDER = 2
FILE = 3
TRASH = 4
# END Enum nwItemType
+4 -18
View File
@@ -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(
-3
View File
@@ -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()
+4 -4
View File
@@ -1,13 +1,13 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="1.7-alpha0" hexVersion="0x010700a0" fileVersion="1.4" timeStamp="2022-04-23 15:51:36">
<novelWriterXML appVersion="1.7-alpha0" hexVersion="0x010700a0" fileVersion="1.4" timeStamp="2022-04-23 16:56:31">
<project>
<name>Sample Project</name>
<title>Sample Project</title>
<author>Jane Smith</author>
<author>Jay Doh</author>
<saveCount>1308</saveCount>
<saveCount>1309</saveCount>
<autoCount>201</autoCount>
<editTime>65350</editTime>
<editTime>65353</editTime>
</project>
<settings>
<doBackup>False</doBackup>
@@ -141,7 +141,7 @@
<meta expanded="False" charCount="315" wordCount="55" paraCount="1" cursorPos="322"/>
<name status="s90e6c9" import="ia857f0" exported="True">Old File</name>
</item>
<item handle="98acd8c76c93a" parent="None" root="98acd8c76c93a" order="4" type="TRASH" class="TRASH">
<item handle="98acd8c76c93a" parent="None" root="98acd8c76c93a" order="4" type="ROOT" class="TRASH">
<meta expanded="True"/>
<name status="sf12341" import="ia857f0">Trash</name>
</item>