private void createStepDefinitionFile(final GherkinStep step) {
final PsiFile featureFile = step.getContainingFile();
assert featureFile != null;
final CreateStepDefinitionFileModel model = askUserForFilePath(step);
if (model == null) {
return;
}
String filePath = FileUtil.toSystemDependentName(model.getFilePath());
final BDDFrameworkType frameworkType = model.getSelectedFileType();
// show error if file already exists
if (LocalFileSystem.getInstance().findFileByPath(filePath) == null) {
final String parentDirPath = model.getDirectory().getVirtualFile().getPath();
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
new WriteCommandAction.Simple(step.getProject(), CucumberBundle.message("cucumber.quick.fix.create.step.command.name.create")) {
@Override
protected void run() throws Throwable {
final VirtualFile parentDir = VfsUtil.createDirectories(parentDirPath);
final Project project = getProject();
assert project != null;
final PsiDirectory parentPsiDir = PsiManager.getInstance(project).findDirectory(parentDir);
assert parentPsiDir != null;
PsiFile newFile = CucumberStepsIndex.getInstance(step.getProject())
.createStepDefinitionFile(model.getDirectory(), model.getFileName(), frameworkType);
createStepDefinition(step, newFile);
}
}.execute();
}
});