mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-19 11:26:11 +00:00
* Fix a bug that prevented comments on invalid instructions to be edited * CommentsDialog: Support multiline comments. * DisassemblyContextMenu: Remove base64 comment handling.
This commit is contained in:
parent
df02b91e69
commit
746998be71
@ -7,6 +7,9 @@ CommentsDialog::CommentsDialog(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
|
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
|
||||||
|
|
||||||
|
// Event filter for capturing Ctrl/Cmd+Return
|
||||||
|
ui->textEdit->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommentsDialog::~CommentsDialog() {}
|
CommentsDialog::~CommentsDialog() {}
|
||||||
@ -22,11 +25,29 @@ void CommentsDialog::on_buttonBox_rejected()
|
|||||||
|
|
||||||
QString CommentsDialog::getComment()
|
QString CommentsDialog::getComment()
|
||||||
{
|
{
|
||||||
QString ret = ui->lineEdit->text();
|
QString ret = ui->textEdit->document()->toPlainText();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommentsDialog::setComment(const QString &comment)
|
void CommentsDialog::setComment(const QString &comment)
|
||||||
{
|
{
|
||||||
ui->lineEdit->setText(comment);
|
ui->textEdit->document()->setPlainText(comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CommentsDialog::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
{
|
||||||
|
if(event -> type() == QEvent::KeyPress)
|
||||||
|
{
|
||||||
|
QKeyEvent *keyEvent = static_cast <QKeyEvent*> (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;
|
||||||
}
|
}
|
@ -27,6 +27,8 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Ui::CommentsDialog> ui;
|
std::unique_ptr<Ui::CommentsDialog> ui;
|
||||||
|
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COMMENTSDIALOG_H
|
#endif // COMMENTSDIALOG_H
|
||||||
|
@ -7,40 +7,35 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>400</width>
|
||||||
<height>75</height>
|
<height>118</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Comment</string>
|
<string>Comment</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QPlainTextEdit" name="textEdit"/>
|
||||||
<property name="font">
|
|
||||||
<font>
|
|
||||||
<weight>75</weight>
|
|
||||||
<bold>true</bold>
|
|
||||||
</font>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Comment:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLineEdit" name="lineEdit">
|
|
||||||
<property name="frame">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string notr="true"/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
@ -132,9 +132,8 @@ void DisassemblyContextMenu::aboutToShowSlot()
|
|||||||
bool immBase = keys.contains("val") || keys.contains("ptr");
|
bool immBase = keys.contains("val") || keys.contains("ptr");
|
||||||
setBaseMenuAction->setVisible(immBase);
|
setBaseMenuAction->setVisible(immBase);
|
||||||
|
|
||||||
QJsonObject disasObject = Core()->cmdj("pdj 1 @ " + QString::number(offset)).array().first().toObject();
|
QString comment = Core()->cmd("CC." + RAddressString(offset));
|
||||||
QString comment = disasObject["comment"].toString();
|
if (comment.isNull() || comment.isEmpty())
|
||||||
if (comment.isNull() || QByteArray::fromBase64(comment.toUtf8()).isEmpty())
|
|
||||||
{
|
{
|
||||||
actionAddComment.setText(tr("Add Comment"));
|
actionAddComment.setText(tr("Add Comment"));
|
||||||
}
|
}
|
||||||
@ -230,12 +229,12 @@ void DisassemblyContextMenu::on_actionCopy_triggered()
|
|||||||
|
|
||||||
void DisassemblyContextMenu::on_actionAddComment_triggered()
|
void DisassemblyContextMenu::on_actionAddComment_triggered()
|
||||||
{
|
{
|
||||||
QJsonObject disasObject = Core()->cmdj("pdj 1 @ " + QString::number(offset)).array().first().toObject();
|
QString oldComment = Core()->cmd("CC." + RAddressString(offset));
|
||||||
QString oldComment = QString::fromUtf8(QByteArray::fromBase64(disasObject["comment"].toString().toUtf8()));
|
// Remove newline at the end added by cmd
|
||||||
|
oldComment.remove(oldComment.length()-1, 1);
|
||||||
CommentsDialog *c = new CommentsDialog(this);
|
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)));
|
c->setWindowTitle(tr("Add Comment at %1").arg(RAddressString(offset)));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user