From 725ef8a483c49299665c512c8e8b273616c1397b Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 7 Oct 2009 18:25:22 +0400 Subject: [PATCH] files copied from native file manager can be pasted into IDEA (part of IDEADEV-40725) --- .../src/com/intellij/ide/CopyPasteDelegator.java | 1 + .../com/intellij/ide/FileListPasteProvider.java | 71 ++++++++++++++++++++++ .../src/META-INF/LangExtensions.xml | 2 + 3 files changed, 74 insertions(+) create mode 100644 platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java diff --git a/platform/lang-impl/src/com/intellij/ide/CopyPasteDelegator.java b/platform/lang-impl/src/com/intellij/ide/CopyPasteDelegator.java index b653ff4660..26d890d7d6 100644 --- a/platform/lang-impl/src/com/intellij/ide/CopyPasteDelegator.java +++ b/platform/lang-impl/src/com/intellij/ide/CopyPasteDelegator.java @@ -101,6 +101,7 @@ public abstract class CopyPasteDelegator implements CopyPasteSupport { for(PasteProvider provider: Extensions.getExtensions(EP_NAME)) { if (provider.isPasteEnabled(dataContext)) { provider.performPaste(dataContext); + break; } } } diff --git a/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java b/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java new file mode 100644 index 0000000000..de610642ae --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java @@ -0,0 +1,71 @@ +package com.intellij.ide; + +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.LangDataKeys; +import com.intellij.openapi.ide.CopyPasteManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFileSystemItem; +import com.intellij.psi.PsiManager; +import com.intellij.refactoring.copy.CopyFilesOrDirectoriesHandler; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * @author yole + */ +public class FileListPasteProvider implements PasteProvider { + public void performPaste(DataContext dataContext) { + Project project = LangDataKeys.PROJECT.getData(dataContext); + final IdeView ideView = LangDataKeys.IDE_VIEW.getData(dataContext); + if (project == null || ideView == null) return; + List fileList; + try { + final Transferable contents = CopyPasteManager.getInstance().getContents(); + //noinspection unchecked + fileList = (List)contents.getTransferData(DataFlavor.javaFileListFlavor); + } + catch (UnsupportedFlavorException e) { + return; + } + catch (IOException e) { + return; + } + List elements = new ArrayList(); + for (File file : fileList) { + final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); + if (vFile != null) { + final PsiManager instance = PsiManager.getInstance(project); + PsiFileSystemItem item = vFile.isDirectory() ? instance.findDirectory(vFile) : instance.findFile(vFile); + if (item != null) { + elements.add(item); + } + } + } + if (elements.size() > 0) { + final PsiDirectory dir = ideView.getOrChooseDirectory(); + if (dir != null) { + new CopyFilesOrDirectoriesHandler().doCopy(elements.toArray(new PsiElement[elements.size()]), dir); + } + } + } + + public boolean isPastePossible(DataContext dataContext) { + return true; + } + + public boolean isPasteEnabled(DataContext dataContext) { + final Transferable contents = CopyPasteManager.getInstance().getContents(); + final IdeView ideView = LangDataKeys.IDE_VIEW.getData(dataContext); + return contents.isDataFlavorSupported(DataFlavor.javaFileListFlavor) && ideView != null; + } +} diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 80c06b51dd..516d7e654c 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -519,4 +519,6 @@ + + -- 2.11.4.GIT