forked from qt-creator/qt-creator
ProjectExplorer: Simplify scanning for wizard.json files
No need to manually implement recursion when QDirIterator::Subdirectories exists. Change-Id: I88f04da9a6138e3fc903016dd85b94ba431e3b1a Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -39,7 +39,6 @@ using namespace Utils;
|
||||
namespace ProjectExplorer {
|
||||
|
||||
const char WIZARD_PATH[] = "templates/wizards";
|
||||
const char WIZARD_FILE[] = "wizard.json";
|
||||
|
||||
const char VERSION_KEY[] = "version";
|
||||
const char ENABLED_EXPRESSION_KEY[] = "enabled";
|
||||
@@ -381,10 +380,10 @@ void JsonWizardFactory::createWizardFactories()
|
||||
{
|
||||
QString errorMessage;
|
||||
QString verboseLog;
|
||||
const QString wizardFileName = QLatin1String(WIZARD_FILE);
|
||||
const QString wizardFileName = QLatin1String("wizard.json");
|
||||
|
||||
const Utils::FilePaths paths = searchPaths();
|
||||
for (const Utils::FilePath &path : paths) {
|
||||
const FilePaths paths = searchPaths();
|
||||
for (const FilePath &path : paths) {
|
||||
if (path.isEmpty())
|
||||
continue;
|
||||
|
||||
@@ -396,19 +395,12 @@ void JsonWizardFactory::createWizardFactories()
|
||||
}
|
||||
|
||||
const FileFilter filter {
|
||||
{}, QDir::Dirs|QDir::Readable|QDir::NoDotAndDotDot, QDirIterator::NoIteratorFlags
|
||||
{wizardFileName}, QDir::Files|QDir::Readable|QDir::NoDotAndDotDot, QDirIterator::Subdirectories
|
||||
};
|
||||
const QDir::SortFlags sortflags = QDir::Name|QDir::IgnoreCase;
|
||||
FilePaths dirs = path.dirEntries(filter, sortflags);
|
||||
const FilePaths wizardFiles = path.dirEntries(filter, sortflags);
|
||||
|
||||
while (!dirs.isEmpty()) {
|
||||
const FilePath currentDir = dirs.takeFirst();
|
||||
if (verbose())
|
||||
verboseLog.append(tr("Checking \"%1\" for %2.\n")
|
||||
.arg(currentDir.toUserOutput())
|
||||
.arg(wizardFileName));
|
||||
const FilePath currentFile = currentDir / wizardFileName;
|
||||
if (currentFile.exists()) {
|
||||
for (const FilePath ¤tFile : wizardFiles) {
|
||||
QJsonParseError error;
|
||||
const QByteArray fileData = currentFile.fileContents().value_or(QByteArray());
|
||||
const QJsonDocument json = QJsonDocument::fromJson(fileData, &error);
|
||||
@@ -448,20 +440,10 @@ void JsonWizardFactory::createWizardFactories()
|
||||
continue;
|
||||
}
|
||||
|
||||
IWizardFactory::registerFactoryCreator([data, currentDir] {
|
||||
IWizardFactory::registerFactoryCreator([data, currentFile] {
|
||||
QString errorMessage;
|
||||
return createWizardFactory(data, currentDir, &errorMessage);
|
||||
return createWizardFactory(data, currentFile.parentDir(), &errorMessage);
|
||||
});
|
||||
} else {
|
||||
FilePaths subDirs = currentDir.dirEntries(filter, sortflags);
|
||||
if (!subDirs.isEmpty()) {
|
||||
// There is no QList::prepend(QList)...
|
||||
dirs.swap(subDirs);
|
||||
dirs.append(subDirs);
|
||||
} else if (verbose()) {
|
||||
verboseLog.append(tr("JsonWizard: \"%1\" not found\n").arg(wizardFileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,7 +451,6 @@ void JsonWizardFactory::createWizardFactories()
|
||||
qWarning("%s", qPrintable(verboseLog));
|
||||
Core::MessageManager::writeDisrupting(verboseLog);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
JsonWizardFactory *JsonWizardFactory::createWizardFactory(const QVariantMap &data,
|
||||
|
Reference in New Issue
Block a user