mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-24 05:45:27 +00:00
Add context menu to PseudocodeWidget (#1702)
This commit is contained in:
parent
9c1f4e6a34
commit
d3f91a5ed6
src/widgets
@ -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());
|
||||||
|
}
|
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user