Search in sources :

Example 1 with MoveFilesOrDirectoriesHandler

use of com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesHandler in project intellij-community by JetBrains.

the class FileListPasteProvider method performPaste.

@Override
public void performPaste(@NotNull DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final IdeView ideView = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (project == null || ideView == null)
        return;
    if (!FileCopyPasteUtil.isFileListFlavorAvailable())
        return;
    final Transferable contents = CopyPasteManager.getInstance().getContents();
    if (contents == null)
        return;
    final List<File> fileList = FileCopyPasteUtil.getFileList(contents);
    if (fileList == null)
        return;
    if (DumbService.isDumb(project)) {
        DumbService.getInstance(project).showDumbModeNotification("Sorry, file copy/paste is not available during indexing");
        return;
    }
    final List<PsiElement> 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) {
            final boolean move = LinuxDragAndDropSupport.isMoveOperation(contents);
            if (move) {
                new MoveFilesOrDirectoriesHandler().doMove(PsiUtilCore.toPsiElementArray(elements), dir);
            } else {
                new CopyFilesOrDirectoriesHandler().doCopy(PsiUtilCore.toPsiElementArray(elements), dir);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CopyFilesOrDirectoriesHandler(com.intellij.refactoring.copy.CopyFilesOrDirectoriesHandler) Transferable(java.awt.datatransfer.Transferable) ArrayList(java.util.ArrayList) PsiManager(com.intellij.psi.PsiManager) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) MoveFilesOrDirectoriesHandler(com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesHandler) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement)

Aggregations

Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1 PsiManager (com.intellij.psi.PsiManager)1 CopyFilesOrDirectoriesHandler (com.intellij.refactoring.copy.CopyFilesOrDirectoriesHandler)1 MoveFilesOrDirectoriesHandler (com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesHandler)1 Transferable (java.awt.datatransfer.Transferable)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1