Add context menu to PseudocodeWidget ()

This commit is contained in:
Itay Cohen 2019-08-07 14:38:22 +03:00 committed by GitHub
parent 9c1f4e6a34
commit d3f91a5ed6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#include "PseudocodeWidget.h" #include "PseudocodeWidget.h"
#include "ui_PseudocodeWidget.h" #include "ui_PseudocodeWidget.h"
#include "menus/DisassemblyContextMenu.h"
#include "common/Configuration.h" #include "common/Configuration.h"
#include "common/Helpers.h" #include "common/Helpers.h"
@ -36,6 +37,7 @@ struct DecompiledCodeTextLine
PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) : PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) :
MemoryDockWidget(MemoryWidgetType::Pseudocode, main, action), MemoryDockWidget(MemoryWidgetType::Pseudocode, main, action),
mCtxMenu(new DisassemblyContextMenu(this, main)),
ui(new Ui::PseudocodeWidget) ui(new Ui::PseudocodeWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -72,6 +74,13 @@ PseudocodeWidget::PseudocodeWidget(MainWindow *main, QAction *action) :
connect(ui->decompilerComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &PseudocodeWidget::decompilerSelected); connect(ui->decompilerComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &PseudocodeWidget::decompilerSelected);
connectCursorPositionChanged(false); connectCursorPositionChanged(false);
connect(Core(), &CutterCore::seekChanged, this, &PseudocodeWidget::seekChanged); connect(Core(), &CutterCore::seekChanged, this, &PseudocodeWidget::seekChanged);
ui->textEdit->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->textEdit, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showDisasContextMenu(const QPoint &)));
// refresh the widget when an action in this menu is triggered
connect(mCtxMenu, &QMenu::triggered, this, &PseudocodeWidget::refreshPseudocode);
addActions(mCtxMenu->actions());
doRefresh(RVA_INVALID); doRefresh(RVA_INVALID);
} }
@ -143,6 +152,7 @@ void PseudocodeWidget::cursorPositionChanged()
if (offset != RVA_INVALID && offset != Core()->getOffset()) { if (offset != RVA_INVALID && offset != Core()->getOffset()) {
seekFromCursor = true; seekFromCursor = true;
Core()->seek(offset); Core()->seek(offset);
mCtxMenu->setOffset(offset);
seekFromCursor = false; seekFromCursor = false;
} }
updateSelection(); updateSelection();
@ -247,6 +257,7 @@ void PseudocodeWidget::updateSelection()
extraSelections.append(createSameWordsSelections(ui->textEdit, searchString)); extraSelections.append(createSameWordsSelections(ui->textEdit, searchString));
ui->textEdit->setExtraSelections(extraSelections); ui->textEdit->setExtraSelections(extraSelections);
mCtxMenu->setCurHighlightedWord(searchString);
} }
QString PseudocodeWidget::getWindowTitle() const QString PseudocodeWidget::getWindowTitle() const
@ -262,3 +273,9 @@ void PseudocodeWidget::fontsUpdated()
void PseudocodeWidget::colorsUpdatedSlot() void PseudocodeWidget::colorsUpdatedSlot()
{ {
} }
void PseudocodeWidget::showDisasContextMenu(const QPoint &pt)
{
mCtxMenu->exec(ui->textEdit->mapToGlobal(pt));
doRefresh(Core()->getOffset());
}

View File

@ -13,15 +13,20 @@ class PseudocodeWidget;
class QTextEdit; class QTextEdit;
class QSyntaxHighlighter; class QSyntaxHighlighter;
class QTextCursor; class QTextCursor;
class DisassemblyContextMenu;
struct DecompiledCodeTextLine; struct DecompiledCodeTextLine;
class PseudocodeWidget : public MemoryDockWidget class PseudocodeWidget : public MemoryDockWidget
{ {
Q_OBJECT Q_OBJECT
protected:
DisassemblyContextMenu *mCtxMenu;
public: public:
explicit PseudocodeWidget(MainWindow *main, QAction *action = nullptr); explicit PseudocodeWidget(MainWindow *main, QAction *action = nullptr);
~PseudocodeWidget(); ~PseudocodeWidget();
public slots:
void showDisasContextMenu(const QPoint &pt);
private slots: private slots:
void fontsUpdated(); void fontsUpdated();