summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2023-03-17 16:02:28 +0100
committerThomas Hartmann <thomas.hartmann@qt.io>2023-03-22 10:53:12 +0000
commitb33b25c936eb52f9f018d2469190d6d4446f00cd (patch)
tree2c054f06429bac25ddc61c4117b6246d4e9f0827
parentd3ae7235588d1288e34d56e7c690bdc137207291 (diff)
downloadqt-creator-b33b25c936eb52f9f018d2469190d6d4446f00cd.tar.gz
QmlDesigner: Always try to open in design mode if qmlproject is opened
If there is no ui.qml file then fallback to .qml. Change to design mode in any case if a file was opened. Task-number: QDS-9460 Change-Id: I619292019105f488ff33e6e5ed4294b36eb2627c (cherry picked from commit b63cb2603e4227234f7a2fa255df437f6ab24eeb) Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--src/plugins/qmlprojectmanager/qmlproject.cpp22
-rw-r--r--src/plugins/qmlprojectmanager/qmlproject.h3
2 files changed, 19 insertions, 6 deletions
diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp
index 86f22a2eba..d36ca22be1 100644
--- a/src/plugins/qmlprojectmanager/qmlproject.cpp
+++ b/src/plugins/qmlprojectmanager/qmlproject.cpp
@@ -9,6 +9,7 @@
#include "qmlprojectmanagerconstants.h"
#include "qmlprojectnodes.h"
+#include <coreplugin/coreconstants.h>
#include <coreplugin/documentmanager.h>
#include <coreplugin/editormanager/documentmodel.h>
#include <coreplugin/editormanager/editormanager.h>
@@ -16,6 +17,7 @@
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
+#include <coreplugin/modemanager.h>
#include <projectexplorer/deploymentdata.h>
#include <projectexplorer/devicesupport/idevice.h>
@@ -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 = collectUiQmlFilesForFolder(projectDirectory());
+
if (uiFiles.isEmpty())
- uiFiles = getUiQmlFilesForFolder(projectDirectory());
+ 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 99a137a194..c071e65307 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;
};