void (Project project, PsiElement[] elements, PsiElement[] adjustedElements, PsiDirectory targetDirectory, MoveCallback moveCallback, Runnable doneCallback) { CommandProcessor.getInstance().executeCommand(project, () -> { Collection<PsiElement> toCheck = new SmartList<>(targetDirectory); for (PsiElement e : adjustedElements) { toCheck.add(e instanceof PsiFileSystemItem && e.getParent() != null ? e.getParent() : e); } if (!CommonRefactoringUtil.checkReadOnlyStatus(project, toCheck, false)) { return; } try { int[] choice = elements.length > 1 || elements[0] instanceof PsiDirectory ? new int[]{-1} : null; List<PsiElement> els = new ArrayList<>(); for (PsiElement psiElement : adjustedElements) { if (psiElement instanceof PsiFile file) { if (CopyFilesOrDirectoriesHandler.checkFileExist(targetDirectory, choice, file, file.getName(), RefactoringBundle.message("command.name.move"))) continue; } checkMove(psiElement, targetDirectory); els.add(psiElement); } if (els.isEmpty()) { doneCallback.run(); } else if (DumbService.isDumb(project)) { if (doneCallback != null) { ApplicationManager.getApplication().invokeAndWait(doneCallback); } Set<SmartPsiElementPointer<PsiFile>> filePointers = new HashSet<>(); if (MoveFilesOrDirectoriesDialog.isOpenInEditorProperty()) { SmartPointerManager manager = SmartPointerManager.getInstance(project); for (PsiElement element : elements) { addFilePointers(filePointers, element, manager); } } WriteCommandAction.runWriteCommandAction(project, RefactoringBundle.message("move.title"), null, () -> { try { for (PsiElement element : elements) { if (element instanceof PsiDirectory) { doJustMoveDirectory((PsiDirectory)element, targetDirectory, MoveFilesOrDirectoriesUtil.class); } else if (element instanceof PsiFile movedFile) { PsiFile moving = targetDirectory.findFile(movedFile.getName()); if (moving == null) { doMoveFile(movedFile, targetDirectory); } } } } finally { if (moveCallback != null) { moveCallback.refactoringCompleted(); } if (MoveFilesOrDirectoriesDialog.isOpenInEditorProperty()) { ApplicationManager.getApplication().invokeLater( () -> EditorHelper.openFilesInEditor( filePointers.stream().map(SmartPsiElementPointer::getContainingFile).filter(file -> file != null && file.isValid()) .toArray(PsiFile[]::new)), project.getDisposed()); } } }); } else { new MoveFilesOrDirectoriesProcessor(project, els.toArray(PsiElement.EMPTY_ARRAY), targetDirectory, RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE, false, false, moveCallback, doneCallback).run(); } } catch (IncorrectOperationException e) { CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), e.getMessage(), "refactoring.moveFile", project); } }, MoveHandler.getRefactoringName(), null); }