Comment Menu for the Decompiler Context Menu (#2265)

This commit is contained in:
NIRMAL MANOJ C 2020-07-06 22:48:22 +05:30
parent a4174271f6
commit 8b4c58e07d
2 changed files with 64 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include "dialogs/preferences/PreferencesDialog.h"
#include "MainWindow.h"
#include "dialogs/BreakpointsDialog.h"
#include "dialogs/CommentsDialog.h"
#include <QtCore>
#include <QShortcut>
@ -16,6 +17,8 @@ DecompilerContextMenu::DecompilerContextMenu(QWidget *parent, MainWindow *mainWi
isTogglingBreakpoints(false),
mainWindow(mainWindow),
actionCopy(tr("Copy"), this),
actionAddComment(tr("Add Comment"), this),
actionDeleteComment(tr("Delete comment"), this),
actionToggleBreakpoint(tr("Add/remove breakpoint"), this),
actionAdvancedBreakpoint(tr("Advanced breakpoint"), this),
breakpointsInLineMenu(new QMenu(this)),
@ -25,6 +28,10 @@ DecompilerContextMenu::DecompilerContextMenu(QWidget *parent, MainWindow *mainWi
setActionCopy();
addSeparator();
setActionAddComment();
setActionDeleteComment();
addSeparator();
addBreakpointMenu();
addDebugMenu();
@ -32,6 +39,8 @@ DecompilerContextMenu::DecompilerContextMenu(QWidget *parent, MainWindow *mainWi
connect(this, &DecompilerContextMenu::aboutToShow,
this, &DecompilerContextMenu::aboutToShowSlot);
connect(this, &DecompilerContextMenu::aboutToHide,
this, &DecompilerContextMenu::aboutToHideSlot);
}
DecompilerContextMenu::~DecompilerContextMenu()
@ -95,8 +104,28 @@ bool DecompilerContextMenu::getIsTogglingBreakpoints()
return this->isTogglingBreakpoints;
}
void DecompilerContextMenu::aboutToHideSlot()
{
actionAddComment.setVisible(true);
}
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();
@ -134,6 +163,21 @@ void DecompilerContextMenu::setActionCopy()
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()
{
connect(&actionToggleBreakpoint, &QAction::triggered, this,
@ -166,6 +210,16 @@ void DecompilerContextMenu::actionCopyTriggered()
emit copy();
}
void DecompilerContextMenu::actionAddCommentTriggered()
{
CommentsDialog::addOrEditComment(this->firstOffsetInLine, this);
}
void DecompilerContextMenu::actionDeleteCommentTriggered()
{
Core()->delComment(this->firstOffsetInLine);
}
void DecompilerContextMenu::actionToggleBreakpointTriggered()
{
if (!this->availableBreakpoints.isEmpty()) {

View File

@ -27,9 +27,13 @@ public slots:
private slots:
void aboutToShowSlot();
void aboutToHideSlot();
void actionCopyTriggered();
void actionAddCommentTriggered();
void actionDeleteCommentTriggered();
void actionToggleBreakpointTriggered();
void actionAdvancedBreakpointTriggered();
@ -47,6 +51,9 @@ private:
QAction actionCopy;
QAction *copySeparator;
QAction actionAddComment;
QAction actionDeleteComment;
QMenu *breakpointMenu;
QAction actionToggleBreakpoint;
QAction actionAdvancedBreakpoint;
@ -65,6 +72,9 @@ private:
// Set actions
void setActionCopy();
void setActionAddComment();
void setActionDeleteComment();
void setActionToggleBreakpoint();
void setActionAdvancedBreakpoint();