diff --git a/platform/lang-impl/src/com/intellij/ide/actions/CreateDirectoryOrPackageAction.java b/platform/lang-impl/src/com/intellij/ide/actions/CreateDirectoryOrPackageAction.java index a53dbefd2f6a..22fa0de74221 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/CreateDirectoryOrPackageAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/CreateDirectoryOrPackageAction.java @@ -4,11 +4,15 @@ package com.intellij.ide.actions; import com.intellij.ide.IdeBundle; import com.intellij.ide.IdeView; +import com.intellij.ide.ui.newItemPopup.NewItemPopupUtil; +import com.intellij.ide.ui.newItemPopup.NewItemSimplePopupPanel; import com.intellij.ide.util.DirectoryChooserUtil; import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.application.Experiments; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiElement; @@ -16,6 +20,9 @@ import com.intellij.psi.impl.file.PsiDirectoryFactory; import com.intellij.util.PlatformIcons; import org.jetbrains.annotations.NotNull; +import javax.swing.*; +import java.util.function.Consumer; + public class CreateDirectoryOrPackageAction extends AnAction implements DumbAware { public CreateDirectoryOrPackageAction() { super(IdeBundle.message("action.create.new.directory.or.package"), IdeBundle.message("action.create.new.directory.or.package"), null); @@ -45,11 +52,18 @@ public class CreateDirectoryOrPackageAction extends AnAction implements DumbAwar } String initialText = validator.getInitialText(); - Messages.showInputDialog(project, message, title, null, initialText, validator, TextRange.from(initialText.length(), 0)); + Consumer consumer = element -> { + if (element != null) { + view.selectElement(element); + } + }; - final PsiElement result = validator.getCreatedElement(); - if (result != null) { - view.selectElement(result); + if (Experiments.isFeatureEnabled("show.create.new.element.in.popup")) { + createLightWeightPopup(title, initialText, validator, consumer).showCenteredInCurrentWindow(project); + } + else { + Messages.showInputDialog(project, message, title, null, initialText, validator, TextRange.from(initialText.length(), 0)); + consumer.accept(validator.getCreatedElement()); } } @@ -95,4 +109,24 @@ public class CreateDirectoryOrPackageAction extends AnAction implements DumbAwar presentation.setIcon(PlatformIcons.FOLDER_ICON); } } + + private static JBPopup createLightWeightPopup(String title, String initialText, CreateGroupHandler validator, Consumer consumer) { + NewItemSimplePopupPanel contentPanel = new NewItemSimplePopupPanel(); + JTextField nameField = contentPanel.getTextField(); + nameField.setText(initialText); + JBPopup popup = NewItemPopupUtil.createNewItemPopup(title, contentPanel, nameField); + contentPanel.setApplyAction(event -> { + String name = nameField.getText(); + if (validator.checkInput(name) && validator.canClose(name)) { + popup.closeOk(event); + consumer.accept(validator.getCreatedElement()); + } + else { + String errorMessage = validator.getErrorText(name); + contentPanel.setError(errorMessage); + } + }); + + return popup; + } } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/CreateFileAction.java b/platform/lang-impl/src/com/intellij/ide/actions/CreateFileAction.java index df8802fa0e51..4db00c7549c4 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/CreateFileAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/CreateFileAction.java @@ -84,7 +84,7 @@ public class CreateFileAction extends CreateElementActionBase implements DumbAwa } private JBPopup createLightWeightPopup(MyInputValidator validator, Consumer consumer) { - SimpleCreateFileDialogPanel contentPanel = new SimpleCreateFileDialogPanel(); + NewItemSimplePopupPanel contentPanel = new NewItemSimplePopupPanel(); JTextField nameField = contentPanel.getTextField(); JBPopup popup = NewItemPopupUtil.createNewItemPopup(IdeBundle.message("title.new.file"), contentPanel, nameField); contentPanel.setApplyAction(event -> { @@ -263,11 +263,4 @@ public class CreateFileAction extends CreateElementActionBase implements DumbAwa return super.canClose(getFileName(inputString)); } } - - private static class SimpleCreateFileDialogPanel extends NewItemSimplePopupPanel { - - public JTextField getTextField() { - return myTextField; - } - } } diff --git a/platform/platform-impl/src/com/intellij/ide/ui/newItemPopup/NewItemSimplePopupPanel.java b/platform/platform-impl/src/com/intellij/ide/ui/newItemPopup/NewItemSimplePopupPanel.java index 0e9a66e0a81f..ad31ae3dad65 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/newItemPopup/NewItemSimplePopupPanel.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/newItemPopup/NewItemSimplePopupPanel.java @@ -73,6 +73,10 @@ public class NewItemSimplePopupPanel extends JBPanel implements Disposable { if (myErrorPopup != null && !myErrorPopup.isDisposed()) Disposer.dispose(myErrorPopup); } + public JTextField getTextField() { + return myTextField; + } + @NotNull protected ExtendableTextField createTextField() { ExtendableTextField res = new ExtendableTextField(); diff --git a/python/src/com/jetbrains/python/actions/CreatePackageAction.java b/python/src/com/jetbrains/python/actions/CreatePackageAction.java index b0cef7b0a1ac..19f7a5eae09d 100644 --- a/python/src/com/jetbrains/python/actions/CreatePackageAction.java +++ b/python/src/com/jetbrains/python/actions/CreatePackageAction.java @@ -7,18 +7,25 @@ import com.intellij.ide.actions.CreateDirectoryOrPackageHandler; import com.intellij.ide.fileTemplates.FileTemplate; import com.intellij.ide.fileTemplates.FileTemplateManager; import com.intellij.ide.fileTemplates.FileTemplateUtil; +import com.intellij.ide.ui.newItemPopup.NewItemPopupUtil; +import com.intellij.ide.ui.newItemPopup.NewItemSimplePopupPanel; import com.intellij.ide.util.DirectoryChooserUtil; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.LangDataKeys; +import com.intellij.openapi.application.Experiments; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.psi.*; import com.jetbrains.python.PyNames; import org.jetbrains.annotations.NotNull; +import javax.swing.*; +import java.util.function.Consumer; + /** * @author yole */ @@ -48,13 +55,27 @@ public class CreatePackageAction extends DumbAwareAction { } } }; - 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); + + Consumer consumer = item -> { + if (item != null) { + view.selectElement(item); + } + }; + + if (Experiments.isFeatureEnabled("show.create.new.element.in.popup")) { + JBPopup popup = createLightWeightPopup(validator, consumer); + if (project != null) { + popup.showCenteredInCurrentWindow(project); + } + else { + popup.showInFocusCenter(); + } } + else { + Messages.showInputDialog(project, IdeBundle.message("prompt.enter.new.package.name"), IdeBundle.message("title.new.package"), Messages.getQuestionIcon(), "", validator); + consumer.accept(validator.getCreatedElement()); + } + } public static void createInitPyInHierarchy(PsiDirectory created, PsiDirectory ancestor) { @@ -64,6 +85,26 @@ public class CreatePackageAction extends DumbAwareAction { } while(created != null && !created.equals(ancestor)); } + private static JBPopup createLightWeightPopup(CreateDirectoryOrPackageHandler validator, + Consumer consumer) { + NewItemSimplePopupPanel contentPanel = new NewItemSimplePopupPanel(); + JTextField nameField = contentPanel.getTextField(); + JBPopup popup = NewItemPopupUtil.createNewItemPopup(IdeBundle.message("title.new.package"), contentPanel, nameField); + contentPanel.setApplyAction(event -> { + String name = nameField.getText(); + if (validator.checkInput(name) && validator.canClose(name)) { + popup.closeOk(event); + consumer.accept(validator.getCreatedElement()); + } + else { + String errorMessage = validator.getErrorText(name); + contentPanel.setError(errorMessage); + } + }); + + return popup; + } + private static void createInitPy(PsiDirectory directory) { final FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(directory.getProject()); final FileTemplate template = fileTemplateManager.getInternalTemplate("Python Script");