diff --git a/python/python-community-configure/src/com/jetbrains/python/newProject/steps/ProjectSpecificSettingsStep.java b/python/python-community-configure/src/com/jetbrains/python/newProject/steps/ProjectSpecificSettingsStep.java index 0514a07e923a..fcfac3a74b8d 100644 --- a/python/python-community-configure/src/com/jetbrains/python/newProject/steps/ProjectSpecificSettingsStep.java +++ b/python/python-community-configure/src/com/jetbrains/python/newProject/steps/ProjectSpecificSettingsStep.java @@ -31,6 +31,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.platform.DirectoryProjectGenerator; import com.intellij.ui.DocumentAdapter; import com.intellij.ui.HideableDecorator; +import com.intellij.util.Consumer; import com.intellij.util.ObjectUtils; import com.intellij.util.PathUtil; import com.intellij.util.containers.ContainerUtil; @@ -135,12 +136,9 @@ public class ProjectSpecificSettingsStep extends ProjectSettingsStepBase i protected void registerValidators() { super.registerValidators(); if (myProjectGenerator instanceof PythonProjectGenerator) { - myLocationField.getTextField().getDocument().addDocumentListener(new DocumentAdapter() { - @Override - protected void textChanged(DocumentEvent e) { - final String path = myLocationField.getText().trim(); - ((PythonProjectGenerator)myProjectGenerator).locationChanged(PathUtil.getFileName(path)); - } + addLocationChangeListener(event -> { + final String fileName = PathUtil.getFileName(getNewProjectPath()); + ((PythonProjectGenerator)myProjectGenerator).locationChanged(fileName); }); final PyAddSdkGroupPanel interpreterPanel = myInterpreterPanel; if (interpreterPanel != null) { @@ -291,7 +289,7 @@ public class ProjectSpecificSettingsStep extends ProjectSettingsStepBase i final List existingSdks = getValidPythonSdks(); final Sdk preferredSdk = getPreferredSdk(existingSdks); - final String newProjectPath = myLocationField.getText().trim(); + final String newProjectPath = getNewProjectPath(); final PyAddNewVirtualEnvPanel newVirtualEnvPanel = new PyAddNewVirtualEnvPanel(null, existingSdks, newProjectPath); final PyAddExistingSdkPanel existingSdkPanel = new PyAddExistingSdkPanel(null, existingSdks, newProjectPath, preferredSdk); @@ -306,10 +304,34 @@ public class ProjectSpecificSettingsStep extends ProjectSettingsStepBase i existingSdkPanel.addChangeListener(this::checkValid); myInterpreterPanel.addChangeListener(this::checkValid); + addLocationChangeListener(event -> { + final String path = getNewProjectPath(); + newVirtualEnvPanel.setNewProjectPath(path); + existingSdkPanel.setNewProjectPath(path); + }); + container.add(myInterpreterPanel, BorderLayout.NORTH); return decoratorPanel; } + @NotNull + private String getNewProjectPath() { + final TextFieldWithBrowseButton field = myLocationField; + if (field == null) return ""; + return field.getText().trim(); + } + + private void addLocationChangeListener(@NotNull Consumer listener) { + final TextFieldWithBrowseButton field = myLocationField; + if (field == null) return; + field.getTextField().getDocument().addDocumentListener(new DocumentAdapter() { + @Override + protected void textChanged(DocumentEvent e) { + listener.consume(e); + } + }); + } + @NotNull private static String getProjectInterpreterTitle(@NotNull PyAddSdkPanel panel) { return "Project Interpreter: " + StringUtil.toTitleCase(panel.getPanelName()); diff --git a/python/python-community-configure/src/com/jetbrains/python/newProject/steps/PyAddExistingSdkPanel.kt b/python/python-community-configure/src/com/jetbrains/python/newProject/steps/PyAddExistingSdkPanel.kt index 7e578eb27efa..b04266a847c8 100644 --- a/python/python-community-configure/src/com/jetbrains/python/newProject/steps/PyAddExistingSdkPanel.kt +++ b/python/python-community-configure/src/com/jetbrains/python/newProject/steps/PyAddExistingSdkPanel.kt @@ -39,6 +39,12 @@ class PyAddExistingSdkPanel(project: Project?, val remotePath: String? get() = if (remotePathField.mainPanel.isVisible) remotePathField.textField.text else null + var newProjectPath: String? = newProjectPath + set(value) { + field = value + sdkChooserCombo.setNewProjectPath(value) + } + private val sdkChooserCombo: PythonSdkChooserCombo private val remotePathField = PyRemotePathField().apply { addActionListener { diff --git a/python/src/com/jetbrains/python/sdk/add/PyAddNewVirtualEnvPanel.kt b/python/src/com/jetbrains/python/sdk/add/PyAddNewVirtualEnvPanel.kt index b98f430f6ab4..c8e40468e799 100644 --- a/python/src/com/jetbrains/python/sdk/add/PyAddNewVirtualEnvPanel.kt +++ b/python/src/com/jetbrains/python/sdk/add/PyAddNewVirtualEnvPanel.kt @@ -62,7 +62,7 @@ class PyAddNewVirtualEnvPanel(private val project: Project?, private const val VIRTUALENV_ROOT_DIR_MACRO_NAME = "VIRTUALENV_ROOT_DIR" } - private var newProjectPath: String? = newProjectPath + var newProjectPath: String? = newProjectPath set(value) { field = value pathField.text = defaultBasePath