fixing drag/drop
parent
b1449ebcf6
commit
a95df29d8f
|
@ -22,9 +22,10 @@ using namespace Xybrid::Editing;
|
|||
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "util/macos_urlhelper.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
|
||||
SampleListModel::SampleListModel(QObject* parent, MainWindow* window) : QAbstractItemModel (parent) {
|
||||
this->window = window;
|
||||
root = std::make_shared<DirectoryNode>();
|
||||
|
@ -223,6 +224,7 @@ bool SampleListModel::canDropMimeData(const QMimeData *data, Qt::DropAction acti
|
|||
return data->hasUrls() || data->hasFormat("xybrid-internal/x-sample-entry-move");
|
||||
}
|
||||
|
||||
|
||||
bool SampleListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row [[maybe_unused]], int column [[maybe_unused]], const QModelIndex &parent [[maybe_unused]]) {
|
||||
if (data->hasUrls()) {
|
||||
if (action == Qt::IgnoreAction) return true; // can accept type
|
||||
|
@ -232,7 +234,16 @@ bool SampleListModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
|
|||
if (!tdn->isDirectory()) tdn = tdn->parent;
|
||||
QString p = tdn->path();
|
||||
|
||||
|
||||
QList<QUrl> urls = data->urls();
|
||||
#ifdef Q_OS_MAC
|
||||
QList<QUrl> localUrls;
|
||||
foreach (const QUrl &url, urls) {
|
||||
QUrl localUrl = fromNSUrl(url);
|
||||
localUrls.append(localUrl);
|
||||
urls = localUrls;
|
||||
}
|
||||
#endif
|
||||
bool success = false;
|
||||
for (auto u : urls) {
|
||||
if (!u.isLocalFile()) continue;
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#ifdef __APPLE__
|
||||
#ifndef MACOS_URLHELPER_H
|
||||
#define MACOS_URLHELPER_H
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
QUrl fromNSUrl(const QUrl &url);
|
||||
|
||||
#endif // MACOS_URLHELPER_H
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
#ifdef __APPLE__
|
||||
#include "macos_urlhelper.h"
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
QUrl fromNSUrl(const QUrl &url) {
|
||||
NSURL *nsUrl = url.toNSURL();
|
||||
NSString *path = nsUrl.path;
|
||||
QString qtString = QString::fromNSString(path);
|
||||
return QUrl::fromLocalFile(qtString);
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue