From 4723d6b2be250cadaff8faeb7bcaaa19157cec08 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Wed, 9 Oct 2024 10:28:51 +0200 Subject: [PATCH] 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 --- src/plugins/projectexplorer/projectexplorer.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index adfd6bdd26d..732c7d00974 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -2334,7 +2334,20 @@ OpenProjectResult ProjectExplorerPlugin::openProjects(const FilePaths &filePaths QString errorString; for (const FilePath &fileName : filePaths) { 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(), Utils::equal(&Project::projectFilePath, filePath));