Drag'n'drop now checks that the drop is allowed.
This commit is contained in:
@@ -181,4 +181,32 @@ class GuiDocTree(QTreeWidget):
|
||||
self.clearSelection()
|
||||
return
|
||||
|
||||
def dropEvent(self, theEvent):
|
||||
"""Overload the drop of dragged item event to check whether the drop is allowed
|
||||
or not. Disallowed drops are cancelled.
|
||||
"""
|
||||
sHandle = self._getSelectedHandle()
|
||||
if sHandle is None:
|
||||
return
|
||||
|
||||
dIndex = self.indexAt(theEvent.pos())
|
||||
if not dIndex.isValid():
|
||||
return
|
||||
|
||||
dItem = self.itemFromIndex(dIndex)
|
||||
dHandle = dItem.text(3)
|
||||
snItem = self.theProject.getItem(sHandle)
|
||||
dnItem = self.theProject.getItem(dHandle)
|
||||
isSame = snItem.itemClass == dnItem.itemClass and dnItem.itemType
|
||||
isFile = dnItem.itemType == nwItemType.FILE
|
||||
isRoot = snItem.itemType == nwItemType.ROOT
|
||||
isOnTop = self.dropIndicatorPosition() == QAbstractItemView.OnItem
|
||||
if isSame and not (isFile and isOnTop) and not isRoot:
|
||||
logger.verbose("Drag'n'drop on item %s allowed" % sHandle)
|
||||
QTreeWidget.dropEvent(self, theEvent)
|
||||
else:
|
||||
logger.verbose("Drag'n'drop on item %s not allowed" % sHandle)
|
||||
|
||||
return
|
||||
|
||||
# END Class GuiDocTree
|
||||
|
||||
@@ -76,6 +76,7 @@ class GuiDocTreeCtx(QMenu):
|
||||
self._buildMenuDeleteRoot(vActs)
|
||||
if nwItemAction.EMPTY_TRASH in vActs.keys():
|
||||
self._buildMenuEmptyTrash(vActs)
|
||||
return
|
||||
|
||||
##
|
||||
# Build Sub Menus
|
||||
@@ -87,6 +88,7 @@ class GuiDocTreeCtx(QMenu):
|
||||
nwItemAction.DELETE, None, None
|
||||
))
|
||||
self.addAction(mnuItem)
|
||||
return
|
||||
|
||||
def _buildMenuDeleteRoot(self, vActs):
|
||||
mnuItem = QAction("Remove Root", self)
|
||||
@@ -94,6 +96,7 @@ class GuiDocTreeCtx(QMenu):
|
||||
nwItemAction.DELETE_ROOT, None, None
|
||||
))
|
||||
self.addAction(mnuItem)
|
||||
return
|
||||
|
||||
def _buildMenuEmptyTrash(self, vActs):
|
||||
mnuItem = QAction("Empty Trash", self)
|
||||
@@ -101,6 +104,7 @@ class GuiDocTreeCtx(QMenu):
|
||||
nwItemAction.EMPTY_TRASH, None, None
|
||||
))
|
||||
self.addAction(mnuItem)
|
||||
return
|
||||
|
||||
def _buildMenuSplit(self, vActs):
|
||||
mnuItem = QAction("Split File", self)
|
||||
@@ -108,6 +112,7 @@ class GuiDocTreeCtx(QMenu):
|
||||
nwItemAction.SPLIT, None, None
|
||||
))
|
||||
self.addAction(mnuItem)
|
||||
return
|
||||
|
||||
def _buildMenuMerge(self, vActs):
|
||||
mnuItem = QAction("Merge Folder", self)
|
||||
@@ -115,6 +120,7 @@ class GuiDocTreeCtx(QMenu):
|
||||
nwItemAction.MERGE, None, None
|
||||
))
|
||||
self.addAction(mnuItem)
|
||||
return
|
||||
|
||||
def _buildMenuMoveUp(self, vActs):
|
||||
mnuItem = QAction("Move Up", self)
|
||||
@@ -122,6 +128,7 @@ class GuiDocTreeCtx(QMenu):
|
||||
nwItemAction.MOVE_UP, None, None
|
||||
))
|
||||
self.addAction(mnuItem)
|
||||
return
|
||||
|
||||
def _buildMenuMoveDown(self, vActs):
|
||||
mnuItem = QAction("Move Down", self)
|
||||
@@ -129,6 +136,7 @@ class GuiDocTreeCtx(QMenu):
|
||||
nwItemAction.MOVE_DOWN, None, None
|
||||
))
|
||||
self.addAction(mnuItem)
|
||||
return
|
||||
|
||||
def _buildMenuMoveTrash(self, vActs):
|
||||
mnuItem = QAction("Move to Trash", self)
|
||||
@@ -136,6 +144,7 @@ class GuiDocTreeCtx(QMenu):
|
||||
nwItemAction.MOVE_TRASH, None, None
|
||||
))
|
||||
self.addAction(mnuItem)
|
||||
return
|
||||
|
||||
def _buildMenuMoveTo(self, vActs):
|
||||
mnuItem = QAction("Move to", self)
|
||||
@@ -144,6 +153,7 @@ class GuiDocTreeCtx(QMenu):
|
||||
None
|
||||
))
|
||||
self.addAction(mnuItem)
|
||||
return
|
||||
|
||||
def _buildMenuAddFile(self, vActs):
|
||||
mnuItem = QAction("Add File", self)
|
||||
@@ -153,6 +163,7 @@ class GuiDocTreeCtx(QMenu):
|
||||
nwItemType.FILE
|
||||
))
|
||||
self.addAction(mnuItem)
|
||||
return
|
||||
|
||||
def _buildMenuAddFolder(self, vActs):
|
||||
mnuItem = QAction("Add Folder", self)
|
||||
@@ -162,6 +173,7 @@ class GuiDocTreeCtx(QMenu):
|
||||
nwItemType.FOLDER
|
||||
))
|
||||
self.addAction(mnuItem)
|
||||
return
|
||||
|
||||
def _buildMenuAddRoot(self, vActs):
|
||||
|
||||
|
||||
+4
-3
@@ -206,13 +206,14 @@ class GuiMain(QMainWindow):
|
||||
|
||||
def _openDocTreeContextMenu(self, thePosition):
|
||||
|
||||
ctxMenu = GuiDocTreeCtx(self.treeView, self.theProject, thePosition)
|
||||
|
||||
ctxMenu = GuiDocTreeCtx(self.treeView, self.theProject, thePosition)
|
||||
selHandle = ctxMenu.selHandle
|
||||
selAction = ctxMenu.selAction
|
||||
selClass = ctxMenu.selClass
|
||||
selType = ctxMenu.selType
|
||||
selTarget = ctxMenu.selTarget
|
||||
|
||||
print(selAction, selClass, selType)
|
||||
print(selHandle, selAction, selClass, selType, selTarget)
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<novelWriterXML appVersion="0.0.1" fileVersion="1.0" timeStamp="2019-04-14 16:42:14">
|
||||
<novelWriterXML appVersion="0.0.1" fileVersion="1.0" timeStamp="2019-04-15 21:51:16">
|
||||
<project>
|
||||
<name>Sample Project</name>
|
||||
<title>Sample Project</title>
|
||||
<author>Jane Smith</author>
|
||||
<author>Jay Doh</author>
|
||||
</project>
|
||||
<content count="6">
|
||||
<content count="8">
|
||||
<item handle="7031beac91f75" order="0" parent="None">
|
||||
<name>Novel</name>
|
||||
<type>ROOT</type>
|
||||
@@ -44,13 +44,29 @@
|
||||
<type>ROOT</type>
|
||||
<class>CHARACTER</class>
|
||||
<depth>0</depth>
|
||||
<expanded>True</expanded>
|
||||
<children>True</children>
|
||||
</item>
|
||||
<item handle="14298de4d9524" order="0" parent="f6622b4617424">
|
||||
<name>Jon Smith</name>
|
||||
<type>FILE</type>
|
||||
<class>CHARACTER</class>
|
||||
<depth>1</depth>
|
||||
<expanded>False</expanded>
|
||||
<children>False</children>
|
||||
</item>
|
||||
<item handle="bb2c23b3c42cc" order="1" parent="f6622b4617424">
|
||||
<name>Jane Smith</name>
|
||||
<type>FILE</type>
|
||||
<class>CHARACTER</class>
|
||||
<depth>1</depth>
|
||||
<expanded>False</expanded>
|
||||
<children>False</children>
|
||||
</item>
|
||||
<item handle="73eee34351f85" order="2" parent="None">
|
||||
<name>World</name>
|
||||
<type>ROOT</type>
|
||||
<class>WORLD</class>
|
||||
<class>NONE</class>
|
||||
<depth>0</depth>
|
||||
<expanded>False</expanded>
|
||||
<children>False</children>
|
||||
|
||||
Reference in New Issue
Block a user