From d2243006e275760004729c8a9ebf2113a5bd0c66 Mon Sep 17 00:00:00 2001 From: Islam Bassuni Date: Wed, 13 Apr 2022 06:50:57 +0200 Subject: [PATCH] Created adding comments option inside Hexdump. (#2927) --- src/widgets/HexWidget.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/widgets/HexWidget.h | 5 +++++ 2 files changed, 43 insertions(+) diff --git a/src/widgets/HexWidget.cpp b/src/widgets/HexWidget.cpp index 39d9d2e2..b02a0e12 100644 --- a/src/widgets/HexWidget.cpp +++ b/src/widgets/HexWidget.cpp @@ -2,6 +2,7 @@ #include "Cutter.h" #include "Configuration.h" #include "dialogs/WriteCommandsDialogs.h" +#include "dialogs/CommentsDialog.h" #include #include @@ -120,6 +121,19 @@ HexWidget::HexWidget(QWidget *parent) connect(actionCopyAddress, &QAction::triggered, this, &HexWidget::copyAddress); addAction(actionCopyAddress); + // Add comment option + actionComment = new QAction(tr("Add Comment"), this); + actionComment->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut); + actionComment->setShortcut(Qt::Key_Semicolon); + connect(actionComment, &QAction::triggered, this, &HexWidget::on_actionAddComment_triggered); + addAction(actionComment); + + // delete comment option + actionDeleteComment = new QAction(tr("Delete Comment"), this); + actionDeleteComment->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut); + connect(actionDeleteComment, &QAction::triggered, this, &HexWidget::on_actionDeleteComment_triggered); + addAction(actionDeleteComment); + actionSelectRange = new QAction(tr("Select range"), this); connect(actionSelectRange, &QAction::triggered, this, [this]() { rangeDialog.open(cursor.address); }); @@ -620,6 +634,16 @@ void HexWidget::contextMenuEvent(QContextMenuEvent *event) actionCopyAddress->setDisabled(disable); }; + QString comment = Core()->getCommentAt(cursor.address); + + if (comment.isNull() || comment.isEmpty()) { + actionDeleteComment->setVisible(false); + actionComment->setText(tr("Add Comment")); + } else { + actionDeleteComment->setVisible(true); + actionComment->setText(tr("Edit Comment")); + } + QMenu *menu = new QMenu(); QMenu *sizeMenu = menu->addMenu(tr("Item size:")); sizeMenu->addActions(actionsItemSize); @@ -689,6 +713,20 @@ void HexWidget::copyAddress() clipboard->setText(RzAddressString(addr)); } +//slot for add comment action +void HexWidget::on_actionAddComment_triggered() +{ + uint64_t addr = cursor.address; + CommentsDialog::addOrEditComment(addr, this); +} + +//slot for deleting comment action +void HexWidget::on_actionDeleteComment_triggered() +{ + uint64_t addr = cursor.address; + Core()->delComment(addr); +} + void HexWidget::onRangeDialogAccepted() { if (rangeDialog.empty()) { diff --git a/src/widgets/HexWidget.h b/src/widgets/HexWidget.h index 5a6a15f0..b46f0574 100644 --- a/src/widgets/HexWidget.h +++ b/src/widgets/HexWidget.h @@ -311,6 +311,8 @@ private slots: void copy(); void copyAddress(); void onRangeDialogAccepted(); + void on_actionAddComment_triggered(); + void on_actionDeleteComment_triggered(); // Write command slots void w_writeString(); @@ -475,6 +477,9 @@ private: QAction *actionHexPairs; QAction *actionCopy; QAction *actionCopyAddress; + QAction *actionComment; + QAction *actionDeleteComment; + QAction *actionSetFlag; QAction *actionSelectRange; QList actionsWriteString; QList actionsWriteOther;