diff options
| author | Mikaƫl Capelle <capelle.mikael@gmail.com> | 2021-01-24 10:40:40 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-24 10:40:40 +0100 |
| commit | b9c8554ee38c418582f43828bb00e1e8aa606338 (patch) | |
| tree | c3d20ba1a83faa4c4be64d873139ec7b07db929a | |
| parent | 14536009c08e876a6930469de35485d5f99c57e1 (diff) | |
| parent | 51eeefa49d7e1f3781457d628182a4af27d1ddaf (diff) | |
Merge pull request #1380 from Holt59/fix-pluginlist-contextmenu
Fix error when right-clicking on an empty space in the pluginlist.
| -rw-r--r-- | src/pluginlistcontextmenu.cpp | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/src/pluginlistcontextmenu.cpp b/src/pluginlistcontextmenu.cpp index e6afd996..c6d4ecec 100644 --- a/src/pluginlistcontextmenu.cpp +++ b/src/pluginlistcontextmenu.cpp @@ -18,14 +18,16 @@ PluginListContextMenu::PluginListContextMenu( if (view->selectionModel()->hasSelection()) { m_selected = view->indexViewToModel(view->selectionModel()->selectedRows()); } - else { + else if (index.isValid()) { 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); }); + if (!m_selected.isEmpty()) { + addAction(tr("Enable selected"), [=]() { m_core.pluginList()->setEnabled(m_selected, true); }); + addAction(tr("Disable selected"), [=]() { m_core.pluginList()->setEnabled(m_selected, false); }); - addSeparator(); + addSeparator(); + } addAction(tr("Enable all"), [=]() { if (QMessageBox::question( @@ -42,43 +44,47 @@ PluginListContextMenu::PluginListContextMenu( } }); - addSeparator(); + if (!m_selected.isEmpty()) { + addSeparator(); + addMenu(createSendToContextMenu()); - addMenu(createSendToContextMenu()); - addSeparator(); + 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; + 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); }); + if (hasLocked) { + addAction(tr("Unlock load order"), [=]() { setESPLock(m_selected, false); }); + } + if (hasUnlocked) { + addAction(tr("Lock load order"), [=]() { setESPLock(m_selected, true); }); + } } - addSeparator(); + if (m_index.isValid()) { + 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(); + 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); + if (!modInfo->isForeign() && m_selected.size() == 1) { + QAction* infoAction = addAction(tr("Open Origin Info..."), [=]() { openOriginInformation(index); }); + setDefaultAction(infoAction); + } } } |
