From 51eeefa49d7e1f3781457d628182a4af27d1ddaf Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Thu, 21 Jan 2021 20:05:07 +0100 Subject: Fix error when right-clicking on an empty space in the pluginlist. --- src/pluginlistcontextmenu.cpp | 74 +++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 34 deletions(-) (limited to 'src') 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(); - - 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 (!m_selected.isEmpty()) { + 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); }); + 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 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 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); + } } } -- cgit v1.3.1