mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-26443 Update virtualenv path on new project path change
This commit is contained in:
+29
-7
@@ -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<T> extends ProjectSettingsStepBase<T> 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<T> extends ProjectSettingsStepBase<T> i
|
||||
final List<Sdk> 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<T> extends ProjectSettingsStepBase<T> 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<DocumentEvent> 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());
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user