|
1 | 1 | #include "mainwindow.h" |
2 | 2 | #include "ui_mainwindow.h" |
3 | 3 | #include "searchwidget.h" |
| 4 | +#include "gotodialog.h" |
4 | 5 | #include "dockwidget.h" |
5 | 6 | #include "utils.h" |
6 | 7 | #include "../../core/schedule.h" |
|
12 | 13 | #include <QtCore/QRegularExpression> |
13 | 14 | #include <QtWidgets/QMessageBox> |
14 | 15 | #include <QtWidgets/QInputDialog> |
| 16 | +#include <algorithm> |
15 | 17 | #include <QtWidgets/QScrollBar> |
16 | 18 |
|
17 | 19 | #ifdef _MSC_VER |
@@ -105,24 +107,43 @@ void MainWindow::memUpdateEdit(HexWidget *edit, bool force) { |
105 | 107 | } |
106 | 108 |
|
107 | 109 | void MainWindow::flashGotoPressed() { |
108 | | - bool accept = false; |
109 | | - QString addrStr = getAddressString(m_flashGotoAddr, &accept); |
110 | | - |
111 | | - if (accept) { |
112 | | - m_flashGotoAddr = addrStr; |
113 | | - ui->flashEdit->setFocus(); |
114 | | - ui->flashEdit->setOffset(hex2int(addrStr)); |
| 110 | + if (GotoDialog dlg(m_flashGotoAddr, m_memGotoHistory, this); dlg.exec() == QDialog::Accepted) { |
| 111 | + const QString typed = dlg.text().toUpper().trimmed(); |
| 112 | + bool ok = false; |
| 113 | + const QString resolved = resolveAddressOrEquate(typed, &ok); |
| 114 | + if (ok) { |
| 115 | + m_flashGotoAddr = typed; |
| 116 | + ui->flashEdit->setFocus(); |
| 117 | + ui->flashEdit->setOffset(hex2int(resolved)); |
| 118 | + |
| 119 | + auto &hist = m_memGotoHistory; |
| 120 | + std::erase_if(hist, [&](const QString &s){ return s.compare(typed, Qt::CaseInsensitive) == 0; }); |
| 121 | + hist.insert(hist.begin(), typed); |
| 122 | + if (hist.size() > 50) { hist.resize(50); } |
| 123 | + } else { |
| 124 | + QMessageBox::warning(this, MSG_WARNING, tr("Error when reading input string")); |
| 125 | + } |
115 | 126 | } |
116 | 127 | } |
117 | 128 |
|
118 | 129 | void MainWindow::ramGotoPressed() { |
119 | | - bool accept = false; |
120 | | - QString addrStr = getAddressString(m_RamGotoAddr, &accept); |
121 | | - |
122 | | - if (accept) { |
123 | | - m_RamGotoAddr = addrStr; |
124 | | - ui->ramEdit->setFocus(); |
125 | | - ui->ramEdit->setOffset(hex2int(addrStr) - 0xD00000); |
| 130 | + GotoDialog dlg(m_RamGotoAddr, m_memGotoHistory, this); |
| 131 | + if (dlg.exec() == QDialog::Accepted) { |
| 132 | + const QString typed = dlg.text().toUpper().trimmed(); |
| 133 | + bool ok = false; |
| 134 | + const QString resolved = resolveAddressOrEquate(typed, &ok); |
| 135 | + if (ok) { |
| 136 | + m_RamGotoAddr = typed; |
| 137 | + ui->ramEdit->setFocus(); |
| 138 | + ui->ramEdit->setOffset(hex2int(resolved) - 0xD00000); |
| 139 | + |
| 140 | + auto &hist = m_memGotoHistory; |
| 141 | + std::erase_if(hist, [&](const QString &s){ return s.compare(typed, Qt::CaseInsensitive) == 0; }); |
| 142 | + hist.insert(hist.begin(), typed); |
| 143 | + if (hist.size() > 50) { hist.resize(50); } |
| 144 | + } else { |
| 145 | + QMessageBox::warning(this, MSG_WARNING, tr("Error when reading input string")); |
| 146 | + } |
126 | 147 | } |
127 | 148 | } |
128 | 149 |
|
@@ -194,11 +215,22 @@ void MainWindow::memGotoEdit(HexWidget *edit) { |
194 | 215 | return; |
195 | 216 | } |
196 | 217 |
|
197 | | - bool accept = false; |
198 | | - QString address = getAddressString(m_memGotoAddr, &accept); |
199 | | - |
200 | | - if (accept) { |
201 | | - memGoto(edit, static_cast<uint32_t>(hex2int(m_memGotoAddr = address))); |
| 218 | + GotoDialog dlg(m_memGotoAddr, m_memGotoHistory, this); |
| 219 | + if (dlg.exec() == QDialog::Accepted) { |
| 220 | + QString typed = dlg.text().toUpper().trimmed(); |
| 221 | + bool ok = false; |
| 222 | + QString resolved = resolveAddressOrEquate(typed, &ok); |
| 223 | + if (ok) { |
| 224 | + m_memGotoAddr = typed; |
| 225 | + memGoto(edit, static_cast<uint32_t>(hex2int(resolved))); |
| 226 | + // MRU update |
| 227 | + auto &hist = m_memGotoHistory; |
| 228 | + hist.erase(std::remove_if(hist.begin(), hist.end(), [&](const QString &s){ return s.compare(typed, Qt::CaseInsensitive) == 0; }), hist.end()); |
| 229 | + hist.insert(hist.begin(), typed); |
| 230 | + if (hist.size() > 50) { hist.resize(50); } |
| 231 | + } else { |
| 232 | + QMessageBox::warning(this, MSG_WARNING, tr("Error when reading input string")); |
| 233 | + } |
202 | 234 | } |
203 | 235 | } |
204 | 236 |
|
|
0 commit comments