2019-08-19 13:35:25 +00:00
|
|
|
#include "AddressableItemContextMenu.h"
|
|
|
|
#include "dialogs/XrefsDialog.h"
|
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "dialogs/CommentsDialog.h"
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QShortcut>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
AddressableItemContextMenu::AddressableItemContextMenu(QWidget *parent, MainWindow *mainWindow)
|
|
|
|
: QMenu(parent)
|
|
|
|
, mainWindow(mainWindow)
|
|
|
|
{
|
2020-02-06 17:32:15 +00:00
|
|
|
actionShowInMenu = new QAction(tr("Show in"), this);
|
|
|
|
actionCopyAddress = new QAction(tr("Copy address"), this);
|
|
|
|
actionShowXrefs = new QAction(tr("Show X-Refs"), this);
|
|
|
|
actionAddcomment = new QAction(tr("Add comment"), this);
|
|
|
|
|
|
|
|
connect(actionCopyAddress, &QAction::triggered, this,
|
2019-08-19 13:35:25 +00:00
|
|
|
&AddressableItemContextMenu::onActionCopyAddress);
|
2020-02-06 17:32:15 +00:00
|
|
|
actionCopyAddress->setShortcuts({Qt::CTRL + Qt::SHIFT + Qt::Key_C});
|
|
|
|
actionCopyAddress->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);
|
2019-08-19 13:35:25 +00:00
|
|
|
|
2020-02-06 17:32:15 +00:00
|
|
|
connect(actionShowXrefs, &QAction::triggered, this,
|
2019-08-19 13:35:25 +00:00
|
|
|
&AddressableItemContextMenu::onActionShowXrefs);
|
2020-02-06 17:32:15 +00:00
|
|
|
actionShowXrefs->setShortcut({Qt::Key_X});
|
|
|
|
actionShowXrefs->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);
|
2019-08-19 13:35:25 +00:00
|
|
|
|
2020-02-06 17:32:15 +00:00
|
|
|
connect(actionAddcomment, &QAction::triggered, this,
|
2019-08-19 13:35:25 +00:00
|
|
|
&AddressableItemContextMenu::onActionAddComment);
|
2020-02-06 17:32:15 +00:00
|
|
|
actionAddcomment->setShortcut({Qt::Key_Semicolon});
|
|
|
|
actionAddcomment->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);
|
2019-08-19 13:35:25 +00:00
|
|
|
|
2020-02-06 17:32:15 +00:00
|
|
|
addAction(actionShowInMenu);
|
|
|
|
addAction(actionCopyAddress);
|
|
|
|
addAction(actionShowXrefs);
|
2019-08-19 13:35:25 +00:00
|
|
|
addSeparator();
|
2020-02-06 17:32:15 +00:00
|
|
|
addAction(actionAddcomment);
|
2019-08-19 13:35:25 +00:00
|
|
|
|
2020-01-24 09:49:52 +00:00
|
|
|
addSeparator();
|
2020-01-31 10:13:28 +00:00
|
|
|
pluginMenu = mainWindow->getContextMenuExtensions(MainWindow::ContextMenuType::Addressable);
|
|
|
|
pluginMenuAction = addMenu(pluginMenu);
|
2020-01-24 09:49:52 +00:00
|
|
|
addSeparator();
|
|
|
|
|
2019-09-01 21:30:25 +00:00
|
|
|
setHasTarget(hasTarget);
|
2020-01-24 09:49:52 +00:00
|
|
|
|
2019-08-19 13:35:25 +00:00
|
|
|
connect(this, &QMenu::aboutToShow, this, &AddressableItemContextMenu::aboutToShowSlot);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddressableItemContextMenu::~AddressableItemContextMenu()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddressableItemContextMenu::setWholeFunction(bool wholeFunciton)
|
|
|
|
{
|
|
|
|
this->wholeFunction = wholeFunciton;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddressableItemContextMenu::setOffset(RVA offset)
|
|
|
|
{
|
|
|
|
setTarget(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddressableItemContextMenu::setTarget(RVA offset, QString name)
|
|
|
|
{
|
|
|
|
this->offset = offset;
|
|
|
|
this->name = name;
|
2019-09-01 21:30:25 +00:00
|
|
|
setHasTarget(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddressableItemContextMenu::clearTarget()
|
|
|
|
{
|
|
|
|
setHasTarget(false);
|
2019-08-19 13:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddressableItemContextMenu::onActionCopyAddress()
|
|
|
|
{
|
|
|
|
auto clipboard = QApplication::clipboard();
|
|
|
|
clipboard->setText(RAddressString(offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddressableItemContextMenu::onActionShowXrefs()
|
|
|
|
{
|
2019-09-01 21:30:25 +00:00
|
|
|
emit xrefsTriggered();
|
2020-08-03 17:11:02 +00:00
|
|
|
XrefsDialog dialog(mainWindow, nullptr, true);
|
2019-08-19 13:35:25 +00:00
|
|
|
QString tmpName = name;
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
name = RAddressString(offset);
|
|
|
|
}
|
|
|
|
dialog.fillRefsForAddress(offset, name, wholeFunction);
|
|
|
|
dialog.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddressableItemContextMenu::onActionAddComment()
|
|
|
|
{
|
2019-09-01 21:30:25 +00:00
|
|
|
CommentsDialog::addOrEditComment(offset, this);
|
2019-08-19 13:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddressableItemContextMenu::aboutToShowSlot()
|
|
|
|
{
|
2020-02-06 17:32:15 +00:00
|
|
|
if (actionShowInMenu->menu()) {
|
|
|
|
actionShowInMenu->menu()->deleteLater();
|
2019-08-19 13:35:25 +00:00
|
|
|
}
|
2020-02-06 17:32:15 +00:00
|
|
|
actionShowInMenu->setMenu(mainWindow->createShowInMenu(this, offset));
|
2020-01-24 09:49:52 +00:00
|
|
|
|
2020-01-31 10:13:28 +00:00
|
|
|
pluginMenuAction->setVisible(!pluginMenu->isEmpty());
|
2020-01-24 09:49:52 +00:00
|
|
|
for (QAction *pluginAction : pluginMenu->actions()) {
|
|
|
|
pluginAction->setData(QVariant::fromValue(offset));
|
|
|
|
}
|
2019-08-19 13:35:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-01 21:30:25 +00:00
|
|
|
void AddressableItemContextMenu::setHasTarget(bool hasTarget)
|
|
|
|
{
|
|
|
|
this->hasTarget = hasTarget;
|
|
|
|
for (const auto &action : this->actions()) {
|
|
|
|
action->setEnabled(hasTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|