!XT (BREAK-16) (Sandbox) Remove double-newlines at the end of files.
[CRYENGINE.git] / Code / Sandbox / Plugins / EditorCommon / Dialogs / QStringDialog.cpp
blob7fadcca835868d3c114e04b27a93cafd4127901e
1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 #include "stdafx.h"
5 #include "QStringDialog.h"
6 #include <QLineEdit>
7 #include <QVBoxLayout>
8 #include <QDialogButtonBox>
10 QStringDialog::QStringDialog(const QString& title, QWidget* pParent /*= NULL*/, bool bFileNameLimitation /*= false*/, bool bFileNameAsciiOnly /*= false*/)
11 : CEditorDialog(QStringLiteral("QStringDialog"), pParent ? pParent : QApplication::widgetAt(QCursor::pos()), false)
12 , m_bFileNameLimitation(bFileNameLimitation)
13 , m_bFileNameAsciiOnly(bFileNameAsciiOnly)
15 setWindowTitle(title.isEmpty() ? tr("Enter a string") : title);
17 m_pEdit = new QLineEdit(this);
18 QDialogButtonBox* okCancelButton = new QDialogButtonBox(this);
19 okCancelButton->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
20 connect(okCancelButton, &QDialogButtonBox::accepted, this, &QStringDialog::accept);
21 connect(okCancelButton, &QDialogButtonBox::rejected, this, &QStringDialog::reject);
23 QVBoxLayout* layout = new QVBoxLayout(this);
24 layout->addWidget(m_pEdit);
25 layout->addWidget(okCancelButton);
27 setLayout(layout);
28 SetResizable(false);
31 void QStringDialog::SetString(const char* str)
33 m_pEdit->setText(str);
36 const string QStringDialog::GetString()
38 return m_pEdit->text().toUtf8().constData();
41 void QStringDialog::showEvent(QShowEvent* event)
43 CEditorDialog::showEvent(event);
44 m_pEdit->setFocus();
47 void QStringDialog::accept()
49 string str = GetString();
51 if (m_bFileNameLimitation)
53 const string reservedCharacters("<>:\"/\\|?*}");
54 for (int i = 0, iCount(reservedCharacters.GetLength()); i < iCount; ++i)
56 if (-1 != str.Find(reservedCharacters[i]))
58 string msg;
59 msg.Format("This string can't contain %s characters", reservedCharacters);
60 CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_ERROR, msg);
61 return;
65 if (m_bFileNameAsciiOnly)
67 for (size_t i = 0; i < str.GetLength(); ++i)
69 if (static_cast<unsigned char>(str[i]) > 0x7F)
71 CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_ERROR, "This string can't contain non-ASCII characters");
72 return;
77 if (m_check && !m_check(str))
78 return;
80 CEditorDialog::accept();