|
@@ -7,12 +7,20 @@
|
|
|
*/
|
|
|
|
|
|
#include "LUAEditorGoToLineDialog.hxx"
|
|
|
-#include <Source/LUA/moc_LUAEditorGoToLineDialog.cpp>
|
|
|
|
|
|
+#include <Source/LUA/moc_LUAEditorGoToLineDialog.cpp>
|
|
|
#include <Source/LUA/ui_LUAEditorGoToLineDialog.h>
|
|
|
|
|
|
+#include <QDialogButtonBox>
|
|
|
+#include <QLineEdit>
|
|
|
+#include <QPushButton>
|
|
|
+#include <QRegExp>
|
|
|
+#include <QRegExpValidator>
|
|
|
+
|
|
|
namespace LUAEditor
|
|
|
{
|
|
|
+ static constexpr const char* GotoLineDialogRegEx = "(^\\d+(:\\d+)?$)";
|
|
|
+
|
|
|
LUAEditorGoToLineDialog::LUAEditorGoToLineDialog(QWidget* parent)
|
|
|
: QDialog(parent)
|
|
|
{
|
|
@@ -20,7 +28,14 @@ namespace LUAEditor
|
|
|
m_gui = azcreate(Ui::goToLineDlg, ());
|
|
|
m_gui->setupUi(this);
|
|
|
this->setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
|
|
- connect(m_gui->lineNumberSpinBox, SIGNAL(valueChanged (int)), this, SLOT(spinBoxLineNumberChanged(int)));
|
|
|
+
|
|
|
+ const QRegExp rx(GotoLineDialogRegEx);
|
|
|
+ QRegExpValidator* const validator = new QRegExpValidator(rx, this);
|
|
|
+ m_gui->lineNumber->setValidator(validator);
|
|
|
+
|
|
|
+ connect(m_gui->lineNumber, &QLineEdit::textChanged, this, &LUAEditorGoToLineDialog::handleLineNumberInput);
|
|
|
+ connect(m_gui->buttonBox, &QDialogButtonBox::accepted, this, &LUAEditorGoToLineDialog::validateAndAccept);
|
|
|
+ connect(m_gui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
}
|
|
|
|
|
|
LUAEditorGoToLineDialog::~LUAEditorGoToLineDialog()
|
|
@@ -28,16 +43,45 @@ namespace LUAEditor
|
|
|
azdestroy(m_gui);
|
|
|
}
|
|
|
|
|
|
- void LUAEditorGoToLineDialog::setLineNumber(int newNumber)
|
|
|
+ void LUAEditorGoToLineDialog::setLineNumber(int line, int newColumn) const
|
|
|
+ {
|
|
|
+ const QString text = QString::number(line) + QString(":") + QString::number(newColumn);
|
|
|
+ m_gui->lineNumber->setText(text);
|
|
|
+ m_gui->lineNumber->setFocus();
|
|
|
+ m_gui->lineNumber->selectAll();
|
|
|
+ }
|
|
|
+
|
|
|
+ void LUAEditorGoToLineDialog::handleLineNumberInput(const QString& input)
|
|
|
{
|
|
|
- m_gui->lineNumberSpinBox->setValue(newNumber);
|
|
|
- m_gui->lineNumberSpinBox->setFocus();
|
|
|
- m_gui->lineNumberSpinBox->selectAll();
|
|
|
+ const QRegularExpression re(GotoLineDialogRegEx);
|
|
|
+ QPushButton* const button = m_gui->buttonBox->button(QDialogButtonBox::StandardButton::Ok);
|
|
|
+ button->setEnabled(re.match(input).hasMatch());
|
|
|
}
|
|
|
|
|
|
- void LUAEditorGoToLineDialog::spinBoxLineNumberChanged(int newNumber)
|
|
|
+ void LUAEditorGoToLineDialog::validateAndAccept()
|
|
|
{
|
|
|
- m_lineNumber = newNumber;
|
|
|
- emit lineNumberChanged(newNumber);
|
|
|
+ m_columnNumber = 0;
|
|
|
+
|
|
|
+ const QString input = m_gui->lineNumber->text();
|
|
|
+ const QStringList parts = input.split(':');
|
|
|
+
|
|
|
+ if (parts.size() < 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool lineValid = false;
|
|
|
+ bool columnValid = false;
|
|
|
+
|
|
|
+ const int lineNumber = parts[0].toInt(&lineValid);
|
|
|
+ if (lineValid && !parts[0].isEmpty()) {
|
|
|
+ m_lineNumber = AZStd::max(lineNumber, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (parts.size() == 2) {
|
|
|
+ const int columnNumber = parts[1].toInt(&columnValid);
|
|
|
+ if (columnValid && !parts[1].isEmpty()) {
|
|
|
+ m_columnNumber = AZStd::max(columnNumber, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|