forked from qt-creator/qt-creator
Project: Make Project::file take a std::function to match files
Make Project::files take a standard function to match files with instead of an enum (and a std::function). Change-Id: I6a24e40dba0e972ff96c0a57e775d2377e2545e0 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -728,7 +728,9 @@ void CMakeProject::createGeneratedCodeModelSupport()
|
||||
= Utils::transform<QSet>(factories, [](const ExtraCompilerFactory *f) { return f->sourceTag(); });
|
||||
|
||||
// Find all files generated by any of the extra compilers, in a rather crude way.
|
||||
const FileNameList fileList = files(SourceFiles, [&fileExtensions](const Node *n) {
|
||||
const FileNameList fileList = files([&fileExtensions](const Node *n) {
|
||||
if (!SourceFiles(n))
|
||||
return false;
|
||||
const QString fp = n->filePath().toString();
|
||||
const int pos = fp.lastIndexOf('.');
|
||||
return pos >= 0 && fileExtensions.contains(fp.mid(pos + 1));
|
||||
|
@@ -177,7 +177,7 @@ bool NimProject::supportsKit(Kit *k, QString *errorMessage) const
|
||||
|
||||
FileNameList NimProject::nimFiles() const
|
||||
{
|
||||
return files(AllFiles, [](const ProjectExplorer::Node *n) { return n->filePath().endsWith(".nim"); });
|
||||
return files([](const ProjectExplorer::Node *n) { return AllFiles(n) && n->filePath().endsWith(".nim"); });
|
||||
}
|
||||
|
||||
QVariantMap NimProject::toMap() const
|
||||
|
@@ -86,6 +86,23 @@ const char PLUGIN_SETTINGS_KEY[] = "ProjectExplorer.Project.PluginSettings";
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
static bool isListedFileNode(const Node *node)
|
||||
{
|
||||
return node->nodeType() == NodeType::File && node->listInProject();
|
||||
}
|
||||
|
||||
const Project::NodeMatcher Project::AllFiles = [](const Node *node) {
|
||||
return isListedFileNode(node);
|
||||
};
|
||||
|
||||
const Project::NodeMatcher Project::SourceFiles = [](const Node *node) {
|
||||
return isListedFileNode(node) && !node->isGenerated();
|
||||
};
|
||||
|
||||
const Project::NodeMatcher Project::GeneratedFiles = [](const Node *node) {
|
||||
return isListedFileNode(node) && node->isGenerated();
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// ProjectDocument:
|
||||
// --------------------------------------------------------------------
|
||||
@@ -557,8 +574,7 @@ Project::RestoreResult Project::restoreSettings(QString *errorMessage)
|
||||
return result;
|
||||
}
|
||||
|
||||
Utils::FileNameList Project::files(Project::FilesMode fileMode,
|
||||
const std::function<bool(const Node *)> &filter) const
|
||||
Utils::FileNameList Project::files(const Project::NodeMatcher &filter) const
|
||||
{
|
||||
Utils::FileNameList result;
|
||||
|
||||
@@ -567,24 +583,20 @@ Utils::FileNameList Project::files(Project::FilesMode fileMode,
|
||||
|
||||
QSet<Utils::FileName> alreadySeen;
|
||||
rootProjectNode()->forEachGenericNode([&](const Node *n) {
|
||||
if (filter && !filter(n))
|
||||
return;
|
||||
|
||||
const Utils::FileName path = n->filePath();
|
||||
const int count = alreadySeen.count();
|
||||
alreadySeen.insert(path);
|
||||
if (count == alreadySeen.count())
|
||||
return; // skip duplicates
|
||||
if (!n->listInProject())
|
||||
return;
|
||||
if (filter && !filter(n))
|
||||
return;
|
||||
if ((fileMode == AllFiles)
|
||||
|| (fileMode == SourceFiles && !n->isGenerated())
|
||||
|| (fileMode == GeneratedFiles && n->isGenerated()))
|
||||
result.append(path);
|
||||
|
||||
result.append(path);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
Serializes all data into a QVariantMap.
|
||||
|
||||
|
@@ -130,13 +130,12 @@ public:
|
||||
enum class RestoreResult { Ok, Error, UserAbort };
|
||||
RestoreResult restoreSettings(QString *errorMessage);
|
||||
|
||||
enum FilesMode {
|
||||
SourceFiles = 0x1,
|
||||
GeneratedFiles = 0x2,
|
||||
AllFiles = SourceFiles | GeneratedFiles
|
||||
};
|
||||
Utils::FileNameList files(FilesMode fileMode,
|
||||
const std::function<bool(const Node *)> &filter = {}) const;
|
||||
using NodeMatcher = std::function<bool(const Node*)>;
|
||||
static const NodeMatcher AllFiles;
|
||||
static const NodeMatcher SourceFiles;
|
||||
static const NodeMatcher GeneratedFiles;
|
||||
|
||||
Utils::FileNameList files(const NodeMatcher &matcher) const;
|
||||
virtual QStringList filesGeneratedFrom(const QString &sourceFile) const;
|
||||
|
||||
static QString makeUnique(const QString &preferredName, const QStringList &usedNames);
|
||||
|
@@ -86,14 +86,13 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
|
||||
Constants::QMLPROJECT_MIMETYPE,
|
||||
Constants::QMLTYPES_MIMETYPE,
|
||||
Constants::QMLUI_MIMETYPE };
|
||||
projectInfo.sourceFiles = Utils::transform(project->files(Project::SourceFiles,
|
||||
[&qmlTypeNames](const Node *n) {
|
||||
if (const FileNode *fn = n->asFileNode()) {
|
||||
return fn->fileType() == FileType::QML
|
||||
&& qmlTypeNames.contains(Utils::mimeTypeForFile(fn->filePath().toString(),
|
||||
MimeMatchMode::MatchExtension).name());
|
||||
}
|
||||
return false;
|
||||
projectInfo.sourceFiles = Utils::transform(project->files([&qmlTypeNames](const Node *n) {
|
||||
if (!Project::SourceFiles(n))
|
||||
return false;
|
||||
const FileNode *fn = n->asFileNode();
|
||||
return fn && fn->fileType() == FileType::QML
|
||||
&& qmlTypeNames.contains(Utils::mimeTypeForFile(fn->filePath().toString(),
|
||||
MimeMatchMode::MatchExtension).name());
|
||||
}), &FileName::toString);
|
||||
activeTarget = project->activeTarget();
|
||||
}
|
||||
|
Reference in New Issue
Block a user