From 96ec295fc6393770e91802ab5824333792369527 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Thu, 3 Feb 2022 19:44:07 +0100 Subject: [PATCH] QmlProject: Search in content for .ui.qml files first Change-Id: I1cf8a0bc83c24a0207e68a12a9a441cc7432a013 Reviewed-by: Qt CI Bot Reviewed-by: Reviewed-by: Thomas Hartmann --- src/plugins/qmlprojectmanager/qmlproject.cpp | 55 +++++++++++++------- src/plugins/qmlprojectmanager/qmlproject.h | 2 + 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp index e0db9f53c62..a51b207203c 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.cpp +++ b/src/plugins/qmlprojectmanager/qmlproject.cpp @@ -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()); + }); + } + } + }); } } diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h index 89f5dd34454..3fa11a9128b 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.h +++ b/src/plugins/qmlprojectmanager/qmlproject.h @@ -151,6 +151,8 @@ protected: private: ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override; + Utils::FilePaths getUiQmlFilesForFolder(const Utils::FilePath &folder); + QMetaObject::Connection m_openFileConnection; };