diff --git a/src/plugins/debugger/moduleshandler.cpp b/src/plugins/debugger/moduleshandler.cpp index 398152b9e44..1262a3a827d 100644 --- a/src/plugins/debugger/moduleshandler.cpp +++ b/src/plugins/debugger/moduleshandler.cpp @@ -25,6 +25,7 @@ #include "moduleshandler.h" +#include "debuggeractions.h" #include "debuggerconstants.h" #include "debuggercore.h" #include "debuggerengine.h" @@ -32,6 +33,7 @@ #include #include #include +#include #include #include @@ -52,12 +54,8 @@ class ModuleItem : public TreeItem public: QVariant data(int column, int role) const override; - bool setData(int column, const QVariant &data, int role) override; - - bool contextMenuEvent(const ItemViewEvent &event); public: - DebuggerEngine *engine; Module module; bool updated; }; @@ -144,45 +142,61 @@ QVariant ModuleItem::data(int column, int role) const return QVariant(); } -bool ModuleItem::setData(int, const QVariant &data, int role) +////////////////////////////////////////////////////////////////// +// +// ModulesModel +// +////////////////////////////////////////////////////////////////// + +class ModulesModel : public TreeModel, ModuleItem> { - if (role == BaseTreeView::ItemActivatedRole) { - engine->gotoLocation(module.modulePath); - return true; + Q_DECLARE_TR_FUNCTIONS(Debuggger::Internal::ModulesHandler) + +public: + bool setData(const QModelIndex &idx, const QVariant &data, int role) override + { + if (role == BaseTreeView::ItemViewEventRole) { + ItemViewEvent ev = data.value(); + if (ev.type() == QEvent::ContextMenu) + return contextMenuEvent(ev); + } + + return TreeModel::setData(idx, data, role); } - if (role == BaseTreeView::ItemViewEventRole) { - ItemViewEvent ev = data.value(); - if (ev.type() == QEvent::ContextMenu) - return contextMenuEvent(ev); - } + bool contextMenuEvent(const ItemViewEvent &ev); - return false; -} + DebuggerEngine *engine; +}; -bool ModuleItem::contextMenuEvent(const ItemViewEvent &event) +bool ModulesModel::contextMenuEvent(const ItemViewEvent &ev) { - auto menu = new QMenu; + ModuleItem *item = itemForIndexAtLevel<1>(ev.index()); const bool enabled = engine->debuggerActionsEnabled(); const bool canReload = engine->hasCapability(ReloadModuleCapability); const bool canLoadSymbols = engine->hasCapability(ReloadModuleSymbolsCapability); const bool canShowSymbols = engine->hasCapability(ShowModuleSymbolsCapability); - const bool moduleNameValid = !module.moduleName.isEmpty(); + const bool moduleNameValid = item && !item->module.moduleName.isEmpty(); + const QString moduleName = item ? item->module.moduleName : QString(); + const QString modulePath = item ? item->module.modulePath : QString(); + + auto menu = new QMenu; addAction(menu, tr("Update Module List"), enabled && canReload, [this] { engine->reloadModules(); }); - addAction(menu, tr("Show Source Files for Module \"%1\"").arg(module.moduleName), - enabled && canReload, - [this] { engine->loadSymbols(module.modulePath); }); + addAction(menu, tr("Show Source Files for Module \"%1\"").arg(moduleName), + tr("Show Source Files for Module"), + moduleNameValid && enabled && canReload, + [this, modulePath] { engine->loadSymbols(modulePath); }); // FIXME: Dependencies only available on Windows, when "depends" is installed. - addAction(menu, tr("Show Dependencies of \"%1\"").arg(module.moduleName), + addAction(menu, tr("Show Dependencies of \"%1\"").arg(moduleName), tr("Show Dependencies"), - moduleNameValid && !module.modulePath.isEmpty() && HostOsInfo::isWindowsHost(), - [this] { QProcess::startDetached("depends", QStringList(module.modulePath)); }); + moduleNameValid && !moduleName.isEmpty() && HostOsInfo::isWindowsHost(), + [this, modulePath] { QProcess::startDetached("depends", { modulePath }); }); addAction(menu, tr("Load Symbols for All Modules"), enabled && canLoadSymbols, @@ -192,27 +206,30 @@ bool ModuleItem::contextMenuEvent(const ItemViewEvent &event) enabled && canLoadSymbols, [this] { engine->examineModules(); }); - addAction(menu, tr("Load Symbols for Module \"%1\"").arg(module.moduleName), + addAction(menu, tr("Load Symbols for Module \"%1\"").arg(moduleName), tr("Load Symbols for Module"), - canLoadSymbols, - [this] { engine->loadSymbols(module.modulePath); }); + moduleNameValid && canLoadSymbols, + [this, modulePath] { engine->loadSymbols(modulePath); }); - addAction(menu, tr("Edit File \"%1\"").arg(module.moduleName), + addAction(menu, tr("Edit File \"%1\"").arg(moduleName), tr("Edit File"), moduleNameValid, - [this] { engine->gotoLocation(module.modulePath); }); + [this, modulePath] { engine->gotoLocation(modulePath); }); - addAction(menu, tr("Show Symbols in File \"%1\"").arg(module.moduleName), + addAction(menu, tr("Show Symbols in File \"%1\"").arg(moduleName), tr("Show Symbols"), canShowSymbols && moduleNameValid, - [this] { engine->requestModuleSymbols(module.modulePath); }); + [this, modulePath] { engine->requestModuleSymbols(modulePath); }); - addAction(menu, tr("Show Sections in File \"%1\"").arg(module.moduleName), + addAction(menu, tr("Show Sections in File \"%1\"").arg(moduleName), tr("Show Sections"), canShowSymbols && moduleNameValid, - [this] { engine->requestModuleSections(module.modulePath); }); + [this, modulePath] { engine->requestModuleSections(modulePath); }); - menu->popup(event.globalPos()); + menu->addSeparator(); + menu->addAction(action(SettingsDialog)); + + menu->popup(ev.globalPos()); return true; } @@ -224,10 +241,9 @@ bool ModuleItem::contextMenuEvent(const ItemViewEvent &event) ModulesHandler::ModulesHandler(DebuggerEngine *engine) { - m_engine = engine; - QString pad = " "; m_model = new ModulesModel; + m_model->engine = engine; m_model->setObjectName("ModulesModel"); m_model->setHeader(QStringList({ tr("Module Name") + pad, @@ -285,7 +301,6 @@ void ModulesHandler::updateModule(const Module &module) } else { item = new ModuleItem; item->module = module; - item->engine = m_engine; m_model->rootItem()->appendChild(item); } diff --git a/src/plugins/debugger/moduleshandler.h b/src/plugins/debugger/moduleshandler.h index 2be31da5ffa..6d189772ed4 100644 --- a/src/plugins/debugger/moduleshandler.h +++ b/src/plugins/debugger/moduleshandler.h @@ -110,7 +110,7 @@ typedef QVector Modules; // ////////////////////////////////////////////////////////////////// -using ModulesModel = Utils::TreeModel, ModuleItem>; +class ModulesModel; class ModulesHandler : public QObject { @@ -133,7 +133,6 @@ public: private: ModuleItem *moduleFromPath(const QString &modulePath) const; - DebuggerEngine *m_engine; ModulesModel *m_model; QSortFilterProxyModel *m_proxyModel; };