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 self._type = value
elif isItemType(value): elif isItemType(value):
self._type = nwItemType[value] self._type = nwItemType[value]
elif value == "TRASH":
self._type = nwItemType.ROOT
else: else:
logger.error("Unrecognised item type '%s'", value) logger.error("Unrecognised item type '%s'", value)
self._type = nwItemType.NO_TYPE self._type = nwItemType.NO_TYPE
+1 -1
View File
@@ -158,7 +158,7 @@ class NWProject():
if trashHandle is None: if trashHandle is None:
newItem = NWItem(self) newItem = NWItem(self)
newItem.setName(trConst(nwLabels.CLASS_NAME[nwItemClass.TRASH])) newItem.setName(trConst(nwLabels.CLASS_NAME[nwItemClass.TRASH]))
newItem.setType(nwItemType.TRASH) newItem.setType(nwItemType.ROOT)
newItem.setClass(nwItemClass.TRASH) newItem.setClass(nwItemClass.TRASH)
self.projTree.append(None, None, newItem) self.projTree.append(None, None, newItem)
self.projTree.updateItemData(newItem.itemHandle) self.projTree.updateItemData(newItem.itemHandle)
+7 -8
View File
@@ -100,14 +100,13 @@ class NWTree():
if nwItem.itemClass == nwItemClass.ARCHIVE: if nwItem.itemClass == nwItemClass.ARCHIVE:
logger.verbose("Item '%s' is the archive folder", str(tHandle)) logger.verbose("Item '%s' is the archive folder", str(tHandle))
self._archRoot = tHandle self._archRoot = tHandle
elif nwItem.itemClass == nwItemClass.TRASH:
if nwItem.itemType == nwItemType.TRASH: if self._trashRoot is None:
if self._trashRoot is None: logger.verbose("Item '%s' is the trash folder", str(tHandle))
logger.verbose("Item '%s' is the trash folder", str(tHandle)) self._trashRoot = tHandle
self._trashRoot = tHandle else:
else: logger.error("Only one trash folder allowed")
logger.error("Only one trash folder allowed") return False
return False
self._projTree[tHandle] = nwItem self._projTree[tHandle] = nwItem
self._treeOrder.append(tHandle) self._treeOrder.append(tHandle)
-1
View File
@@ -32,7 +32,6 @@ class nwItemType(Enum):
ROOT = 1 ROOT = 1
FOLDER = 2 FOLDER = 2
FILE = 3 FILE = 3
TRASH = 4
# END Enum nwItemType # END Enum nwItemType
+4 -18
View File
@@ -762,31 +762,18 @@ class GuiProjectTree(QTreeWidget):
drop is allowed or not. Disallowed drops are cancelled. drop is allowed or not. Disallowed drops are cancelled.
""" """
sHandle = self.getSelectedHandle() sHandle = self.getSelectedHandle()
dIndex = self.indexAt(theEvent.pos()) if sHandle is None:
if sHandle is None or not dIndex.isValid():
logger.error("Invalid drag and drop event") logger.error("Invalid drag and drop event")
return 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) logger.debug("Drag'n'drop of item '%s' accepted", sHandle)
self.propagateCount(sHandle, 0) self.propagateCount(sHandle, 0)
QTreeWidget.dropEvent(self, theEvent) QTreeWidget.dropEvent(self, theEvent)
self._postItemMove(sHandle) self._postItemMove(sHandle)
# Record undo information
sItem = self._getTreeItem(sHandle)
pItem = sItem.parent() pItem = sItem.parent()
pIndex = 0 pIndex = 0
if pItem is not None: if pItem is not None:
@@ -895,8 +882,7 @@ class GuiProjectTree(QTreeWidget):
self._treeMap[tHandle] = newItem self._treeMap[tHandle] = newItem
if pHandle is None: if pHandle is None:
if nwItem.itemType == nwItemType.ROOT: if nwItem.itemType == nwItemType.ROOT:
self.addTopLevelItem(newItem) newItem.setFlags(newItem.flags() ^ Qt.ItemIsDragEnabled)
elif nwItem.itemType == nwItemType.TRASH:
self.addTopLevelItem(newItem) self.addTopLevelItem(newItem)
else: else:
self.theParent.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
-3
View File
@@ -639,9 +639,6 @@ class GuiIcons:
iconName = "proj_scene" iconName = "proj_scene"
elif tLayout == nwItemLayout.NOTE: elif tLayout == nwItemLayout.NOTE:
iconName = "proj_note" iconName = "proj_note"
elif tType == nwItemType.TRASH:
iconName = nwLabels.CLASS_ICON[tClass]
if iconName is None: if iconName is None:
return QIcon() return QIcon()
+4 -4
View File
@@ -1,13 +1,13 @@
<?xml version='1.0' encoding='utf-8'?> <?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> <project>
<name>Sample Project</name> <name>Sample Project</name>
<title>Sample Project</title> <title>Sample Project</title>
<author>Jane Smith</author> <author>Jane Smith</author>
<author>Jay Doh</author> <author>Jay Doh</author>
<saveCount>1308</saveCount> <saveCount>1309</saveCount>
<autoCount>201</autoCount> <autoCount>201</autoCount>
<editTime>65350</editTime> <editTime>65353</editTime>
</project> </project>
<settings> <settings>
<doBackup>False</doBackup> <doBackup>False</doBackup>
@@ -141,7 +141,7 @@
<meta expanded="False" charCount="315" wordCount="55" paraCount="1" cursorPos="322"/> <meta expanded="False" charCount="315" wordCount="55" paraCount="1" cursorPos="322"/>
<name status="s90e6c9" import="ia857f0" exported="True">Old File</name> <name status="s90e6c9" import="ia857f0" exported="True">Old File</name>
</item> </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"/> <meta expanded="True"/>
<name status="sf12341" import="ia857f0">Trash</name> <name status="sf12341" import="ia857f0">Trash</name>
</item> </item>