| 9 | using namespace MOBase; |
| 10 | |
| 11 | PluginListContextMenu::PluginListContextMenu(const QModelIndex& index, |
| 12 | OrganizerCore& core, PluginListView* view) |
| 13 | : QMenu(view), m_core(core), |
| 14 | m_index(index.model() == view->model() ? view->indexViewToModel(index) : index), |
| 15 | m_view(view) |
| 16 | { |
| 17 | if (view->selectionModel()->hasSelection()) { |
| 18 | m_selected = view->indexViewToModel(view->selectionModel()->selectedRows()); |
| 19 | } else if (index.isValid()) { |
| 20 | m_selected = {index}; |
| 21 | } |
| 22 | |
| 23 | if (!m_selected.isEmpty()) { |
| 24 | addAction(tr("Enable selected"), [=]() { |
| 25 | m_core.pluginList()->setEnabled(m_selected, true); |
| 26 | }); |
| 27 | addAction(tr("Disable selected"), [=]() { |
| 28 | m_core.pluginList()->setEnabled(m_selected, false); |
| 29 | }); |
| 30 | |
| 31 | addSeparator(); |
| 32 | } |
| 33 | |
| 34 | addAction(tr("Enable all"), [=]() { |
| 35 | if (QMessageBox::question(m_view->topLevelWidget(), tr("Confirm"), |
| 36 | tr("Really enable all plugins?"), |
| 37 | QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { |
| 38 | m_core.pluginList()->setEnabledAll(true); |
| 39 | } |
| 40 | }); |
| 41 | addAction(tr("Disable all"), [=]() { |
| 42 | if (QMessageBox::question(m_view->topLevelWidget(), tr("Confirm"), |
| 43 | tr("Really disable all plugins?"), |
| 44 | QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { |
| 45 | m_core.pluginList()->setEnabledAll(false); |
| 46 | } |
| 47 | }); |
| 48 | |
| 49 | if (!m_selected.isEmpty()) { |
| 50 | addSeparator(); |
| 51 | addMenu(createSendToContextMenu()); |
| 52 | |
| 53 | addSeparator(); |
| 54 | |
| 55 | bool hasLocked = false; |
| 56 | bool hasUnlocked = false; |
| 57 | for (auto& idx : m_selected) { |
| 58 | if (m_core.pluginList()->isEnabled(idx.row())) { |
| 59 | if (m_core.pluginList()->isESPLocked(idx.row())) { |
| 60 | hasLocked = true; |
| 61 | } else { |
| 62 | hasUnlocked = true; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if (hasLocked) { |
| 68 | addAction(tr("Unlock load order"), [=]() { |
nothing calls this directly
no test coverage detected