diff --git a/src/menus/DecompilerContextMenu.cpp b/src/menus/DecompilerContextMenu.cpp index 16711149..5ce34f79 100644 --- a/src/menus/DecompilerContextMenu.cpp +++ b/src/menus/DecompilerContextMenu.cpp @@ -2,6 +2,7 @@ #include "dialogs/preferences/PreferencesDialog.h" #include "MainWindow.h" #include "dialogs/BreakpointsDialog.h" +#include "dialogs/CommentsDialog.h" #include #include @@ -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()) { diff --git a/src/menus/DecompilerContextMenu.h b/src/menus/DecompilerContextMenu.h index 99d629bb..bb2cb0b2 100644 --- a/src/menus/DecompilerContextMenu.h +++ b/src/menus/DecompilerContextMenu.h @@ -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();