forked from qt-creator/qt-creator
JsonWizard: Allow Generated files without a source
These are expected to be found in the target location. They will have the KeepExisting attribute set and their contents will not be touched. Having this is useful to specify which files to open. Change-Id: I958f271405ca780e0052f069e0df89bd402da6c4 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -109,9 +109,9 @@ bool JsonWizardFileGenerator::setup(const QVariant &data, QString *errorMessage)
|
||||
f.openInEditor = tmp.value(QLatin1String("openInEditor"), false);
|
||||
f.openAsProject = tmp.value(QLatin1String("openAsProject"), false);
|
||||
|
||||
if (f.source.isEmpty()) {
|
||||
if (f.source.isEmpty() && f.target.isEmpty()) {
|
||||
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
||||
"No source given for file in file list.");
|
||||
"Source and target are both empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -139,21 +139,27 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
|
||||
if (!JsonWizard::boolFromVariant(f.condition, expander))
|
||||
continue;
|
||||
|
||||
const bool keepExisting = f.source.isEmpty();
|
||||
const QString targetPath = project.absoluteFilePath(expander->expand(f.target));
|
||||
const QString sourcePath
|
||||
= keepExisting ? targetPath : wizard.absoluteFilePath(expander->expand(f.source));
|
||||
const bool isBinary = JsonWizard::boolFromVariant(f.isBinary, expander);
|
||||
|
||||
// Read contents of source file
|
||||
const QString src = wizard.absoluteFilePath(expander->expand(f.source));
|
||||
const QFile::OpenMode openMode
|
||||
= JsonWizard::boolFromVariant(f.isBinary, expander)
|
||||
= JsonWizard::boolFromVariant(isBinary, expander)
|
||||
? QIODevice::ReadOnly : (QIODevice::ReadOnly|QIODevice::Text);
|
||||
|
||||
Utils::FileReader reader;
|
||||
if (!reader.fetch(src, openMode, errorMessage))
|
||||
if (!reader.fetch(sourcePath, openMode, errorMessage))
|
||||
return Core::GeneratedFiles();
|
||||
|
||||
// Generate file information:
|
||||
Core::GeneratedFile gf;
|
||||
gf.setPath(project.absoluteFilePath(expander->expand(f.target)));
|
||||
gf.setPath(targetPath);
|
||||
|
||||
if (JsonWizard::boolFromVariant(f.isBinary, expander)) {
|
||||
if (!keepExisting) {
|
||||
if (isBinary) {
|
||||
gf.setBinary(true);
|
||||
gf.setBinaryContents(reader.data());
|
||||
} else {
|
||||
@@ -162,10 +168,11 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
|
||||
gf.setContents(processTextFileContents(expander, QString::fromUtf8(reader.data()), errorMessage));
|
||||
if (!errorMessage->isEmpty()) {
|
||||
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", "When processing \"%1\":<br>%2")
|
||||
.arg(src, *errorMessage);
|
||||
.arg(sourcePath, *errorMessage);
|
||||
return Core::GeneratedFiles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Core::GeneratedFile::Attributes attributes = 0;
|
||||
if (JsonWizard::boolFromVariant(f.openInEditor, expander))
|
||||
@@ -174,6 +181,10 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
|
||||
attributes |= Core::GeneratedFile::OpenProjectAttribute;
|
||||
if (JsonWizard::boolFromVariant(f.overwrite, expander))
|
||||
attributes |= Core::GeneratedFile::ForceOverwrite;
|
||||
|
||||
if (keepExisting)
|
||||
attributes |= Core::GeneratedFile::KeepExistingFileAttribute;
|
||||
|
||||
gf.setAttributes(attributes);
|
||||
result.append(gf);
|
||||
}
|
||||
|
Reference in New Issue
Block a user