diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index e0870d06..8661c199 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -449,6 +449,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow view->installEventFilter(this); view->setContextMenuPolicy(Qt::CustomContextMenu); connect(view, &QWidget::customContextMenuRequested, this, &MainWindow::showInstanceContextMenu); + connect(view, &GroupView::droppedURLs, this, &MainWindow::droppedURLs); proxymodel = new InstanceProxyModel(this); proxymodel->setSourceModel(MMC->instances().get()); @@ -1076,7 +1077,7 @@ void MainWindow::finalizeInstance(InstancePtr inst) } } -void MainWindow::on_actionAddInstance_triggered() +void MainWindow::addInstance(QString url) { QString groupName; do @@ -1098,7 +1099,7 @@ void MainWindow::on_actionAddInstance_triggered() groupName = MMC->settings()->get("LastUsedGroupForNewInstance").toString(); } - NewInstanceDialog newInstDlg(groupName, this); + NewInstanceDialog newInstDlg(groupName, url, this); if (!newInstDlg.exec()) return; @@ -1116,6 +1117,28 @@ void MainWindow::on_actionAddInstance_triggered() } } +void MainWindow::on_actionAddInstance_triggered() +{ + addInstance(); +} + +void MainWindow::droppedURLs(QList urls) +{ + for(auto & url:urls) + { + if(url.isLocalFile()) + { + addInstance(url.toLocalFile()); + } + else + { + addInstance(url.toString()); + } + // Only process one dropped file... + break; + } +} + void MainWindow::on_actionREDDIT_triggered() { DesktopServices::openUrl(QUrl("https://www.reddit.com/r/MultiMC/")); diff --git a/application/MainWindow.h b/application/MainWindow.h index a7ab9172..e21d2830 100644 --- a/application/MainWindow.h +++ b/application/MainWindow.h @@ -161,7 +161,10 @@ private slots: */ void downloadUpdates(GoUpdate::Status status); + void droppedURLs(QList urls); + private: + void addInstance(QString url = QString()); void activateInstance(InstancePtr instance); void setCatBackground(bool enabled); void updateInstanceToolIcon(QString new_icon); diff --git a/application/dialogs/NewInstanceDialog.cpp b/application/dialogs/NewInstanceDialog.cpp index 8180aa27..d1a2bbfa 100644 --- a/application/dialogs/NewInstanceDialog.cpp +++ b/application/dialogs/NewInstanceDialog.cpp @@ -57,7 +57,7 @@ public: } }; -NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, QWidget *parent) +NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString & url, QWidget *parent) : QDialog(parent), ui(new Ui::NewInstanceDialog) { ui->setupUi(this); @@ -112,6 +112,11 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, QWidget *pare ui->buttonBox->setFocus(); originalPlaceholderText = ui->instNameTextBox->placeholderText(); + if(!url.isEmpty()) + { + ui->modpackBox->setChecked(true); + ui->modpackEdit->setText(url); + } updateDialogState(); } diff --git a/application/dialogs/NewInstanceDialog.h b/application/dialogs/NewInstanceDialog.h index 1741dab8..000b6a06 100644 --- a/application/dialogs/NewInstanceDialog.h +++ b/application/dialogs/NewInstanceDialog.h @@ -29,7 +29,7 @@ class NewInstanceDialog : public QDialog Q_OBJECT public: - explicit NewInstanceDialog(const QString & initialGroup, QWidget *parent = 0); + explicit NewInstanceDialog(const QString & initialGroup, const QString & url = QString(), QWidget *parent = 0); ~NewInstanceDialog(); void updateDialogState(); diff --git a/application/groupview/GroupView.cpp b/application/groupview/GroupView.cpp index a6844102..1ce0568b 100644 --- a/application/groupview/GroupView.cpp +++ b/application/groupview/GroupView.cpp @@ -534,31 +534,46 @@ void GroupView::dropEvent(QDropEvent *event) stopAutoScroll(); setState(NoState); - if (event->source() != this || !(event->possibleActions() & Qt::MoveAction)) + if (event->source() == this) + { + if(event->possibleActions() & Qt::MoveAction) + { + QPair dropPos = rowDropPos(event->pos() + offset()); + const VisualGroup *category = dropPos.first; + const int row = dropPos.second; + + if (row == -1) + { + viewport()->update(); + return; + } + + const QString categoryText = category->text; + if (model()->dropMimeData(event->mimeData(), Qt::MoveAction, row, 0, QModelIndex())) + { + model()->setData(model()->index(row, 0), categoryText, + GroupViewRoles::GroupRole); + event->setDropAction(Qt::MoveAction); + event->accept(); + } + updateGeometries(); + viewport()->update(); + } + } + auto mimedata = event->mimeData(); + + // check if the action is supported + if (!mimedata) { return; } - QPair dropPos = rowDropPos(event->pos() + offset()); - const VisualGroup *category = dropPos.first; - const int row = dropPos.second; - - if (row == -1) + // files dropped from outside? + if (mimedata->hasUrls()) { - viewport()->update(); - return; + auto urls = mimedata->urls(); + emit droppedURLs(urls); } - - const QString categoryText = category->text; - if (model()->dropMimeData(event->mimeData(), Qt::MoveAction, row, 0, QModelIndex())) - { - model()->setData(model()->index(row, 0), categoryText, - GroupViewRoles::GroupRole); - event->setDropAction(Qt::MoveAction); - event->accept(); - } - updateGeometries(); - viewport()->update(); } void GroupView::startDrag(Qt::DropActions supportedActions) @@ -707,7 +722,7 @@ QList> GroupView::draggablePaintPairs(const QModelInde bool GroupView::isDragEventAccepted(QDropEvent *event) { - return false; + return true; } QPair GroupView::rowDropPos(const QPoint &pos) diff --git a/application/groupview/GroupView.h b/application/groupview/GroupView.h index e0ff1cd9..37c37f2f 100644 --- a/application/groupview/GroupView.h +++ b/application/groupview/GroupView.h @@ -62,6 +62,9 @@ protected slots: void modelReset(); void rowsRemoved(); +signals: + void droppedURLs(QList urls); + protected: virtual bool isIndexHidden(const QModelIndex &index) const override; void mousePressEvent(QMouseEvent *event) override;