Wizards: Let user decide which project file to use

When importing projects, it can happen that several files are
encountered that could serve as the main project file. Until now, we
basically opened a random one, which was less than ideal. Now the user
can choose.

Fixes: QTCREATORBUG-17828
Change-Id: Iec08c942d0f9ff349c9752503c8157556f07b416
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
This commit is contained in:
Christian Kandeler
2019-04-10 18:15:47 +02:00
parent a1944d800f
commit 31517f00bb
4 changed files with 119 additions and 11 deletions

View File

@@ -42,6 +42,8 @@
#include <QDir>
#include <QVariant>
#include <limits>
namespace ProjectExplorer {
namespace Internal {
@@ -70,8 +72,6 @@ bool JsonWizardScannerGenerator::setup(const QVariant &data, QString *errorMessa
m_subDirectoryExpressions << regexp;
}
m_firstProjectOnly = gen.value(QLatin1String("firstProjectOnly"), QLatin1String("true")).toString();
return true;
}
@@ -97,17 +97,28 @@ Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander *
}
}
bool onlyFirst = JsonWizard::boolFromVariant(m_firstProjectOnly, expander);
result = scan(project.absolutePath(), project);
int projectCount = 0;
static const auto getDepth = [](const QString &filePath) { return filePath.count('/'); };
int minDepth = std::numeric_limits<int>::max();
for (auto it = result.begin(); it != result.end(); ++it) {
const QString relPath = project.relativeFilePath(it->path());
it->setBinary(binaryPattern.match(relPath).hasMatch());
bool found = ProjectManager::canOpenProjectForMimeType(Utils::mimeTypeForFile(relPath));
if (found && !(onlyFirst && projectCount++))
if (found) {
it->setAttributes(it->attributes() | Core::GeneratedFile::OpenProjectAttribute);
minDepth = std::min(minDepth, getDepth(it->path()));
}
}
// Project files that appear on a lower level in the file system hierarchy than
// other project files are not candidates for opening.
for (Core::GeneratedFile &f : result) {
if (f.attributes().testFlag(Core::GeneratedFile::OpenProjectAttribute)
&& getDepth(f.path()) > minDepth) {
f.setAttributes(f.attributes().setFlag(Core::GeneratedFile::OpenProjectAttribute,
false));
}
}
return result;