summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/mainwindow.cpp224
-rw-r--r--src/mainwindow.h11
-rw-r--r--src/modlistcontextmenu.h2
-rw-r--r--src/pluginlist.cpp46
-rw-r--r--src/pluginlist.h14
-rw-r--r--src/pluginlistcontextmenu.cpp132
-rw-r--r--src/pluginlistcontextmenu.h54
-rw-r--r--src/pluginlistview.cpp71
-rw-r--r--src/pluginlistview.h6
10 files changed, 280 insertions, 281 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7773e845..ecb95c9e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -146,6 +146,7 @@ add_filter(NAME src/plugins GROUPS
pluginlist
pluginlistsortproxy
pluginlistview
+ pluginlistcontextmenu
)
add_filter(NAME src/previews GROUPS
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 38417df5..a530fbf4 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -2340,28 +2340,6 @@ void MainWindow::setWindowEnabled(bool enabled)
setEnabled(enabled);
}
-void MainWindow::openPluginOriginExplorer_clicked()
-{
- QItemSelectionModel *selection = ui->espList->selectionModel();
- if (selection->hasSelection() && selection->selectedRows().count() > 0) {
- for (QModelIndex idx : selection->selectedRows()) {
- QString fileName = idx.data().toString();
- unsigned int modIndex = ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName));
- if (modIndex == UINT_MAX) {
- continue;
- }
- ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
- shell::Explore(modInfo->absolutePath());
- }
- }
- else {
- QModelIndex idx = selection->currentIndex();
- QString fileName = idx.data().toString();
- ModInfo::Ptr modInfo = ModInfo::getByIndex(ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName)));
- shell::Explore(modInfo->absolutePath());
- }
-}
-
void MainWindow::openExplorer_activated()
{
if (ui->modList->hasFocus()) {
@@ -2406,93 +2384,6 @@ void MainWindow::refreshProfile_activated()
m_OrganizerCore.profileRefresh();
}
-void MainWindow::openOriginInformation_clicked()
-{
- try {
- QItemSelectionModel *selection = ui->espList->selectionModel();
- //we don't want to open multiple modinfodialogs.
- /*if (selection->hasSelection() && selection->selectedRows().count() > 0) {
-
- for (QModelIndex idx : selection->selectedRows()) {
- QString fileName = idx.data().toString();
- ModInfo::Ptr modInfo = ModInfo::getByIndex(ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName)));
- std::vector<ModInfo::EFlag> flags = modInfo->getFlags();
-
- if (modInfo->isRegular() || (std::find(flags.begin(), flags.end(), ModInfo::FLAG_OVERWRITE) != flags.end())) {
- displayModInformation(ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName)));
- }
- }
- }
- else {}*/
- QModelIndex idx = selection->currentIndex();
- QString fileName = idx.data().toString();
-
- ModInfo::Ptr modInfo = ModInfo::getByIndex(ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName)));
- std::vector<ModInfo::EFlag> flags = modInfo->getFlags();
-
- if (modInfo->isRegular() || (std::find(flags.begin(), flags.end(), ModInfo::FLAG_OVERWRITE) != flags.end())) {
- ui->modList->actions().displayModInformation(ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName)));
- }
- }
- catch (const std::exception &e) {
- reportError(e.what());
- }
-}
-
-void MainWindow::on_espList_doubleClicked(const QModelIndex &index)
-{
- if (!index.isValid()) {
- return;
- }
-
- if (m_OrganizerCore.pluginList()->timeElapsedSinceLastChecked() <= QApplication::doubleClickInterval()) {
- // don't interpret double click if we only just checked a plugin
- return;
- }
-
- QModelIndex sourceIdx = mapToModel(m_OrganizerCore.pluginList(), index);
- if (!sourceIdx.isValid()) {
- return;
- }
- try {
-
- QItemSelectionModel *selection = ui->espList->selectionModel();
-
- if (selection->hasSelection() && selection->selectedRows().count() == 1) {
-
- QModelIndex idx = selection->currentIndex();
- QString fileName = idx.data().toString();
-
- if (ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName)) == UINT_MAX)
- return;
-
- ModInfo::Ptr modInfo = ModInfo::getByIndex(ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName)));
- std::vector<ModInfo::EFlag> flags = modInfo->getFlags();
-
- if (modInfo->isRegular() || (std::find(flags.begin(), flags.end(), ModInfo::FLAG_OVERWRITE) != flags.end())) {
-
- Qt::KeyboardModifiers modifiers = QApplication::queryKeyboardModifiers();
- if (modifiers.testFlag(Qt::ControlModifier)) {
- openExplorer_activated();
- // workaround to cancel the editor that might have opened because of
- // selection-click
- ui->espList->closePersistentEditor(index);
- }
- else {
-
- ui->modList->actions().displayModInformation(ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName)));
- // workaround to cancel the editor that might have opened because of
- // selection-click
- ui->espList->closePersistentEditor(index);
- }
- }
- }
- }
- catch (const std::exception &e) {
- reportError(e.what());
- }
-}
-
void MainWindow::saveArchiveList()
{
if (m_OrganizerCore.isArchivesInit()) {
@@ -2606,21 +2497,6 @@ QMenu *MainWindow::openFolderMenu()
return FolderMenu;
}
-void MainWindow::addPluginSendToContextMenu(QMenu *menu)
-{
- if (ui->espList->sortColumn() != PluginList::COL_PRIORITY)
- return;
-
- QMenu *sub_menu = new QMenu(this);
- sub_menu->setTitle(tr("Send to"));
- sub_menu->addAction(tr("Top"), [&]() { sendSelectedPluginsToTop_clicked(); });
- sub_menu->addAction(tr("Bottom"), [&]() { sendSelectedPluginsToBottom_clicked(); });
- sub_menu->addAction(tr("Priority..."), [&]() { sendSelectedPluginsToPriority_clicked(); });
-
- menu->addMenu(sub_menu);
- menu->addSeparator();
-}
-
void MainWindow::linkToolbar()
{
Executable* exe = getSelectedExecutable();
@@ -2855,41 +2731,6 @@ void MainWindow::originModified(int originID)
DirectoryRefresher::cleanStructure(m_OrganizerCore.directoryStructure());
}
-void MainWindow::enableSelectedPlugins_clicked()
-{
- m_OrganizerCore.pluginList()->enableSelected(ui->espList->selectionModel());
-}
-
-
-void MainWindow::disableSelectedPlugins_clicked()
-{
- m_OrganizerCore.pluginList()->disableSelected(ui->espList->selectionModel());
-}
-
-void MainWindow::sendSelectedPluginsToTop_clicked()
-{
- m_OrganizerCore.pluginList()->sendToPriority(
- ui->espList->indexViewToModel(ui->espList->selectionModel()->selectedRows()), 0);
-}
-
-void MainWindow::sendSelectedPluginsToBottom_clicked()
-{
- m_OrganizerCore.pluginList()->sendToPriority(
- ui->espList->indexViewToModel(ui->espList->selectionModel()->selectedRows()), INT_MAX);
-}
-
-void MainWindow::sendSelectedPluginsToPriority_clicked()
-{
- bool ok;
- int newPriority = QInputDialog::getInt(this,
- tr("Set Priority"), tr("Set the priority of the selected plugins"),
- 0, 0, INT_MAX, 1, &ok);
- if (!ok) return;
-
- m_OrganizerCore.pluginList()->sendToPriority(
- ui->espList->indexViewToModel(ui->espList->selectionModel()->selectedRows()), newPriority);
-}
-
void MainWindow::updateAvailable()
{
ui->actionUpdate->setEnabled(true);
@@ -3551,71 +3392,6 @@ void MainWindow::toolBar_customContextMenuRequested(const QPoint &point)
m->exec(ui->toolBar->mapToGlobal(point));
}
-void MainWindow::on_espList_customContextMenuRequested(const QPoint &pos)
-{
-
- int espIndex = ui->espList->indexViewToModel(ui->espList->indexAt(pos)).row();
-
- QMenu menu;
- menu.addAction(tr("Enable selected"), [=]() { enableSelectedPlugins_clicked(); });
- menu.addAction(tr("Disable selected"), [=]() { disableSelectedPlugins_clicked(); });
-
- menu.addSeparator();
-
- menu.addAction(tr("Enable all"), m_OrganizerCore.pluginList(), &PluginList::enableAll);
- menu.addAction(tr("Disable all"), m_OrganizerCore.pluginList(), &PluginList::disableAll);
-
- menu.addSeparator();
-
- addPluginSendToContextMenu(&menu);
-
- QItemSelection currentSelection = ui->espList->selectionModel()->selection();
- bool hasLocked = false;
- bool hasUnlocked = false;
- for (const QModelIndex &idx : currentSelection.indexes()) {
- int row = ui->espList->indexViewToModel(idx).row();
- if (m_OrganizerCore.pluginList()->isEnabled(row)) {
- if (m_OrganizerCore.pluginList()->isESPLocked(row)) {
- hasLocked = true;
- } else {
- hasUnlocked = true;
- }
- }
- }
-
- if (hasLocked) {
- menu.addAction(tr("Unlock load order"), [&, espIndex]() { updateESPLock(espIndex, false); });
- }
- if (hasUnlocked) {
- menu.addAction(tr("Lock load order"), [&, espIndex]() { updateESPLock(espIndex, true); });
- }
-
- menu.addSeparator();
-
-
- QModelIndex idx = ui->espList->selectionModel()->currentIndex();
- unsigned int modInfoIndex = ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(idx.data().toString()));
- //this is to avoid showing the option on game files like skyrim.esm
- if (modInfoIndex != UINT_MAX) {
- menu.addAction(tr("Open Origin in Explorer"), [=]() { openPluginOriginExplorer_clicked(); });
- ModInfo::Ptr modInfo = ModInfo::getByIndex(modInfoIndex);
- std::vector<ModInfo::EFlag> flags = modInfo->getFlags();
-
- if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_FOREIGN) == flags.end()) {
- QAction* infoAction = menu.addAction(tr("Open Origin Info..."), [=]() { openOriginInformation_clicked(); });
- menu.setDefaultAction(infoAction);
- }
- }
-
- try {
- menu.exec(ui->espList->viewport()->mapToGlobal(pos));
- } catch (const std::exception &e) {
- reportError(tr("Exception: ").arg(e.what()));
- } catch (...) {
- reportError(tr("Unknown exception"));
- }
-}
-
Executable* MainWindow::getSelectedExecutable()
{
const QString name = ui->executablesListBox->itemText(
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 71845874..5e3cc798 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -320,15 +320,6 @@ private slots:
void openExplorer_activated();
void refreshProfile_activated();
- // pluginlist context menu
- void enableSelectedPlugins_clicked();
- void disableSelectedPlugins_clicked();
- void sendSelectedPluginsToTop_clicked();
- void sendSelectedPluginsToBottom_clicked();
- void sendSelectedPluginsToPriority_clicked();
- void openOriginInformation_clicked();
- void openPluginOriginExplorer_clicked();
-
void linkToolbar();
void linkDesktop();
void linkMenu();
@@ -444,12 +435,10 @@ private slots: // ui slots
void on_centralWidget_customContextMenuRequested(const QPoint &pos);
void on_bsaList_customContextMenuRequested(const QPoint &pos);
void on_executablesListBox_currentIndexChanged(int index);
- void on_espList_doubleClicked(const QModelIndex &index);
void on_profileBox_currentIndexChanged(int index);
void on_startButton_clicked();
void on_tabWidget_currentChanged(int index);
- void on_espList_customContextMenuRequested(const QPoint &pos);
void on_displayCategoriesBtn_toggled(bool checked);
void on_linkButton_pressed();
void on_showHiddenBox_toggled(bool checked);
diff --git a/src/modlistcontextmenu.h b/src/modlistcontextmenu.h
index 8452bc65..d009c9d8 100644
--- a/src/modlistcontextmenu.h
+++ b/src/modlistcontextmenu.h
@@ -74,7 +74,7 @@ public:
ModListContextMenu(
const QModelIndex& index, OrganizerCore& core, CategoryFactory& categories, ModListView* modListView);
-public: // TODO: Move this to private when all is done
+private:
// create the "Send to... " context menu
//
diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp
index 053f91b3..f6a52a80 100644
--- a/src/pluginlist.cpp
+++ b/src/pluginlist.cpp
@@ -338,43 +338,21 @@ int PluginList::findPluginByPriority(int priority)
return -1;
}
-void PluginList::enableSelected(const QItemSelectionModel *selectionModel)
+void PluginList::setEnabled(const QModelIndexList& indices, bool enabled)
{
- if (selectionModel->hasSelection()) {
- QStringList dirty;
- for (auto row : selectionModel->selectedRows(COL_PRIORITY)) {
- int rowIndex = findPluginByPriority(row.data().toInt());
- if (!m_ESPs[rowIndex].enabled) {
- m_ESPs[rowIndex].enabled = true;
- dirty.append(m_ESPs[rowIndex].name);
- }
- }
- if (!dirty.isEmpty()) {
- emit writePluginsList();
- pluginStatesChanged(dirty, IPluginList::PluginState::STATE_ACTIVE);
+ QStringList dirty;
+ for (auto& idx : indices) {
+ if (m_ESPs[idx.row()].enabled != enabled) {
+ m_ESPs[idx.row()].enabled = enabled;
+ dirty.append(m_ESPs[idx.row()].name);
}
}
-}
-
-void PluginList::disableSelected(const QItemSelectionModel *selectionModel)
-{
- if (selectionModel->hasSelection()) {
- QStringList dirty;
- for (auto row : selectionModel->selectedRows(COL_PRIORITY)) {
- int rowIndex = findPluginByPriority(row.data().toInt());
- if (!m_ESPs[rowIndex].forceEnabled && m_ESPs[rowIndex].enabled) {
- m_ESPs[rowIndex].enabled = false;
- dirty.append(m_ESPs[rowIndex].name);
- }
- }
- if (!dirty.isEmpty()) {
- emit writePluginsList();
- pluginStatesChanged(dirty, IPluginList::PluginState::STATE_INACTIVE);
- }
+ if (!dirty.isEmpty()) {
+ emit writePluginsList();
+ pluginStatesChanged(dirty, IPluginList::PluginState::STATE_ACTIVE);
}
}
-
void PluginList::enableAll()
{
if (QMessageBox::question(nullptr, tr("Confirm"), tr("Really enable all plugins?"),
@@ -393,7 +371,6 @@ void PluginList::enableAll()
}
}
-
void PluginList::disableAll()
{
if (QMessageBox::question(nullptr, tr("Confirm"), tr("Really disable all plugins?"),
@@ -416,9 +393,8 @@ void PluginList::sendToPriority(const QModelIndexList& indices, int newPriority)
{
std::vector<int> pluginsToMove;
for (auto& idx : indices) {
- int rowIndex = findPluginByPriority(idx.row());
- if (!m_ESPs[rowIndex].forceEnabled) {
- pluginsToMove.push_back(rowIndex);
+ if (!m_ESPs[idx.row()].forceEnabled) {
+ pluginsToMove.push_back(idx.row());
}
}
if (pluginsToMove.size()) {
diff --git a/src/pluginlist.h b/src/pluginlist.h
index 3a5f5412..6b0f584c 100644
--- a/src/pluginlist.h
+++ b/src/pluginlist.h
@@ -258,16 +258,6 @@ public: // implementation of the QAbstractTableModel interface
public slots:
/**
- * @brief enables selected plugins
- **/
- void enableSelected(const QItemSelectionModel *selectionModel);
-
- /**
- * @brief disables selected plugins
- **/
- void disableSelected(const QItemSelectionModel *selectionModel);
-
- /**
* @brief enables ALL plugins
**/
void enableAll();
@@ -277,6 +267,10 @@ public slots:
**/
void disableAll();
+ // enable/disable plugins at the given indices.
+ //
+ void setEnabled(const QModelIndexList& indices, bool enabled);
+
// send plugins to the given priority
//
void sendToPriority(const QModelIndexList& selectionModel, int priority);
diff --git a/src/pluginlistcontextmenu.cpp b/src/pluginlistcontextmenu.cpp
new file mode 100644
index 00000000..787e5c0c
--- /dev/null
+++ b/src/pluginlistcontextmenu.cpp
@@ -0,0 +1,132 @@
+#include "pluginlistcontextmenu.h"
+
+#include <report.h>
+#include <utility.h>
+
+#include "pluginlistview.h"
+#include "organizercore.h"
+
+using namespace MOBase;
+
+PluginListContextMenu::PluginListContextMenu(
+ const QModelIndex& index, OrganizerCore& core, PluginListView* view) :
+ QMenu(view)
+ , m_core(core)
+ , m_index(index.model() == view->model() ? view->indexViewToModel(index) : index)
+ , m_view(view)
+{
+ if (view->selectionModel()->hasSelection()) {
+ m_selected = view->indexViewToModel(view->selectionModel()->selectedRows());
+ }
+ else {
+ m_selected = { index };
+ }
+
+ addAction(tr("Enable selected"), [=]() { m_core.pluginList()->setEnabled(m_selected, true); });
+ addAction(tr("Disable selected"), [=]() { m_core.pluginList()->setEnabled(m_selected, false); });
+
+ addSeparator();
+
+ addAction(tr("Enable all"), m_core.pluginList(), &PluginList::enableAll);
+ addAction(tr("Disable all"), m_core.pluginList(), &PluginList::disableAll);
+
+ addSeparator();
+
+ addMenu(createSendToContextMenu());
+ addSeparator();
+
+ bool hasLocked = false;
+ bool hasUnlocked = false;
+ for (auto& idx : m_selected) {
+ if (m_core.pluginList()->isEnabled(idx.row())) {
+ if (m_core.pluginList()->isESPLocked(idx.row())) {
+ hasLocked = true;
+ }
+ else {
+ hasUnlocked = true;
+ }
+ }
+ }
+
+ if (hasLocked) {
+ addAction(tr("Unlock load order"), [=]() { setESPLock(m_selected, false); });
+ }
+ if (hasUnlocked) {
+ addAction(tr("Lock load order"), [=]() { setESPLock(m_selected, true); });
+ }
+
+ addSeparator();
+
+ unsigned int modInfoIndex = ModInfo::getIndex(m_core.pluginList()->origin(m_index.data().toString()));
+ // this is to avoid showing the option on game files like skyrim.esm
+ if (modInfoIndex != UINT_MAX) {
+ addAction(tr("Open Origin in Explorer"), [=]() { openOriginExplorer(m_selected); });
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(modInfoIndex);
+ std::vector<ModInfo::EFlag> flags = modInfo->getFlags();
+
+ if (!modInfo->isForeign() && m_selected.size() == 1) {
+ QAction* infoAction = addAction(tr("Open Origin Info..."), [=]() { openOriginInformation(index); });
+ setDefaultAction(infoAction);
+ }
+ }
+
+}
+
+QMenu* PluginListContextMenu::createSendToContextMenu()
+{
+ QMenu* menu = new QMenu(m_view);
+ menu->setTitle(tr("Send to... "));
+ menu->addAction(tr("Top"), [=]() { m_core.pluginList()->sendToPriority(m_selected, 0); });
+ menu->addAction(tr("Bottom"), [=]() { m_core.pluginList()->sendToPriority(m_selected, INT_MAX); });
+ menu->addAction(tr("Priority..."), [=]() { sendPluginsToPriority(m_selected); });
+ return menu;
+}
+
+void PluginListContextMenu::sendPluginsToPriority(const QModelIndexList& indices)
+{
+ bool ok;
+ int newPriority = QInputDialog::getInt(m_view->topLevelWidget(),
+ tr("Set Priority"), tr("Set the priority of the selected plugins"),
+ 0, 0, INT_MAX, 1, &ok);
+ if (!ok) return;
+
+ m_core.pluginList()->sendToPriority(m_selected, newPriority);
+}
+
+void PluginListContextMenu::setESPLock(const QModelIndexList& indices, bool locked)
+{
+ for (auto& idx : indices) {
+ if (m_core.pluginList()->isEnabled(idx.row())) {
+ m_core.pluginList()->lockESPIndex(idx.row(), locked);
+ }
+ }
+}
+
+void PluginListContextMenu::openOriginExplorer(const QModelIndexList& indices)
+{
+ for (auto& idx : indices) {
+ QString fileName = idx.data().toString();
+ unsigned int modIndex = ModInfo::getIndex(m_core.pluginList()->origin(fileName));
+ if (modIndex == UINT_MAX) {
+ continue;
+ }
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
+ shell::Explore(modInfo->absolutePath());
+ }
+}
+
+void PluginListContextMenu::openOriginInformation(const QModelIndex& index)
+{
+ try {
+ QString fileName = index.data().toString();
+ unsigned int modIndex = ModInfo::getIndex(m_core.pluginList()->origin(fileName));
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
+
+ if (modInfo->isRegular() || modInfo->isOverwrite()) {
+ emit openModInformation(modIndex);
+ }
+ }
+ catch (const std::exception& e) {
+ reportError(e.what());
+ }
+}
diff --git a/src/pluginlistcontextmenu.h b/src/pluginlistcontextmenu.h
new file mode 100644
index 00000000..0a9a01fe
--- /dev/null
+++ b/src/pluginlistcontextmenu.h
@@ -0,0 +1,54 @@
+#ifndef PLUGINLISTCONTEXTMENU_H
+#define PLUGINLISTCONTEXTMENU_H
+
+#include <QMenu>
+#include <QModelIndex>
+#include <QTreeView>
+
+#include "modinfo.h"
+
+class PluginListView;
+class OrganizerCore;
+
+class PluginListContextMenu : public QMenu
+{
+ Q_OBJECT
+
+public:
+
+ // creates a new context menu, the given index is the one for the click and should be valid
+ //
+ PluginListContextMenu(
+ const QModelIndex& index, OrganizerCore& core, PluginListView* modListView);
+
+signals:
+
+ // emitted to open a mod information
+ //
+ void openModInformation(unsigned int modIndex);
+
+public:
+
+ // create the "Send to... " context menu
+ //
+ QMenu* createSendToContextMenu();
+ void sendPluginsToPriority(const QModelIndexList& indices);
+
+ // set ESP lock on the given plugins
+ //
+ void setESPLock(const QModelIndexList& indices, bool locked);
+
+ // open explorer or mod information for the origin of the plugins
+ //
+ void openOriginExplorer(const QModelIndexList& indices);
+ void openOriginInformation(const QModelIndex& index);
+
+
+ OrganizerCore& m_core;
+ QModelIndex m_index;
+ QModelIndexList m_selected;
+ PluginListView* m_view;
+
+};
+
+#endif
diff --git a/src/pluginlistview.cpp b/src/pluginlistview.cpp
index 70b3ebc1..16e3dac0 100644
--- a/src/pluginlistview.cpp
+++ b/src/pluginlistview.cpp
@@ -3,15 +3,21 @@
#include <QUrl>
#include <QMimeData>
+#include <report.h>
#include <widgetutility.h>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "organizercore.h"
#include "pluginlistsortproxy.h"
+#include "pluginlistcontextmenu.h"
+#include "modlistview.h"
+#include "modlistviewactions.h"
#include "genericicondelegate.h"
#include "modelutils.h"
+using namespace MOBase;
+
PluginListView::PluginListView(QWidget *parent)
: QTreeView(parent)
, m_Scrollbar(new ViewMarkingScrollBar(this->model(), this))
@@ -135,6 +141,7 @@ void PluginListView::setup(OrganizerCore& core, MainWindow* mw, Ui::MainWindow*
{
m_core = &core;
ui = { mwui->activePluginsCounter, mwui->espFilterEdit };
+ m_modActions = &mwui->modList->actions();
m_sortProxy = new PluginListSortProxy(&core);
m_sortProxy->setSourceModel(core.pluginList());
@@ -146,6 +153,70 @@ void PluginListView::setup(OrganizerCore& core, MainWindow* mw, Ui::MainWindow*
connect(ui.filter, &QLineEdit::textChanged, m_sortProxy, &PluginListSortProxy::updateFilter);
connect(ui.filter, &QLineEdit::textChanged, this, &PluginListView::onFilterChanged);
+ // using a lambda here to avoid storing the mod list actions
+ connect(this, &QTreeView::customContextMenuRequested, [=](auto&& pos) { onCustomContextMenuRequested(pos); });
+ connect(this, &QTreeView::doubleClicked, [=](auto&& index) { onDoubleClicked(index); });
+}
+
+void PluginListView::onCustomContextMenuRequested(const QPoint& pos)
+{
+ try {
+ PluginListContextMenu menu(indexViewToModel(indexAt(pos)), *m_core, this);
+ connect(&menu, &PluginListContextMenu::openModInformation, [=](auto&& modIndex) {
+ m_modActions->displayModInformation(modIndex); });
+ menu.exec(viewport()->mapToGlobal(pos));
+ }
+ catch (const std::exception& e) {
+ reportError(tr("Exception: ").arg(e.what()));
+ }
+ catch (...) {
+ reportError(tr("Unknown exception"));
+ }
+}
+
+void PluginListView::onDoubleClicked(const QModelIndex& index)
+{
+ if (!index.isValid()) {
+ return;
+ }
+
+ if (m_core->pluginList()->timeElapsedSinceLastChecked() <= QApplication::doubleClickInterval()) {
+ // don't interpret double click if we only just checked a plugin
+ return;
+ }
+
+ try {
+ if (selectionModel()->hasSelection() && selectionModel()->selectedRows().count() == 1) {
+
+ QModelIndex idx = selectionModel()->currentIndex();
+ QString fileName = idx.data().toString();
+
+ if (ModInfo::getIndex(m_core->pluginList()->origin(fileName)) == UINT_MAX) {
+ return;
+ }
+
+ auto modIndex = ModInfo::getIndex(m_core->pluginList()->origin(fileName));
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
+
+ if (modInfo->isRegular() || modInfo->isOverwrite()) {
+
+ Qt::KeyboardModifiers modifiers = QApplication::queryKeyboardModifiers();
+ if (modifiers.testFlag(Qt::ControlModifier)) {
+ m_modActions->openExplorer({ m_core->modList()->index(modIndex, 0) });
+ }
+ else {
+ m_modActions->displayModInformation(ModInfo::getIndex(m_core->pluginList()->origin(fileName)));
+ }
+
+ // workaround to cancel the editor that might have opened because of
+ // selection-click
+ closePersistentEditor(index);
+ }
+ }
+ }
+ catch (const std::exception& e) {
+ reportError(e.what());
+ }
}
bool PluginListView::moveSelection(int key)
diff --git a/src/pluginlistview.h b/src/pluginlistview.h
index 92f03588..4a637bd1 100644
--- a/src/pluginlistview.h
+++ b/src/pluginlistview.h
@@ -11,6 +11,7 @@ namespace Ui {
class OrganizerCore;
class MainWindow;
+class ModListViewActions;
class PluginListSortProxy;
class PluginListView : public QTreeView
@@ -41,6 +42,9 @@ public:
protected slots:
+ void onCustomContextMenuRequested(const QPoint& pos);
+ void onDoubleClicked(const QModelIndex& index);
+
void onFilterChanged(const QString& filter);
protected:
@@ -74,6 +78,8 @@ private:
PluginListSortProxy* m_sortProxy;
+ ModListViewActions* m_modActions;
+
ViewMarkingScrollBar* m_Scrollbar;
};