forked from qt-creator/qt-creator
QmlDesigner: Improve project open functions
This patch: unifies lookup for the first qml file to open; increases number of possible fallback options; adds missing implementations to some methods in QmlBuildSystem. Task-number: QDS-9984 Change-Id: Ib282b1fca8b0564fe80f00e3d9ffe82c1a15c540 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Burak Hancerli <burak.hancerli@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -67,40 +67,24 @@ void QmlProject::parsingFinished(const Target *target, bool success)
|
||||
// trigger only once
|
||||
disconnect(this, &QmlProject::anyParsingFinished, this, &QmlProject::parsingFinished);
|
||||
|
||||
// FIXME: what to do in this case?
|
||||
if (!target || !success || !activeTarget())
|
||||
return;
|
||||
|
||||
auto targetActive = activeTarget();
|
||||
auto qmlBuildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>(
|
||||
targetActive->buildSystem());
|
||||
|
||||
const Utils::FilePath mainUiFile = qmlBuildSystem->mainUiFilePath();
|
||||
|
||||
if (mainUiFile.completeSuffix() == "ui.qml" && mainUiFile.exists()) {
|
||||
QTimer::singleShot(1000, [mainUiFile]() {
|
||||
Core::EditorManager::openEditor(mainUiFile, Utils::Id());
|
||||
});
|
||||
const auto qmlBuildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>(
|
||||
activeTarget()->buildSystem());
|
||||
if (!qmlBuildSystem)
|
||||
return;
|
||||
}
|
||||
|
||||
Utils::FilePaths uiFiles = collectUiQmlFilesForFolder(
|
||||
projectDirectory().pathAppended("content"));
|
||||
if (uiFiles.isEmpty()) {
|
||||
uiFiles = collectUiQmlFilesForFolder(projectDirectory());
|
||||
if (uiFiles.isEmpty())
|
||||
return;
|
||||
}
|
||||
|
||||
Utils::FilePath currentFile;
|
||||
if (auto cd = Core::EditorManager::currentDocument())
|
||||
currentFile = cd->filePath();
|
||||
|
||||
if (currentFile.isEmpty() || !isKnownFile(currentFile)) {
|
||||
QTimer::singleShot(1000, [uiFiles]() {
|
||||
Core::EditorManager::openEditor(uiFiles.first(), Utils::Id());
|
||||
const auto openFile = [&](const Utils::FilePath file) {
|
||||
//why is this timer needed here?
|
||||
QTimer::singleShot(1000, this, [file] {
|
||||
Core::EditorManager::openEditor(file, Utils::Id());
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const Utils::FilePath fileToOpen = qmlBuildSystem->getStartupQmlFileWithFallback();
|
||||
if (!fileToOpen.isEmpty() && fileToOpen.exists() && !fileToOpen.isDir())
|
||||
openFile(fileToOpen);
|
||||
}
|
||||
|
||||
Project::RestoreResult QmlProject::fromMap(const QVariantMap &map, QString *errorMessage)
|
||||
@@ -175,6 +159,14 @@ Utils::FilePaths QmlProject::collectUiQmlFilesForFolder(const Utils::FilePath &f
|
||||
return uiFiles;
|
||||
}
|
||||
|
||||
Utils::FilePaths QmlProject::collectQmlFiles() const
|
||||
{
|
||||
const Utils::FilePaths qmlFiles = files([&](const Node *node) {
|
||||
return node->filePath().completeSuffix() == "qml";
|
||||
});
|
||||
return qmlFiles;
|
||||
}
|
||||
|
||||
Tasks QmlProject::projectIssues(const Kit *k) const
|
||||
{
|
||||
Tasks result = Project::projectIssues(k);
|
||||
|
||||
Reference in New Issue
Block a user