forked from radareorg/iaito
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommentsDialog.cpp
More file actions
75 lines (61 loc) · 1.93 KB
/
CommentsDialog.cpp
File metadata and controls
75 lines (61 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "CommentsDialog.h"
#include "ui_CommentsDialog.h"
#include "core/Iaito.h"
CommentsDialog::CommentsDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::CommentsDialog)
{
ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
// Event filter for capturing Ctrl/Cmd+Return
ui->textEdit->installEventFilter(this);
}
CommentsDialog::~CommentsDialog() {}
void CommentsDialog::on_buttonBox_accepted() {}
void CommentsDialog::on_buttonBox_rejected()
{
close();
}
QString CommentsDialog::getComment()
{
QString ret = ui->textEdit->document()->toPlainText();
return ret;
}
void CommentsDialog::setComment(const QString &comment)
{
ui->textEdit->document()->setPlainText(comment);
}
void CommentsDialog::addOrEditComment(RVA offset, QWidget *parent)
{
QString oldComment = Core()->cmdRawAt("CC.", offset);
// Remove newline at the end added by cmd
oldComment.remove(oldComment.length() - 1, 1);
CommentsDialog c(parent);
if (oldComment.isNull() || oldComment.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();
if (comment.isEmpty()) {
Core()->delComment(offset);
} else {
Core()->setComment(offset, 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;
}