summaryrefslogtreecommitdiff
path: root/src/modlistviewactions.cpp
diff options
context:
space:
mode:
authorMikaƫl Capelle <capelle.mikael@gmail.com>2021-01-14 09:11:37 +0100
committerGitHub <noreply@github.com>2021-01-14 09:11:37 +0100
commit34f7ae24501f75d5a74a09b6af939db6edaf6f1c (patch)
tree616c67f6d23f951c98003c710bab63e2192a4b7b /src/modlistviewactions.cpp
parentc3334e7b4d17f3005bd3c4dab8eee42b1e5510f8 (diff)
parent18f70a2dff138f273a9b6babaec226775a03649f (diff)
Merge pull request #1357 from Holt59/collapsible-separators
Collapsible separators in descending priority.
Diffstat (limited to 'src/modlistviewactions.cpp')
-rw-r--r--src/modlistviewactions.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp
index cc50f009..09142026 100644
--- a/src/modlistviewactions.cpp
+++ b/src/modlistviewactions.cpp
@@ -103,22 +103,33 @@ void ModListViewActions::createEmptyMod(const QModelIndex& index) const
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 the current priority and look for the next
+ // start right after/before the current priority and look for the next
// separator
- auto it = ibp.find(newPriority + 1);
- for (; it != ibp.end(); ++it) {
- auto info = ModInfo::getByIndex(it->second);
- if (info->isSeparator()) {
+ 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;
- break;
+ }
+ else {
+ newPriority = -1;
}
}
-
- // no separator found, create at the end
- if (it == ibp.end()) {
- 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;
+ }
}
}
}