IDEA-94350 Create from template: remember last selected project sdk for a template

This commit is contained in:
Dmitry Avdeev
2013-04-23 13:50:16 +04:00
parent 8e01b981c4
commit 4e368a3b3a
@@ -17,9 +17,12 @@ package com.intellij.ide.util.projectWizard;
import com.intellij.CommonBundle;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkTypeId;
import com.intellij.openapi.roots.ProjectRootManager;
@@ -31,6 +34,8 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* @author Dmitry Avdeev
@@ -52,6 +57,17 @@ public class SdkSettingsStep extends ModuleWizardStep {
myJdkComboBox = new JdkComboBox(myModel, sdkFilter);
final PropertiesComponent component = project == null ? PropertiesComponent.getInstance() : PropertiesComponent.getInstance(project);
ModuleType moduleType = moduleBuilder.getModuleType();
final String selectedJdkProperty = "jdk.selected." + (moduleType == null ? "" : moduleType.getId());
myJdkComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Sdk jdk = myJdkComboBox.getSelectedJdk();
component.setValue(selectedJdkProperty, jdk == null ? "" : jdk.getName());
}
});
if (project != null) {
Sdk sdk = ProjectRootManager.getInstance(project).getProjectSdk();
if (sdk != null && moduleBuilder.isSuitableSdkType(sdk.getSdkType())) {
@@ -68,6 +84,14 @@ public class SdkSettingsStep extends ModuleWizardStep {
}
}
String value = component.getValue(selectedJdkProperty);
if (value != null) {
Sdk jdk = ProjectJdkTable.getInstance().findJdk(value);
if (jdk != null) {
myJdkComboBox.setSelectedJdk(jdk);
}
}
JButton button = new JButton("Ne\u001Bw...");
myJdkComboBox.setSetupButton(button, project, myModel,
project == null ? new JdkComboBox.NoneJdkComboBoxItem() : new JdkComboBox.ProjectJdkComboBoxItem(),