Skip to content

Commit

Permalink
Merge pull request #53 from ChrisHal/improvements
Browse files Browse the repository at this point in the history
Improve file dropping, reject attempt to move file or drop of multiple files
  • Loading branch information
ChrisHal authored Dec 6, 2024
2 parents 86f973e + 41c4ad5 commit 0e7dbae
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions QtPMbrowser/pmbrowserwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,29 +1150,39 @@ void PMbrowserWindow::openPreferences()

void PMbrowserWindow::dragEnterEvent(QDragEnterEvent* event)
{
auto mimedata = event->mimeData();
if (mimedata->hasUrls()) {
auto urls = mimedata->urls();
auto& url = urls[0];
if (url.isLocalFile()) {
auto filename = url.toLocalFile();
if (filename.endsWith(".dat")) {
event->acceptProposedAction();
if (event->dropAction() == Qt::CopyAction) {
auto mimedata = event->mimeData();
if (mimedata->hasUrls()) {
auto urls = mimedata->urls();
if (urls.length() == 1) { // only accept 1 file at a time
auto& url = urls[0];
if (url.isLocalFile()) {
auto filename = url.toLocalFile();
if (filename.endsWith(".dat")) {
event->acceptProposedAction();
}
}
}
}
}
}

void PMbrowserWindow::dropEvent(QDropEvent* event)
{
auto mimedata = event->mimeData();
if (mimedata->hasUrls()) {
auto urls = mimedata->urls();
auto& url = urls[0];
if (url.isLocalFile()) {
auto filename = url.toLocalFile();
if (filename.endsWith(".dat")) {
loadFile(filename);
if (event->dropAction() == Qt::CopyAction) {
auto mimedata = event->mimeData();
if (mimedata->hasUrls()) {
auto urls = mimedata->urls();
if (urls.length() == 1) {
auto& url = urls[0];
if (url.isLocalFile()) {
auto filename = url.toLocalFile();
if (filename.endsWith(".dat")) {
loadFile(filename);
// check file has been loaded:
if(datfile) event->acceptProposedAction();
}
}
}
}
}
Expand Down

0 comments on commit 0e7dbae

Please sign in to comment.