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 b63cb2603e)
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Thomas Hartmann
2023-03-17 16:02:28 +01:00
parent d3ae723558
commit b33b25c936
2 changed files with 19 additions and 6 deletions

View File

@@ -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 = 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);
});
}
}

View File

@@ -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;
};