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(); });
|
= 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.
|
// 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 QString fp = n->filePath().toString();
|
||||||
const int pos = fp.lastIndexOf('.');
|
const int pos = fp.lastIndexOf('.');
|
||||||
return pos >= 0 && fileExtensions.contains(fp.mid(pos + 1));
|
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
|
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
|
QVariantMap NimProject::toMap() const
|
||||||
|
@@ -86,6 +86,23 @@ const char PLUGIN_SETTINGS_KEY[] = "ProjectExplorer.Project.PluginSettings";
|
|||||||
|
|
||||||
namespace ProjectExplorer {
|
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:
|
// ProjectDocument:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
@@ -557,8 +574,7 @@ Project::RestoreResult Project::restoreSettings(QString *errorMessage)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FileNameList Project::files(Project::FilesMode fileMode,
|
Utils::FileNameList Project::files(const Project::NodeMatcher &filter) const
|
||||||
const std::function<bool(const Node *)> &filter) const
|
|
||||||
{
|
{
|
||||||
Utils::FileNameList result;
|
Utils::FileNameList result;
|
||||||
|
|
||||||
@@ -567,24 +583,20 @@ Utils::FileNameList Project::files(Project::FilesMode fileMode,
|
|||||||
|
|
||||||
QSet<Utils::FileName> alreadySeen;
|
QSet<Utils::FileName> alreadySeen;
|
||||||
rootProjectNode()->forEachGenericNode([&](const Node *n) {
|
rootProjectNode()->forEachGenericNode([&](const Node *n) {
|
||||||
|
if (filter && !filter(n))
|
||||||
|
return;
|
||||||
|
|
||||||
const Utils::FileName path = n->filePath();
|
const Utils::FileName path = n->filePath();
|
||||||
const int count = alreadySeen.count();
|
const int count = alreadySeen.count();
|
||||||
alreadySeen.insert(path);
|
alreadySeen.insert(path);
|
||||||
if (count == alreadySeen.count())
|
if (count == alreadySeen.count())
|
||||||
return; // skip duplicates
|
return; // skip duplicates
|
||||||
if (!n->listInProject())
|
|
||||||
return;
|
result.append(path);
|
||||||
if (filter && !filter(n))
|
|
||||||
return;
|
|
||||||
if ((fileMode == AllFiles)
|
|
||||||
|| (fileMode == SourceFiles && !n->isGenerated())
|
|
||||||
|| (fileMode == GeneratedFiles && n->isGenerated()))
|
|
||||||
result.append(path);
|
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Serializes all data into a QVariantMap.
|
Serializes all data into a QVariantMap.
|
||||||
|
|
||||||
|
@@ -130,13 +130,12 @@ public:
|
|||||||
enum class RestoreResult { Ok, Error, UserAbort };
|
enum class RestoreResult { Ok, Error, UserAbort };
|
||||||
RestoreResult restoreSettings(QString *errorMessage);
|
RestoreResult restoreSettings(QString *errorMessage);
|
||||||
|
|
||||||
enum FilesMode {
|
using NodeMatcher = std::function<bool(const Node*)>;
|
||||||
SourceFiles = 0x1,
|
static const NodeMatcher AllFiles;
|
||||||
GeneratedFiles = 0x2,
|
static const NodeMatcher SourceFiles;
|
||||||
AllFiles = SourceFiles | GeneratedFiles
|
static const NodeMatcher GeneratedFiles;
|
||||||
};
|
|
||||||
Utils::FileNameList files(FilesMode fileMode,
|
Utils::FileNameList files(const NodeMatcher &matcher) const;
|
||||||
const std::function<bool(const Node *)> &filter = {}) const;
|
|
||||||
virtual QStringList filesGeneratedFrom(const QString &sourceFile) const;
|
virtual QStringList filesGeneratedFrom(const QString &sourceFile) const;
|
||||||
|
|
||||||
static QString makeUnique(const QString &preferredName, const QStringList &usedNames);
|
static QString makeUnique(const QString &preferredName, const QStringList &usedNames);
|
||||||
|
@@ -86,14 +86,13 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
|
|||||||
Constants::QMLPROJECT_MIMETYPE,
|
Constants::QMLPROJECT_MIMETYPE,
|
||||||
Constants::QMLTYPES_MIMETYPE,
|
Constants::QMLTYPES_MIMETYPE,
|
||||||
Constants::QMLUI_MIMETYPE };
|
Constants::QMLUI_MIMETYPE };
|
||||||
projectInfo.sourceFiles = Utils::transform(project->files(Project::SourceFiles,
|
projectInfo.sourceFiles = Utils::transform(project->files([&qmlTypeNames](const Node *n) {
|
||||||
[&qmlTypeNames](const Node *n) {
|
if (!Project::SourceFiles(n))
|
||||||
if (const FileNode *fn = n->asFileNode()) {
|
return false;
|
||||||
return fn->fileType() == FileType::QML
|
const FileNode *fn = n->asFileNode();
|
||||||
&& qmlTypeNames.contains(Utils::mimeTypeForFile(fn->filePath().toString(),
|
return fn && fn->fileType() == FileType::QML
|
||||||
MimeMatchMode::MatchExtension).name());
|
&& qmlTypeNames.contains(Utils::mimeTypeForFile(fn->filePath().toString(),
|
||||||
}
|
MimeMatchMode::MatchExtension).name());
|
||||||
return false;
|
|
||||||
}), &FileName::toString);
|
}), &FileName::toString);
|
||||||
activeTarget = project->activeTarget();
|
activeTarget = project->activeTarget();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user