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
(cherry picked from commit b63cb2603e
)
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include "qmlprojectmanagerconstants.h"
|
#include "qmlprojectmanagerconstants.h"
|
||||||
#include "qmlprojectnodes.h"
|
#include "qmlprojectnodes.h"
|
||||||
|
|
||||||
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/documentmanager.h>
|
#include <coreplugin/documentmanager.h>
|
||||||
#include <coreplugin/editormanager/documentmodel.h>
|
#include <coreplugin/editormanager/documentmodel.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
@@ -16,6 +17,7 @@
|
|||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
|
#include <coreplugin/modemanager.h>
|
||||||
|
|
||||||
#include <projectexplorer/deploymentdata.h>
|
#include <projectexplorer/deploymentdata.h>
|
||||||
#include <projectexplorer/devicesupport/idevice.h>
|
#include <projectexplorer/devicesupport/idevice.h>
|
||||||
@@ -74,15 +76,20 @@ static bool allowOnlySingleProject()
|
|||||||
return !settings->value(qdsAllowMultipleProjects, false).toBool();
|
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) {
|
const Utils::FilePaths uiFiles = files([&](const ProjectExplorer::Node *node) {
|
||||||
return node->filePath().completeSuffix() == "ui.qml"
|
return node->filePath().completeSuffix() == "ui.qml"
|
||||||
&& node->filePath().parentDir() == folder;
|
&& node->filePath().parentDir() == folder;
|
||||||
});
|
});
|
||||||
return uiFiles;
|
return uiFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilePaths QmlProject::collectQmlFiles() const
|
||||||
|
{
|
||||||
|
return files([](const Node *node) { return node->filePath().suffix() == "qml"; });
|
||||||
|
}
|
||||||
|
|
||||||
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,10 +131,13 @@ QmlProject::QmlProject(const Utils::FilePath &fileName)
|
|||||||
Utils::Id());
|
Utils::Id());
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Utils::FilePaths uiFiles = getUiQmlFilesForFolder(projectDirectory()
|
Utils::FilePaths uiFiles = collectUiQmlFilesForFolder(
|
||||||
+ "/content");
|
projectDirectory() + "/content");
|
||||||
if (uiFiles.isEmpty())
|
if (uiFiles.isEmpty())
|
||||||
uiFiles = getUiQmlFilesForFolder(projectDirectory());
|
uiFiles = collectUiQmlFilesForFolder(projectDirectory());
|
||||||
|
|
||||||
|
if (uiFiles.isEmpty())
|
||||||
|
uiFiles = collectQmlFiles();
|
||||||
|
|
||||||
if (!uiFiles.isEmpty()) {
|
if (!uiFiles.isEmpty()) {
|
||||||
Utils::FilePath currentFile;
|
Utils::FilePath currentFile;
|
||||||
@@ -138,6 +148,8 @@ QmlProject::QmlProject(const Utils::FilePath &fileName)
|
|||||||
QTimer::singleShot(1000, [uiFiles]() {
|
QTimer::singleShot(1000, [uiFiles]() {
|
||||||
Core::EditorManager::openEditor(uiFiles.first(),
|
Core::EditorManager::openEditor(uiFiles.first(),
|
||||||
Utils::Id());
|
Utils::Id());
|
||||||
|
Core::ModeManager::activateMode(
|
||||||
|
Core::Constants::MODE_DESIGN);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -150,7 +150,8 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override;
|
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;
|
QMetaObject::Connection m_openFileConnection;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user