forked from qt-creator/qt-creator
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 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user