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 "debuggeractions.h"
#include "debuggerconstants.h"
#include "debuggercore.h"
#include "debuggerengine.h"
@@ -32,6 +33,7 @@
#include <utils/basetreeview.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <utils/savedaction.h>
#include <utils/treemodel.h>
#include <QCoreApplication>
@@ -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)
{
if (role == BaseTreeView::ItemActivatedRole) {
engine->gotoLocation(module.modulePath);
return true;
}
//////////////////////////////////////////////////////////////////
//
// ModulesModel
//
//////////////////////////////////////////////////////////////////
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) {
ItemViewEvent ev = data.value<ItemViewEvent>();
if (ev.type() == QEvent::ContextMenu)
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 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);
}

View File

@@ -110,7 +110,7 @@ typedef QVector<Module> Modules;
//
//////////////////////////////////////////////////////////////////
using ModulesModel = Utils::TreeModel<Utils::TypedTreeItem<ModuleItem>, 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;
};