From 5de173ba1ae9531aaca0c0f022a2b0dae1c09250 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Wed, 31 Oct 2018 17:05:05 -0500 Subject: Add send to top/bottom options for the plugin list --- src/mainwindow.cpp | 15 ++++++++++ src/mainwindow.h | 2 ++ src/pluginlist.cpp | 88 +++++++++++++++++++++++++++++++++++++----------------- src/pluginlist.h | 12 ++++++++ 4 files changed, 90 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 24def4ef..d279da91 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -4341,6 +4341,16 @@ void MainWindow::disableSelectedPlugins_clicked() m_OrganizerCore.pluginList()->disableSelected(ui->espList->selectionModel()); } +void MainWindow::sendSelectedPluginsToTop_clicked() +{ + m_OrganizerCore.pluginList()->sendToTop(ui->espList->selectionModel()); +} + +void MainWindow::sendSelectedPluginsToBottom_clicked() +{ + m_OrganizerCore.pluginList()->sendToBottom(ui->espList->selectionModel()); +} + void MainWindow::enableSelectedMods_clicked() { @@ -4966,6 +4976,11 @@ void MainWindow::on_espList_customContextMenuRequested(const QPoint &pos) menu.addAction(tr("Enable all"), m_OrganizerCore.pluginList(), SLOT(enableAll())); menu.addAction(tr("Disable all"), m_OrganizerCore.pluginList(), SLOT(disableAll())); + menu.addSeparator(); + + menu.addAction(tr("Send to top"), this, SLOT(sendSelectedPluginsToTop_clicked())); + menu.addAction(tr("Send to bottom"), this, SLOT(sendSelectedPluginsToBottom_clicked())); + QItemSelection currentSelection = ui->espList->selectionModel()->selection(); bool hasLocked = false; bool hasUnlocked = false; diff --git a/src/mainwindow.h b/src/mainwindow.h index 923a8330..9dee2953 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -439,6 +439,8 @@ private slots: // pluginlist context menu void enableSelectedPlugins_clicked(); void disableSelectedPlugins_clicked(); + void sendSelectedPluginsToTop_clicked(); + void sendSelectedPluginsToBottom_clicked(); void linkToolbar(); void linkDesktop(); diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 18e40a6e..4097ba98 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -289,21 +289,26 @@ void PluginList::enableESP(const QString &name, bool enable) } } +int PluginList::findPluginByPriority(int priority) +{ + for (int i = 0; i < m_ESPs.size(); i++ ) { + if (m_ESPs[i].m_Priority == priority) { + return i; + } + } + qCritical(QString("No plugin with priority %1").arg(priority).toLocal8Bit()); + return -1; +} + void PluginList::enableSelected(const QItemSelectionModel *selectionModel) { - if (selectionModel->hasSelection()){ + if (selectionModel->hasSelection()) { bool dirty = false; for (auto row : selectionModel->selectedRows(COL_PRIORITY)) { - int rowPriority = row.data().toInt(); - for (int i = 0; i < m_ESPs.size(); i++) { - if (m_ESPs[i].m_Priority == rowPriority) { - if (!m_ESPs[i].m_Enabled) { - m_ESPs[i].m_Enabled = true; - dirty = true; - } - - break; - } + int rowIndex = findPluginByPriority(row.data().toInt()); + if (!m_ESPs[rowIndex].m_Enabled) { + m_ESPs[rowIndex].m_Enabled = true; + dirty = true; } } if (dirty) emit writePluginsList(); @@ -312,18 +317,13 @@ void PluginList::enableSelected(const QItemSelectionModel *selectionModel) void PluginList::disableSelected(const QItemSelectionModel *selectionModel) { - if (selectionModel->hasSelection()){ + if (selectionModel->hasSelection()) { bool dirty = false; for (auto row : selectionModel->selectedRows(COL_PRIORITY)) { - int rowPriority = row.data().toInt(); - for (int i = 0; i < m_ESPs.size(); i++) { - if (m_ESPs[i].m_Priority == rowPriority) { - if (!m_ESPs[i].m_ForceEnabled && m_ESPs[i].m_Enabled) { - m_ESPs[i].m_Enabled = false; - dirty = true; - } - break; - } + int rowIndex = findPluginByPriority(row.data().toInt()); + if (!m_ESPs[rowIndex].m_ForceEnabled && m_ESPs[rowIndex].m_Enabled) { + m_ESPs[rowIndex].m_Enabled = false; + dirty = true; } } if (dirty) emit writePluginsList(); @@ -356,6 +356,40 @@ void PluginList::disableAll() } } +void PluginList::sendToTop(const QItemSelectionModel *selectionModel) +{ + if (selectionModel->hasSelection()) { + std::vector pluginsToMove; + for (auto row: selectionModel->selectedRows(COL_PRIORITY)) { + int rowIndex = findPluginByPriority(row.data().toInt()); + if (!m_ESPs[rowIndex].m_ForceEnabled) { + pluginsToMove.push_back(rowIndex); + } + } + if (pluginsToMove.size()) { + changePluginPriority(pluginsToMove, 0); + emit SIGNAL(displayPlugin(0)); + } + } +} + +void PluginList::sendToBottom(const QItemSelectionModel *selectionModel) +{ + if (selectionModel->hasSelection()) { + std::vector pluginsToMove; + for (auto row: selectionModel->selectedRows(COL_PRIORITY)) { + int rowIndex = findPluginByPriority(row.data().toInt()); + if (!m_ESPs[rowIndex].m_ForceEnabled) { + pluginsToMove.push_back(rowIndex); + } + } + if (pluginsToMove.size()) { + changePluginPriority(pluginsToMove, INT_MAX); + emit SIGNAL(displayPlugin(INT_MAX)); + } + } +} + bool PluginList::isEnabled(const QString &name) { @@ -1092,6 +1126,12 @@ void PluginList::setPluginPriority(int row, int &newPriority) { int newPriorityTemp = newPriority; + // enforce valid range + if (newPriorityTemp < 0) + newPriorityTemp = 0; + else if (newPriorityTemp >= static_cast(m_ESPsByPriority.size())) + newPriorityTemp = static_cast(m_ESPsByPriority.size()) - 1; + if (!m_ESPs[row].m_IsMaster && !m_ESPs[row].m_IsLight) { // don't allow esps to be moved above esms while ((newPriorityTemp < static_cast(m_ESPsByPriority.size() - 1)) && @@ -1113,12 +1153,6 @@ void PluginList::setPluginPriority(int row, int &newPriority) } } - // enforce valid range - if (newPriorityTemp < 0) - newPriorityTemp = 0; - else if (newPriorityTemp >= static_cast(m_ESPsByPriority.size())) - newPriorityTemp = static_cast(m_ESPsByPriority.size()) - 1; - try { int oldPriority = m_ESPs.at(row).m_Priority; if (newPriorityTemp > oldPriority) { diff --git a/src/pluginlist.h b/src/pluginlist.h index 03d6426a..009c9153 100644 --- a/src/pluginlist.h +++ b/src/pluginlist.h @@ -264,6 +264,16 @@ public slots: **/ void disableAll(); + /** + * @brief moves selected plugins to the top (lowest priority) + **/ + void sendToTop(const QItemSelectionModel *selectionModel); + + /** + * @brief moves selected plugins to the bottom (highest priority) + **/ + void sendToBottom(const QItemSelectionModel *selectionModel); + /** * @brief The currently managed game has changed * @param gamePlugin @@ -340,6 +350,8 @@ private: void fixPriorities(); + int findPluginByPriority(int priority); + private: std::vector m_ESPs; -- cgit v1.3.1