From d6718fa8381f2f35bce1f85ea0072eb30ebec47e Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 15 Mar 2022 13:02:15 +0200 Subject: [PATCH] QmlDesigner: Remove unnecessary import dialog for complex assets Also remove target folder highlights for dragged complex assets. Fixes: QDS-6433 Change-Id: I499da9444e9f153672fb38b66a6841fb6035cbbd Reviewed-by: Mahmoud Badri Reviewed-by: --- .../itemLibraryQmlSources/Assets.qml | 33 +++++++++++------ .../assetslibrary/assetslibrarywidget.cpp | 35 +++++++++---------- .../assetslibrary/assetslibrarywidget.h | 6 ++-- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/share/qtcreator/qmldesigner/itemLibraryQmlSources/Assets.qml b/share/qtcreator/qmldesigner/itemLibraryQmlSources/Assets.qml index 5ac4d0fc6eb..57c0fe25213 100644 --- a/share/qtcreator/qmldesigner/itemLibraryQmlSources/Assets.qml +++ b/share/qtcreator/qmldesigner/itemLibraryQmlSources/Assets.qml @@ -39,7 +39,12 @@ Item { property string contextFilePath: "" property var contextDir: undefined property bool isDirContextMenu: false - property var dropExtFiles: [] // array of supported externally dropped files + + // Array of supported externally dropped files that are imported as-is + property var dropSimpleExtFiles: [] + + // Array of supported externally dropped files that trigger custom import process + property var dropComplexExtFiles: [] function clearSearchFilter() { @@ -48,18 +53,23 @@ Item { function updateDropExtFiles(drag) { - root.dropExtFiles = [] + root.dropSimpleExtFiles = [] + root.dropComplexExtFiles = [] + var simpleSuffixes = rootView.supportedAssetSuffixes(false); + var complexSuffixes = rootView.supportedAssetSuffixes(true); for (const u of drag.urls) { var url = u.toString(); if (url.startsWith("file:///")) // remove file scheme (happens on Windows) url = url.substr(8) - var ext = url.slice(url.lastIndexOf('.') + 1).toLowerCase() - if (rootView.supportedDropSuffixes().includes('*.' + ext)) - root.dropExtFiles.push(url) + var ext = '*.' + url.slice(url.lastIndexOf('.') + 1).toLowerCase() + if (simpleSuffixes.includes(ext)) + root.dropSimpleExtFiles.push(url) + else if (complexSuffixes.includes(ext)) + root.dropComplexExtFiles.push(url) } - drag.accepted = root.dropExtFiles.length > 0 + drag.accepted = root.dropSimpleExtFiles.length > 0 || root.dropComplexExtFiles.length > 0 } DropArea { // handles external drop on empty area of the view (goes to root folder) @@ -73,13 +83,14 @@ Item { } onDropped: { - rootView.handleExtFilesDrop(root.dropExtFiles, assetsModel.rootDir().dirPath) + rootView.handleExtFilesDrop(root.dropSimpleExtFiles, root.dropComplexExtFiles, + assetsModel.rootDir().dirPath) } Canvas { // marker for the drop area id: dropCanvas anchors.fill: parent - visible: dropArea.containsDrag + visible: dropArea.containsDrag && root.dropSimpleExtFiles.length > 0 onWidthChanged: dropCanvas.requestPaint() onHeightChanged: dropCanvas.requestPaint() @@ -546,7 +557,7 @@ Item { onDropEnter: (drag)=> { root.updateDropExtFiles(drag) - section.highlight = drag.accepted + section.highlight = drag.accepted && root.dropSimpleExtFiles.length > 0 } onDropExit: { @@ -555,7 +566,9 @@ Item { onDrop: { section.highlight = false - rootView.handleExtFilesDrop(root.dropExtFiles, dirPath) + rootView.handleExtFilesDrop(root.dropSimpleExtFiles, + root.dropComplexExtFiles, + dirPath) } onShowContextMenu: { diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp index b68128099b5..bed85b99e84 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp @@ -213,34 +213,33 @@ void AssetsLibraryWidget::handleAddAsset() addResources({}); } -void AssetsLibraryWidget::handleExtFilesDrop(const QStringList &filesPaths, const QString &targetDirPath) +void AssetsLibraryWidget::handleExtFilesDrop(const QStringList &simpleFilesPaths, + const QStringList &complexFilesPaths, + const QString &targetDirPath) { - QStringList assetPaths; - QStringList otherPaths; // as of now 3D models, and 3D Studio presentations - std::tie(assetPaths, otherPaths) = Utils::partition(filesPaths, [](const QString &path) { - QString suffix = "*." + path.split('.').last().toLower(); - return AssetsLibraryModel::supportedSuffixes().contains(suffix); - }); - - AddFilesResult result = ModelNodeOperations::addFilesToProject(assetPaths, targetDirPath); - if (result == AddFilesResult::Failed) { - Core::AsynchronousMessageBox::warning(tr("Failed to Add Files"), - tr("Could not add %1 to project.") - .arg(filesPaths.join(' '))); + if (!simpleFilesPaths.isEmpty()) { + AddFilesResult result = ModelNodeOperations::addFilesToProject(simpleFilesPaths, targetDirPath); + if (result == AddFilesResult::Failed) { + Core::AsynchronousMessageBox::warning(tr("Failed to Add Files"), + tr("Could not add %1 to project.") + .arg(simpleFilesPaths.join(' '))); + } } - if (!otherPaths.empty()) - addResources(otherPaths); + if (!complexFilesPaths.empty()) + addResources(complexFilesPaths); } -QSet AssetsLibraryWidget::supportedDropSuffixes() +QSet AssetsLibraryWidget::supportedAssetSuffixes(bool complex) { const QList handlers = QmlDesignerPlugin::instance()->viewManager() .designerActionManager().addResourceHandler(); QSet suffixes; - for (const AddResourceHandler &handler : handlers) - suffixes.insert(handler.filter); + for (const AddResourceHandler &handler : handlers) { + if (AssetsLibraryModel::supportedSuffixes().contains(handler.filter) != complex) + suffixes.insert(handler.filter); + } return suffixes; } diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.h b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.h index 7d3f48ef4dc..47a9ce681d6 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.h +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.h @@ -80,8 +80,10 @@ public: Q_INVOKABLE void startDragAsset(const QStringList &assetPaths, const QPointF &mousePos); Q_INVOKABLE void handleAddAsset(); Q_INVOKABLE void handleSearchfilterChanged(const QString &filterText); - Q_INVOKABLE void handleExtFilesDrop(const QStringList &filesPaths, const QString &targetDirPath); - Q_INVOKABLE QSet supportedDropSuffixes(); + Q_INVOKABLE void handleExtFilesDrop(const QStringList &simpleFilesPaths, + const QStringList &complexFilesPaths, + const QString &targetDirPath); + Q_INVOKABLE QSet supportedAssetSuffixes(bool complex); signals: void itemActivated(const QString &itemName);