diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/ModuleNameLocationComponent.java b/java/idea-ui/src/com/intellij/ide/projectWizard/ModuleNameLocationComponent.java index 7b1103611db4..cb4e303fa081 100644 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/ModuleNameLocationComponent.java +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/ModuleNameLocationComponent.java @@ -197,7 +197,7 @@ public class ModuleNameLocationComponent { VirtualFile baseDir = project.getBaseDir(); if (baseDir != null) { //e.g. was deleted final String baseDirPath = baseDir.getPath(); - String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, "untitled", ""); + String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, myWizardContext.getDefaultModuleName(), ""); String contentRoot = baseDirPath + "/" + moduleName; if (!Comparing.strEqual(project.getName(), myWizardContext.getProjectName()) && !myWizardContext.isCreatingNewProject() && diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/NewProjectWizard.java b/java/idea-ui/src/com/intellij/ide/projectWizard/NewProjectWizard.java index 038959e1ddb1..03f37f5989f9 100644 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/NewProjectWizard.java +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/NewProjectWizard.java @@ -39,8 +39,9 @@ public class NewProjectWizard extends AbstractProjectWizard { init(modulesProvider); } - public NewProjectWizard(Project project, Component dialogParent, ModulesProvider modulesProvider) { + public NewProjectWizard(Project project, Component dialogParent, ModulesProvider modulesProvider, String defaultModuleName) { super(IdeBundle.message("title.add.module"), project, dialogParent); + myWizardContext.setDefaultModuleName(defaultModuleName); init(modulesProvider); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModulesConfigurator.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModulesConfigurator.java index c1424e0615b2..8d97e808fa73 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModulesConfigurator.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModulesConfigurator.java @@ -370,9 +370,9 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change @Nullable - public List addModule(Component parent, boolean anImport) { + public List addModule(Component parent, boolean anImport, String defaultModuleName) { if (myProject.isDefault()) return null; - final ProjectBuilder builder = runModuleWizard(parent, anImport); + final ProjectBuilder builder = runModuleWizard(parent, anImport, defaultModuleName); if (builder != null ) { final List modules = new ArrayList<>(); final List committedModules; @@ -426,7 +426,7 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change } @Nullable - ProjectBuilder runModuleWizard(Component dialogParent, boolean anImport) { + private ProjectBuilder runModuleWizard(Component dialogParent, boolean anImport, String defaultModuleName) { AbstractProjectWizard wizard; if (anImport) { wizard = ImportModuleAction.selectFileAndCreateWizard(myProject, dialogParent); @@ -438,7 +438,7 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change } } else { - wizard = new NewProjectWizard(myProject, dialogParent, this); + wizard = new NewProjectWizard(myProject, dialogParent, this, defaultModuleName); } if (!wizard.showAndGet()) { return null; diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java index 9e2964f35bdd..b91dd49eee5f 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java @@ -541,8 +541,8 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple return myContext.myModulesConfigurator.getFacetsConfigurator(); } - private void addModule(boolean anImport) { - final List modules = myContext.myModulesConfigurator.addModule(myTree, anImport); + private void addModule(boolean anImport, String defaultModuleName) { + final List modules = myContext.myModulesConfigurator.addModule(myTree, anImport, defaultModuleName); if (modules != null) { for (Module module : modules) { addModuleNode(module); @@ -1006,7 +1006,15 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple @Override public void actionPerformed(final AnActionEvent e) { - addModule(myImport); + String defaultModuleName = "untitled"; + MyNode selectedNode = getSelectedNode(); + if (ModuleGrouperKt.isQualifiedModuleNamesEnabled(myProject) && selectedNode instanceof ModuleGroupNodeImpl) { + ModuleGroup group = ((ModuleGroupNode)selectedNode).getModuleGroup(); + if (group != null && !group.getGroupPathList().isEmpty()) { + defaultModuleName = StringUtil.join(group.getGroupPathList(), ".") + ".untitled"; + } + } + addModule(myImport, defaultModuleName); } } diff --git a/platform/lang-api/src/com/intellij/ide/util/projectWizard/WizardContext.java b/platform/lang-api/src/com/intellij/ide/util/projectWizard/WizardContext.java index c2dde7532fc6..1566d3cacda2 100644 --- a/platform/lang-api/src/com/intellij/ide/util/projectWizard/WizardContext.java +++ b/platform/lang-api/src/com/intellij/ide/util/projectWizard/WizardContext.java @@ -57,6 +57,7 @@ public class WizardContext extends UserDataHolderBase { private ModulesProvider myModulesProvider; private boolean myProjectFileDirectorySetExplicitly; private AbstractWizard myWizard; + private String myDefaultModuleName = "untitled"; public void setProjectStorageFormat(StorageScheme format) { myProjectStorageFormat = format; @@ -86,6 +87,14 @@ public class WizardContext extends UserDataHolderBase { myWizard = wizard; } + public void setDefaultModuleName(String defaultModuleName) { + myDefaultModuleName = defaultModuleName; + } + + public String getDefaultModuleName() { + return myDefaultModuleName; + } + public interface Listener { void buttonsUpdateRequested(); void nextStepRequested(); diff --git a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java index ab2e811663a7..e43bfc9034d1 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java @@ -601,12 +601,16 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom return null; } + public final MyNode getSelectedNode() { + TreePath path = myTree.getSelectionPath(); + return path != null ? (MyNode)path.getLastPathComponent() : null; + } + @Nullable public NamedConfigurable getSelectedConfigurable() { - final TreePath selectionPath = myTree.getSelectionPath(); - if (selectionPath != null) { - MyNode node = (MyNode)selectionPath.getLastPathComponent(); - final NamedConfigurable configurable = node.getConfigurable(); + MyNode selectedNode = getSelectedNode(); + if (selectedNode != null) { + final NamedConfigurable configurable = selectedNode.getConfigurable(); LOG.assertTrue(configurable != null, "already disposed"); return configurable; }