summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mainwindow.cpp121
-rw-r--r--src/mainwindow.h7
-rw-r--r--src/modlist.cpp22
-rw-r--r--src/modlist.h6
-rw-r--r--src/modlistcontextmenu.cpp39
-rw-r--r--src/modlistcontextmenu.h17
-rw-r--r--src/modlistview.cpp2
-rw-r--r--src/modlistviewactions.cpp68
-rw-r--r--src/modlistviewactions.h6
9 files changed, 148 insertions, 140 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 265cc5c2..91897d2f 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -3832,22 +3832,6 @@ QMenu *MainWindow::openFolderMenu()
return FolderMenu;
}
-void MainWindow::addModSendToContextMenu(QMenu *menu)
-{
- if (ui->modList->sortColumn() != ModList::COL_PRIORITY)
- return;
-
- QMenu *sub_menu = new QMenu(menu);
- sub_menu->setTitle(tr("Send to"));
- sub_menu->addAction(tr("Top"), [&]() { sendSelectedModsToTop_clicked(); });
- sub_menu->addAction(tr("Bottom"), [&]() { sendSelectedModsToBottom_clicked(); });
- sub_menu->addAction(tr("Priority..."), [&]() { sendSelectedModsToPriority_clicked(); });
- sub_menu->addAction(tr("Separator..."), [&]() { sendSelectedModsToSeparator_clicked(); });
-
- menu->addMenu(sub_menu);
- menu->addSeparator();
-}
-
void MainWindow::addPluginSendToContextMenu(QMenu *menu)
{
if (m_PluginListSortProxy->sortColumn() != PluginList::COL_PRIORITY)
@@ -3932,7 +3916,10 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos)
menu.addAction(tr("Rename Separator..."), [=]() { renameMod_clicked(); });
menu.addAction(tr("Remove Separator..."), [=]() { removeMod_clicked(modIndex); });
menu.addSeparator();
- addModSendToContextMenu(&menu);
+ if (ui->modList->sortColumn() == ModList::COL_PRIORITY) {
+ menu.addMenu(menu.createSendToContextMenu());
+ menu.addSeparator();
+ }
menu.addAction(tr("Select Color..."), [=]() { setColor_clicked(modIndex); });
if (info->color().isValid()) {
@@ -3944,7 +3931,6 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos)
// foregin
else if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_FOREIGN) != flags.end()) {
- addModSendToContextMenu(&menu);
}
// regular
@@ -3981,7 +3967,10 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos)
menu.addSeparator();
- addModSendToContextMenu(&menu);
+ if (ui->modList->sortColumn() == ModList::COL_PRIORITY) {
+ menu.addMenu(menu.createSendToContextMenu());
+ menu.addSeparator();
+ }
menu.addAction(tr("Rename Mod..."), [=]() { renameMod_clicked(); });
menu.addAction(tr("Reinstall Mod"), [=]() { reinstallMod_clicked(modIndex); });
@@ -5477,97 +5466,3 @@ void MainWindow::on_clearFiltersButton_clicked()
ui->modFilterEdit->clear();
deselectFilters();
}
-
-void MainWindow::sendSelectedModsToPriority(int newPriority)
-{
- QItemSelectionModel *selection = ui->modList->selectionModel();
- if (selection->hasSelection()) {
- std::vector<int> modsToMove;
- for (auto idx : selection->selectedRows(ModList::COL_PRIORITY)) {
- modsToMove.push_back(m_OrganizerCore.currentProfile()->modIndexByPriority(idx.data().toInt()));
- }
-
- if (modsToMove.size() == 1) {
- m_OrganizerCore.modList()->changeModPriority(modsToMove[0], newPriority);
- }
- else {
- m_OrganizerCore.modList()->changeModPriority(modsToMove, newPriority);
- }
- }
-}
-
-void MainWindow::sendSelectedModsToTop_clicked()
-{
- sendSelectedModsToPriority(0);
-}
-
-void MainWindow::sendSelectedModsToBottom_clicked()
-{
- sendSelectedModsToPriority(INT_MAX);
-}
-
-void MainWindow::sendSelectedModsToPriority_clicked()
-{
- bool ok;
- int newPriority = QInputDialog::getInt(this,
- tr("Set Priority"), tr("Set the priority of the selected mods"),
- 0, 0, INT_MAX, 1, &ok);
- if (!ok) return;
-
- sendSelectedModsToPriority(newPriority);
-}
-
-void MainWindow::sendSelectedModsToSeparator_clicked()
-{
- QStringList separators;
- auto indexesByPriority = m_OrganizerCore.currentProfile()->getAllIndexesByPriority();
- for (auto iter = indexesByPriority.begin(); iter != indexesByPriority.end(); iter++) {
- if ((iter->second != UINT_MAX)) {
- ModInfo::Ptr modInfo = ModInfo::getByIndex(iter->second);
- if (modInfo->hasFlag(ModInfo::FLAG_SEPARATOR)) {
- separators << modInfo->name().chopped(10); // Chops the "_separator" away from the name
- }
- }
- }
-
- ListDialog dialog(this);
- dialog.setWindowTitle("Select a separator...");
- dialog.setChoices(separators);
-
- if (dialog.exec() == QDialog::Accepted) {
- QString result = dialog.getChoice();
- if (!result.isEmpty()) {
- result += "_separator";
-
- int newPriority = INT_MAX;
- bool foundSection = false;
- for (auto mod : m_OrganizerCore.modsSortedByProfilePriority(m_OrganizerCore.currentProfile())) {
- unsigned int modIndex = ModInfo::getIndex(mod);
- ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
- if (!foundSection && result.compare(mod) == 0) {
- foundSection = true;
- } else if (foundSection && modInfo->hasFlag(ModInfo::FLAG_SEPARATOR)) {
- newPriority = m_OrganizerCore.currentProfile()->getModPriority(modIndex);
- break;
- }
- }
-
- QItemSelectionModel *selection = ui->modList->selectionModel();
- if (selection->hasSelection()) {
- std::vector<int> modsToMove;
- for (QModelIndex idx : selection->selectedRows(ModList::COL_PRIORITY)) {
- modsToMove.push_back(m_OrganizerCore.currentProfile()->modIndexByPriority(idx.data().toInt()));
- }
- if (modsToMove.size() == 1) {
- int oldPriority = m_OrganizerCore.currentProfile()->getModPriority(modsToMove[0]);
- if (oldPriority < newPriority)
- --newPriority;
- m_OrganizerCore.modList()->changeModPriority(modsToMove[0], newPriority);
- }
- else {
- m_OrganizerCore.modList()->changeModPriority(modsToMove, newPriority);
- }
- }
- }
- }
-}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 57f26220..790960e1 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -244,15 +244,12 @@ private:
bool createBackup(const QString &filePath, const QDateTime &time);
QString queryRestore(const QString &filePath);
- void addModSendToContextMenu(QMenu *menu);
void addPluginSendToContextMenu(QMenu *menu);
QMenu *openFolderMenu();
void dropLocalFile(const QUrl &url, const QString &outputDir, bool move);
- void sendSelectedModsToPriority(int newPriority);
-
void toggleMO2EndorseState();
void toggleUpdateAction();
@@ -374,10 +371,6 @@ private slots:
void information_clicked(int modIndex);
void enableSelectedMods_clicked();
void disableSelectedMods_clicked();
- void sendSelectedModsToTop_clicked();
- void sendSelectedModsToBottom_clicked();
- void sendSelectedModsToPriority_clicked();
- void sendSelectedModsToSeparator_clicked();
// data-tree context menu
// pluginlist context menu
diff --git a/src/modlist.cpp b/src/modlist.cpp
index 7da6fe3b..22899aaa 100644
--- a/src/modlist.cpp
+++ b/src/modlist.cpp
@@ -1417,7 +1417,7 @@ QString ModList::getColumnToolTip(int column) const
}
}
-void ModList::shiftMods(const QModelIndexList& indices, int offset)
+void ModList::shiftModsPriority(const QModelIndexList& indices, int offset)
{
// retrieve the mod index and sort them by priority to avoid issue
// when moving them
@@ -1451,6 +1451,26 @@ void ModList::shiftMods(const QModelIndexList& indices, int offset)
emit modPrioritiesChanged(allIndex);
}
+void ModList::changeModsPriority(const QModelIndexList& indices, int priority)
+{
+ if (indices.isEmpty()) {
+ return;
+ }
+
+ std::vector<int> allIndex;
+ for (auto& idx : indices) {
+ auto index = idx.data(IndexRole).toInt();
+ allIndex.push_back(index);
+ }
+
+ if (allIndex.size() == 1) {
+ changeModPriority(allIndex[0], priority);
+ }
+ else {
+ changeModPriority(allIndex, priority);
+ }
+}
+
bool ModList::toggleState(const QModelIndexList& indices)
{
emit aboutToChangeData();
diff --git a/src/modlist.h b/src/modlist.h
index 870978f9..cabd1f32 100644
--- a/src/modlist.h
+++ b/src/modlist.h
@@ -226,7 +226,11 @@ public slots:
// shift the priority of mods at the given indices by the given offset
//
- void shiftMods(const QModelIndexList& indices, int offset);
+ void shiftModsPriority(const QModelIndexList& indices, int offset);
+
+ // change the priority of the mods specified by the given indices
+ //
+ void changeModsPriority(const QModelIndexList& indices, int priority);
// toggle the active state of mods at the given indices
//
diff --git a/src/modlistcontextmenu.cpp b/src/modlistcontextmenu.cpp
index 41031eaa..c4a82e46 100644
--- a/src/modlistcontextmenu.cpp
+++ b/src/modlistcontextmenu.cpp
@@ -45,6 +45,7 @@ ModListContextMenu::ModListContextMenu(OrganizerCore& core, const QModelIndex& i
QMenu(view)
, m_core(core)
, m_index()
+ , m_view(view)
{
if (view->selectionModel()->hasSelection()) {
m_index = view->indexViewToModel(view->selectionModel()->selectedRows());
@@ -68,20 +69,23 @@ ModListContextMenu::ModListContextMenu(OrganizerCore& core, const QModelIndex& i
// Add type-specific items
ModInfo::Ptr info = ModInfo::getByIndex(index.data(ModList::IndexRole).toInt());
+ // TODO:
+ // - Don't forget to check for the sort priority for "Send To... "
+
if (info->isOverwrite()) {
- addOverwriteActions(core, view);
+ addOverwriteActions();
}
else if (info->isBackup()) {
- addBackupActions(core, view);
+ addBackupActions();
}
else if (info->isSeparator()) {
- addSeparatorActions(core, view);
+ addSeparatorActions();
}
else if (info->isForeign()) {
- addForeignActions(core, view);
+ addForeignActions();
}
else {
- addRegularActions(core, view);
+ addRegularActions();
}
// add information for all except foreign
@@ -91,27 +95,40 @@ ModListContextMenu::ModListContextMenu(OrganizerCore& core, const QModelIndex& i
}
}
-void ModListContextMenu::addOverwriteActions(OrganizerCore& core, ModListView* modListView)
+QMenu* ModListContextMenu::createSendToContextMenu()
{
-
+ QMenu* menu = new QMenu(m_view);
+ menu->setTitle(tr("Send to... "));
+ menu->addAction(tr("Top"), [=]() { m_view->actions().sendModsToTop(m_index); });
+ menu->addAction(tr("Bottom"), [=]() { m_view->actions().sendModsToBottom(m_index); });
+ menu->addAction(tr("Priority..."), [=]() { m_view->actions().sendModsToPriority(m_index); });
+ menu->addAction(tr("Separator..."), [=]() { m_view->actions().sendModsToSeparator(m_index); });
+ return menu;
}
-void ModListContextMenu::addSeparatorActions(OrganizerCore& core, ModListView* modListView)
+void ModListContextMenu::addOverwriteActions()
{
}
-void ModListContextMenu::addForeignActions(OrganizerCore& core, ModListView* modListView)
+void ModListContextMenu::addSeparatorActions()
{
}
-void ModListContextMenu::addBackupActions(OrganizerCore& core, ModListView* modListView)
+void ModListContextMenu::addForeignActions()
+{
+ if (m_view->sortColumn() == ModList::COL_PRIORITY) {
+ addMenu(createSendToContextMenu());
+ }
+}
+
+void ModListContextMenu::addBackupActions()
{
}
-void ModListContextMenu::addRegularActions(OrganizerCore& core, ModListView* modListView)
+void ModListContextMenu::addRegularActions()
{
}
diff --git a/src/modlistcontextmenu.h b/src/modlistcontextmenu.h
index 9d015afc..3bc15c57 100644
--- a/src/modlistcontextmenu.h
+++ b/src/modlistcontextmenu.h
@@ -29,18 +29,23 @@ public:
//
ModListContextMenu(OrganizerCore& core, const QModelIndex& index, ModListView* modListView);
-private:
+public: // TODO: Move this to private when all is done
+
+ // create the "Send to... " context menu
+ //
+ QMenu* createSendToContextMenu();
// add actions/menus to this menu for each type of mod
//
- void addOverwriteActions(OrganizerCore& core, ModListView* modListView);
- void addSeparatorActions(OrganizerCore& core, ModListView* modListView);
- void addForeignActions(OrganizerCore& core, ModListView* modListView);
- void addBackupActions(OrganizerCore& core, ModListView* modListView);
- void addRegularActions(OrganizerCore& core, ModListView* modListView);
+ void addOverwriteActions();
+ void addSeparatorActions();
+ void addForeignActions();
+ void addBackupActions();
+ void addRegularActions();
OrganizerCore& m_core;
QModelIndexList m_index;
+ ModListView* m_view;
};
diff --git a/src/modlistview.cpp b/src/modlistview.cpp
index f8192758..8c826882 100644
--- a/src/modlistview.cpp
+++ b/src/modlistview.cpp
@@ -575,7 +575,7 @@ bool ModListView::moveSelection(int key)
offset = -offset;
}
- m_core->modList()->shiftMods(sourceRows, offset);
+ m_core->modList()->shiftModsPriority(sourceRows, offset);
// reset the selection and the index
setCurrentIndex(indexModelToView(cindex));
diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp
index 6faebc15..0d556e64 100644
--- a/src/modlistviewactions.cpp
+++ b/src/modlistviewactions.cpp
@@ -11,6 +11,7 @@
#include "categories.h"
#include "filedialogmemory.h"
#include "filterlist.h"
+#include "listdialog.h"
#include "modinfodialog.h"
#include "modlist.h"
#include "modlistview.h"
@@ -430,3 +431,70 @@ void ModListViewActions::displayModInformation(ModInfo::Ptr modInfo, unsigned in
}
}
}
+
+void ModListViewActions::sendModsToTop(const QModelIndexList& index) const
+{
+ m_core.modList()->changeModsPriority(index, 0);
+}
+
+void ModListViewActions::sendModsToBottom(const QModelIndexList& index) const
+{
+ m_core.modList()->changeModsPriority(index, std::numeric_limits<int>::max());
+}
+
+void ModListViewActions::sendModsToPriority(const QModelIndexList& index) const
+{
+ bool ok;
+ int priority = QInputDialog::getInt(m_view,
+ tr("Set Priority"), tr("Set the priority of the selected mods"),
+ 0, 0, std::numeric_limits<int>::max(), 1, &ok);
+ if (!ok) return;
+
+ m_core.modList()->changeModsPriority(index, priority);
+}
+
+void ModListViewActions::sendModsToSeparator(const QModelIndexList& index) const
+{
+ QStringList separators;
+ auto indexesByPriority = m_core.currentProfile()->getAllIndexesByPriority();
+ for (auto iter = indexesByPriority.begin(); iter != indexesByPriority.end(); iter++) {
+ if ((iter->second != UINT_MAX)) {
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(iter->second);
+ if (modInfo->hasFlag(ModInfo::FLAG_SEPARATOR)) {
+ separators << modInfo->name().chopped(10); // Chops the "_separator" away from the name
+ }
+ }
+ }
+
+ ListDialog dialog(m_view);
+ dialog.setWindowTitle("Select a separator...");
+ dialog.setChoices(separators);
+
+ if (dialog.exec() == QDialog::Accepted) {
+ QString result = dialog.getChoice();
+ if (!result.isEmpty()) {
+ result += "_separator";
+
+ int newPriority = std::numeric_limits<int>::max();
+ bool foundSection = false;
+ for (auto mod : m_core.modsSortedByProfilePriority(m_core.currentProfile())) {
+ unsigned int modIndex = ModInfo::getIndex(mod);
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
+ if (!foundSection && result.compare(mod) == 0) {
+ foundSection = true;
+ }
+ else if (foundSection && modInfo->isSeparator()) {
+ newPriority = m_core.currentProfile()->getModPriority(modIndex);
+ break;
+ }
+ }
+
+ if (index.size() == 1
+ && m_core.currentProfile()->getModPriority(index[0].data(ModList::IndexRole).toInt()) < newPriority) {
+ --newPriority;
+ }
+
+ m_core.modList()->changeModsPriority(index, newPriority);
+ }
+ }
+}
diff --git a/src/modlistviewactions.h b/src/modlistviewactions.h
index b01b8e79..d8e1a3d0 100644
--- a/src/modlistviewactions.h
+++ b/src/modlistviewactions.h
@@ -53,6 +53,12 @@ public:
void displayModInformation(unsigned int index, ModInfoTabIDs tab = ModInfoTabIDs::None) const;
void displayModInformation(ModInfo::Ptr modInfo, unsigned int modIndex, ModInfoTabIDs tabID = ModInfoTabIDs::None) const;
+ // move mods to top/bottom, start the "Send to priority" and "Send to separator" dialog
+ //
+ void sendModsToTop(const QModelIndexList& index) const;
+ void sendModsToBottom(const QModelIndexList& index) const;
+ void sendModsToPriority(const QModelIndexList& index) const;
+ void sendModsToSeparator(const QModelIndexList& index) const;
private: