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:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "../qmlprojectconstants.h"
|
||||
#include "../qmlprojectmanagertr.h"
|
||||
#include "../qmlproject.h"
|
||||
|
||||
#include <QtCore5Compat/qtextcodec.h>
|
||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||
@@ -155,6 +156,11 @@ bool QmlBuildSystem::updateProjectFile()
|
||||
return true;
|
||||
}
|
||||
|
||||
QmlProject *QmlBuildSystem::qmlProject() const
|
||||
{
|
||||
return qobject_cast<QmlProject *>(project());
|
||||
}
|
||||
|
||||
void QmlBuildSystem::triggerParsing()
|
||||
{
|
||||
refresh(RefreshOptions::Project);
|
||||
@@ -315,6 +321,66 @@ void QmlBuildSystem::setBlockFilesUpdate(bool newBlockFilesUpdate)
|
||||
m_blockFilesUpdate = newBlockFilesUpdate;
|
||||
}
|
||||
|
||||
Utils::FilePath QmlBuildSystem::getStartupQmlFileWithFallback() const
|
||||
{
|
||||
const auto currentProject = project();
|
||||
|
||||
if (!currentProject)
|
||||
return {};
|
||||
|
||||
if (!target())
|
||||
return {};
|
||||
|
||||
const auto getFirstFittingFile = [](const Utils::FilePaths &files) -> Utils::FilePath {
|
||||
for (const auto &file : files) {
|
||||
if (file.exists())
|
||||
return file;
|
||||
}
|
||||
return {};
|
||||
};
|
||||
|
||||
const QStringView uiqmlstr = u"ui.qml";
|
||||
const QStringView qmlstr = u"qml";
|
||||
|
||||
//we will check mainUiFile twice:
|
||||
//first priority if it's ui.qml file, second if it's just a qml file
|
||||
const Utils::FilePath mainUiFile = mainUiFilePath();
|
||||
if (mainUiFile.exists() && mainUiFile.completeSuffix() == uiqmlstr)
|
||||
return mainUiFile;
|
||||
|
||||
const Utils::FilePaths uiFiles = currentProject->files([&](const ProjectExplorer::Node *node) {
|
||||
return node->filePath().completeSuffix() == uiqmlstr;
|
||||
});
|
||||
if (!uiFiles.isEmpty()) {
|
||||
if (const auto file = getFirstFittingFile(uiFiles); !file.isEmpty())
|
||||
return file;
|
||||
}
|
||||
|
||||
//check the suffix of mainUiFile again, since there are no ui.qml files:
|
||||
if (mainUiFile.exists() && mainUiFile.completeSuffix() == qmlstr)
|
||||
return mainUiFile;
|
||||
|
||||
const Utils::FilePath mainQmlFile = mainFilePath();
|
||||
if (mainQmlFile.exists() && mainQmlFile.completeSuffix() == qmlstr)
|
||||
return mainQmlFile;
|
||||
|
||||
//maybe it's also worth priotizing qml files containing common words like "Screen"?
|
||||
const Utils::FilePaths qmlFiles = currentProject->files([&](const ProjectExplorer::Node *node) {
|
||||
return node->filePath().completeSuffix() == qmlstr;
|
||||
});
|
||||
if (!qmlFiles.isEmpty()) {
|
||||
if (const auto file = getFirstFittingFile(qmlFiles); !file.isEmpty())
|
||||
return file;
|
||||
}
|
||||
|
||||
//if no source files exist in the project, lets try to open the .qmlproject file itself
|
||||
const Utils::FilePath projectFile = projectFilePath();
|
||||
if (projectFile.exists())
|
||||
return projectFile;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Utils::FilePath QmlBuildSystem::mainFilePath() const
|
||||
{
|
||||
const QString fileName = mainFile();
|
||||
|
||||
Reference in New Issue
Block a user