diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp index 86f22a2eba9..d36ca22be1c 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.cpp +++ b/src/plugins/qmlprojectmanager/qmlproject.cpp @@ -9,6 +9,7 @@ #include "qmlprojectmanagerconstants.h" #include "qmlprojectnodes.h" +#include #include #include #include @@ -16,6 +17,7 @@ #include #include #include +#include #include #include @@ -74,15 +76,20 @@ static bool allowOnlySingleProject() return !settings->value(qdsAllowMultipleProjects, false).toBool(); } -Utils::FilePaths QmlProject::getUiQmlFilesForFolder(const Utils::FilePath &folder) +Utils::FilePaths QmlProject::collectUiQmlFilesForFolder(const Utils::FilePath &folder) const { const Utils::FilePaths uiFiles = files([&](const ProjectExplorer::Node *node) { return node->filePath().completeSuffix() == "ui.qml" - && node->filePath().parentDir() == folder; + && node->filePath().parentDir() == folder; }); return uiFiles; } +FilePaths QmlProject::collectQmlFiles() const +{ + return files([](const Node *node) { return node->filePath().suffix() == "qml"; }); +} + QmlProject::QmlProject(const Utils::FilePath &fileName) : Project(QString::fromLatin1(Constants::QMLPROJECT_MIMETYPE), fileName) { @@ -124,10 +131,13 @@ QmlProject::QmlProject(const Utils::FilePath &fileName) Utils::Id()); }); } else { - Utils::FilePaths uiFiles = getUiQmlFilesForFolder(projectDirectory() - + "/content"); + Utils::FilePaths uiFiles = collectUiQmlFilesForFolder( + projectDirectory() + "/content"); if (uiFiles.isEmpty()) - uiFiles = getUiQmlFilesForFolder(projectDirectory()); + uiFiles = collectUiQmlFilesForFolder(projectDirectory()); + + if (uiFiles.isEmpty()) + uiFiles = collectQmlFiles(); if (!uiFiles.isEmpty()) { Utils::FilePath currentFile; @@ -138,6 +148,8 @@ QmlProject::QmlProject(const Utils::FilePath &fileName) QTimer::singleShot(1000, [uiFiles]() { Core::EditorManager::openEditor(uiFiles.first(), Utils::Id()); + Core::ModeManager::activateMode( + Core::Constants::MODE_DESIGN); }); } } diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h index 99a137a194b..c071e653076 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.h +++ b/src/plugins/qmlprojectmanager/qmlproject.h @@ -150,7 +150,8 @@ protected: private: ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override; - Utils::FilePaths getUiQmlFilesForFolder(const Utils::FilePath &folder); + Utils::FilePaths collectUiQmlFilesForFolder(const Utils::FilePath &folder) const; + Utils::FilePaths collectQmlFiles() const; QMetaObject::Connection m_openFileConnection; };