Debugger: Re-enable Moduleshandler context menu also below entries

Change-Id: I2e8cb9289770b46145de0850d15b4124aa5a1536
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
hjk
2016-09-20 14:01:17 +02:00
committed by hjk
parent 8151a09fdc
commit 6d22c8dafb
2 changed files with 53 additions and 39 deletions

View File

@@ -25,6 +25,7 @@
#include "moduleshandler.h" #include "moduleshandler.h"
#include "debuggeractions.h"
#include "debuggerconstants.h" #include "debuggerconstants.h"
#include "debuggercore.h" #include "debuggercore.h"
#include "debuggerengine.h" #include "debuggerengine.h"
@@ -32,6 +33,7 @@
#include <utils/basetreeview.h> #include <utils/basetreeview.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/savedaction.h>
#include <utils/treemodel.h> #include <utils/treemodel.h>
#include <QCoreApplication> #include <QCoreApplication>
@@ -52,12 +54,8 @@ class ModuleItem : public TreeItem
public: public:
QVariant data(int column, int role) const override; QVariant data(int column, int role) const override;
bool setData(int column, const QVariant &data, int role) override;
bool contextMenuEvent(const ItemViewEvent &event);
public: public:
DebuggerEngine *engine;
Module module; Module module;
bool updated; bool updated;
}; };
@@ -144,45 +142,61 @@ QVariant ModuleItem::data(int column, int role) const
return QVariant(); return QVariant();
} }
bool ModuleItem::setData(int, const QVariant &data, int role) //////////////////////////////////////////////////////////////////
{ //
if (role == BaseTreeView::ItemActivatedRole) { // ModulesModel
engine->gotoLocation(module.modulePath); //
return true; //////////////////////////////////////////////////////////////////
}
class ModulesModel : public TreeModel<TypedTreeItem<ModuleItem>, ModuleItem>
{
Q_DECLARE_TR_FUNCTIONS(Debuggger::Internal::ModulesHandler)
public:
bool setData(const QModelIndex &idx, const QVariant &data, int role) override
{
if (role == BaseTreeView::ItemViewEventRole) { if (role == BaseTreeView::ItemViewEventRole) {
ItemViewEvent ev = data.value<ItemViewEvent>(); ItemViewEvent ev = data.value<ItemViewEvent>();
if (ev.type() == QEvent::ContextMenu) if (ev.type() == QEvent::ContextMenu)
return contextMenuEvent(ev); return contextMenuEvent(ev);
} }
return false; return TreeModel::setData(idx, data, role);
} }
bool ModuleItem::contextMenuEvent(const ItemViewEvent &event) bool contextMenuEvent(const ItemViewEvent &ev);
DebuggerEngine *engine;
};
bool ModulesModel::contextMenuEvent(const ItemViewEvent &ev)
{ {
auto menu = new QMenu; ModuleItem *item = itemForIndexAtLevel<1>(ev.index());
const bool enabled = engine->debuggerActionsEnabled(); const bool enabled = engine->debuggerActionsEnabled();
const bool canReload = engine->hasCapability(ReloadModuleCapability); const bool canReload = engine->hasCapability(ReloadModuleCapability);
const bool canLoadSymbols = engine->hasCapability(ReloadModuleSymbolsCapability); const bool canLoadSymbols = engine->hasCapability(ReloadModuleSymbolsCapability);
const bool canShowSymbols = engine->hasCapability(ShowModuleSymbolsCapability); 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"), addAction(menu, tr("Update Module List"),
enabled && canReload, enabled && canReload,
[this] { engine->reloadModules(); }); [this] { engine->reloadModules(); });
addAction(menu, tr("Show Source Files for Module \"%1\"").arg(module.moduleName), addAction(menu, tr("Show Source Files for Module \"%1\"").arg(moduleName),
enabled && canReload, tr("Show Source Files for Module"),
[this] { engine->loadSymbols(module.modulePath); }); moduleNameValid && enabled && canReload,
[this, modulePath] { engine->loadSymbols(modulePath); });
// FIXME: Dependencies only available on Windows, when "depends" is installed. // 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"), tr("Show Dependencies"),
moduleNameValid && !module.modulePath.isEmpty() && HostOsInfo::isWindowsHost(), moduleNameValid && !moduleName.isEmpty() && HostOsInfo::isWindowsHost(),
[this] { QProcess::startDetached("depends", QStringList(module.modulePath)); }); [this, modulePath] { QProcess::startDetached("depends", { modulePath }); });
addAction(menu, tr("Load Symbols for All Modules"), addAction(menu, tr("Load Symbols for All Modules"),
enabled && canLoadSymbols, enabled && canLoadSymbols,
@@ -192,27 +206,30 @@ bool ModuleItem::contextMenuEvent(const ItemViewEvent &event)
enabled && canLoadSymbols, enabled && canLoadSymbols,
[this] { engine->examineModules(); }); [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"), tr("Load Symbols for Module"),
canLoadSymbols, moduleNameValid && canLoadSymbols,
[this] { engine->loadSymbols(module.modulePath); }); [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"), tr("Edit File"),
moduleNameValid, 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"), tr("Show Symbols"),
canShowSymbols && moduleNameValid, 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"), tr("Show Sections"),
canShowSymbols && moduleNameValid, 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; return true;
} }
@@ -224,10 +241,9 @@ bool ModuleItem::contextMenuEvent(const ItemViewEvent &event)
ModulesHandler::ModulesHandler(DebuggerEngine *engine) ModulesHandler::ModulesHandler(DebuggerEngine *engine)
{ {
m_engine = engine;
QString pad = " "; QString pad = " ";
m_model = new ModulesModel; m_model = new ModulesModel;
m_model->engine = engine;
m_model->setObjectName("ModulesModel"); m_model->setObjectName("ModulesModel");
m_model->setHeader(QStringList({ m_model->setHeader(QStringList({
tr("Module Name") + pad, tr("Module Name") + pad,
@@ -285,7 +301,6 @@ void ModulesHandler::updateModule(const Module &module)
} else { } else {
item = new ModuleItem; item = new ModuleItem;
item->module = module; item->module = module;
item->engine = m_engine;
m_model->rootItem()->appendChild(item); m_model->rootItem()->appendChild(item);
} }

View File

@@ -110,7 +110,7 @@ typedef QVector<Module> Modules;
// //
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
using ModulesModel = Utils::TreeModel<Utils::TypedTreeItem<ModuleItem>, ModuleItem>; class ModulesModel;
class ModulesHandler : public QObject class ModulesHandler : public QObject
{ {
@@ -133,7 +133,6 @@ public:
private: private:
ModuleItem *moduleFromPath(const QString &modulePath) const; ModuleItem *moduleFromPath(const QString &modulePath) const;
DebuggerEngine *m_engine;
ModulesModel *m_model; ModulesModel *m_model;
QSortFilterProxyModel *m_proxyModel; QSortFilterProxyModel *m_proxyModel;
}; };