diff options
| -rw-r--r-- | src/modlistcontextmenu.cpp | 13 | ||||
| -rw-r--r-- | src/modlistviewactions.cpp | 85 | ||||
| -rw-r--r-- | src/modlistviewactions.h | 5 |
3 files changed, 54 insertions, 49 deletions
diff --git a/src/modlistcontextmenu.cpp b/src/modlistcontextmenu.cpp index 66516ed5..c7cbb033 100644 --- a/src/modlistcontextmenu.cpp +++ b/src/modlistcontextmenu.cpp @@ -30,16 +30,19 @@ void ModListGlobalContextMenu::populate(OrganizerCore& core, ModListView* view, auto info = ModInfo::getByIndex(modIndex.toInt()); if (!info->isBackup()) { - addAction(tr("Install mod above..."), [=]() { view->actions().installMod("", index); }); - QString text = tr("Create empty mod above"); + QString installText = tr("Install mod above... "); + QString createText = tr("Create empty mod above"); if (info->isSeparator()) { - text = tr("Create empty mod inside"); + installText = tr("Install mod inside... "); + createText = tr("Create empty mod inside"); } else if (view->sortOrder() == Qt::DescendingOrder) { - text = tr("Create empty mod below"); + installText = tr("Install mod below... "); + createText = tr("Create empty mod below"); } - addAction(text, [=]() { view->actions().createEmptyMod(index); }); + addAction(installText, [=]() { view->actions().installMod("", index); }); + addAction(createText, [=]() { view->actions().createEmptyMod(index); }); addAction(tr("Create separator above"), [=]() { view->actions().createSeparator(index); }); } } diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index fe0bfc38..0042d9c0 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -50,18 +50,51 @@ ModListViewActions::ModListViewActions( } -void ModListViewActions::installMod(const QString& archivePath, const QModelIndex& index) const +int ModListViewActions::findInstallPriority(const QModelIndex& index) const { int newPriority = -1; - if (index.isValid() && m_view->sortColumn() == ModList::COL_PRIORITY) { - newPriority = m_core.currentProfile()->getModPriority(index.data(ModList::IndexRole).toInt()); + 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()) { - // descending order, we need to fix the priority - if (m_view->sortOrder() == Qt::DescendingOrder) { - newPriority++; + 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; if (path.isEmpty()) { @@ -78,7 +111,7 @@ void ModListViewActions::installMod(const QString& archivePath, const QModelInde return; } else { - m_core.installMod(path, newPriority, false, nullptr, QString()); + m_core.installMod(path, findInstallPriority(index), false, nullptr, QString()); } } catch (const std::exception& e) { @@ -107,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; @@ -151,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); diff --git a/src/modlistviewactions.h b/src/modlistviewactions.h index 069bb1e6..429c37b6 100644 --- a/src/modlistviewactions.h +++ b/src/modlistviewactions.h @@ -134,6 +134,11 @@ signals: private: + // find the priority where to install or create a mod for the + // given index (e.g. above, below, inside separator or at the end) + // + int findInstallPriority(const QModelIndex& current) const; + // move the contents of the overwrite to the given path // void moveOverwriteContentsTo(const QString& absolutePath) const; |
