private static NamePathComponent initNamePathComponent(WizardContext context) { NamePathComponent component = new NamePathComponent( IdeBundle.message("label.project.name"), IdeBundle.message("label.project.files.location"), IdeBundle.message( "title.select.project.file.directory", IdeBundle.message("project.new.wizard.project.identification")), IdeBundle.message( "description.select.project.file.directory", StringUtil.capitalize( IdeBundle.message("project.new.wizard.project.identification"))), true, false); final String baseDir = context.getProjectFileDirectory(); final String projectName = context.getProjectName(); final String initialProjectName = projectName != null ? projectName : ProjectWizardUtil.findNonExistingFileName(baseDir, "untitled", ""); component.setPath( projectName == null ? (baseDir + File.separator + initialProjectName) : baseDir); component.setNameValue(initialProjectName); component.getNameComponent().select(0, initialProjectName.length()); return component; }
public void bindModuleSettings() { myNamePathComponent .getNameComponent() .getDocument() .addDocumentListener( new DocumentAdapter() { protected void textChanged(final DocumentEvent e) { if (!myModuleNameChangedByUser) { setModuleName(myNamePathComponent.getNameValue()); } } }); myModuleContentRoot.addBrowseFolderListener( ProjectBundle.message("project.new.wizard.module.content.root.chooser.title"), ProjectBundle.message("project.new.wizard.module.content.root.chooser.description"), myWizardContext.getProject(), BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR); myNamePathComponent .getPathComponent() .getDocument() .addDocumentListener( new DocumentAdapter() { protected void textChanged(final DocumentEvent e) { if (!myContentRootChangedByUser) { setModuleContentRoot(myNamePathComponent.getPath()); } } }); myModuleName .getDocument() .addDocumentListener( new DocumentAdapter() { protected void textChanged(final DocumentEvent e) { if (myModuleNameDocListenerEnabled) { myModuleNameChangedByUser = true; } String path = getDefaultBaseDir(myWizardContext); final String moduleName = getModuleName(); if (path.length() > 0 && !Comparing.strEqual(moduleName, myNamePathComponent.getNameValue())) { path += "/" + moduleName; } if (!myContentRootChangedByUser) { final boolean f = myModuleNameChangedByUser; myModuleNameChangedByUser = true; setModuleContentRoot(path); myModuleNameChangedByUser = f; } if (!myImlLocationChangedByUser) { setImlFileLocation(path); } } }); myModuleContentRoot .getTextField() .getDocument() .addDocumentListener( new DocumentAdapter() { protected void textChanged(final DocumentEvent e) { if (myContentRootDocListenerEnabled) { myContentRootChangedByUser = true; } if (!myImlLocationChangedByUser) { setImlFileLocation(getModuleContentRoot()); } if (!myModuleNameChangedByUser) { final String path = FileUtil.toSystemIndependentName(getModuleContentRoot()); final int idx = path.lastIndexOf("/"); boolean f = myContentRootChangedByUser; myContentRootChangedByUser = true; boolean i = myImlLocationChangedByUser; myImlLocationChangedByUser = true; setModuleName(idx >= 0 ? path.substring(idx + 1) : ""); myContentRootChangedByUser = f; myImlLocationChangedByUser = i; } } }); myModuleFileLocation.addBrowseFolderListener( ProjectBundle.message("project.new.wizard.module.file.chooser.title"), ProjectBundle.message("project.new.wizard.module.file.description"), myWizardContext.getProject(), BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR); myModuleFileLocation .getTextField() .getDocument() .addDocumentListener( new DocumentAdapter() { protected void textChanged(final DocumentEvent e) { if (myImlLocationDocListenerEnabled) { myImlLocationChangedByUser = true; } } }); myNamePathComponent .getPathComponent() .getDocument() .addDocumentListener( new DocumentAdapter() { protected void textChanged(final DocumentEvent e) { if (!myImlLocationChangedByUser) { setImlFileLocation(myNamePathComponent.getPath()); } } }); if (myWizardContext.isCreatingNewProject()) { setModuleName(myNamePathComponent.getNameValue()); setModuleContentRoot(myNamePathComponent.getPath()); setImlFileLocation(myNamePathComponent.getPath()); } else { final Project project = myWizardContext.getProject(); assert project != null; VirtualFile baseDir = project.getBaseDir(); if (baseDir != null) { // e.g. was deleted final String baseDirPath = baseDir.getPath(); String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, "untitled", ""); String contentRoot = baseDirPath + "/" + moduleName; if (!Comparing.strEqual(project.getName(), myWizardContext.getProjectName()) && !myWizardContext.isCreatingNewProject() && myWizardContext.getProjectName() != null) { moduleName = ProjectWizardUtil.findNonExistingFileName( myWizardContext.getProjectFileDirectory(), myWizardContext.getProjectName(), ""); contentRoot = myWizardContext.getProjectFileDirectory(); } setModuleName(moduleName); setModuleContentRoot(contentRoot); setImlFileLocation(contentRoot); myModuleName.select(0, moduleName.length()); } } }