From a7d7df3312a8428be21a17390a36980a9f1518ba Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Wed, 22 Feb 2023 15:18:03 +0100 Subject: [PATCH] StudioWelcome: Fallback to the first ui.qml file if there is no main ui.qml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If there is no main ui.qml, then fallback to the first ui.qml in the project. Task-number: QDS-9242 Change-Id: Ie5294aeaf087a6b7cd2ca21ec13fb674c496f1a9 Reviewed-by: Henning Gründl --- .../studiowelcome/studiowelcomeplugin.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/plugins/studiowelcome/studiowelcomeplugin.cpp b/src/plugins/studiowelcome/studiowelcomeplugin.cpp index 62af8cb96a4..91155fa9b4a 100644 --- a/src/plugins/studiowelcome/studiowelcomeplugin.cpp +++ b/src/plugins/studiowelcome/studiowelcomeplugin.cpp @@ -98,7 +98,7 @@ QPointer s_viewWindow = nullptr; QPointer 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( 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 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()); };