forked from qt-creator/qt-creator
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:
@@ -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 ©File : 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ©FileStr : 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user