ProjectExplorer: Add ProjectManager::projectsForFile

Change-Id: I4a91e2e3d5b94d27cc7cb0e772ec1dd45531dc0a
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-08-15 10:16:42 +02:00
parent a71fd8a770
commit 3a67a30dbf
2 changed files with 8 additions and 0 deletions

View File

@@ -521,6 +521,13 @@ Project *ProjectManager::projectForFile(const FilePath &fileName)
}); });
} }
QList<Project *> ProjectManager::projectsForFile(const Utils::FilePath &fileName)
{
return Utils::filtered(ProjectManager::projects(), [&fileName](Project *p) {
return p->isKnownFile(fileName) || isInProjectSourceDir(fileName, *p);
});
}
bool ProjectManager::isInProjectSourceDir(const Utils::FilePath &filePath, const Project &project) bool ProjectManager::isInProjectSourceDir(const Utils::FilePath &filePath, const Project &project)
{ {
for (const Target * const target : project.targets()) { for (const Target * const target : project.targets()) {

View File

@@ -80,6 +80,7 @@ public:
static QList<Project *> projectOrder(const Project *project = nullptr); static QList<Project *> projectOrder(const Project *project = nullptr);
static Project *projectForFile(const Utils::FilePath &fileName); static Project *projectForFile(const Utils::FilePath &fileName);
static QList<Project *> projectsForFile(const Utils::FilePath &fileName);
static bool isInProjectSourceDir(const Utils::FilePath &filePath, const Project &project); static bool isInProjectSourceDir(const Utils::FilePath &filePath, const Project &project);
static Project *projectWithProjectFilePath(const Utils::FilePath &filePath); static Project *projectWithProjectFilePath(const Utils::FilePath &filePath);