mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-22 12:56:11 +00:00
Add copy to DisassemblyWidget
This commit is contained in:
parent
dfc80a3b9b
commit
903f2042e6
@ -10,6 +10,8 @@
|
|||||||
DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
|
DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
|
||||||
: QMenu(parent),
|
: QMenu(parent),
|
||||||
offset(0),
|
offset(0),
|
||||||
|
canCopy(false),
|
||||||
|
actionCopy(this),
|
||||||
actionAddComment(this),
|
actionAddComment(this),
|
||||||
actionAddFlag(this),
|
actionAddFlag(this),
|
||||||
actionRename(this),
|
actionRename(this),
|
||||||
@ -24,6 +26,11 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
|
|||||||
actionSetBaseSyscall(this),
|
actionSetBaseSyscall(this),
|
||||||
actionSetBaseString(this)
|
actionSetBaseString(this)
|
||||||
{
|
{
|
||||||
|
actionCopy.setText(tr("Copy"));
|
||||||
|
this->addAction(&actionCopy);
|
||||||
|
actionCopy.setShortcut(getCopySequence());
|
||||||
|
copySeparator = addSeparator();
|
||||||
|
|
||||||
actionAddComment.setText(tr("Add Comment"));
|
actionAddComment.setText(tr("Add Comment"));
|
||||||
this->addAction(&actionAddComment);
|
this->addAction(&actionAddComment);
|
||||||
actionAddComment.setShortcut(getCommentSequence());
|
actionAddComment.setShortcut(getCommentSequence());
|
||||||
@ -67,6 +74,11 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
|
|||||||
|
|
||||||
auto pWidget = parentWidget();
|
auto pWidget = parentWidget();
|
||||||
|
|
||||||
|
QShortcut *shortcut_Copy = new QShortcut(getCopySequence(), pWidget);
|
||||||
|
shortcut_Copy->setContext(Qt::WidgetWithChildrenShortcut);
|
||||||
|
connect(shortcut_Copy, &QShortcut::activated,
|
||||||
|
this, &DisassemblyContextMenu::on_actionCopy_triggered);
|
||||||
|
|
||||||
QShortcut *shortcut_dispOptions = new QShortcut(getDisplayOptionsSequence(), pWidget);
|
QShortcut *shortcut_dispOptions = new QShortcut(getDisplayOptionsSequence(), pWidget);
|
||||||
shortcut_dispOptions->setContext(Qt::WidgetWithChildrenShortcut);
|
shortcut_dispOptions->setContext(Qt::WidgetWithChildrenShortcut);
|
||||||
connect(shortcut_dispOptions, &QShortcut::activated,
|
connect(shortcut_dispOptions, &QShortcut::activated,
|
||||||
@ -92,6 +104,8 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
|
|||||||
connect(shortcut_renameSequence, &QShortcut::activated,
|
connect(shortcut_renameSequence, &QShortcut::activated,
|
||||||
this, &DisassemblyContextMenu::on_actionRename_triggered);
|
this, &DisassemblyContextMenu::on_actionRename_triggered);
|
||||||
|
|
||||||
|
connect(&actionCopy, SIGNAL(triggered(bool)), this, SLOT(on_actionCopy_triggered()));
|
||||||
|
|
||||||
connect(&actionAddComment, SIGNAL(triggered(bool)), this, SLOT(on_actionAddComment_triggered()));
|
connect(&actionAddComment, SIGNAL(triggered(bool)), this, SLOT(on_actionAddComment_triggered()));
|
||||||
connect(&actionAddFlag, SIGNAL(triggered(bool)), this, SLOT(on_actionAddFlag_triggered()));
|
connect(&actionAddFlag, SIGNAL(triggered(bool)), this, SLOT(on_actionAddFlag_triggered()));
|
||||||
connect(&actionRename, SIGNAL(triggered(bool)), this, SLOT(on_actionRename_triggered()));
|
connect(&actionRename, SIGNAL(triggered(bool)), this, SLOT(on_actionRename_triggered()));
|
||||||
@ -115,6 +129,11 @@ void DisassemblyContextMenu::setOffset(RVA offset)
|
|||||||
this->offset = offset;
|
this->offset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DisassemblyContextMenu::setCanCopy(bool enabled)
|
||||||
|
{
|
||||||
|
this->canCopy = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void DisassemblyContextMenu::aboutToShowSlot()
|
void DisassemblyContextMenu::aboutToShowSlot()
|
||||||
{
|
{
|
||||||
// check if set immediate base menu makes sense
|
// check if set immediate base menu makes sense
|
||||||
@ -133,6 +152,14 @@ void DisassemblyContextMenu::aboutToShowSlot()
|
|||||||
{
|
{
|
||||||
actionAddComment.setText(tr("Edit Comment"));
|
actionAddComment.setText(tr("Edit Comment"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actionCopy.setVisible(canCopy);
|
||||||
|
copySeparator->setVisible(canCopy);
|
||||||
|
}
|
||||||
|
|
||||||
|
QKeySequence DisassemblyContextMenu::getCopySequence() const
|
||||||
|
{
|
||||||
|
return QKeySequence::Copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
QKeySequence DisassemblyContextMenu::getCommentSequence() const
|
QKeySequence DisassemblyContextMenu::getCommentSequence() const
|
||||||
@ -160,6 +187,11 @@ QKeySequence DisassemblyContextMenu::getDisplayOptionsSequence() const
|
|||||||
return {}; //TODO insert correct sequence
|
return {}; //TODO insert correct sequence
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DisassemblyContextMenu::on_actionCopy_triggered()
|
||||||
|
{
|
||||||
|
emit copy();
|
||||||
|
}
|
||||||
|
|
||||||
void DisassemblyContextMenu::on_actionAddComment_triggered()
|
void DisassemblyContextMenu::on_actionAddComment_triggered()
|
||||||
{
|
{
|
||||||
QJsonObject disasObject = Core()->cmdj("pdj 1 @ " + QString::number(offset)).array().first().toObject();
|
QJsonObject disasObject = Core()->cmdj("pdj 1 @ " + QString::number(offset)).array().first().toObject();
|
||||||
|
@ -13,12 +13,18 @@ public:
|
|||||||
DisassemblyContextMenu(QWidget *parent = nullptr);
|
DisassemblyContextMenu(QWidget *parent = nullptr);
|
||||||
~DisassemblyContextMenu() = default;
|
~DisassemblyContextMenu() = default;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void copy();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setOffset(RVA offset);
|
void setOffset(RVA offset);
|
||||||
|
void setCanCopy(bool enabled);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void aboutToShowSlot();
|
void aboutToShowSlot();
|
||||||
|
|
||||||
|
void on_actionCopy_triggered();
|
||||||
|
|
||||||
void on_actionAddComment_triggered();
|
void on_actionAddComment_triggered();
|
||||||
void on_actionAddFlag_triggered();
|
void on_actionAddFlag_triggered();
|
||||||
void on_actionRename_triggered();
|
void on_actionRename_triggered();
|
||||||
@ -35,6 +41,7 @@ private slots:
|
|||||||
void on_actionSetBaseString_triggered();
|
void on_actionSetBaseString_triggered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QKeySequence getCopySequence() const;
|
||||||
QKeySequence getCommentSequence() const;
|
QKeySequence getCommentSequence() const;
|
||||||
QKeySequence getAddFlagSequence() const;
|
QKeySequence getAddFlagSequence() const;
|
||||||
QKeySequence getRenameSequence() const;
|
QKeySequence getRenameSequence() const;
|
||||||
@ -42,6 +49,10 @@ private:
|
|||||||
QKeySequence getDisplayOptionsSequence() const;
|
QKeySequence getDisplayOptionsSequence() const;
|
||||||
|
|
||||||
RVA offset;
|
RVA offset;
|
||||||
|
bool canCopy;
|
||||||
|
|
||||||
|
QAction actionCopy;
|
||||||
|
QAction *copySeparator;
|
||||||
|
|
||||||
QAction actionAddComment;
|
QAction actionAddComment;
|
||||||
QAction actionAddFlag;
|
QAction actionAddFlag;
|
||||||
|
@ -103,6 +103,8 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent)
|
|||||||
refreshDisasm(Core()->getOffset());
|
refreshDisasm(Core()->getOffset());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(mCtxMenu, SIGNAL(copy()), mDisasTextEdit, SLOT(copy()));
|
||||||
|
|
||||||
// Dirty
|
// Dirty
|
||||||
QShortcut *shortcut_escape = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
QShortcut *shortcut_escape = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
||||||
shortcut_escape->setContext(Qt::WidgetShortcut);
|
shortcut_escape->setContext(Qt::WidgetShortcut);
|
||||||
@ -402,9 +404,9 @@ void DisassemblyWidget::cursorPositionChanged()
|
|||||||
RVA offset = readCurrentDisassemblyOffset();
|
RVA offset = readCurrentDisassemblyOffset();
|
||||||
Core()->seek(offset);
|
Core()->seek(offset);
|
||||||
highlightCurrentLine();
|
highlightCurrentLine();
|
||||||
|
mCtxMenu->setCanCopy(mDisasTextEdit->textCursor().hasSelection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event)
|
bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event)
|
||||||
{
|
{
|
||||||
if ((obj == mDisasTextEdit || obj == mDisasTextEdit->viewport()) && event->type() == QEvent::MouseButtonDblClick)
|
if ((obj == mDisasTextEdit || obj == mDisasTextEdit->viewport()) && event->type() == QEvent::MouseButtonDblClick)
|
||||||
@ -547,7 +549,7 @@ void DisassemblyTextEdit::mousePressEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
QPlainTextEdit::mousePressEvent(event);
|
QPlainTextEdit::mousePressEvent(event);
|
||||||
|
|
||||||
if (event->button() == Qt::RightButton)
|
if (event->button() == Qt::RightButton && !textCursor().hasSelection())
|
||||||
{
|
{
|
||||||
setTextCursor(cursorForPosition(event->pos()));
|
setTextCursor(cursorForPosition(event->pos()));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user