feat: select items after it has been pasted
This commit is contained in:
parent
7c0188656b
commit
8319832a92
3 changed files with 68 additions and 27 deletions
|
@ -144,32 +144,7 @@ FolderModel::FolderModel(QObject *parent)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Position dropped items at the desired target position.
|
// Position dropped items at the desired target position.
|
||||||
connect(this, &QAbstractItemModel::rowsInserted, this, [this](const QModelIndex &parent, int first, int last) {
|
connect(this, &QAbstractItemModel::rowsInserted, this, &FolderModel::onRowsInserted);
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dropped files may not actually show up as new files, e.g. when we overwrite
|
* 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
|
// Update paste action
|
||||||
if (QAction *paste = m_actionCollection.action(QStringLiteral("paste"))) {
|
if (QAction *paste = m_actionCollection.action(QStringLiteral("paste"))) {
|
||||||
QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData);
|
QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData);
|
||||||
|
const QString ¤tUrl = rootItem().url().toLocalFile();
|
||||||
|
|
||||||
if (!urls.isEmpty()) {
|
if (!urls.isEmpty()) {
|
||||||
if (!rootItem().isNull()) {
|
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);
|
paste->setEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -990,6 +973,7 @@ void FolderModel::paste()
|
||||||
}
|
}
|
||||||
|
|
||||||
KIO::Job *job = KIO::paste(data, m_dirModel->dirLister()->url());
|
KIO::Job *job = KIO::paste(data, m_dirModel->dirLister()->url());
|
||||||
|
connect(job, &KIO::Job::finished, this, &FolderModel::delayUpdateNeedSelectUrls);
|
||||||
job->start();
|
job->start();
|
||||||
|
|
||||||
// Clear system clipboard.
|
// 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
|
bool FolderModel::isSupportThumbnails(const QString &mimeType) const
|
||||||
{
|
{
|
||||||
const QStringList supportsMimetypes = {"image/bmp", "image/png", "image/gif", "image/jpeg", "image/web",
|
const QStringList supportsMimetypes = {"image/bmp", "image/png", "image/gif", "image/jpeg", "image/web",
|
||||||
|
|
|
@ -260,6 +260,9 @@ signals:
|
||||||
private slots:
|
private slots:
|
||||||
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
void dragSelectedInternal(int x, int y);
|
void dragSelectedInternal(int x, int y);
|
||||||
|
void onRowsInserted(const QModelIndex &parent, int first, int last);
|
||||||
|
void delayUpdateNeedSelectUrls();
|
||||||
|
void updateNeedSelectUrls();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void invalidateIfComplete();
|
void invalidateIfComplete();
|
||||||
|
@ -284,6 +287,7 @@ private:
|
||||||
QItemSelection m_pinnedSelection;
|
QItemSelection m_pinnedSelection;
|
||||||
QString m_url;
|
QString m_url;
|
||||||
QUrl m_newDocumentUrl;
|
QUrl m_newDocumentUrl;
|
||||||
|
QList<QUrl> m_needSelectUrls;
|
||||||
|
|
||||||
Status m_status;
|
Status m_status;
|
||||||
int m_sortMode;
|
int m_sortMode;
|
||||||
|
|
|
@ -45,7 +45,7 @@ Item {
|
||||||
Image {
|
Image {
|
||||||
id: _image
|
id: _image
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
width: control.height * 0.64
|
width: 18
|
||||||
height: width
|
height: width
|
||||||
sourceSize: Qt.size(width, height)
|
sourceSize: Qt.size(width, height)
|
||||||
smooth: false
|
smooth: false
|
||||||
|
|
Loading…
Reference in a new issue