diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index e595fd6..27074a4 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -144,32 +144,7 @@ FolderModel::FolderModel(QObject *parent) }); // Position dropped items at the desired target position. - connect(this, &QAbstractItemModel::rowsInserted, this, [this](const QModelIndex &parent, int first, int last) { - QModelIndex changeIdx; - - for (int i = first; i <= last; ++i) { - const auto idx = index(i, 0, parent); - const auto url = itemForIndex(idx).url(); - auto it = m_dropTargetPositions.find(url.fileName()); - if (it != m_dropTargetPositions.end()) { - const auto pos = it.value(); - m_dropTargetPositions.erase(it); - Q_EMIT move(pos.x(), pos.y(), {url}); - } - - if (url == m_newDocumentUrl) { - changeIdx = idx; - m_newDocumentUrl.clear(); - } - } - - QTimer::singleShot(0, this, [=] { - if (changeIdx.isValid()) { - setSelected(changeIdx.row()); - emit requestRename(); - } - }); - }); + connect(this, &QAbstractItemModel::rowsInserted, this, &FolderModel::onRowsInserted); /* * Dropped files may not actually show up as new files, e.g. when we overwrite @@ -972,6 +947,7 @@ void FolderModel::paste() // Update paste action if (QAction *paste = m_actionCollection.action(QStringLiteral("paste"))) { QList urls = KUrlMimeData::urlsFromMimeData(mimeData); + const QString ¤tUrl = rootItem().url().toLocalFile(); if (!urls.isEmpty()) { if (!rootItem().isNull()) { @@ -979,6 +955,13 @@ void FolderModel::paste() } } + if (enable && !urls.isEmpty()) { + for (QUrl url : urls) { + m_needSelectUrls.append(QUrl::fromLocalFile(QString("%1/%2").arg(currentUrl) + .arg(url.fileName()))); + } + } + paste->setEnabled(enable); } @@ -990,6 +973,7 @@ void FolderModel::paste() } KIO::Job *job = KIO::paste(data, m_dirModel->dirLister()->url()); + connect(job, &KIO::Job::finished, this, &FolderModel::delayUpdateNeedSelectUrls); job->start(); // Clear system clipboard. @@ -1592,6 +1576,59 @@ void FolderModel::dragSelectedInternal(int x, int y) } } +void FolderModel::onRowsInserted(const QModelIndex &parent, int first, int last) +{ + QModelIndex changeIdx; + + for (int i = first; i <= last; ++i) { + const auto idx = index(i, 0, parent); + const auto url = itemForIndex(idx).url(); + auto it = m_dropTargetPositions.find(url.fileName()); + if (it != m_dropTargetPositions.end()) { + const auto pos = it.value(); + m_dropTargetPositions.erase(it); + Q_EMIT move(pos.x(), pos.y(), {url}); + } + + if (url == m_newDocumentUrl) { + changeIdx = idx; + m_newDocumentUrl.clear(); + } + } + + QTimer::singleShot(0, this, [=] { + if (changeIdx.isValid()) { + setSelected(changeIdx.row()); + emit requestRename(); + } + }); +} + +void FolderModel::delayUpdateNeedSelectUrls() +{ + QTimer::singleShot(100, this, &FolderModel::updateNeedSelectUrls); +} + +void FolderModel::updateNeedSelectUrls() +{ + QModelIndexList needSelectList; + + for (const QUrl &url : m_needSelectUrls) { + const QModelIndex &idx = indexForUrl(url); + + if (!idx.isValid()) + continue; + + needSelectList.append(idx); + } + + m_needSelectUrls.clear(); + + for (const QModelIndex &idx : needSelectList) { + setSelected(idx.row()); + } +} + bool FolderModel::isSupportThumbnails(const QString &mimeType) const { const QStringList supportsMimetypes = {"image/bmp", "image/png", "image/gif", "image/jpeg", "image/web", diff --git a/model/foldermodel.h b/model/foldermodel.h index 6920ec8..078f6cf 100644 --- a/model/foldermodel.h +++ b/model/foldermodel.h @@ -260,6 +260,9 @@ signals: private slots: void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void dragSelectedInternal(int x, int y); + void onRowsInserted(const QModelIndex &parent, int first, int last); + void delayUpdateNeedSelectUrls(); + void updateNeedSelectUrls(); private: void invalidateIfComplete(); @@ -284,6 +287,7 @@ private: QItemSelection m_pinnedSelection; QString m_url; QUrl m_newDocumentUrl; + QList m_needSelectUrls; Status m_status; int m_sortMode; diff --git a/qml/Controls/IconButton.qml b/qml/Controls/IconButton.qml index e390b64..df84f24 100644 --- a/qml/Controls/IconButton.qml +++ b/qml/Controls/IconButton.qml @@ -45,7 +45,7 @@ Item { Image { id: _image anchors.centerIn: parent - width: control.height * 0.64 + width: 18 height: width sourceSize: Qt.size(width, height) smooth: false