GH-1652 save all instance settings on launch if instance window is already open
This commit is contained in:
		@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -41,6 +41,9 @@ public:
 | 
			
		||||
		m_shouldQuit = shouldQuit;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// save all settings and changes (prepare for launch)
 | 
			
		||||
	bool saveAll();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
	void isClosing();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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());
 | 
			
		||||
 
 | 
			
		||||
@@ -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())
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user