private void addCreatedSdk(@Nullable final Sdk sdk, boolean newVirtualEnv) { if (sdk != null) { final PySdkService sdkService = PySdkService.getInstance(); sdkService.restoreSdk(sdk); boolean isVirtualEnv = PythonSdkType.isVirtualEnv(sdk); if (isVirtualEnv && !newVirtualEnv) { AddVEnvOptionsDialog dialog = new AddVEnvOptionsDialog(myMainPanel); dialog.show(); if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) { return; } SdkModificator modificator = myModificators.get(sdk); setSdkAssociated(modificator, !dialog.makeAvailableToAll()); myModifiedModificators.add(modificator); } final Sdk oldSdk = myProjectSdksModel.findSdk(sdk); if (oldSdk == null) { myProjectSdksModel.addSdk(sdk); } refreshSdkList(); mySdkList.setSelectedValue(myProjectSdksModel.findSdk(sdk.getName()), true); mySdkListChanged = true; } }
private void removeSdk() { final Sdk currentSdk = getSelectedSdk(); if (currentSdk != null) { final Sdk sdk = myProjectSdksModel.findSdk(currentSdk); final PySdkService sdkService = PySdkService.getInstance(); sdkService.removeSdk(currentSdk); DumbService.allowStartingDumbModeInside( DumbModePermission.MAY_START_MODAL, () -> SdkConfigurationUtil.removeSdk(sdk)); myProjectSdksModel.removeSdk(sdk); myProjectSdksModel.removeSdk(currentSdk); if (myModificators.containsKey(currentSdk)) { SdkModificator modificator = myModificators.get(currentSdk); myModifiedModificators.remove(modificator); myModificators.remove(currentSdk); } refreshSdkList(); mySdkListChanged = true; // TODO select initially selected SDK if (mySdkList.getSelectedIndex() < 0) { mySdkList.setSelectedIndex(0); } } }
public boolean isModified() { Sdk projectSdk = getSdk(); if (projectSdk != null) { projectSdk = myProjectSdksModel.findSdk(projectSdk.getName()); } return getSelectedSdk() != projectSdk || mySdkListChanged || myProjectSdksModel.isModified() || !myModifiedModificators.isEmpty(); }
@Override public void consume(@Nullable AbstractProjectSettingsStep settingsStep) { if (myRunnable != null) { myRunnable.run(); } if (settingsStep == null) return; Sdk sdk = settingsStep.getSdk(); final Project project = ProjectManager.getInstance().getDefaultProject(); final ProjectSdksModel model = PyConfigurableInterpreterList.getInstance(project).getModel(); if (sdk instanceof PyDetectedSdk) { final String name = sdk.getName(); VirtualFile sdkHome = ApplicationManager.getApplication() .runWriteAction( new Computable<VirtualFile>() { @Override public VirtualFile compute() { return LocalFileSystem.getInstance().refreshAndFindFileByPath(name); } }); PySdkService.getInstance().solidifySdk(sdk); sdk = SdkConfigurationUtil.setupSdk( ProjectJdkTable.getInstance().getAllJdks(), sdkHome, PythonSdkType.getInstance(), true, null, null); model.addSdk(sdk); settingsStep.setSdk(sdk); try { model.apply(); } catch (ConfigurationException exception) { LOG.error("Error adding detected python interpreter " + exception.getMessage()); } } Project newProject = generateProject(project, settingsStep); if (newProject != null) { SdkConfigurationUtil.setDirectoryProjectSdk(newProject, sdk); final List<Sdk> sdks = PythonSdkType.getAllSdks(); for (Sdk s : sdks) { final SdkAdditionalData additionalData = s.getSdkAdditionalData(); if (additionalData instanceof PythonSdkAdditionalData) { ((PythonSdkAdditionalData) additionalData).reassociateWithCreatedProject(newProject); } } } }
private void addListeners() { myListener = new SdkModel.Listener() { @Override public void sdkAdded(Sdk sdk) {} @Override public void beforeSdkRemove(Sdk sdk) {} @Override public void sdkChanged(Sdk sdk, String previousName) { refreshSdkList(); } @Override public void sdkHomeSelected(Sdk sdk, String newSdkHome) {} }; myProjectSdksModel.addListener(myListener); mySdkList.addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { updateOkButton(); } }); }
private void addSdk(AnActionButton button) { PythonSdkDetailsStep.show( myProject, myProjectSdksModel.getSdks(), null, myMainPanel, button.getPreferredPopupPoint().getScreenPoint(), sdk -> addCreatedSdk(sdk, true)); }
private void editRemoteSdk(Sdk currentSdk) { PythonRemoteInterpreterManager remoteInterpreterManager = PythonRemoteInterpreterManager.getInstance(); if (remoteInterpreterManager != null) { final SdkModificator modificator = myModificators.get(currentSdk); Set<Sdk> existingSdks = Sets.newHashSet(myProjectSdksModel.getSdks()); existingSdks.remove(currentSdk); if (remoteInterpreterManager.editSdk(myProject, modificator, existingSdks)) { myModifiedModificators.add(modificator); } } }
public ScalaApplicationSettingsForm(ScalaApplicationSettings settings) { mySettings = settings; myEnableCompileServer.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { updateCompilationServerSettingsPanel(); } }); initCompilerTypeCmb(); initCompileOrderCmb(); ProjectSdksModel model = new ProjectSdksModel(); model.reset(null); myCompilationServerSdk = new JdkComboBox(model); myCompilationServerSdk.insertItemAt(new JdkComboBox.NoneJdkComboBoxItem(), 0); mySdkPanel.add(myCompilationServerSdk, BorderLayout.CENTER); mySdkPanel.setSize(mySdkPanel.getPreferredSize()); myNote.setForeground(JBColor.GRAY); delaySpinner.setEnabled(showTypeInfoOnCheckBox.isSelected()); showTypeInfoOnCheckBox.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { delaySpinner.setEnabled(showTypeInfoOnCheckBox.isSelected()); } }); delaySpinner.setValue(mySettings.SHOW_TYPE_TOOLTIP_DELAY); updateCompilationServerSettingsPanel(); }
private boolean isDuplicateSdkName(String s, Sdk sdk) { for (Sdk existingSdk : myProjectSdksModel.getSdks()) { if (existingSdk == sdk) { continue; } String existingName; if (myModificators.containsKey(existingSdk)) { existingName = myModificators.get(existingSdk).getName(); } else { existingName = existingSdk.getName(); } if (existingName.equals(s)) { return true; } } return false; }
private void refreshSdkList() { final List<Sdk> pythonSdks = myInterpreterList.getAllPythonSdks(myProject); Sdk projectSdk = getSdk(); if (!myShowOtherProjectVirtualenvs) { VirtualEnvProjectFilter.removeNotMatching(myProject, pythonSdks); } //noinspection unchecked mySdkList.setModel(new CollectionListModel<Sdk>(pythonSdks)); mySdkListChanged = false; if (projectSdk != null) { projectSdk = myProjectSdksModel.findSdk(projectSdk.getName()); mySdkList.clearSelection(); mySdkList.setSelectedValue(projectSdk, true); mySdkList.updateUI(); } }
@Override public void reset() { // need this to ensure VFS operations will not block because of storage flushing // and other maintenance IO tasks run in background HeavyProcessLatch.INSTANCE.processStarted(); try { myWasUiDisposed = false; myContext.reset(); myProjectJdksModel.reset(myProject); Configurable toSelect = null; for (Configurable each : myName2Config) { if (myUiState.lastEditedConfigurable != null && myUiState.lastEditedConfigurable.equals(each.getDisplayName())) { toSelect = each; } if (each instanceof MasterDetailsComponent) { ((MasterDetailsComponent) each).setHistory(myHistory); } each.reset(); } myHistory.clear(); if (toSelect == null && myName2Config.size() > 0) { toSelect = myName2Config.iterator().next(); } removeSelected(); navigateTo(toSelect != null ? createPlaceFor(toSelect) : null, false); if (myUiState.proportion > 0) { mySplitter.setProportion(myUiState.proportion); } } finally { HeavyProcessLatch.INSTANCE.processFinished(); } }
public void apply() throws ConfigurationException { // validate content and source roots final Map<VirtualFile, String> contentRootToModuleNameMap = new HashMap<VirtualFile, String>(); final Map<VirtualFile, VirtualFile> srcRootsToContentRootMap = new HashMap<VirtualFile, VirtualFile>(); for (final ModuleEditor moduleEditor : myModuleEditors.values()) { final ModifiableRootModel rootModel = moduleEditor.getModifiableRootModel(); final ContentEntry[] contents = rootModel.getContentEntries(); for (ContentEntry contentEntry : contents) { final VirtualFile contentRoot = contentEntry.getFile(); if (contentRoot == null) { continue; } final String moduleName = moduleEditor.getName(); final String previousName = contentRootToModuleNameMap.put(contentRoot, moduleName); if (previousName != null && !previousName.equals(moduleName)) { throw new ConfigurationException( ProjectBundle.message( "module.paths.validation.duplicate.content.error", contentRoot.getPresentableUrl(), previousName, moduleName)); } for (VirtualFile srcRoot : contentEntry.getSourceFolderFiles()) { final VirtualFile anotherContentRoot = srcRootsToContentRootMap.put(srcRoot, contentRoot); if (anotherContentRoot != null) { final String problematicModule; final String correctModule; if (VfsUtilCore.isAncestor(anotherContentRoot, contentRoot, true)) { problematicModule = contentRootToModuleNameMap.get(anotherContentRoot); correctModule = contentRootToModuleNameMap.get(contentRoot); } else { problematicModule = contentRootToModuleNameMap.get(contentRoot); correctModule = contentRootToModuleNameMap.get(anotherContentRoot); } throw new ConfigurationException( ProjectBundle.message( "module.paths.validation.duplicate.source.root.error", problematicModule, srcRoot.getPresentableUrl(), correctModule)); } } } } // additional validation: directories marked as src roots must belong to the same module as // their corresponding content root for (Map.Entry<VirtualFile, VirtualFile> entry : srcRootsToContentRootMap.entrySet()) { final VirtualFile srcRoot = entry.getKey(); final VirtualFile correspondingContent = entry.getValue(); final String expectedModuleName = contentRootToModuleNameMap.get(correspondingContent); for (VirtualFile candidateContent = srcRoot; candidateContent != null && !candidateContent.equals(correspondingContent); candidateContent = candidateContent.getParent()) { final String moduleName = contentRootToModuleNameMap.get(candidateContent); if (moduleName != null && !moduleName.equals(expectedModuleName)) { throw new ConfigurationException( ProjectBundle.message( "module.paths.validation.source.root.belongs.to.another.module.error", srcRoot.getPresentableUrl(), expectedModuleName, moduleName)); } } } final List<ModifiableRootModel> models = new ArrayList<ModifiableRootModel>(myModuleEditors.size()); for (ModuleEditor moduleEditor : myModuleEditors.values()) { moduleEditor.canApply(); } final Map<Sdk, Sdk> modifiedToOriginalMap = new HashMap<Sdk, Sdk>(); final ProjectSdksModel projectJdksModel = ProjectStructureConfigurable.getInstance(myProject).getProjectJdksModel(); for (Map.Entry<Sdk, Sdk> entry : projectJdksModel.getProjectSdks().entrySet()) { modifiedToOriginalMap.put(entry.getValue(), entry.getKey()); } final Ref<ConfigurationException> exceptionRef = Ref.create(); DumbService.getInstance(myProject) .allowStartingDumbModeInside( DumbModePermission.MAY_START_BACKGROUND, new Runnable() { public void run() { ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { try { for (final ModuleEditor moduleEditor : myModuleEditors.values()) { final ModifiableRootModel model = moduleEditor.apply(); if (model != null) { if (!model.isSdkInherited()) { // make sure the sdk is set to original SDK stored in the JDK // Table final Sdk modelSdk = model.getSdk(); if (modelSdk != null) { final Sdk original = modifiedToOriginalMap.get(modelSdk); if (original != null) { model.setSdk(original); } } } models.add(model); } } myFacetsConfigurator.applyEditors(); } catch (ConfigurationException e) { exceptionRef.set(e); return; } try { final ModifiableRootModel[] rootModels = models.toArray(new ModifiableRootModel[models.size()]); ModifiableModelCommitter.multiCommit(rootModels, myModuleModel); myModuleModelCommitted = true; myFacetsConfigurator.commitFacets(); } finally { ModuleStructureConfigurable.getInstance(myProject) .getFacetEditorFacade() .clearMaps(false); myFacetsConfigurator = createFacetsConfigurator(); myModuleModel = ModuleManager.getInstance(myProject).getModifiableModel(); myModuleModelCommitted = false; } } }); } }); if (!exceptionRef.isNull()) { throw exceptionRef.get(); } myModified = false; }
@Override protected void dispose() { myProjectSdksModel.removeListener(myListener); super.dispose(); }