QmlDesigner: Fix project path inside imported subcomponent

When user goes inside a Qml that is part of an imported component, project
path is not accessible. This commit fixes it.

Fixes: QDS-6201
Change-Id: I4efff48399e487b586b10383f19c2d6877714dc9
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@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:
Mahmoud Badri
2022-02-21 13:35:30 +02:00
parent 3f078ee89d
commit f7020a83c6
3 changed files with 14 additions and 16 deletions

View File

@@ -989,15 +989,6 @@ void addTabBarToStackedContainer(const SelectionContext &selectionContext)
} }
Utils::FilePath projectFilePath()
{
if (auto *doc = QmlDesignerPlugin::instance()->documentManager().currentDesignDocument()) {
if (auto *proj = ProjectExplorer::SessionManager::projectForFile(doc->fileName()))
return proj->projectDirectory();
}
return Utils::FilePath();
}
static AddFilesResult addFilesToProject(const QStringList &fileNames, const QString &defaultDirectory) static AddFilesResult addFilesToProject(const QStringList &fileNames, const QString &defaultDirectory)
{ {
QString directory = AddImagesDialog::getDirectory(fileNames, defaultDirectory); QString directory = AddImagesDialog::getDirectory(fileNames, defaultDirectory);
@@ -1050,7 +1041,7 @@ static QString getAssetDefaultDirectory(const QString &assetDir, const QString &
{ {
QString adjustedDefaultDirectory = defaultDirectory; QString adjustedDefaultDirectory = defaultDirectory;
Utils::FilePath contentPath = projectFilePath(); Utils::FilePath contentPath = QmlDesignerPlugin::instance()->documentManager().currentProjectDirPath();
if (contentPath.pathAppended("content").exists()) if (contentPath.pathAppended("content").exists())
contentPath = contentPath.pathAppended("content"); contentPath = contentPath.pathAppended("content");

View File

@@ -344,7 +344,7 @@ Utils::FilePath DesignDocument::projectFolder() const
bool DesignDocument::hasProject() const bool DesignDocument::hasProject() const
{ {
return ProjectExplorer::SessionManager::projectForFile(fileName()); return !DocumentManager::currentProjectDirPath().isEmpty();
} }
void DesignDocument::changeToInFileComponentModel(ComponentTextModifier *textModifer) void DesignDocument::changeToInFileComponentModel(ComponentTextModifier *textModifer)

View File

@@ -358,11 +358,18 @@ Utils::FilePath DocumentManager::currentProjectDirPath()
return {}; return {};
Utils::FilePath qmlFileName = QmlDesignerPlugin::instance()->currentDesignDocument()->fileName(); Utils::FilePath qmlFileName = QmlDesignerPlugin::instance()->currentDesignDocument()->fileName();
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::projectForFile(qmlFileName);
if (!project)
return {};
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::projectForFile(qmlFileName);
if (project)
return project->projectDirectory(); return project->projectDirectory();
const QList projects = ProjectExplorer::SessionManager::projects();
for (auto p : projects) {
if (qmlFileName.startsWith(p->projectDirectory().toString()))
return p->projectDirectory();
}
return {};
} }
QStringList DocumentManager::isoIconsQmakeVariableValue(const QString &proPath) QStringList DocumentManager::isoIconsQmakeVariableValue(const QString &proPath)