summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2021-01-16 15:55:56 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-16 15:55:56 +0100
commit89a735d6e11b8339b5b350d15ddd8fbfdf7998f5 (patch)
tree364ce83427e503e5c1f07bb48a192c72599d8248
parent56d039274776078cfff0565cf66fbb0b4852f90e (diff)
Maintain selection after 'Send to... ' and add send to first conflict.
-rw-r--r--src/modlistcontextmenu.cpp15
-rw-r--r--src/modlistviewactions.cpp52
-rw-r--r--src/modlistviewactions.h6
3 files changed, 59 insertions, 14 deletions
diff --git a/src/modlistcontextmenu.cpp b/src/modlistcontextmenu.cpp
index cdadbf8a..8bc73e40 100644
--- a/src/modlistcontextmenu.cpp
+++ b/src/modlistcontextmenu.cpp
@@ -247,7 +247,12 @@ void ModListContextMenu::addSendToContextMenu()
ModInfo::EConflictFlag::FLAG_CONFLICT_REDUNDANT
};
- bool overwritten = false;
+ static const std::vector overwrite_flags{
+ ModInfo::EConflictFlag::FLAG_CONFLICT_MIXED,
+ ModInfo::EConflictFlag::FLAG_CONFLICT_OVERWRITE
+ };
+
+ bool overwrite = false, overwritten = false;
for (auto& idx : m_selected) {
auto index = idx.data(ModList::IndexRole);
if (index.isValid()) {
@@ -256,7 +261,10 @@ void ModListContextMenu::addSendToContextMenu()
if (std::find_first_of(flags.begin(), flags.end(),
overwritten_flags.begin(), overwritten_flags.end()) != flags.end()) {
overwritten = true;
- break;
+ }
+ if (std::find_first_of(flags.begin(), flags.end(),
+ overwrite_flags.begin(), overwrite_flags.end()) != flags.end()) {
+ overwrite = true;
}
}
}
@@ -267,6 +275,9 @@ void ModListContextMenu::addSendToContextMenu()
menu->addAction(tr("Highest priority"), [this] { m_actions.sendModsToBottom(m_selected); });
menu->addAction(tr("Priority..."), [this] { m_actions.sendModsToPriority(m_selected); });
menu->addAction(tr("Separator..."), [this] { m_actions.sendModsToSeparator(m_selected); });
+ if (overwrite) {
+ menu->addAction(tr("First conflict"), [this] { m_actions.sendModsToFirstConflict(m_selected); });
+ }
if (overwritten) {
menu->addAction(tr("Last conflict"), [this] { m_actions.sendModsToLastConflict(m_selected); });
}
diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp
index 097c2538..03afa587 100644
--- a/src/modlistviewactions.cpp
+++ b/src/modlistviewactions.cpp
@@ -513,17 +513,24 @@ void ModListViewActions::displayModInformation(ModInfo::Ptr modInfo, unsigned in
}
}
-void ModListViewActions::sendModsToTop(const QModelIndexList& index) const
+void ModListViewActions::setModsPriority(const QModelIndexList& indexes, int priority) const
{
- m_core.modList()->changeModsPriority(index, 0);
+ auto [current, selected] = m_view->selected();
+ m_core.modList()->changeModsPriority(indexes, priority);
+ m_view->setSelected(current, selected);
}
-void ModListViewActions::sendModsToBottom(const QModelIndexList& index) const
+void ModListViewActions::sendModsToTop(const QModelIndexList& indexes) const
{
- m_core.modList()->changeModsPriority(index, std::numeric_limits<int>::max());
+ setModsPriority(indexes, 0);
}
-void ModListViewActions::sendModsToPriority(const QModelIndexList& index) const
+void ModListViewActions::sendModsToBottom(const QModelIndexList& indexes) const
+{
+ setModsPriority(indexes, std::numeric_limits<int>::max());
+}
+
+void ModListViewActions::sendModsToPriority(const QModelIndexList& indexes) const
{
bool ok;
int priority = QInputDialog::getInt(m_parent,
@@ -531,10 +538,10 @@ void ModListViewActions::sendModsToPriority(const QModelIndexList& index) const
0, 0, std::numeric_limits<int>::max(), 1, &ok);
if (!ok) return;
- m_core.modList()->changeModsPriority(index, priority);
+ setModsPriority(indexes, priority);
}
-void ModListViewActions::sendModsToSeparator(const QModelIndexList& index) const
+void ModListViewActions::sendModsToSeparator(const QModelIndexList& indexes) const
{
QStringList separators;
auto indexesByPriority = m_core.currentProfile()->getAllIndexesByPriority();
@@ -570,14 +577,35 @@ void ModListViewActions::sendModsToSeparator(const QModelIndexList& index) const
}
}
- if (index.size() == 1
- && m_core.currentProfile()->getModPriority(index[0].data(ModList::IndexRole).toInt()) < newPriority) {
+ if (indexes.size() == 1
+ && m_core.currentProfile()->getModPriority(indexes[0].data(ModList::IndexRole).toInt()) < newPriority) {
--newPriority;
}
- m_core.modList()->changeModsPriority(index, newPriority);
- m_view->scrollToAndSelect(index.first());
+ setModsPriority(indexes, newPriority);
+ }
+ }
+}
+
+void ModListViewActions::sendModsToFirstConflict(const QModelIndexList& indexes) const
+{
+ std::set<unsigned int> conflicts;
+
+ for (auto& idx : indexes) {
+ if (!idx.data(ModList::IndexRole).isValid()) {
+ continue;
}
+ auto info = ModInfo::getByIndex(idx.data(ModList::IndexRole).toInt());
+ conflicts.insert(info->getModOverwrite().begin(), info->getModOverwrite().end());
+ }
+
+ std::set<int> priorities;
+ std::transform(conflicts.begin(), conflicts.end(), std::inserter(priorities, priorities.end()), [=](auto index) {
+ return m_core.currentProfile()->getModPriority(index);
+ });
+
+ if (!priorities.empty()) {
+ setModsPriority(indexes, *priorities.begin());
}
}
@@ -599,7 +627,7 @@ void ModListViewActions::sendModsToLastConflict(const QModelIndexList& indexes)
});
if (!priorities.empty()) {
- m_core.modList()->changeModsPriority(indexes, *priorities.rbegin());
+ setModsPriority(indexes, *priorities.rbegin());
}
}
diff --git a/src/modlistviewactions.h b/src/modlistviewactions.h
index 153d0d2b..a3ae1b1a 100644
--- a/src/modlistviewactions.h
+++ b/src/modlistviewactions.h
@@ -62,6 +62,7 @@ public:
void sendModsToBottom(const QModelIndexList& index) const;
void sendModsToPriority(const QModelIndexList& index) const;
void sendModsToSeparator(const QModelIndexList& index) const;
+ void sendModsToFirstConflict(const QModelIndexList& index) const;
void sendModsToLastConflict(const QModelIndexList& index) const;
// actions for most regular mods
@@ -145,6 +146,11 @@ private:
//
void checkModsForUpdates(std::multimap<QString, int> const& IDs) const;
+ // set the priorities of the given mods while maintaining the
+ // mod list selection (which may be different from the list of mods)
+ //
+ void setModsPriority(const QModelIndexList& indexes, int priority) const;
+
private:
OrganizerCore& m_core;