QmlProject: Search in content for .ui.qml files first

Change-Id: I1cf8a0bc83c24a0207e68a12a9a441cc7432a013
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Thomas Hartmann
2022-02-03 19:44:07 +01:00
parent d408e4c22c
commit 96ec295fc6
2 changed files with 38 additions and 19 deletions

View File

@@ -95,6 +95,15 @@ static int preferedQtTarget(Target *target)
const char openInQDSAppSetting[] = "OpenInQDSApp";
Utils::FilePaths QmlProject::getUiQmlFilesForFolder(const Utils::FilePath &folder)
{
const Utils::FilePaths uiFiles = files([&](const ProjectExplorer::Node *node) {
return node->filePath().completeSuffix() == "ui.qml"
&& node->filePath().parentDir() == folder;
});
return uiFiles;
}
QmlProject::QmlProject(const Utils::FilePath &fileName)
: Project(QString::fromLatin1(Constants::QMLPROJECT_MIMETYPE), fileName)
{
@@ -124,27 +133,35 @@ QmlProject::QmlProject(const Utils::FilePath &fileName)
QTimer::singleShot(0, this, lambda);
}
} else {
m_openFileConnection = connect(
this, &QmlProject::anyParsingFinished, this, [this](Target *target, bool success) {
if (m_openFileConnection)
disconnect(m_openFileConnection);
m_openFileConnection
= connect(this,
&QmlProject::anyParsingFinished,
this,
[this](Target *target, bool success) {
if (m_openFileConnection)
disconnect(m_openFileConnection);
if (target && success) {
const Utils::FilePath &folder = projectDirectory();
const Utils::FilePaths &uiFiles = files([&](const ProjectExplorer::Node *node) {
return node->filePath().completeSuffix() == "ui.qml"
&& node->filePath().parentDir() == folder;
});
if (!uiFiles.isEmpty()) {
Utils::FilePath currentFile;
if (auto cd = Core::EditorManager::currentDocument())
currentFile = cd->filePath();
if (target && success) {
const Utils::FilePath &folder = projectDirectory() + "/content";
if (currentFile.isEmpty() || !isKnownFile(currentFile))
Core::EditorManager::openEditor(uiFiles.first(), Utils::Id());
}
}
});
Utils::FilePaths uiFiles = getUiQmlFilesForFolder(projectDirectory()
+ "/content");
if (uiFiles.isEmpty())
uiFiles = getUiQmlFilesForFolder(projectDirectory());
if (!uiFiles.isEmpty()) {
Utils::FilePath currentFile;
if (auto cd = Core::EditorManager::currentDocument())
currentFile = cd->filePath();
if (currentFile.isEmpty() || !isKnownFile(currentFile))
QTimer::singleShot(1000, [uiFiles]() {
Core::EditorManager::openEditor(uiFiles.first(),
Utils::Id());
});
}
}
});
}
}

View File

@@ -151,6 +151,8 @@ protected:
private:
ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override;
Utils::FilePaths getUiQmlFilesForFolder(const Utils::FilePath &folder);
QMetaObject::Connection m_openFileConnection;
};