Skip to content

Commit

Permalink
PICARD-2696: Fix file deletion when shift-dropping files on Windows
Browse files Browse the repository at this point in the history
When dropping while pressing shift on Windows the files get sent as a
"move" event to the application. Accepting this results in file deletion.
Picard must always handle such events as "copy" to avoid this.
  • Loading branch information
phw committed Aug 13, 2023
1 parent a2bb94a commit ddc695c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
13 changes: 5 additions & 8 deletions picard/ui/coverartbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,9 @@ def __eq__(self, other):
else:
return True

@staticmethod
def dragEnterEvent(event):
event.acceptProposedAction()

@staticmethod
def dragMoveEvent(event):
event.acceptProposedAction()
def dragEnterEvent(self, event):
event.setDropAction(QtCore.Qt.DropAction.CopyAction)
event.accept()

def dropEvent(self, event):
accepted = False
Expand Down Expand Up @@ -170,7 +166,8 @@ def dropEvent(self, event):
self.image_dropped.emit(QtCore.QUrl(''), dropped_data)

if accepted:
event.acceptProposedAction()
event.setDropAction(QtCore.Qt.DropAction.CopyAction)
event.accept()

def scaled(self, *dimensions):
return (round(self.pixel_ratio * dimension) for dimension in dimensions)
Expand Down
12 changes: 9 additions & 3 deletions picard/ui/itemviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Copyright (C) 2007 Robert Kaye
# Copyright (C) 2008 Gary van der Merwe
# Copyright (C) 2008 Hendrik van Antwerpen
# Copyright (C) 2008-2011, 2014-2015, 2018-2022 Philipp Wolfer
# Copyright (C) 2008-2011, 2014-2015, 2018-2023 Philipp Wolfer
# Copyright (C) 2009 Carlin Mangar
# Copyright (C) 2009 Nikolai Prokoschenko
# Copyright (C) 2011 Tim Blechmann
Expand Down Expand Up @@ -695,7 +695,7 @@ def mimeTypes(self):
return ["text/uri-list", "application/picard.album-list"]

def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
if not event.source() or event.mimeData().hasUrls():
event.setDropAction(QtCore.Qt.DropAction.CopyAction)
event.accept()
else:
Expand Down Expand Up @@ -767,7 +767,13 @@ def dropEvent(self, event):
# assigned to the same track.
if event.keyboardModifiers() == QtCore.Qt.KeyboardModifier.AltModifier:
self._move_to_multi_tracks = False
return QtWidgets.QTreeView.dropEvent(self, event)
QtWidgets.QTreeView.dropEvent(self, event)
# The parent dropEvent implementation automatically accepts the proposed
# action. Override this, for external drops we never support move (which
# can result in file deletion, e.g. on Windows).
if event.isAccepted() and (not event.source() or event.mimeData().hasUrls()):
event.setDropAction(QtCore.Qt.DropAction.CopyAction)
event.accept()

def dropMimeData(self, parent, index, data, action):
target = None
Expand Down

0 comments on commit ddc695c

Please sign in to comment.