GH-1873 allow closing main window, fix window ref count

This commit is contained in:
Petr Mrázek 2017-05-01 01:27:10 +02:00
parent f06ac02396
commit 21df531db1
3 changed files with 10 additions and 25 deletions

View File

@ -1403,28 +1403,11 @@ void MainWindow::on_actionViewSelectedInstFolder_triggered()
void MainWindow::closeEvent(QCloseEvent *event)
{
if(MMC->numRunningInstances())
{
auto resBtn = QMessageBox::question(
this,
tr("Do you want to close MultiMC?"),
tr("<p>You still have instances running.</p><p>Closing MultiMC will result in inaccurate time tracking and no Minecraft crash handling.</p><p>Are you sure?</p>"),
QMessageBox::No | QMessageBox::Yes,
QMessageBox::Yes
);
if (resBtn != QMessageBox::Yes)
{
event->ignore();
return;
}
}
// no running instances or user said yes.
event->accept();
// Save the window state and geometry.
MMC->settings()->set("MainWindowState", saveState().toBase64());
MMC->settings()->set("MainWindowGeometry", saveGeometry().toBase64());
QApplication::exit();
event->accept();
emit isClosing();
}
void MainWindow::changeEvent(QEvent* event)

View File

@ -54,6 +54,9 @@ public:
void checkInstancePathForProblems();
signals:
void isClosing();
private slots:
void onCatToggled(bool);

View File

@ -444,8 +444,6 @@ void MultiMC::performMainStartupAction()
auto inst = instances()->getInstanceById(m_instanceIdToLaunch);
if(inst)
{
// minimized main window
showMainWindow(true);
launch(inst, true, nullptr);
return;
}
@ -1020,7 +1018,7 @@ void MultiMC::controllerSucceeded()
if(m_openWindows == 0 && m_runningInstances == 0)
{
m_status = Status::Succeeded;
quit();
exit(0);
}
}
@ -1041,7 +1039,7 @@ void MultiMC::controllerFailed(const QString& error)
if(m_openWindows == 0 && m_runningInstances == 0)
{
m_status = Status::Failed;
quit();
exit(1);
}
}
@ -1068,6 +1066,7 @@ MainWindow* MultiMC::showMainWindow(bool minimized)
}
m_mainWindow->checkInstancePathForProblems();
connect(m_mainWindow, &MainWindow::isClosing, this, &MultiMC::on_windowClose);
m_openWindows++;
}
// FIXME: move this somewhere else...
@ -1157,9 +1156,9 @@ void MultiMC::on_windowClose()
m_mainWindow = nullptr;
}
// quit when there are no more windows.
if(m_openWindows == 0)
if(m_openWindows == 0 && m_runningInstances == 0)
{
quit();
exit(0);
}
}