QmlDesigner: Fix DocumentManager::currentFilePath

If no QML file was opened this was not working
since we returned too early. This fixes the
function in case no QML file was opened.

Pick-to: qds/4.7
Change-Id: Ie6b8b4becfee4ed05760e31b766d8d0a9b88a666
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2025-03-06 17:34:17 +01:00
committed by Thomas Hartmann
parent 3ca60700ce
commit 77455efafa

View File

@@ -351,12 +351,16 @@ Utils::FilePath DocumentManager::currentProjectDirPath()
{
QTC_ASSERT(QmlDesignerPlugin::instance(), return {});
if (!QmlDesignerPlugin::instance()->currentDesignDocument())
if (!QmlDesignerPlugin::instance()->currentDesignDocument()) {
if (ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject())
return project->projectDirectory();
return {};
}
Utils::FilePath qmlFileName = QmlDesignerPlugin::instance()->currentDesignDocument()->fileName();
ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::projectForFile(qmlFileName);
if (project)
return project->projectDirectory();