summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2021-01-21 20:05:07 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-21 20:10:30 +0100
commit51eeefa49d7e1f3781457d628182a4af27d1ddaf (patch)
tree512d49c605b9740294ebb7db7b458509f113fa27 /src
parent20a87c9cb966e418da055424670b9e661097441d (diff)
Fix error when right-clicking on an empty space in the pluginlist.
Diffstat (limited to 'src')
-rw-r--r--src/pluginlistcontextmenu.cpp70
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);
+ }
}
}