From f33b31e048affecf76083fbc56d02e883d0fffad Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Tue, 2 Aug 2022 14:14:45 +1000 Subject: [PATCH] Check for running instance when re-opening the mod folder page and when selecting mods Signed-off-by: Gingeh <39150378+Gingeh@users.noreply.github.com> --- .../pages/instance/ExternalResourcesPage.cpp | 2 +- launcher/ui/pages/instance/ModFolderPage.cpp | 25 +++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.cpp b/launcher/ui/pages/instance/ExternalResourcesPage.cpp index 69c20309..39fbe3e2 100644 --- a/launcher/ui/pages/instance/ExternalResourcesPage.cpp +++ b/launcher/ui/pages/instance/ExternalResourcesPage.cpp @@ -101,7 +101,7 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared { ui->setupUi(this); - runningStateChanged(m_instance && m_instance->isRunning()); + ExternalResourcesPage::runningStateChanged(m_instance && m_instance->isRunning()); ui->actionsToolbar->insertSpacer(ui->actionViewConfigs); diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index 0db6a0ca..b3f4759f 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -84,21 +84,30 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr ui->actionsToolbar->insertActionAfter(ui->actionAddItem, ui->actionUpdateItem); connect(ui->actionUpdateItem, &QAction::triggered, this, &ModFolderPage::updateMods); - connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, - [this] { ui->actionUpdateItem->setEnabled(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); }); + connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this] { + ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && + (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); + }); - connect(mods.get(), &ModFolderModel::rowsInserted, this, - [this] { ui->actionUpdateItem->setEnabled(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); }); + connect(mods.get(), &ModFolderModel::rowsInserted, this, [this] { + ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && + (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); + }); + + connect(mods.get(), &ModFolderModel::rowsRemoved, this, [this] { + ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && + (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); + }); - connect(mods.get(), &ModFolderModel::rowsRemoved, this, - [this] { ui->actionUpdateItem->setEnabled(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); }); - connect(mods.get(), &ModFolderModel::updateFinished, this, [this, mods] { - ui->actionUpdateItem->setEnabled(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); + ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && + (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); // Prevent a weird crash when trying to open the mods page twice in a session o.O disconnect(mods.get(), &ModFolderModel::updateFinished, this, 0); }); + + ModFolderPage::runningStateChanged(m_instance && m_instance->isRunning()); } }