Skip to content

Commit

Permalink
Comment Menu for the Decompiler Context Menu (#2265)
Browse files Browse the repository at this point in the history
  • Loading branch information
NirmalManoj committed Aug 15, 2020
1 parent bc3d679 commit 61d0454
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/menus/DecompilerContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "dialogs/preferences/PreferencesDialog.h"
#include "MainWindow.h"
#include "dialogs/BreakpointsDialog.h"
#include "dialogs/CommentsDialog.h"

#include <QtCore>
#include <QShortcut>
Expand All @@ -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)),
Expand All @@ -25,13 +28,19 @@ DecompilerContextMenu::DecompilerContextMenu(QWidget *parent, MainWindow *mainWi
setActionCopy();
addSeparator();

setActionAddComment();
setActionDeleteComment();

addSeparator();
addBreakpointMenu();
addDebugMenu();

setShortcutContextInActions(this);

connect(this, &DecompilerContextMenu::aboutToShow,
this, &DecompilerContextMenu::aboutToShowSlot);
connect(this, &DecompilerContextMenu::aboutToHide,
this, &DecompilerContextMenu::aboutToHideSlot);
}

DecompilerContextMenu::~DecompilerContextMenu()
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()) {
Expand Down
10 changes: 10 additions & 0 deletions src/menus/DecompilerContextMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ public slots:

private slots:
void aboutToShowSlot();
void aboutToHideSlot();

void actionCopyTriggered();

void actionAddCommentTriggered();
void actionDeleteCommentTriggered();

void actionToggleBreakpointTriggered();
void actionAdvancedBreakpointTriggered();

Expand All @@ -47,6 +51,9 @@ private slots:
QAction actionCopy;
QAction *copySeparator;

QAction actionAddComment;
QAction actionDeleteComment;

QMenu *breakpointMenu;
QAction actionToggleBreakpoint;
QAction actionAdvancedBreakpoint;
Expand All @@ -65,6 +72,9 @@ private slots:
// Set actions
void setActionCopy();

void setActionAddComment();
void setActionDeleteComment();

void setActionToggleBreakpoint();
void setActionAdvancedBreakpoint();

Expand Down

0 comments on commit 61d0454

Please sign in to comment.