void (final PsiElement[] elementsToDelete, final Project project, boolean needConfirmation) { if (elementsToDelete == null || elementsToDelete.length == 0) return; needConfirmation = ourOverrideNeedsConfirmation != null ? ourOverrideNeedsConfirmation : needConfirmation; final PsiElement[] elements = PsiTreeUtil.filterAncestors(elementsToDelete); boolean safeDeleteApplicable = ContainerUtil.and(elements, SafeDeleteProcessor::validElement); final boolean dumb = DumbService.getInstance(project).isDumb(); if (safeDeleteApplicable && !dumb) { if (needConfirmation) { final Ref<Boolean> exit = Ref.create(false); final SafeDeleteDialog dialog = new SafeDeleteDialog(project, elements, new SafeDeleteDialog.Callback() { @Override public void run(final SafeDeleteDialog dialog) { if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, Arrays.asList(elements), true)) return; SafeDeleteProcessor processor = SafeDeleteProcessor.createInstance(project, () -> { exit.set(true); dialog.close(DialogWrapper.OK_EXIT_CODE); }, elements, dialog.isSearchInComments(), dialog.isSearchForTextOccurences(), true); processor.run(); } }) { @Override protected boolean isDelete() { return true; } }; dialog.setTitle(RefactoringBundle.message("delete.title")); if (!dialog.showAndGet() || exit.get()) { return; } } } else { String warningMessage = DeleteUtil.generateWarningMessage("prompt.delete.elements", elements); boolean anyDirectories = false; String directoryName = null; for (PsiElement psiElement : elementsToDelete) { if (psiElement instanceof PsiDirectory && !PsiUtilBase.isSymLink((PsiDirectory)psiElement)) { anyDirectories = true; directoryName = ((PsiDirectory)psiElement).getName(); break; } } if (anyDirectories) { if (elements.length == 1) { warningMessage += IdeBundle.message("warning.delete.all.files.and.subdirectories", directoryName); } else { warningMessage += IdeBundle.message("warning.delete.all.files.and.subdirectories.in.the.selected.directory"); } } if (safeDeleteApplicable) { warningMessage += LangBundle.message("dialog.message.warning.safe.delete.not.available.while.updates.indices.no.usages.will.be.checked", ApplicationNamesInfo.getInstance().getFullProductName()); } if (needConfirmation) { int result = Messages.showOkCancelDialog(project, warningMessage, IdeBundle.message("title.delete"), ApplicationBundle.message("button.delete"), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon()); if (result != Messages.OK) return; } } deleteInCommand(project, elements); }