summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2021-01-18 20:05:13 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-18 20:05:13 +0100
commit792a402782f979c2fe5747d30b8faffb054a4c26 (patch)
treeb79922a015644aff9a17751b1c2c836f62d34da2 /src
parent59f055ba93381b965cdc04557ac1dce2df36bd07 (diff)
Modify 'Install mod... ' in context menu to install above current mod.
Diffstat (limited to 'src')
-rw-r--r--src/modlistcontextmenu.cpp5
-rw-r--r--src/modlistviewactions.cpp16
-rw-r--r--src/modlistviewactions.h5
-rw-r--r--src/organizercore.cpp3
-rw-r--r--src/organizercore.h2
-rw-r--r--src/organizerproxy.cpp2
6 files changed, 24 insertions, 9 deletions
diff --git a/src/modlistcontextmenu.cpp b/src/modlistcontextmenu.cpp
index f4aea109..66516ed5 100644
--- a/src/modlistcontextmenu.cpp
+++ b/src/modlistcontextmenu.cpp
@@ -24,12 +24,14 @@ void ModListGlobalContextMenu::populate(OrganizerCore& core, ModListView* view,
{
clear();
- addAction(tr("Install Mod..."), [=]() { view->actions().installMod(); });
auto modIndex = index.data(ModList::IndexRole);
if (modIndex.isValid() && view->sortColumn() == ModList::COL_PRIORITY) {
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");
if (info->isSeparator()) {
text = tr("Create empty mod inside");
@@ -42,6 +44,7 @@ void ModListGlobalContextMenu::populate(OrganizerCore& core, ModListView* view,
}
}
else {
+ addAction(tr("Install mod..."), [=]() { view->actions().installMod(); });
addAction(tr("Create empty mod"), [=]() { view->actions().createEmptyMod(); });
addAction(tr("Create separator"), [=]() { view->actions().createSeparator(); });
}
diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp
index 5af79b3b..fe0bfc38 100644
--- a/src/modlistviewactions.cpp
+++ b/src/modlistviewactions.cpp
@@ -50,8 +50,18 @@ ModListViewActions::ModListViewActions(
}
-void ModListViewActions::installMod(const QString& archivePath) const
+void ModListViewActions::installMod(const QString& archivePath, 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());
+
+ // descending order, we need to fix the priority
+ if (m_view->sortOrder() == Qt::DescendingOrder) {
+ newPriority++;
+ }
+ }
+
try {
QString path = archivePath;
if (path.isEmpty()) {
@@ -68,7 +78,7 @@ void ModListViewActions::installMod(const QString& archivePath) const
return;
}
else {
- m_core.installMod(path, false, nullptr, QString());
+ m_core.installMod(path, newPriority, false, nullptr, QString());
}
}
catch (const std::exception& e) {
@@ -864,7 +874,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"));
diff --git a/src/modlistviewactions.h b/src/modlistviewactions.h
index 3c225fbc..069bb1e6 100644
--- a/src/modlistviewactions.h
+++ b/src/modlistviewactions.h
@@ -31,9 +31,10 @@ public:
PluginListView* pluginView,
QObject* nxmReceiver);
- // install the mod from the given archive
+ // install the mod from the given archive before "above" the mod with
+ // the given index
//
- void installMod(const QString& archivePath = "") const;
+ void installMod(const QString& archivePath = "", const QModelIndex& index = QModelIndex()) const;
// create an empty mod/a separator before the given mod or at
// the end of the list if the index is invalid
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index e95aa565..8766ebb9 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -733,11 +733,12 @@ QString OrganizerCore::pluginDataPath()
}
MOBase::IModInterface *OrganizerCore::installMod(const QString & archivePath,
+ int priority,
bool reinstallation,
ModInfo::Ptr currentMod,
const QString &initModName)
{
- return installArchive(archivePath, -1, reinstallation, currentMod, initModName).get();
+ return installArchive(archivePath, reinstallation ? -1 : priority, reinstallation, currentMod, initModName).get();
}
ModInfo::Ptr OrganizerCore::installDownload(int index, int priority)
diff --git a/src/organizercore.h b/src/organizercore.h
index 8add5542..72359a90 100644
--- a/src/organizercore.h
+++ b/src/organizercore.h
@@ -318,7 +318,7 @@ public:
QVariant persistent(const QString &pluginName, const QString &key, const QVariant &def) const;
void setPersistent(const QString &pluginName, const QString &key, const QVariant &value, bool sync);
static QString pluginDataPath();
- virtual MOBase::IModInterface *installMod(const QString &fileName, bool reinstallation, ModInfo::Ptr currentMod, const QString &initModName);
+ virtual MOBase::IModInterface *installMod(const QString &fileName, int priority, bool reinstallation, ModInfo::Ptr currentMod, const QString &initModName);
QString resolvePath(const QString &fileName) const;
QStringList listDirectories(const QString &directoryName) const;
QStringList findFiles(const QString &path, const std::function<bool (const QString &)> &filter) const;
diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp
index acfb8404..f9943623 100644
--- a/src/organizerproxy.cpp
+++ b/src/organizerproxy.cpp
@@ -228,7 +228,7 @@ void OrganizerProxy::refresh(bool saveChanges)
IModInterface *OrganizerProxy::installMod(const QString &fileName, const QString &nameSuggestion)
{
- return m_Proxied->installMod(fileName, false, nullptr, nameSuggestion);
+ return m_Proxied->installMod(fileName, -1, false, nullptr, nameSuggestion);
}
QString OrganizerProxy::resolvePath(const QString &fileName) const