void () { final Project project = myCurrentDirectory.getProject(); final String directoryName = myTargetDirectoryField.getText().replace(File.separatorChar, '/'); final String targetFileName = getTargetFileName(); if (isFileExist(directoryName, targetFileName)) { Messages.showErrorDialog(project, RefactoringBundle.message("file.already.exist", targetFileName), RefactoringBundle.message("file.already.exist.title")); return; } final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(targetFileName); if (type == null) { return; } CommandProcessor.getInstance().executeCommand(project, () -> { final Runnable action = () -> { try { PsiDirectory targetDirectory = DirectoryUtil.mkdirs(PsiManager.getInstance(project), directoryName); assert targetDirectory != null : directoryName; targetDirectory.checkCreateFile(targetFileName); String webPath = PsiFileSystemItemUtil.findRelativePath(myCurrentDirectory, targetDirectory); myTargetDirectory = webPath == null ? null : targetDirectory; } catch (IncorrectOperationException e) { CommonRefactoringUtil.showErrorMessage(getRefactoringName(), e.getMessage(), null, project); } }; ApplicationManager.getApplication().runWriteAction(action); }, RefactoringBundle.message("create.directory"), null); if (myTargetDirectory == null) return; super.doOKAction(); }