Move large condition into a new lambda
Signed-off-by: Gingeh <39150378+Gingeh@users.noreply.github.com>
This commit is contained in:
parent
f33b31e048
commit
a8aa862919
@ -84,24 +84,25 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel>
|
|||||||
ui->actionsToolbar->insertActionAfter(ui->actionAddItem, ui->actionUpdateItem);
|
ui->actionsToolbar->insertActionAfter(ui->actionAddItem, ui->actionUpdateItem);
|
||||||
connect(ui->actionUpdateItem, &QAction::triggered, this, &ModFolderPage::updateMods);
|
connect(ui->actionUpdateItem, &QAction::triggered, this, &ModFolderPage::updateMods);
|
||||||
|
|
||||||
connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this] {
|
auto check_allow_update = [this] {
|
||||||
ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) &&
|
return (!m_instance || !m_instance->isRunning()) &&
|
||||||
(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()));
|
(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] {
|
connect(mods.get(), &ModFolderModel::rowsInserted, this, [this, check_allow_update] {
|
||||||
ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) &&
|
ui->actionUpdateItem->setEnabled(check_allow_update());
|
||||||
(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(mods.get(), &ModFolderModel::rowsRemoved, this, [this] {
|
connect(mods.get(), &ModFolderModel::rowsRemoved, this, [this, check_allow_update] {
|
||||||
ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) &&
|
ui->actionUpdateItem->setEnabled(check_allow_update());
|
||||||
(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(mods.get(), &ModFolderModel::updateFinished, this, [this, mods] {
|
connect(mods.get(), &ModFolderModel::updateFinished, this, [this, check_allow_update, mods] {
|
||||||
ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) &&
|
ui->actionUpdateItem->setEnabled(check_allow_update());
|
||||||
(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()));
|
|
||||||
|
|
||||||
// Prevent a weird crash when trying to open the mods page twice in a session o.O
|
// Prevent a weird crash when trying to open the mods page twice in a session o.O
|
||||||
disconnect(mods.get(), &ModFolderModel::updateFinished, this, 0);
|
disconnect(mods.get(), &ModFolderModel::updateFinished, this, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user