ProjectExplorer: Consider project patterns when opening directories

In the case of opening directories as project files, we now look to see
if there is one existing project file in the directory. If so open that
project file.

This is the case for 'qtcreator .' in a directory that either contains a
'CMakeLists.txt' as a source directory, or a 'CMakeCache.txt' as a build
directory.

Fixes: QTCREATORBUG-24439
Fixes: QTCREATORBUG-30507
Change-Id: Ib7a47343369f2575782f2424b7af2e51072a9974
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Cristian Adam
2024-10-09 10:28:51 +02:00
parent c9b438c04a
commit 4723d6b2be

View File

@@ -2334,7 +2334,20 @@ OpenProjectResult ProjectExplorerPlugin::openProjects(const FilePaths &filePaths
QString errorString; QString errorString;
for (const FilePath &fileName : filePaths) { for (const FilePath &fileName : filePaths) {
QTC_ASSERT(!fileName.isEmpty(), continue); QTC_ASSERT(!fileName.isEmpty(), continue);
const FilePath filePath = fileName.absoluteFilePath(); const FilePath filePath = [fileName] {
if (!fileName.isDir())
return fileName.absoluteFilePath();
// For the case of directories, try to see if there is a project file in the directory
const QStringList existingProjectFilePatterns
= Utils::filtered(projectFilePatterns(), [fileName](const QString &pattern) {
return fileName.pathAppended(pattern).exists();
});
if (existingProjectFilePatterns.size() == 1)
return fileName.pathAppended(existingProjectFilePatterns.first()).absoluteFilePath();
return fileName.absoluteFilePath();
}();
Project *found = Utils::findOrDefault(ProjectManager::projects(), Project *found = Utils::findOrDefault(ProjectManager::projects(),
Utils::equal(&Project::projectFilePath, filePath)); Utils::equal(&Project::projectFilePath, filePath));