diff --git a/application/InstanceWindow.cpp b/application/InstanceWindow.cpp index 9fdd3ca87..7b3e1d10d 100644 --- a/application/InstanceWindow.cpp +++ b/application/InstanceWindow.cpp @@ -162,7 +162,7 @@ void InstanceWindow::closeEvent(QCloseEvent *event) bool proceed = true; if(!m_doNotSave) { - proceed &= m_container->requestClose(event); + proceed &= m_container->prepareToClose(); } if(!proceed) @@ -181,6 +181,11 @@ void InstanceWindow::closeEvent(QCloseEvent *event) } } +bool InstanceWindow::saveAll() +{ + return m_container->prepareToClose(); +} + void InstanceWindow::on_btnKillMinecraft_clicked() { if(m_instance->isRunning()) @@ -195,7 +200,8 @@ void InstanceWindow::on_btnKillMinecraft_clicked() m_proc->abort(); } } - else + // FIXME: duplicate logic between MainWindow and InstanceWindow + else if(saveAll()) { m_launchController.reset(new LaunchController()); m_launchController->setInstance(m_instance); @@ -207,7 +213,7 @@ void InstanceWindow::on_btnKillMinecraft_clicked() void InstanceWindow::onSucceeded() { - if (m_instance->settings()->get("AutoCloseConsole").toBool() && m_container->requestClose(nullptr)) + if (m_instance->settings()->get("AutoCloseConsole").toBool() && m_container->prepareToClose()) { this->close(); return; diff --git a/application/InstanceWindow.h b/application/InstanceWindow.h index 71bf4d40c..1a6bc8c3a 100644 --- a/application/InstanceWindow.h +++ b/application/InstanceWindow.h @@ -41,6 +41,9 @@ public: m_shouldQuit = shouldQuit; } + // save all settings and changes (prepare for launch) + bool saveAll(); + signals: void isClosing(); diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 3a2977849..e07686dd7 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -1463,6 +1463,15 @@ void MainWindow::launch(InstancePtr instance, bool online, BaseProfilerFactory * { if(instance->canLaunch()) { + // FIXME: duplicate logic between MainWindow and InstanceWindow + auto window = m_instanceWindows.find(instance->id()); + if(window != m_instanceWindows.end()) + { + if(!(*window)->saveAll()) + { + return; + } + } m_launchController.reset(new LaunchController()); m_launchController->setInstance(instance); m_launchController->setOnline(online); diff --git a/application/pagedialog/PageDialog.cpp b/application/pagedialog/PageDialog.cpp index 7665ddf70..4101da4f8 100644 --- a/application/pagedialog/PageDialog.cpp +++ b/application/pagedialog/PageDialog.cpp @@ -53,7 +53,7 @@ PageDialog::PageDialog(BasePageProviderPtr pageProvider, QString defaultId, QWid void PageDialog::closeEvent(QCloseEvent *event) { qDebug() << "Paged dialog close requested"; - if (m_container->requestClose(event)) + if (m_container->prepareToClose()) { qDebug() << "Paged dialog close approved"; MMC->settings()->set("PagedGeometry", saveGeometry().toBase64()); diff --git a/application/widgets/PageContainer.cpp b/application/widgets/PageContainer.cpp index 24814d577..840b39d42 100644 --- a/application/widgets/PageContainer.cpp +++ b/application/widgets/PageContainer.cpp @@ -215,7 +215,7 @@ void PageContainer::currentChanged(const QModelIndex ¤t) showPage(current.isValid() ? m_proxyModel->mapToSource(current).row() : -1); } -bool PageContainer::requestClose(QCloseEvent *event) +bool PageContainer::prepareToClose() { for (auto page : m_model->pages()) { diff --git a/application/widgets/PageContainer.h b/application/widgets/PageContainer.h index 939712097..e7dc8b084 100644 --- a/application/widgets/PageContainer.h +++ b/application/widgets/PageContainer.h @@ -41,7 +41,11 @@ public: void addButtons(QWidget * buttons); void addButtons(QLayout * buttons); - bool requestClose(QCloseEvent *event); + /* + * Save any unsaved state and prepare to be closed. + * @return true if everything can be saved, false if there is something that requires attention + */ + bool prepareToClose(); virtual bool selectPage(QString pageId) override;