diff options
| author | Mikaƫl Capelle <capelle.mikael@gmail.com> | 2021-01-18 21:17:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-18 21:17:46 +0100 |
| commit | 0a683c0a5adda925e7dce5c9e0df5222b5ce3462 (patch) | |
| tree | fdf38d77f9ab5615161141d9df314551f696870e /src/modlistviewactions.cpp | |
| parent | 1f9a1da7f450937810a7ac8ee317cd28bdac0bdd (diff) | |
| parent | 3c0201a79909a878e6ae572b28bc7fc9588ff1c2 (diff) | |
Merge pull request #1372 from Holt59/install-mod-at
Modify 'Install mod... ' in context menu to install above current mod.
Diffstat (limited to 'src/modlistviewactions.cpp')
| -rw-r--r-- | src/modlistviewactions.cpp | 87 |
1 files changed, 47 insertions, 40 deletions
diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index 123fbf75..e7e74b16 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -50,7 +50,50 @@ ModListViewActions::ModListViewActions( } -void ModListViewActions::installMod(const QString& archivePath) const +int ModListViewActions::findInstallPriority(const QModelIndex& index) const +{ + int newPriority = -1; + if (index.isValid() && index.data(ModList::IndexRole).isValid() + && m_view->sortColumn() == ModList::COL_PRIORITY) { + auto mIndex = index.data(ModList::IndexRole).toInt(); + auto info = ModInfo::getByIndex(mIndex); + newPriority = m_core.currentProfile()->getModPriority(mIndex); + if (info->isSeparator()) { + + auto isSeparator = [](const auto& p) { + return ModInfo::getByIndex(p.second)->isSeparator(); + }; + + auto& ibp = m_core.currentProfile()->getAllIndexesByPriority(); + + // start right after/before the current priority and look for the next + // separator + if (m_view->sortOrder() == Qt::AscendingOrder) { + auto it = std::find_if(ibp.find(newPriority + 1), ibp.end(), isSeparator); + if (it != ibp.end()) { + newPriority = it->first; + } + else { + newPriority = -1; + } + } + else { + auto it = std::find_if(std::reverse_iterator{ ibp.find(newPriority - 1) }, ibp.rend(), isSeparator); + if (it != ibp.rend()) { + newPriority = it->first + 1; + } + else { + // create "before" priority 0, i.e. at the end in descending priority. + newPriority = 0; + } + } + } + } + + return newPriority; +} + +void ModListViewActions::installMod(const QString& archivePath, const QModelIndex& index) const { try { QString path = archivePath; @@ -68,7 +111,7 @@ void ModListViewActions::installMod(const QString& archivePath) const return; } else { - m_core.installMod(path, false, nullptr, QString()); + m_core.installMod(path, findInstallPriority(index), false, nullptr, QString()); } } catch (const std::exception& e) { @@ -97,43 +140,6 @@ void ModListViewActions::createEmptyMod(const QModelIndex& index) const return; } - int newPriority = -1; - if (index.isValid() && index.data(ModList::IndexRole).isValid() - && m_view->sortColumn() == ModList::COL_PRIORITY) { - auto mIndex = index.data(ModList::IndexRole).toInt(); - auto info = ModInfo::getByIndex(mIndex); - newPriority = m_core.currentProfile()->getModPriority(mIndex); - if (info->isSeparator()) { - - auto isSeparator = [](const auto& p) { - return ModInfo::getByIndex(p.second)->isSeparator(); - }; - - auto& ibp = m_core.currentProfile()->getAllIndexesByPriority(); - - // start right after/before the current priority and look for the next - // separator - if (m_view->sortOrder() == Qt::AscendingOrder) { - auto it = std::find_if(ibp.find(newPriority + 1), ibp.end(), isSeparator); - if (it != ibp.end()) { - newPriority = it->first; - } - else { - newPriority = -1; - } - } - else { - auto it = std::find_if(std::reverse_iterator{ ibp.find(newPriority - 1) }, ibp.rend(), isSeparator); - if (it != ibp.rend()) { - newPriority = it->first + 1; - } - else { - // create "before" priority 0, i.e. at the end in descending priority. - newPriority = 0; - } - } - } - } if (m_core.createMod(name) == nullptr) { return; @@ -141,6 +147,7 @@ void ModListViewActions::createEmptyMod(const QModelIndex& index) const m_core.refresh(); + const int newPriority = findInstallPriority(index); const auto mIndex = ModInfo::getIndex(name); if (newPriority >= 0) { m_core.modList()->changeModPriority(mIndex, newPriority); @@ -857,7 +864,7 @@ void ModListViewActions::reinstallMod(const QModelIndex& index) const fullInstallationFile = m_core.downloadManager()->getOutputDirectory() + "/" + installationFile; } if (QFile::exists(fullInstallationFile)) { - m_core.installMod(fullInstallationFile, true, modInfo, modInfo->name()); + m_core.installMod(fullInstallationFile, -1, true, modInfo, modInfo->name()); } else { QMessageBox::information(m_parent, tr("Failed"), tr("Installation file no longer exists")); |
