mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-19 19:36:11 +00:00
Comment Menu for the Decompiler Context Menu (#2265)
This commit is contained in:
parent
a4174271f6
commit
8b4c58e07d
@ -2,6 +2,7 @@
|
|||||||
#include "dialogs/preferences/PreferencesDialog.h"
|
#include "dialogs/preferences/PreferencesDialog.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "dialogs/BreakpointsDialog.h"
|
#include "dialogs/BreakpointsDialog.h"
|
||||||
|
#include "dialogs/CommentsDialog.h"
|
||||||
|
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
@ -16,6 +17,8 @@ DecompilerContextMenu::DecompilerContextMenu(QWidget *parent, MainWindow *mainWi
|
|||||||
isTogglingBreakpoints(false),
|
isTogglingBreakpoints(false),
|
||||||
mainWindow(mainWindow),
|
mainWindow(mainWindow),
|
||||||
actionCopy(tr("Copy"), this),
|
actionCopy(tr("Copy"), this),
|
||||||
|
actionAddComment(tr("Add Comment"), this),
|
||||||
|
actionDeleteComment(tr("Delete comment"), this),
|
||||||
actionToggleBreakpoint(tr("Add/remove breakpoint"), this),
|
actionToggleBreakpoint(tr("Add/remove breakpoint"), this),
|
||||||
actionAdvancedBreakpoint(tr("Advanced breakpoint"), this),
|
actionAdvancedBreakpoint(tr("Advanced breakpoint"), this),
|
||||||
breakpointsInLineMenu(new QMenu(this)),
|
breakpointsInLineMenu(new QMenu(this)),
|
||||||
@ -25,6 +28,10 @@ DecompilerContextMenu::DecompilerContextMenu(QWidget *parent, MainWindow *mainWi
|
|||||||
setActionCopy();
|
setActionCopy();
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
|
||||||
|
setActionAddComment();
|
||||||
|
setActionDeleteComment();
|
||||||
|
|
||||||
|
addSeparator();
|
||||||
addBreakpointMenu();
|
addBreakpointMenu();
|
||||||
addDebugMenu();
|
addDebugMenu();
|
||||||
|
|
||||||
@ -32,6 +39,8 @@ DecompilerContextMenu::DecompilerContextMenu(QWidget *parent, MainWindow *mainWi
|
|||||||
|
|
||||||
connect(this, &DecompilerContextMenu::aboutToShow,
|
connect(this, &DecompilerContextMenu::aboutToShow,
|
||||||
this, &DecompilerContextMenu::aboutToShowSlot);
|
this, &DecompilerContextMenu::aboutToShowSlot);
|
||||||
|
connect(this, &DecompilerContextMenu::aboutToHide,
|
||||||
|
this, &DecompilerContextMenu::aboutToHideSlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
DecompilerContextMenu::~DecompilerContextMenu()
|
DecompilerContextMenu::~DecompilerContextMenu()
|
||||||
@ -95,8 +104,28 @@ bool DecompilerContextMenu::getIsTogglingBreakpoints()
|
|||||||
return this->isTogglingBreakpoints;
|
return this->isTogglingBreakpoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DecompilerContextMenu::aboutToHideSlot()
|
||||||
|
{
|
||||||
|
actionAddComment.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
void DecompilerContextMenu::aboutToShowSlot()
|
void DecompilerContextMenu::aboutToShowSlot()
|
||||||
{
|
{
|
||||||
|
if (this->firstOffsetInLine != RVA_MAX) {
|
||||||
|
QString comment = Core()->cmdRawAt("CC.", this->firstOffsetInLine);
|
||||||
|
actionAddComment.setVisible(true);
|
||||||
|
if (comment.isEmpty()) {
|
||||||
|
actionDeleteComment.setVisible(false);
|
||||||
|
actionAddComment.setText(tr("Add Comment"));
|
||||||
|
} else {
|
||||||
|
actionDeleteComment.setVisible(true);
|
||||||
|
actionAddComment.setText(tr("Edit Comment"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
actionAddComment.setVisible(false);
|
||||||
|
actionDeleteComment.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
setupBreakpointsInLineMenu();
|
setupBreakpointsInLineMenu();
|
||||||
|
|
||||||
@ -134,6 +163,21 @@ void DecompilerContextMenu::setActionCopy()
|
|||||||
actionCopy.setShortcut(QKeySequence::Copy);
|
actionCopy.setShortcut(QKeySequence::Copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DecompilerContextMenu::setActionAddComment()
|
||||||
|
{
|
||||||
|
connect(&actionAddComment, &QAction::triggered, this,
|
||||||
|
&DecompilerContextMenu::actionAddCommentTriggered);
|
||||||
|
addAction(&actionAddComment);
|
||||||
|
actionAddComment.setShortcut(Qt::Key_Semicolon);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecompilerContextMenu::setActionDeleteComment()
|
||||||
|
{
|
||||||
|
connect(&actionDeleteComment, &QAction::triggered, this,
|
||||||
|
&DecompilerContextMenu::actionDeleteCommentTriggered);
|
||||||
|
addAction(&actionDeleteComment);
|
||||||
|
}
|
||||||
|
|
||||||
void DecompilerContextMenu::setActionToggleBreakpoint()
|
void DecompilerContextMenu::setActionToggleBreakpoint()
|
||||||
{
|
{
|
||||||
connect(&actionToggleBreakpoint, &QAction::triggered, this,
|
connect(&actionToggleBreakpoint, &QAction::triggered, this,
|
||||||
@ -166,6 +210,16 @@ void DecompilerContextMenu::actionCopyTriggered()
|
|||||||
emit copy();
|
emit copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DecompilerContextMenu::actionAddCommentTriggered()
|
||||||
|
{
|
||||||
|
CommentsDialog::addOrEditComment(this->firstOffsetInLine, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecompilerContextMenu::actionDeleteCommentTriggered()
|
||||||
|
{
|
||||||
|
Core()->delComment(this->firstOffsetInLine);
|
||||||
|
}
|
||||||
|
|
||||||
void DecompilerContextMenu::actionToggleBreakpointTriggered()
|
void DecompilerContextMenu::actionToggleBreakpointTriggered()
|
||||||
{
|
{
|
||||||
if (!this->availableBreakpoints.isEmpty()) {
|
if (!this->availableBreakpoints.isEmpty()) {
|
||||||
|
@ -27,9 +27,13 @@ public slots:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void aboutToShowSlot();
|
void aboutToShowSlot();
|
||||||
|
void aboutToHideSlot();
|
||||||
|
|
||||||
void actionCopyTriggered();
|
void actionCopyTriggered();
|
||||||
|
|
||||||
|
void actionAddCommentTriggered();
|
||||||
|
void actionDeleteCommentTriggered();
|
||||||
|
|
||||||
void actionToggleBreakpointTriggered();
|
void actionToggleBreakpointTriggered();
|
||||||
void actionAdvancedBreakpointTriggered();
|
void actionAdvancedBreakpointTriggered();
|
||||||
|
|
||||||
@ -47,6 +51,9 @@ private:
|
|||||||
QAction actionCopy;
|
QAction actionCopy;
|
||||||
QAction *copySeparator;
|
QAction *copySeparator;
|
||||||
|
|
||||||
|
QAction actionAddComment;
|
||||||
|
QAction actionDeleteComment;
|
||||||
|
|
||||||
QMenu *breakpointMenu;
|
QMenu *breakpointMenu;
|
||||||
QAction actionToggleBreakpoint;
|
QAction actionToggleBreakpoint;
|
||||||
QAction actionAdvancedBreakpoint;
|
QAction actionAdvancedBreakpoint;
|
||||||
@ -65,6 +72,9 @@ private:
|
|||||||
// Set actions
|
// Set actions
|
||||||
void setActionCopy();
|
void setActionCopy();
|
||||||
|
|
||||||
|
void setActionAddComment();
|
||||||
|
void setActionDeleteComment();
|
||||||
|
|
||||||
void setActionToggleBreakpoint();
|
void setActionToggleBreakpoint();
|
||||||
void setActionAdvancedBreakpoint();
|
void setActionAdvancedBreakpoint();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user