summaryrefslogtreecommitdiff
path: root/src/modlist.cpp
diff options
context:
space:
mode:
authorLostDragonist <lost.dragonist@gmail.com>2018-10-31 20:00:20 -0500
committerLostDragonist <lost.dragonist@gmail.com>2018-11-01 06:40:55 -0500
commit122744454c9befc06b582a8f0feb03bfbb85aa71 (patch)
treeebd98ab890695fb6c80ed5a50eefabc4e27b62cc /src/modlist.cpp
parent5de173ba1ae9531aaca0c0f022a2b0dae1c09250 (diff)
Improve changing mod and plugin priorities
Diffstat (limited to 'src/modlist.cpp')
-rw-r--r--src/modlist.cpp44
1 files changed, 33 insertions, 11 deletions
diff --git a/src/modlist.cpp b/src/modlist.cpp
index 6caafeb2..7b57eeda 100644
--- a/src/modlist.cpp
+++ b/src/modlist.cpp
@@ -654,26 +654,48 @@ void ModList::changeModPriority(std::vector<int> sourceIndices, int newPriority)
emit layoutAboutToBeChanged();
Profile *profile = m_Profile;
- // sort rows to insert by their old priority (ascending) and insert them move them in that order
+
+ // sort the moving mods by ascending priorities
std::sort(sourceIndices.begin(), sourceIndices.end(),
- [profile](const int &LHS, const int &RHS) {
- return profile->getModPriority(LHS) < profile->getModPriority(RHS);
- });
+ [profile](const int &LHS, const int &RHS) {
+ return profile->getModPriority(LHS) > profile->getModPriority(RHS);
+ });
- // odd stuff: if any of the dragged sources has priority lower than the destination then the
- // target idx is that of the row BELOW the dropped location, otherwise it's the one above. why?
+ // move mods that are decreasing in priority
for (std::vector<int>::const_iterator iter = sourceIndices.begin();
iter != sourceIndices.end(); ++iter) {
- if (profile->getModPriority(*iter) < newPriority) {
+ int oldPriority = profile->getModPriority(*iter);
+ if (oldPriority > newPriority) {
+ profile->setModPriority(*iter, newPriority);
+ m_ModMoved(ModInfo::getByIndex(*iter)->name(), oldPriority, newPriority);
+ }
+ }
+
+ // sort the moving mods by descending priorities
+ std::sort(sourceIndices.begin(), sourceIndices.end(),
+ [profile](const int &LHS, const int &RHS) {
+ return profile->getModPriority(LHS) < profile->getModPriority(RHS);
+ });
+
+ // if at least one mod is increasing in priority, the target index is
+ // that of the row BELOW the dropped location, otherwise it's the one above
+ for (std::vector<int>::const_iterator iter = sourceIndices.begin();
+ iter != sourceIndices.end(); ++iter) {
+ int oldPriority = profile->getModPriority(*iter);
+ if (oldPriority < newPriority) {
--newPriority;
break;
}
}
+
+ // move mods that are increasing in priority
for (std::vector<int>::const_iterator iter = sourceIndices.begin();
- iter != sourceIndices.end(); ++iter) {
- int oldPriority = m_Profile->getModPriority(*iter);
- m_Profile->setModPriority(*iter, newPriority);
- m_ModMoved(ModInfo::getByIndex(*iter)->name(), oldPriority, newPriority);
+ iter != sourceIndices.end(); ++iter) {
+ int oldPriority = profile->getModPriority(*iter);
+ if (oldPriority < newPriority) {
+ profile->setModPriority(*iter, newPriority);
+ m_ModMoved(ModInfo::getByIndex(*iter)->name(), oldPriority, newPriority);
+ }
}
emit layoutChanged();