mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
'Project Structure' dialog: suggest prefix for new module names
If a module group is selected in 'Project Structure' dialog use its name as a prefix for module name if 'New Module' action is invoked (see also IDEA-179968).
This commit is contained in:
@@ -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() &&
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -370,9 +370,9 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change
|
||||
|
||||
|
||||
@Nullable
|
||||
public List<Module> addModule(Component parent, boolean anImport) {
|
||||
public List<Module> 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<Module> modules = new ArrayList<>();
|
||||
final List<Module> 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;
|
||||
|
||||
+11
-3
@@ -541,8 +541,8 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
|
||||
return myContext.myModulesConfigurator.getFacetsConfigurator();
|
||||
}
|
||||
|
||||
private void addModule(boolean anImport) {
|
||||
final List<Module> modules = myContext.myModulesConfigurator.addModule(myTree, anImport);
|
||||
private void addModule(boolean anImport, String defaultModuleName) {
|
||||
final List<Module> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user