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.openInEditor = tmp.value(QLatin1String("openInEditor"), false);
|
||||||
f.openAsProject = tmp.value(QLatin1String("openAsProject"), false);
|
f.openAsProject = tmp.value(QLatin1String("openAsProject"), false);
|
||||||
|
|
||||||
if (f.source.isEmpty()) {
|
if (f.source.isEmpty() && f.target.isEmpty()) {
|
||||||
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
|
||||||
"No source given for file in file list.");
|
"Source and target are both empty.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,31 +139,38 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
|
|||||||
if (!JsonWizard::boolFromVariant(f.condition, expander))
|
if (!JsonWizard::boolFromVariant(f.condition, expander))
|
||||||
continue;
|
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
|
// Read contents of source file
|
||||||
const QString src = wizard.absoluteFilePath(expander->expand(f.source));
|
|
||||||
const QFile::OpenMode openMode
|
const QFile::OpenMode openMode
|
||||||
= JsonWizard::boolFromVariant(f.isBinary, expander)
|
= JsonWizard::boolFromVariant(isBinary, expander)
|
||||||
? QIODevice::ReadOnly : (QIODevice::ReadOnly|QIODevice::Text);
|
? QIODevice::ReadOnly : (QIODevice::ReadOnly|QIODevice::Text);
|
||||||
|
|
||||||
Utils::FileReader reader;
|
Utils::FileReader reader;
|
||||||
if (!reader.fetch(src, openMode, errorMessage))
|
if (!reader.fetch(sourcePath, openMode, errorMessage))
|
||||||
return Core::GeneratedFiles();
|
return Core::GeneratedFiles();
|
||||||
|
|
||||||
// Generate file information:
|
// Generate file information:
|
||||||
Core::GeneratedFile gf;
|
Core::GeneratedFile gf;
|
||||||
gf.setPath(project.absoluteFilePath(expander->expand(f.target)));
|
gf.setPath(targetPath);
|
||||||
|
|
||||||
if (JsonWizard::boolFromVariant(f.isBinary, expander)) {
|
if (!keepExisting) {
|
||||||
gf.setBinary(true);
|
if (isBinary) {
|
||||||
gf.setBinaryContents(reader.data());
|
gf.setBinary(true);
|
||||||
} else {
|
gf.setBinaryContents(reader.data());
|
||||||
// TODO: Document that input files are UTF8 encoded!
|
} else {
|
||||||
gf.setBinary(false);
|
// TODO: Document that input files are UTF8 encoded!
|
||||||
gf.setContents(processTextFileContents(expander, QString::fromUtf8(reader.data()), errorMessage));
|
gf.setBinary(false);
|
||||||
if (!errorMessage->isEmpty()) {
|
gf.setContents(processTextFileContents(expander, QString::fromUtf8(reader.data()), errorMessage));
|
||||||
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", "When processing \"%1\":<br>%2")
|
if (!errorMessage->isEmpty()) {
|
||||||
.arg(src, *errorMessage);
|
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", "When processing \"%1\":<br>%2")
|
||||||
return Core::GeneratedFiles();
|
.arg(sourcePath, *errorMessage);
|
||||||
|
return Core::GeneratedFiles();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +181,10 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
|
|||||||
attributes |= Core::GeneratedFile::OpenProjectAttribute;
|
attributes |= Core::GeneratedFile::OpenProjectAttribute;
|
||||||
if (JsonWizard::boolFromVariant(f.overwrite, expander))
|
if (JsonWizard::boolFromVariant(f.overwrite, expander))
|
||||||
attributes |= Core::GeneratedFile::ForceOverwrite;
|
attributes |= Core::GeneratedFile::ForceOverwrite;
|
||||||
|
|
||||||
|
if (keepExisting)
|
||||||
|
attributes |= Core::GeneratedFile::KeepExistingFileAttribute;
|
||||||
|
|
||||||
gf.setAttributes(attributes);
|
gf.setAttributes(attributes);
|
||||||
result.append(gf);
|
result.append(gf);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user