From a8aa86291965ddd3cdfa2bb5f5fc7a34170559ed Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Wed, 3 Aug 2022 16:39:30 +1000 Subject: [PATCH] Move large condition into a new lambda Signed-off-by: Gingeh <39150378+Gingeh@users.noreply.github.com> --- launcher/ui/pages/instance/ModFolderPage.cpp | 25 ++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index b3f4759f..1b2cde0c 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -84,24 +84,25 @@ 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(!(m_instance && m_instance->isRunning()) && - (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); + auto check_allow_update = [this] { + return (!m_instance || !m_instance->isRunning()) && + (ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); + }; + + connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this, check_allow_update] { + ui->actionUpdateItem->setEnabled(check_allow_update()); }); - 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::rowsInserted, this, [this, check_allow_update] { + ui->actionUpdateItem->setEnabled(check_allow_update()); }); - 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, check_allow_update] { + ui->actionUpdateItem->setEnabled(check_allow_update()); }); - connect(mods.get(), &ModFolderModel::updateFinished, this, [this, mods] { - ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && - (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); + connect(mods.get(), &ModFolderModel::updateFinished, this, [this, check_allow_update, mods] { + ui->actionUpdateItem->setEnabled(check_allow_update()); // Prevent a weird crash when trying to open the mods page twice in a session o.O disconnect(mods.get(), &ModFolderModel::updateFinished, this, 0);