forked from qt-creator/qt-creator
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:
@@ -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));
|
||||||
|
Reference in New Issue
Block a user