Search in sources :

Example 1 with CreateDirectoryOrPackageHandler

use of com.intellij.ide.actions.CreateDirectoryOrPackageHandler in project intellij-community by JetBrains.

the class CreatePackageAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    if (view == null) {
        return;
    }
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
    if (directory == null)
        return;
    final CreateDirectoryOrPackageHandler validator = new CreateDirectoryOrPackageHandler(project, directory, false, ".") {

        @Override
        protected void createDirectories(String subDirName) {
            super.createDirectories(subDirName);
            PsiFileSystemItem element = getCreatedElement();
            if (element instanceof PsiDirectory) {
                createInitPyInHierarchy((PsiDirectory) element, directory);
            }
        }
    };
    Messages.showInputDialog(project, IdeBundle.message("prompt.enter.new.package.name"), IdeBundle.message("title.new.package"), Messages.getQuestionIcon(), "", validator);
    final PsiFileSystemItem result = validator.getCreatedElement();
    if (result != null) {
        view.selectElement(result);
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) CreateDirectoryOrPackageHandler(com.intellij.ide.actions.CreateDirectoryOrPackageHandler) IdeView(com.intellij.ide.IdeView) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

Aggregations

IdeView (com.intellij.ide.IdeView)1 CreateDirectoryOrPackageHandler (com.intellij.ide.actions.CreateDirectoryOrPackageHandler)1 Project (com.intellij.openapi.project.Project)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1