Search in sources :

Example 6 with ProjectSdksModel

use of com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel in project intellij-community by JetBrains.

the class UIRootConfigurationAccessor method getProjectSdkName.

@Override
@Nullable
public String getProjectSdkName(final Project project) {
    final String projectJdkName = ProjectRootManager.getInstance(project).getProjectSdkName();
    final Sdk projectJdk = getProjectSdk(project);
    if (projectJdk != null) {
        return projectJdk.getName();
    } else {
        final ProjectSdksModel projectJdksModel = ProjectStructureConfigurable.getInstance(project).getProjectJdksModel();
        return projectJdksModel.findSdk(projectJdkName) == null ? projectJdkName : null;
    }
}
Also used : ProjectSdksModel(com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel) Sdk(com.intellij.openapi.projectRoots.Sdk) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with ProjectSdksModel

use of com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel in project intellij-community by JetBrains.

the class JdkComboBox method setSetupButton.

public void setSetupButton(final JButton setUpButton, @Nullable final Project project, final ProjectSdksModel jdksModel, final JdkComboBoxItem firstItem, @Nullable final Condition<Sdk> additionalSetup, final String actionGroupTitle) {
    mySetUpButton = setUpButton;
    mySetUpButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DefaultActionGroup group = new DefaultActionGroup();
            jdksModel.createAddActions(group, JdkComboBox.this, getSelectedJdk(), jdk -> {
                if (project != null) {
                    final JdkListConfigurable configurable = JdkListConfigurable.getInstance(project);
                    configurable.addJdkNode(jdk, false);
                }
                reloadModel(new ActualJdkComboBoxItem(jdk), project);
                setSelectedJdk(jdk);
                if (additionalSetup != null) {
                    if (additionalSetup.value(jdk)) {
                        setSelectedJdk(firstItem.getJdk());
                    }
                }
            }, myCreationFilter);
            final DataContext dataContext = DataManager.getInstance().getDataContext(JdkComboBox.this);
            if (group.getChildrenCount() > 1) {
                JBPopupFactory.getInstance().createActionGroupPopup(actionGroupTitle, group, dataContext, JBPopupFactory.ActionSelectionAid.MNEMONICS, false).showUnderneathOf(setUpButton);
            } else {
                final AnActionEvent event = new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0);
                group.getChildren(event)[0].actionPerformed(event);
            }
        }
    });
}
Also used : Arrays(java.util.Arrays) ActionListener(java.awt.event.ActionListener) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) JBUI(com.intellij.util.ui.JBUI) ComboBoxWithWidePopup(com.intellij.openapi.ui.ComboBoxWithWidePopup) Project(com.intellij.openapi.project.Project) Conditions(com.intellij.openapi.util.Conditions) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) DataManager(com.intellij.ide.DataManager) JdkListConfigurable(com.intellij.openapi.roots.ui.configuration.projectRoot.JdkListConfigurable) ProjectSdksModel(com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) EmptyIcon(com.intellij.util.ui.EmptyIcon) ProjectBundle(com.intellij.openapi.project.ProjectBundle) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) ScreenUtil(com.intellij.ui.ScreenUtil) ActionEvent(java.awt.event.ActionEvent) Sdk(com.intellij.openapi.projectRoots.Sdk) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) OrderEntryAppearanceService(com.intellij.openapi.roots.ui.OrderEntryAppearanceService) SdkType(com.intellij.openapi.projectRoots.SdkType) NotNull(org.jetbrains.annotations.NotNull) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) ActionListener(java.awt.event.ActionListener) JdkListConfigurable(com.intellij.openapi.roots.ui.configuration.projectRoot.JdkListConfigurable) ActionEvent(java.awt.event.ActionEvent)

Example 8 with ProjectSdksModel

use of com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel in project intellij-community by JetBrains.

the class PyConfigurableInterpreterList method getModel.

public ProjectSdksModel getModel() {
    if (myModel == null) {
        myModel = new ProjectSdksModel();
        myModel.reset(null);
    }
    return myModel;
}
Also used : ProjectSdksModel(com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel)

Example 9 with ProjectSdksModel

use of com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel in project intellij-community by JetBrains.

the class PyStudyDirectoryProjectGenerator method createAndAddVirtualEnv.

public void createAndAddVirtualEnv(Project project, PyNewProjectSettings settings) {
    final ProjectSdksModel model = PyConfigurableInterpreterList.getInstance(project).getModel();
    final String baseSdk = getBaseSdk(project);
    if (baseSdk != null) {
        final PyPackageManager packageManager = PyPackageManager.getInstance(new PyDetectedSdk(baseSdk));
        try {
            final String path = packageManager.createVirtualEnv(project.getBasePath() + "/.idea/VirtualEnvironment", false);
            AbstractCreateVirtualEnvDialog.setupVirtualEnvSdk(path, true, new AbstractCreateVirtualEnvDialog.VirtualEnvCallback() {

                @Override
                public void virtualEnvCreated(Sdk createdSdk, boolean associateWithProject) {
                    settings.setSdk(createdSdk);
                    model.addSdk(createdSdk);
                    try {
                        model.apply();
                    } catch (ConfigurationException exception) {
                        LOG.error("Error adding created virtual env " + exception.getMessage());
                    }
                    if (associateWithProject) {
                        SdkAdditionalData additionalData = createdSdk.getSdkAdditionalData();
                        if (additionalData == null) {
                            additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(createdSdk.getHomePath()));
                            ((ProjectJdkImpl) createdSdk).setSdkAdditionalData(additionalData);
                        }
                        ((PythonSdkAdditionalData) additionalData).associateWithNewProject();
                    }
                }
            });
        } catch (ExecutionException e) {
            LOG.warn("Failed to create virtual env " + e.getMessage());
        }
    }
}
Also used : ProjectSdksModel(com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) AbstractCreateVirtualEnvDialog(com.jetbrains.python.sdk.AbstractCreateVirtualEnvDialog) PyPackageManager(com.jetbrains.python.packaging.PyPackageManager) ConfigurationException(com.intellij.openapi.options.ConfigurationException) PyDetectedSdk(com.jetbrains.python.sdk.PyDetectedSdk) PyDetectedSdk(com.jetbrains.python.sdk.PyDetectedSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData)

Example 10 with ProjectSdksModel

use of com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel in project intellij-community by JetBrains.

the class PyIdeCommonOptionsForm method subscribe.

@Override
public void subscribe() {
    PyConfigurableInterpreterList myInterpreterList = PyConfigurableInterpreterList.getInstance(myProject);
    ProjectSdksModel myProjectSdksModel = myInterpreterList.getModel();
    myProjectSdksModel.addListener(new MyListener(this, myInterpreterList));
    updateSdkList(true, myInterpreterList);
}
Also used : PyConfigurableInterpreterList(com.jetbrains.python.configuration.PyConfigurableInterpreterList) ProjectSdksModel(com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel)

Aggregations

ProjectSdksModel (com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel)10 Sdk (com.intellij.openapi.projectRoots.Sdk)7 ConfigurationException (com.intellij.openapi.options.ConfigurationException)4 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PyConfigurableInterpreterList (com.jetbrains.python.configuration.PyConfigurableInterpreterList)2 Nullable (org.jetbrains.annotations.Nullable)2 ModuleSourceSet (com.intellij.compiler.ModuleSourceSet)1 ExecutionException (com.intellij.execution.ExecutionException)1 DataManager (com.intellij.ide.DataManager)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 ProjectBundle (com.intellij.openapi.project.ProjectBundle)1 SdkAdditionalData (com.intellij.openapi.projectRoots.SdkAdditionalData)1 SdkType (com.intellij.openapi.projectRoots.SdkType)1 SdkTypeId (com.intellij.openapi.projectRoots.SdkTypeId)1 ContentEntry (com.intellij.openapi.roots.ContentEntry)1 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)1 OrderEntryAppearanceService (com.intellij.openapi.roots.ui.OrderEntryAppearanceService)1 JdkListConfigurable (com.intellij.openapi.roots.ui.configuration.projectRoot.JdkListConfigurable)1 ComboBoxWithWidePopup (com.intellij.openapi.ui.ComboBoxWithWidePopup)1