MCPcopy Create free account
hub / github.com/KDE/kdevelop / pasteFromContextMenu

Method pasteFromContextMenu

plugins/projectmanagerview/projectmanagerviewplugin.cpp:744–792  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

742}
743
744void ProjectManagerViewPlugin::pasteFromContextMenu()
745{
746 auto* ctx = static_cast<KDevelop::ProjectItemContext*>(ICore::self()->selectionController()->currentSelection());
747 if (ctx->items().count() != 1) {
748 return; //do nothing if multiple or none items are selected
749 }
750
751 ProjectBaseItem* destItem = ctx->items().at(0);
752 if (!destItem->folder()) {
753 return; //do nothing if the target is not a directory
754 }
755
756 const QMimeData* data = qApp->clipboard()->mimeData();
757 qCDebug(PLUGIN_PROJECTMANAGERVIEW) << data->urls();
758 Path::List origPaths = toPathList(data->urls());
759 const bool isCut = KIO::isClipboardDataCut(data);
760
761 const CutCopyPasteHelpers::SourceToDestinationMap map = CutCopyPasteHelpers::mapSourceToDestination(origPaths, destItem->folder()->path());
762
763 const QVector<CutCopyPasteHelpers::TaskInfo> tasks = CutCopyPasteHelpers::copyMoveItems(
764 map.filteredPaths, destItem,
765 isCut ? CutCopyPasteHelpers::Operation::CUT : CutCopyPasteHelpers::Operation::COPY);
766
767 // Select new items in the project manager view
768 auto* itemCtx = dynamic_cast<ProjectManagerViewItemContext*>(ICore::self()->selectionController()->currentSelection());
769 if (itemCtx) {
770 Path::List finalPathsList;
771 for (const auto& task : tasks) {
772 if (task.m_status == CutCopyPasteHelpers::TaskStatus::SUCCESS && task.m_type != CutCopyPasteHelpers::TaskType::DELETION) {
773 finalPathsList.reserve(finalPathsList.size() + task.m_src.size());
774 for (const Path& src : task.m_src) {
775 finalPathsList.append(map.finalPaths[src]);
776 }
777 }
778 }
779
780 selectItemsByPaths(itemCtx->view(), finalPathsList);
781 }
782
783 // If there was a single failure, display a warning dialog.
784 const bool anyFailed = std::any_of(tasks.begin(), tasks.end(),
785 [](const CutCopyPasteHelpers::TaskInfo& task) {
786 return task.m_status != CutCopyPasteHelpers::TaskStatus::SUCCESS;
787 });
788 if (anyFailed) {
789 QWidget* window = ICore::self()->uiController()->activeMainWindow()->window();
790 showWarningDialogForFailedPaste(window, tasks);
791 }
792}
793
794#include "projectmanagerviewplugin.moc"
795#include "moc_projectmanagerviewplugin.cpp"

Callers 1

eventFilterMethod · 0.80

Calls 15

toPathListFunction · 0.85
mapSourceToDestinationFunction · 0.85
copyMoveItemsFunction · 0.85
selectItemsByPathsFunction · 0.85
currentSelectionMethod · 0.80
selectionControllerMethod · 0.80
folderMethod · 0.80
windowMethod · 0.80
uiControllerMethod · 0.80
countMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected