mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-21 04:16:12 +00:00
Edit Comment from DisassemblyContextMenu
This commit is contained in:
parent
82e2ddf6e6
commit
61549f401e
@ -332,7 +332,7 @@ void CutterCore::renameFlag(QString old_name, QString new_name)
|
||||
cmd("fr " + old_name + " " + new_name);
|
||||
}
|
||||
|
||||
void CutterCore::setComment(RVA addr, QString cmt)
|
||||
void CutterCore::setComment(RVA addr, const QString &cmt)
|
||||
{
|
||||
cmd("CCu base64:" + cmt.toLocal8Bit().toBase64() + " @ " + QString::number(addr));
|
||||
emit commentsChanged();
|
||||
|
@ -204,8 +204,10 @@ public:
|
||||
QStringList cmdList(const QString &str) { auto l = cmd(str).split("\n"); l.removeAll(""); return l; }
|
||||
void renameFunction(QString prev_name, QString new_name);
|
||||
void renameFlag(QString old_name, QString new_name);
|
||||
void setComment(RVA addr, QString cmt);
|
||||
|
||||
void setComment(RVA addr, const QString &cmt);
|
||||
void delComment(ut64 addr);
|
||||
|
||||
void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID);
|
||||
QMap<QString, QList<QList<QString>>> getNestedComments();
|
||||
void setOptions(QString key);
|
||||
|
@ -25,3 +25,8 @@ QString CommentsDialog::getComment()
|
||||
QString ret = ui->lineEdit->text();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CommentsDialog::setComment(const QString &comment)
|
||||
{
|
||||
ui->lineEdit->setText(comment);
|
||||
}
|
@ -18,6 +18,7 @@ public:
|
||||
~CommentsDialog();
|
||||
|
||||
QString getComment();
|
||||
void setComment(const QString &comment);
|
||||
|
||||
private slots:
|
||||
void on_buttonBox_accepted();
|
||||
|
@ -122,6 +122,17 @@ void DisassemblyContextMenu::aboutToShowSlot()
|
||||
auto keys = instObject.keys();
|
||||
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())
|
||||
{
|
||||
actionAddComment.setText(tr("Add Comment"));
|
||||
}
|
||||
else
|
||||
{
|
||||
actionAddComment.setText(tr("Edit Comment"));
|
||||
}
|
||||
}
|
||||
|
||||
QKeySequence DisassemblyContextMenu::getCommentSequence() const
|
||||
@ -151,11 +162,32 @@ QKeySequence DisassemblyContextMenu::getDisplayOptionsSequence() const
|
||||
|
||||
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()));
|
||||
|
||||
CommentsDialog *c = new CommentsDialog(this);
|
||||
|
||||
if (oldComment.isNull() || QByteArray::fromBase64(oldComment.toUtf8()).isEmpty())
|
||||
{
|
||||
c->setWindowTitle(tr("Add Comment at %1").arg(RAddressString(offset)));
|
||||
}
|
||||
else
|
||||
{
|
||||
c->setWindowTitle(tr("Edit Comment at %1").arg(RAddressString(offset)));
|
||||
}
|
||||
|
||||
c->setComment(oldComment);
|
||||
if (c->exec())
|
||||
{
|
||||
QString comment = c->getComment();
|
||||
Core()->setComment(offset, comment);
|
||||
if (comment.isEmpty())
|
||||
{
|
||||
Core()->delComment(offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
Core()->setComment(offset, comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user