get rid of make active for selected checkbox in create virtual env

This commit is contained in:
Ekaterina Tuzova
2014-02-11 14:07:12 +04:00
parent e7bd55b7ec
commit 038550fbff
6 changed files with 24 additions and 77 deletions
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.python.configuration.AddVEnvOptionsDialog">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
@@ -8,23 +8,14 @@
<properties/>
<border type="none"/>
<children>
<component id="6ea43" class="com.intellij.ui.components.JBCheckBox" binding="myUseForThisProjectJBCheckBox" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text value="Set as project interpreter for &amp;this project"/>
</properties>
</component>
<vspacer id="46c2b">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="b3884" class="com.intellij.ui.components.JBCheckBox" binding="myMakeAvailableToAllJBCheckBox" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Make available to &amp;all projects"/>
@@ -25,7 +25,6 @@ import java.awt.*;
* @author yole
*/
public class AddVEnvOptionsDialog extends DialogWrapper {
private JBCheckBox myUseForThisProjectJBCheckBox;
private JBCheckBox myMakeAvailableToAllJBCheckBox;
private JPanel myMainPanel;
@@ -40,10 +39,6 @@ public class AddVEnvOptionsDialog extends DialogWrapper {
return myMainPanel;
}
public boolean useForThisProject() {
return myUseForThisProjectJBCheckBox.isSelected();
}
public boolean makeAvailableToAll() {
return myMakeAvailableToAllJBCheckBox.isSelected();
}
@@ -17,7 +17,6 @@ package com.jetbrains.python.configuration;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.intellij.CommonBundle;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
@@ -35,7 +34,6 @@ import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.Splitter;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vfs.VirtualFile;
@@ -71,7 +69,6 @@ public class PythonSdkConfigurable implements Configurable, Configurable.NoScrol
private JPanel myNotificationsPlaceholder;
private PythonPathEditor myPathEditor;
private boolean mySdkListChanged = false;
private boolean myMakeActiveAdded = false;
private Sdk myAddedSdk;
private final PyConfigurableInterpreterList myInterpreterList;
private final ProjectSdksModel myProjectSdksModel;
@@ -228,7 +225,7 @@ public class PythonSdkConfigurable implements Configurable, Configurable.NoScrol
private void createVirtualEnv(Sdk sdk) {
CreateVirtualEnvDialog.VirtualEnvCallback callback = new CreateVirtualEnvDialog.VirtualEnvCallback() {
@Override
public void virtualEnvCreated(Sdk sdk, boolean associateWithProject, boolean setAsProjectInterpreter) {
public void virtualEnvCreated(Sdk sdk, boolean associateWithProject) {
PythonSdkType.setupSdkPaths(sdk, myProject, null);
if (associateWithProject) {
SdkAdditionalData additionalData = sdk.getSdkAdditionalData();
@@ -243,12 +240,11 @@ public class PythonSdkConfigurable implements Configurable, Configurable.NoScrol
((PythonSdkAdditionalData)additionalData).associateWithProject(myProject);
}
}
myMakeActiveAdded = setAsProjectInterpreter;
addCreatedSdk(sdk, true);
}
};
final List<Sdk> allSdks = PyConfigurableInterpreterList.getInstance(myProject).getAllPythonSdks(myProject);
final CreateVirtualEnvDialog dialog = new CreateVirtualEnvDialog(myProject, myNewProject, allSdks, sdk);
final CreateVirtualEnvDialog dialog = new CreateVirtualEnvDialog(myProject, allSdks, sdk);
dialog.show();
if (dialog.isOK()) {
dialog.createVirtualEnv(allSdks, callback);
@@ -291,11 +287,9 @@ public class PythonSdkConfigurable implements Configurable, Configurable.NoScrol
myModifiedModificators.clear();
myProjectSdksModel.apply();
mySdkListChanged = false;
if (myMakeActiveAdded) {
SdkConfigurationUtil.setDirectoryProjectSdk(myProject, myAddedSdk);
myProjectSdksModel.setProjectSdk(myAddedSdk);
myInterpreterList.setSelectedSdk(myAddedSdk);
}
SdkConfigurationUtil.setDirectoryProjectSdk(myProject, myAddedSdk);
myProjectSdksModel.setProjectSdk(myAddedSdk);
myInterpreterList.setSelectedSdk(myAddedSdk);
}
/**
@@ -369,7 +363,6 @@ public class PythonSdkConfigurable implements Configurable, Configurable.NoScrol
.show(myProject, myProjectSdksModel.getSdks(), new PythonSdkConfigurable(myProject).createComponent(), button.getPreferredPopupPoint(), false, new NullableConsumer<Sdk>() {
@Override
public void consume(Sdk sdk) {
myMakeActiveAdded = false;
addCreatedSdk(sdk, false);
}
});
@@ -379,8 +372,7 @@ public class PythonSdkConfigurable implements Configurable, Configurable.NoScrol
if (sdk != null) {
myAddedSdk = sdk;
boolean isVirtualEnv = PythonSdkType.isVirtualEnv(sdk);
boolean askSetAsProjectInterpreter = !myProject.isDefault() && !myNewProject;
if (askSetAsProjectInterpreter && isVirtualEnv && !newVirtualEnv) {
if (isVirtualEnv && !newVirtualEnv) {
AddVEnvOptionsDialog dialog = new AddVEnvOptionsDialog(myPanel);
dialog.show();
if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
@@ -389,20 +381,11 @@ public class PythonSdkConfigurable implements Configurable, Configurable.NoScrol
SdkModificator modificator = myModificators.get(sdk);
setSdkAssociated(modificator, !dialog.makeAvailableToAll());
myModifiedModificators.add(modificator);
myMakeActiveAdded = dialog.useForThisProject();
}
myProjectSdksModel.addSdk(sdk);
refreshSdkList();
mySdkList.setSelectedValue(sdk, true);
mySdkListChanged = true;
if (askSetAsProjectInterpreter && !isVirtualEnv && !PythonSdkType.isInvalid(sdk) && !PythonSdkType.isIncompleteRemote(sdk)) {
//TODO: make native mac dialog work
myMakeActiveAdded = Messages.showIdeaMessageDialog(myProject, "Do you want to set this interpreter as Project Interpreter?",
"Project Interpreter",
new String[]{CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText()}, 0, null,
null
) == Messages.YES;
}
}
}
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.python.sdk.CreateVirtualEnvDialog">
<grid id="cbd77" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="7" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="cbd77" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="48" y="54" width="550" height="342"/>
@@ -16,7 +16,7 @@
</component>
<vspacer id="b277d">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="48fd" class="com.intellij.ui.components.JBLabel">
@@ -60,30 +60,22 @@
</component>
<component id="41e08" class="com.intellij.ui.components.JBCheckBox" binding="myMakeAvailableToAllProjectsCheckbox">
<constraints>
<grid row="5" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="false"/>
<text value="Make available to &amp;all projects"/>
</properties>
</component>
<component id="9835d" class="com.intellij.ui.components.JBCheckBox" binding="mySitePackagesCheckBox">
<component id="d10a9" class="com.intellij.ui.components.JBCheckBox" binding="mySitePackagesCheckBox">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="false"/>
<text value="&amp;Inherit global site-packages"/>
</properties>
</component>
<component id="fd5f3" class="com.intellij.ui.components.JBCheckBox" binding="mySetAsProjectInterpreterCheckbox" default-binding="true">
<constraints>
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text value="&amp;Set as project interpreter for this project"/>
</properties>
</component>
</children>
</grid>
</form>
@@ -67,18 +67,16 @@ public class CreateVirtualEnvDialog extends IdeaDialog {
private JTextField myName;
private JBCheckBox mySitePackagesCheckBox;
private JBCheckBox myMakeAvailableToAllProjectsCheckbox;
private JBCheckBox mySetAsProjectInterpreterCheckbox;
@Nullable private Project myProject;
private String myInitialPath;
public interface VirtualEnvCallback {
void virtualEnvCreated(Sdk sdk, boolean associateWithProject, boolean setAsProjectInterpreter);
void virtualEnvCreated(Sdk sdk, boolean associateWithProject);
}
private static void setupVirtualEnvSdk(List<Sdk> allSdks,
final String path,
boolean associateWithProject,
final boolean makeActive,
VirtualEnvCallback callback) {
final VirtualFile sdkHome =
ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
@@ -92,27 +90,25 @@ public class CreateVirtualEnvDialog extends IdeaDialog {
SdkConfigurationUtil.createUniqueSdkName(PythonSdkType.getInstance(), sdkHome.getPath(), allSdks);
final ProjectJdkImpl sdk = new ProjectJdkImpl(name, PythonSdkType.getInstance());
sdk.setHomePath(sdkHome.getPath());
callback.virtualEnvCreated(sdk, associateWithProject, makeActive);
callback.virtualEnvCreated(sdk, associateWithProject);
}
}
public CreateVirtualEnvDialog(Project project,
boolean isNewProject,
final List<Sdk> allSdks,
@Nullable Sdk suggestedBaseSdk) {
super(project);
setupDialog(project, isNewProject, allSdks, suggestedBaseSdk);
setupDialog(project, allSdks, suggestedBaseSdk);
}
public CreateVirtualEnvDialog(Component owner,
boolean isNewProject,
final List<Sdk> allSdks,
@Nullable Sdk suggestedBaseSdk) {
super(owner);
setupDialog(null, isNewProject, allSdks, suggestedBaseSdk);
setupDialog(null, allSdks, suggestedBaseSdk);
}
private void setupDialog(Project project, boolean isNewProject, List<Sdk> allSdks, @Nullable Sdk suggestedBaseSdk) {
private void setupDialog(Project project, List<Sdk> allSdks, @Nullable Sdk suggestedBaseSdk) {
myProject = project;
init();
setTitle("Create Virtual Environment");
@@ -123,15 +119,9 @@ public class CreateVirtualEnvDialog extends IdeaDialog {
}
updateSdkList(allSdks, suggestedBaseSdk);
myMakeAvailableToAllProjectsCheckbox.setBorder(BorderFactory.createEmptyBorder(8, 0, 0, 0));
if (project == null || project.isDefault() || !PlatformUtils.isPyCharm()) {
myMakeAvailableToAllProjectsCheckbox.setSelected(true);
myMakeAvailableToAllProjectsCheckbox.setVisible(false);
mySetAsProjectInterpreterCheckbox.setSelected(false);
mySetAsProjectInterpreterCheckbox.setVisible(false);
}
else if (isNewProject) {
mySetAsProjectInterpreterCheckbox.setText("Set as project interpreter for the project being created");
}
setOKActionEnabled(false);
@@ -288,10 +278,6 @@ public class CreateVirtualEnvDialog extends IdeaDialog {
return !myMakeAvailableToAllProjectsCheckbox.isSelected();
}
public boolean setAsProjectInterpreter() {
return mySetAsProjectInterpreterCheckbox.isSelected();
}
@Override
public JComponent getPreferredFocusedComponent() {
return myName;
@@ -326,7 +312,7 @@ public class CreateVirtualEnvDialog extends IdeaDialog {
application.invokeLater(new Runnable() {
@Override
public void run() {
setupVirtualEnvSdk(allSdks, myPath, associateWithProject(), setAsProjectInterpreter(), callback);
setupVirtualEnvSdk(allSdks, myPath, associateWithProject(), callback);
}
}, ModalityState.any());
}
@@ -138,16 +138,16 @@ public class DetailsChooser extends BaseListPopupStep<String> {
final CreateVirtualEnvDialog dialog;
final List<Sdk> allSdks = Arrays.asList(myExistingSdks);
if (myProject != null) {
dialog = new CreateVirtualEnvDialog(myProject, false, allSdks, null);
dialog = new CreateVirtualEnvDialog(myProject, allSdks, null);
}
else {
dialog = new CreateVirtualEnvDialog(myOwnerComponent, false, allSdks, null);
dialog = new CreateVirtualEnvDialog(myOwnerComponent, allSdks, null);
}
dialog.show();
if (dialog.isOK()) {
dialog.createVirtualEnv(allSdks, new CreateVirtualEnvDialog.VirtualEnvCallback() {
@Override
public void virtualEnvCreated(Sdk sdk, boolean associateWithProject, boolean setAsProjectInterpreter) {
public void virtualEnvCreated(Sdk sdk, boolean associateWithProject) {
myCallback.consume(sdk);
}
});