mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-19 01:46:27 +00:00
Added ability to rename resources/directories in the resource table view
This commit is contained in:
51
src/Editor/CFileNameValidator.h
Normal file
51
src/Editor/CFileNameValidator.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef CFILENAMEVALIDATOR_H
|
||||
#define CFILENAMEVALIDATOR_H
|
||||
|
||||
#include <QValidator>
|
||||
|
||||
#include "UICommon.h"
|
||||
#include <Common/FileUtil.h>
|
||||
|
||||
class CFileNameValidator : public QValidator
|
||||
{
|
||||
bool mIsDirectory;
|
||||
|
||||
public:
|
||||
CFileNameValidator(bool IsDirectory, QObject *pParent = 0)
|
||||
: QValidator(pParent)
|
||||
, mIsDirectory(IsDirectory)
|
||||
{}
|
||||
|
||||
QValidator::State validate(QString& rInput, int&) const
|
||||
{
|
||||
QValidator::State Out = QValidator::Acceptable;
|
||||
|
||||
if (!FileUtil::IsValidName( TO_TSTRING(rInput), mIsDirectory ))
|
||||
{
|
||||
// Uh oh, the input is invalid. Only invalid characters will be considered entirely
|
||||
// invalid; other errors will be considered intermediate.
|
||||
Out = QValidator::Intermediate;
|
||||
|
||||
for (int ChrIdx = 0; ChrIdx < rInput.size(); ChrIdx++)
|
||||
{
|
||||
char Chr = rInput.at(ChrIdx).toLatin1();
|
||||
|
||||
if (!FileUtil::IsValidFileNameCharacter(Chr))
|
||||
{
|
||||
Out = QValidator::Invalid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
void fixup(QString& rInput) const
|
||||
{
|
||||
TString Sanitized = FileUtil::SanitizeName( TO_TSTRING(rInput), mIsDirectory );
|
||||
rInput = TO_QSTRING(Sanitized);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CFILENAMEVALIDATOR_H
|
||||
Reference in New Issue
Block a user