| 742 | } |
| 743 | |
| 744 | void 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" |
no test coverage detected