1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Smarter double-click

This commit is contained in:
nordsoft 2023-09-01 17:40:52 +04:00
parent 31956549e6
commit 5875dc6b8f

View File

@ -893,29 +893,46 @@ void CModListView::on_allModsView_doubleClicked(const QModelIndex &index)
{ {
if(!index.isValid()) if(!index.isValid())
return; return;
auto mod = modModel->getMod(index.data(ModRoles::ModNameRole).toString()); auto modName = index.data(ModRoles::ModNameRole).toString();
auto mod = modModel->getMod(modName);
if(mod.isAvailable() && !mod.getName().contains('.'))
bool hasInvalidDeps = !findInvalidDependencies(modName).empty();
bool hasBlockingMods = !findBlockingMods(modName).empty();
bool hasDependentMods = !findDependentMods(modName, true).empty();
if(!hasInvalidDeps && mod.isAvailable() && !mod.getName().contains('.'))
{ {
on_installButton_clicked(); on_installButton_clicked();
return; return;
} }
if(mod.isUpdateable()) if(!hasInvalidDeps && !hasDependentMods && mod.isUpdateable() && index.column() == ModFields::STATUS_UPDATE)
{ {
on_updateButton_clicked(); on_updateButton_clicked();
return;
}
if(index.column() == ModFields::NAME)
{
if(ui->allModsView->isExpanded(index))
ui->allModsView->collapse(index);
else
ui->allModsView->expand(index);
return;
} }
if(mod.isDisabled()) if(!hasBlockingMods && !hasInvalidDeps && mod.isDisabled())
{ {
on_enableButton_clicked(); on_enableButton_clicked();
return; return;
} }
if(mod.isEnabled()) if(!hasDependentMods && !mod.isEssential() && mod.isEnabled())
{ {
on_disableButton_clicked(); on_disableButton_clicked();
return;
} }
} }