Custom wizard: Introduce 'binary' attribute for source files.

Indicating the file is to be copied as is and not preprocessed.

Task-number: QTCREATORBUG-2344
This commit is contained in:
Friedemann Kleint
2010-09-14 17:03:08 +02:00
parent 4118d70182
commit 2c2f15dbc6
3 changed files with 23 additions and 5 deletions

View File

@@ -151,17 +151,30 @@ static inline bool createFile(Internal::CustomWizardFile cwFile,
const QString targetPath = QDir::toNativeSeparators(targetDirectory + slash + cwFile.target); const QString targetPath = QDir::toNativeSeparators(targetDirectory + slash + cwFile.target);
if (CustomWizardPrivate::verbose) if (CustomWizardPrivate::verbose)
qDebug() << "generating " << targetPath << sourcePath << fm; qDebug() << "generating " << targetPath << sourcePath << fm;
// Read contents of source file
const QFile::OpenMode openMode
= cwFile.binary ? QIODevice::ReadOnly : (QIODevice::ReadOnly|QIODevice::Text);
QFile file(sourcePath); QFile file(sourcePath);
if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) { if (!file.open(openMode)) {
*errorMessage = QString::fromLatin1("Cannot open %1: %2").arg(sourcePath, file.errorString()); *errorMessage = QString::fromLatin1("Cannot open %1: %2").arg(sourcePath, file.errorString());
return false; return false;
} }
// Field replacement on contents const QByteArray contentData = file.readAll();
const QString contentsIn = QString::fromLocal8Bit(file.readAll()); file.close();
Core::GeneratedFile generatedFile; Core::GeneratedFile generatedFile;
generatedFile.setContents(Internal::CustomWizardContext::processFile(fm, contentsIn));
generatedFile.setPath(targetPath); generatedFile.setPath(targetPath);
if (cwFile.binary) {
// Binary file: Set data.
generatedFile.setBinary(true);
generatedFile.setBinaryContents(contentData);
} else {
// Template file: Preprocess.
const QString contentsIn = QString::fromLocal8Bit(contentData);
generatedFile.setContents(Internal::CustomWizardContext::processFile(fm, contentsIn));
}
Core::GeneratedFile::Attributes attributes = 0; Core::GeneratedFile::Attributes attributes = 0;
if (cwFile.openEditor) if (cwFile.openEditor)
attributes |= Core::GeneratedFile::OpenEditorAttribute; attributes |= Core::GeneratedFile::OpenEditorAttribute;

View File

@@ -88,6 +88,7 @@ static const char filesGeneratorScriptAttributeC[] = "generatorscript";
static const char fileElementC[] = "file"; static const char fileElementC[] = "file";
static const char fileSourceAttributeC[] = "source"; static const char fileSourceAttributeC[] = "source";
static const char fileTargetAttributeC[] = "target"; static const char fileTargetAttributeC[] = "target";
static const char fileBinaryAttributeC[] = "binary";
enum ParseState { enum ParseState {
ParseBeginning, ParseBeginning,
@@ -137,7 +138,7 @@ QString CustomWizardField::comboEntryTextKey(int i)
} }
CustomWizardFile::CustomWizardFile() : CustomWizardFile::CustomWizardFile() :
openEditor(false), openProject(false) openEditor(false), openProject(false), binary(false)
{ {
} }
@@ -543,6 +544,7 @@ CustomWizardParameters::ParseResult
file.target = attributeValue(reader, fileTargetAttributeC); file.target = attributeValue(reader, fileTargetAttributeC);
file.openEditor = booleanAttributeValue(reader, customWizardFileOpenEditorAttributeC, false); file.openEditor = booleanAttributeValue(reader, customWizardFileOpenEditorAttributeC, false);
file.openProject = booleanAttributeValue(reader, customWizardFileOpenProjectAttributeC, false); file.openProject = booleanAttributeValue(reader, customWizardFileOpenProjectAttributeC, false);
file.binary = booleanAttributeValue(reader, fileBinaryAttributeC, false);
if (file.target.isEmpty()) if (file.target.isEmpty())
file.target = file.source; file.target = file.source;
if (file.source.isEmpty()) { if (file.source.isEmpty()) {
@@ -644,6 +646,8 @@ QString CustomWizardParameters::toString() const
str << " [editor]"; str << " [editor]";
if (f.openProject) if (f.openProject)
str << " [project]"; str << " [project]";
if (f.binary)
str << " [binary]";
str << '\n'; str << '\n';
} }
foreach(const CustomWizardField &f, fields) { foreach(const CustomWizardField &f, fields) {

View File

@@ -68,6 +68,7 @@ struct CustomWizardFile {
QString target; QString target;
bool openEditor; bool openEditor;
bool openProject; bool openProject;
bool binary;
}; };
// Argument to the generator script containing placeholders to // Argument to the generator script containing placeholders to