QmlDesigner: Copy extra files regardless of the way component is added

ExtraFile property of item library entries was only handled when
item was dragged to navigator. Moved the handling to QmlVisualNode
so it would be done regardless of how the item is created.

Fixes: QDS-10058
Change-Id: Ied0c418a731104cdf727b1e2a0fe15a8e3b6ff5e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2023-06-15 13:20:53 +03:00
parent 6cb6d87746
commit a2b2a2eaa1
2 changed files with 14 additions and 15 deletions

View File

@@ -777,21 +777,6 @@ void NavigatorTreeModel::handleItemLibraryItemDrop(const QMimeData *mimeData, in
if (newQmlObjectNode.isValid())
m_view->setSelectedModelNode(newQmlObjectNode.modelNode());
}
const QStringList copyFiles = itemLibraryEntry.extraFilePaths();
if (!copyFiles.isEmpty()) {
// Files are copied into the same directory as the current qml document
for (const auto &copyFile : copyFiles) {
QFileInfo fi(copyFile);
const QString targetFile = DocumentManager::currentFilePath().toFileInfo().dir()
.absoluteFilePath(fi.fileName());
// We don't want to overwrite existing default files
if (!QFileInfo::exists(targetFile)) {
if (!QFile::copy(copyFile, targetFile))
qWarning() << QStringLiteral("Copying extra file '%1' failed.").arg(copyFile);
}
}
}
}
}

View File

@@ -417,6 +417,20 @@ QmlObjectNode QmlVisualNode::createQmlObjectNode(AbstractView *view,
newQmlObjectNode.setBindingProperty(property, parent.validId());
}
const QStringList copyFiles = itemLibraryEntry.extraFilePaths();
if (!copyFiles.isEmpty()) {
// Files are copied into the same directory as the current qml document
for (const auto &copyFileStr : copyFiles) {
Utils::FilePath sourceFile = Utils::FilePath::fromString(copyFileStr);
Utils::FilePath qmlFilePath = Utils::FilePath::fromString(
view->model()->fileUrl().toLocalFile()).absolutePath();
Utils::FilePath targetFile = qmlFilePath.pathAppended(sourceFile.fileName());
// We don't want to overwrite existing default files
if (!targetFile.exists() && !sourceFile.copyFile(targetFile))
qWarning() << QStringLiteral("Copying extra file '%1' failed.").arg(copyFileStr);
}
}
return newQmlObjectNode;
}