-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2321 from Haehnchen/feature/form-new
migrate new Symfony formtype action
- Loading branch information
Showing
6 changed files
with
105 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/fr/adrienbrault/idea/symfony2plugin/action/NewFormTypeAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package fr.adrienbrault.idea.symfony2plugin.action; | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.fileEditor.OpenFileDescriptor; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.ui.Messages; | ||
import com.intellij.psi.PsiDirectory; | ||
import com.intellij.psi.PsiElement; | ||
import com.jetbrains.php.refactoring.PhpNameUtil; | ||
import com.jetbrains.php.roots.PhpNamespaceCompositeProvider; | ||
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons; | ||
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent; | ||
import fr.adrienbrault.idea.symfony2plugin.util.psi.PhpBundleFileFactory; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Daniel Espendiller <[email protected]> | ||
*/ | ||
public class NewFormTypeAction extends AbstractProjectDumbAwareAction { | ||
public NewFormTypeAction() { | ||
super("Form", "Create FormType Class", Symfony2Icons.SYMFONY); | ||
} | ||
|
||
public void update(AnActionEvent event) { | ||
this.setStatus(event, false); | ||
Project project = getEventProject(event); | ||
if (!Symfony2ProjectComponent.isEnabled(project)) { | ||
return; | ||
} | ||
|
||
if (NewFileActionUtil.getSelectedDirectoryFromAction(event) != null) { | ||
this.setStatus(event, true); | ||
} | ||
} | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent event) { | ||
PsiDirectory directory = NewFileActionUtil.getSelectedDirectoryFromAction(event); | ||
if (directory == null) { | ||
return; | ||
} | ||
|
||
Project project = getEventProject(event); | ||
String className = Messages.showInputDialog(project, "New class name:", "New File", Symfony2Icons.SYMFONY); | ||
if (StringUtils.isBlank(className)) { | ||
return; | ||
} | ||
|
||
if (!PhpNameUtil.isValidClassName(className)) { | ||
JOptionPane.showMessageDialog(null, "Invalid class name"); | ||
return; | ||
} | ||
|
||
List<String> strings = PhpNamespaceCompositeProvider.INSTANCE.suggestNamespaces(directory); | ||
if (strings.isEmpty()) { | ||
JOptionPane.showMessageDialog(null, "No namespace found"); | ||
return; | ||
} | ||
|
||
ApplicationManager.getApplication().runWriteAction(() -> { | ||
HashMap<String, String> hashMap = new HashMap<>() {{ | ||
put("class", className); | ||
put("namespace", strings.get(0)); | ||
}}; | ||
|
||
PsiElement commandAttributes = PhpBundleFileFactory.createFile( | ||
project, | ||
directory.getVirtualFile(), | ||
"form_type", | ||
className, | ||
hashMap | ||
); | ||
|
||
new OpenFileDescriptor(project, commandAttributes.getContainingFile().getVirtualFile(), 0).navigate(true); | ||
}); | ||
} | ||
|
||
public static class Shortcut extends NewFormTypeAction { | ||
@Override | ||
public void update(AnActionEvent event) { | ||
Project project = getEventProject(event); | ||
if (!Symfony2ProjectComponent.isEnabled(project)) { | ||
return; | ||
} | ||
|
||
this.setStatus(event, NewFileActionUtil.isInGivenDirectoryScope(event, "Form", "Type")); | ||
} | ||
} | ||
} |
63 changes: 0 additions & 63 deletions
63
src/main/java/fr/adrienbrault/idea/symfony2plugin/action/bundle/NewBundleFormAction.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.