diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2023-02-22 15:18:03 +0100 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2023-02-22 15:35:10 +0000 |
commit | c6262b8ef5f44ab9f54afca7d2323b1702a7983b (patch) | |
tree | 77bac370b95a1c833d4e882b38f9df658d829ac3 | |
parent | cda92546e22cd0acf517e9cf64cfe7e8ac1d742b (diff) | |
download | qt-creator-c6262b8ef5f44ab9f54afca7d2323b1702a7983b.tar.gz |
StudioWelcome: Fallback to the first ui.qml file if there is no main ui.qml
If there is no main ui.qml, then fallback to the first ui.qml in the project.
(cherry picked from commit a7d7df3312a8428be21a17390a36980a9f1518ba)
Task-number: QDS-9242
Change-Id: Ie5294aeaf087a6b7cd2ca21ec13fb674c496f1a9
Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
-rw-r--r-- | src/plugins/studiowelcome/studiowelcomeplugin.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/plugins/studiowelcome/studiowelcomeplugin.cpp b/src/plugins/studiowelcome/studiowelcomeplugin.cpp index 62af8cb96a..91155fa9b4 100644 --- a/src/plugins/studiowelcome/studiowelcomeplugin.cpp +++ b/src/plugins/studiowelcome/studiowelcomeplugin.cpp @@ -98,7 +98,7 @@ QPointer<QQuickView> s_viewWindow = nullptr; QPointer<QQuickWidget> s_viewWidget = nullptr; static StudioWelcomePlugin *s_pluginInstance = nullptr; -static Utils::FilePath getMainUiFile() +static Utils::FilePath getMainUiFileWithFallback() { auto project = ProjectExplorer::SessionManager::startupProject(); if (!project) @@ -109,7 +109,18 @@ static Utils::FilePath getMainUiFile() auto qmlBuildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>( project->activeTarget()->buildSystem()); - return qmlBuildSystem->mainUiFilePath(); + + auto mainUiFile = qmlBuildSystem->mainUiFilePath(); + if (mainUiFile.exists()) + return mainUiFile; + + const Utils::FilePaths uiFiles = project->files([&](const ProjectExplorer::Node *node) { + return node->filePath().completeSuffix() == "ui.qml"; + }); + if (!uiFiles.isEmpty()) + return uiFiles.first(); + + return {}; } std::unique_ptr<QSettings> makeUserFeedbackSettings() @@ -243,7 +254,7 @@ public: const ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorer::ProjectExplorerPlugin::openProject(projectFile); if (!result && !result.alreadyOpen().isEmpty()) { - const auto mainUiFile = getMainUiFile(); + const auto mainUiFile = getMainUiFileWithFallback(); if (mainUiFile.exists()) Core::EditorManager::openEditor(mainUiFile, Utils::Id()); }; |