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"; 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) QmlProject::QmlProject(const Utils::FilePath &fileName)
: Project(QString::fromLatin1(Constants::QMLPROJECT_MIMETYPE), fileName) : Project(QString::fromLatin1(Constants::QMLPROJECT_MIMETYPE), fileName)
{ {
@@ -124,27 +133,35 @@ QmlProject::QmlProject(const Utils::FilePath &fileName)
QTimer::singleShot(0, this, lambda); QTimer::singleShot(0, this, lambda);
} }
} else { } else {
m_openFileConnection = connect( m_openFileConnection
this, &QmlProject::anyParsingFinished, this, [this](Target *target, bool success) { = connect(this,
if (m_openFileConnection) &QmlProject::anyParsingFinished,
disconnect(m_openFileConnection); this,
[this](Target *target, bool success) {
if (m_openFileConnection)
disconnect(m_openFileConnection);
if (target && success) { if (target && success) {
const Utils::FilePath &folder = projectDirectory(); const Utils::FilePath &folder = projectDirectory() + "/content";
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 (currentFile.isEmpty() || !isKnownFile(currentFile)) Utils::FilePaths uiFiles = getUiQmlFilesForFolder(projectDirectory()
Core::EditorManager::openEditor(uiFiles.first(), Utils::Id()); + "/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: private:
ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override; ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override;
Utils::FilePaths getUiQmlFilesForFolder(const Utils::FilePath &folder);
QMetaObject::Connection m_openFileConnection; QMetaObject::Connection m_openFileConnection;
}; };