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 <mahmoud.badri@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Miikka Heikkinen
2022-03-15 13:02:15 +02:00
parent ab772c50be
commit d6718fa838
3 changed files with 44 additions and 30 deletions

View File

@@ -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: {

View File

@@ -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<QString> AssetsLibraryWidget::supportedDropSuffixes()
QSet<QString> AssetsLibraryWidget::supportedAssetSuffixes(bool complex)
{
const QList<AddResourceHandler> handlers = QmlDesignerPlugin::instance()->viewManager()
.designerActionManager().addResourceHandler();
QSet<QString> 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;
}

View File

@@ -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<QString> supportedDropSuffixes();
Q_INVOKABLE void handleExtFilesDrop(const QStringList &simpleFilesPaths,
const QStringList &complexFilesPaths,
const QString &targetDirPath);
Q_INVOKABLE QSet<QString> supportedAssetSuffixes(bool complex);
signals:
void itemActivated(const QString &itemName);