| 1 | #include "GotoDialog.h" |
| 2 | #include "DebugSession.h" |
| 3 | #include "Convert.h" |
| 4 | #include <QCompleter> |
| 5 | |
| 6 | |
| 7 | GotoDialog::GotoDialog(const MemoryLayout& ml, DebugSession *session, QWidget* parent) |
| 8 | : QDialog(parent), memLayout(ml), currentSymbol(nullptr) |
| 9 | { |
| 10 | setupUi(this); |
| 11 | |
| 12 | debugSession = session; |
| 13 | if (session) { |
| 14 | // create address completer |
| 15 | auto* completer = new QCompleter(session->symbolTable().labelList(true, &ml), this); |
| 16 | completer->setCaseSensitivity(Qt::CaseInsensitive); |
| 17 | edtAddress->setCompleter(completer); |
| 18 | connect(completer, qOverload<const QString&>(&QCompleter::activated), this, &GotoDialog::addressChanged); |
| 19 | } |
| 20 | |
| 21 | connect(edtAddress, &QLineEdit::textEdited, this, &GotoDialog::addressChanged); |
| 22 | } |
| 23 | |
| 24 | std::optional<uint16_t> GotoDialog::address() |
| 25 | { |
| 26 | return currentSymbol ? currentSymbol->value() |
| 27 | : stringToValue<int>(edtAddress->text()); |
| 28 | } |
| 29 | |
| 30 | void GotoDialog::addressChanged(const QString& text) |
| 31 | { |
| 32 | auto addr = stringToValue<uint16_t>(text); |
| 33 | |
| 34 | if (!text.isEmpty() && !addr && debugSession) { |
| 35 | // try finding a label |
| 36 | currentSymbol = debugSession->symbolTable().getAddressSymbol(text); |
| 37 | if (!currentSymbol) currentSymbol = debugSession->symbolTable().getAddressSymbol(text, Qt::CaseInsensitive); |
| 38 | if (currentSymbol) addr = currentSymbol->value(); |
| 39 | } |
| 40 | |
| 41 | QPalette pal; |
| 42 | pal.setColor(QPalette::Text, addr ? Qt::black : Qt::red); |
| 43 | edtAddress->setPalette(pal); |
| 44 | } |