diff --git a/containments/desktop/package/contents/ui/FolderItemDelegate.qml b/containments/desktop/package/contents/ui/FolderItemDelegate.qml --- a/containments/desktop/package/contents/ui/FolderItemDelegate.qml +++ b/containments/desktop/package/contents/ui/FolderItemDelegate.qml @@ -280,6 +280,7 @@ animated: false usesPlasmaTheme: false + enabled: !model.isCut source: model.decoration overlays: model.overlays diff --git a/containments/desktop/plugins/folder/foldermodel.h b/containments/desktop/plugins/folder/foldermodel.h --- a/containments/desktop/plugins/folder/foldermodel.h +++ b/containments/desktop/plugins/folder/foldermodel.h @@ -100,6 +100,7 @@ IsDirRole, IsLinkRole, IsHiddenRole, + IsCutRole, UrlRole, LinkDestinationUrl, SizeRole, @@ -260,6 +261,7 @@ void emptyTrashBin(); void restoreSelectedFromTrash(); void undoTextChanged(const QString &text); + void updateCutUrls(); private: struct DragImage { @@ -305,6 +307,7 @@ bool m_filterPatternMatchAll; QSet m_mimeSet; QList m_regExps; + QSet m_cutUrls; }; #endif diff --git a/containments/desktop/plugins/folder/foldermodel.cpp b/containments/desktop/plugins/folder/foldermodel.cpp --- a/containments/desktop/plugins/folder/foldermodel.cpp +++ b/containments/desktop/plugins/folder/foldermodel.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -144,6 +145,10 @@ setSupportedDragActions(Qt::CopyAction | Qt::MoveAction | Qt::LinkAction); createActions(); + + connect(QApplication::clipboard(), &QClipboard::dataChanged, + this, &FolderModel::updateCutUrls); + updateCutUrls(); } FolderModel::~FolderModel() @@ -166,6 +171,7 @@ roleNames[IsDirRole] = "isDir"; roleNames[IsLinkRole] = "isLink"; roleNames[IsHiddenRole] = "isHidden"; + roleNames[IsCutRole] = "isCut"; roleNames[UrlRole] = "url"; roleNames[LinkDestinationUrl] = "linkDestinationUrl"; roleNames[SizeRole] = "size"; @@ -1060,6 +1066,9 @@ } else if (role == IsHiddenRole) { const KFileItem item = itemForIndex(index); return item.isHidden(); + } else if (role == IsCutRole) { + const QUrl &url = data(index, UrlRole).value(); + return m_cutUrls.contains(url); } else if (role == UrlRole) { return itemForIndex(index).url(); } else if (role == LinkDestinationUrl) { @@ -1680,3 +1689,30 @@ action->setText(text); } } + +void FolderModel::updateCutUrls() +{ + QSet newCutUrls; + + const QMimeData *mimeData = QApplication::clipboard()->mimeData(); + + if (mimeData) { + const QByteArray data = mimeData->data(QStringLiteral("application/x-kde-cutselection")); + const bool isCutSelection = (!data.isEmpty() && data.at(0) == QLatin1Char('1')); + if (isCutSelection) { + newCutUrls = KUrlMimeData::urlsFromMimeData(mimeData).toSet(); + } + } + + // Now store both the old and newly cut items, so we can emit a change for both sets. + const QSet combinedCutUrls = m_cutUrls + newCutUrls; + + m_cutUrls = newCutUrls; + + for (const QUrl &url : combinedCutUrls) { + const QModelIndex &idx = index(indexForUrl(url), 0); + if (idx.isValid()) { + emit dataChanged(idx, idx, {IsCutRole}); + } + } +}