diff --git a/src/dialogs/CommentsDialog.cpp b/src/dialogs/CommentsDialog.cpp index a19ad567..b44f9223 100644 --- a/src/dialogs/CommentsDialog.cpp +++ b/src/dialogs/CommentsDialog.cpp @@ -7,6 +7,9 @@ CommentsDialog::CommentsDialog(QWidget *parent) : { ui->setupUi(this); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); + + // Event filter for capturing Ctrl/Cmd+Return + ui->textEdit->installEventFilter(this); } CommentsDialog::~CommentsDialog() {} @@ -22,11 +25,29 @@ void CommentsDialog::on_buttonBox_rejected() QString CommentsDialog::getComment() { - QString ret = ui->lineEdit->text(); + QString ret = ui->textEdit->document()->toPlainText(); return ret; } void CommentsDialog::setComment(const QString &comment) { - ui->lineEdit->setText(comment); -} \ No newline at end of file + ui->textEdit->document()->setPlainText(comment); +} + +bool CommentsDialog::eventFilter(QObject *obj, QEvent *event) +{ + if(event -> type() == QEvent::KeyPress) + { + QKeyEvent *keyEvent = static_cast (event); + + // Confirm comment by pressing Ctrl/Cmd+Return + if((keyEvent -> modifiers() & Qt::ControlModifier) && + ((keyEvent -> key() == Qt::Key_Enter) || (keyEvent -> key() == Qt::Key_Return))) + { + this->accept(); + return true; + } + } + + return false; +} diff --git a/src/dialogs/CommentsDialog.h b/src/dialogs/CommentsDialog.h index b95461fa..6de5c13d 100644 --- a/src/dialogs/CommentsDialog.h +++ b/src/dialogs/CommentsDialog.h @@ -27,6 +27,8 @@ private slots: private: std::unique_ptr ui; + + bool eventFilter(QObject *obj, QEvent *event); }; #endif // COMMENTSDIALOG_H diff --git a/src/dialogs/CommentsDialog.ui b/src/dialogs/CommentsDialog.ui index f31f8fb7..c73eb248 100644 --- a/src/dialogs/CommentsDialog.ui +++ b/src/dialogs/CommentsDialog.ui @@ -7,40 +7,35 @@ 0 0 400 - 75 + 118 Comment + + 2 + + + 2 + + + 5 + + + 2 + + + 2 + 0 - - - - 75 - true - - - - Comment: - - - - - - - false - - - - - + diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index 891e2cba..c419260a 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -132,9 +132,8 @@ void DisassemblyContextMenu::aboutToShowSlot() bool immBase = keys.contains("val") || keys.contains("ptr"); setBaseMenuAction->setVisible(immBase); - QJsonObject disasObject = Core()->cmdj("pdj 1 @ " + QString::number(offset)).array().first().toObject(); - QString comment = disasObject["comment"].toString(); - if (comment.isNull() || QByteArray::fromBase64(comment.toUtf8()).isEmpty()) + QString comment = Core()->cmd("CC." + RAddressString(offset)); + if (comment.isNull() || comment.isEmpty()) { actionAddComment.setText(tr("Add Comment")); } @@ -230,12 +229,12 @@ void DisassemblyContextMenu::on_actionCopy_triggered() void DisassemblyContextMenu::on_actionAddComment_triggered() { - QJsonObject disasObject = Core()->cmdj("pdj 1 @ " + QString::number(offset)).array().first().toObject(); - QString oldComment = QString::fromUtf8(QByteArray::fromBase64(disasObject["comment"].toString().toUtf8())); - + QString oldComment = Core()->cmd("CC." + RAddressString(offset)); + // Remove newline at the end added by cmd + oldComment.remove(oldComment.length()-1, 1); CommentsDialog *c = new CommentsDialog(this); - if (oldComment.isNull() || QByteArray::fromBase64(oldComment.toUtf8()).isEmpty()) + if (oldComment.isNull() || oldComment.isEmpty()) { c->setWindowTitle(tr("Add Comment at %1").arg(RAddressString(offset))); }