Skip to content

Commit 24827cb

Browse files
committed
1 parent ea82e1e commit 24827cb

4 files changed

Lines changed: 66 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ target_sources(${PROJECT_NAME}
4343
src/dialogs/devgraphs.cpp
4444
src/dialogs/flc.cpp
4545
src/dialogs/goto.cpp
46+
src/dialogs/input.cpp
4647
src/dialogs/loader.cpp
4748
src/dialogs/memorymap.cpp
4849
src/dialogs/patch.cpp

src/dialogs/input.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "input.h"
2+
#include <QKeyEvent>
3+
4+
TextEditInputDialog::TextEditInputDialog(QWidget* parent, Qt::WindowFlags flags)
5+
: QInputDialog{parent, flags} {
6+
this->setOptions(QInputDialog::UsePlainTextEditForTextInput);
7+
}
8+
9+
void TextEditInputDialog::keyPressEvent(QKeyEvent* event) {
10+
if(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
11+
if(event->modifiers() & Qt::ControlModifier) {
12+
this->accept();
13+
event->accept();
14+
return;
15+
}
16+
}
17+
18+
QInputDialog::keyPressEvent(event);
19+
}
20+
21+
namespace input_dialog {
22+
23+
QString get_multi_line_text(QWidget* parent, const QString& title,
24+
const QString& label, const QString& text, bool* ok,
25+
Qt::WindowFlags flags,
26+
Qt::InputMethodHints ime_hints) {
27+
TextEditInputDialog dlg{parent, flags};
28+
dlg.setWindowTitle(title);
29+
dlg.setLabelText(label);
30+
dlg.setTextValue(text);
31+
dlg.setInputMethodHints(ime_hints);
32+
33+
int ret = dlg.exec();
34+
if(ok) *ok = !!ret;
35+
return ret ? dlg.textValue() : QString{};
36+
}
37+
38+
} // namespace input_dialog

src/dialogs/input.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include <QInputDialog>
4+
5+
class TextEditInputDialog: public QInputDialog {
6+
Q_OBJECT
7+
8+
public:
9+
explicit TextEditInputDialog(QWidget* parent = nullptr,
10+
Qt::WindowFlags flags = {});
11+
12+
protected:
13+
void keyPressEvent(QKeyEvent* event) override;
14+
};
15+
16+
namespace input_dialog {
17+
18+
QString get_multi_line_text(QWidget* parent, const QString& title,
19+
const QString& label, const QString& text = {},
20+
bool* ok = nullptr, Qt::WindowFlags flags = {},
21+
Qt::InputMethodHints ime_hints = {});
22+
23+
}

src/support/actions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "dialogs/about.h"
33
#include "dialogs/detail.h"
44
#include "dialogs/goto.h"
5+
#include "dialogs/input.h"
56
#include "dialogs/patch.h"
67
#include "dialogs/settings.h"
78
#include "dialogs/table.h"
@@ -286,9 +287,10 @@ void comment() {
286287
bool ok = false;
287288
const char* cmt = rd_get_comment(cv->context(), *address);
288289

289-
QString s = QInputDialog::getMultiLineText(
290+
QString s = input_dialog::get_multi_line_text(
290291
g_mainwindow, QString{"Comment @ %1"}.arg(utils::to_hex(*address)),
291-
"Insert comment (or leave empty):", cmt ? cmt : QString{}, &ok);
292+
"Insert comment (or leave empty), CTRL+ENTER to accept:",
293+
cmt ? cmt : QString{}, &ok);
292294

293295
if(ok && rd_set_comment(cv->context(), *address, qUtf8Printable(s)))
294296
cv->surface()->invalidate();

0 commit comments

Comments
 (0)