mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-13328 Create New Project: warning about installing template packages is not shown
This commit is contained in:
+5
-4
@@ -107,6 +107,9 @@ abstract public class AbstractProjectSettingsStep extends AbstractActionWithPane
|
||||
final JPanel scrollPanel = new JPanel(new BorderLayout());
|
||||
|
||||
mainPanel.setPreferredSize(new Dimension(mainPanel.getPreferredSize().width, 400));
|
||||
myErrorLabel = new JLabel("");
|
||||
myErrorLabel.setForeground(JBColor.RED);
|
||||
myCreateButton = new Button(myCreateAction, myCreateAction.getTemplatePresentation());
|
||||
|
||||
final JPanel panel = createBasePanel();
|
||||
scrollPanel.add(panel, BorderLayout.NORTH);
|
||||
@@ -120,11 +123,9 @@ abstract public class AbstractProjectSettingsStep extends AbstractActionWithPane
|
||||
mainPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
final JPanel bottomPanel = new JPanel(new BorderLayout());
|
||||
myCreateButton = new Button(myCreateAction, myCreateAction.getTemplatePresentation());
|
||||
|
||||
|
||||
myCreateButton.setPreferredSize(new Dimension(mainPanel.getPreferredSize().width, 40));
|
||||
myErrorLabel = new JLabel("");
|
||||
myErrorLabel.setForeground(JBColor.RED);
|
||||
bottomPanel.add(myErrorLabel, BorderLayout.NORTH);
|
||||
bottomPanel.add(myCreateButton, BorderLayout.CENTER);
|
||||
mainPanel.add(bottomPanel, BorderLayout.SOUTH);
|
||||
@@ -242,7 +243,7 @@ abstract public class AbstractProjectSettingsStep extends AbstractActionWithPane
|
||||
return false;
|
||||
}
|
||||
if (myProjectGenerator instanceof PythonProjectGenerator) {
|
||||
final ValidationResult warningResult = ((PythonProjectGenerator)myProjectGenerator).warningValidation();
|
||||
final ValidationResult warningResult = ((PythonProjectGenerator)myProjectGenerator).warningValidation(getSdk());
|
||||
if (!warningResult.isOk()) {
|
||||
setWarningText(warningResult.getErrorMessage());
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.jetbrains.python.newProject;
|
||||
|
||||
import com.intellij.facet.ui.ValidationResult;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -22,7 +23,7 @@ public abstract class PythonProjectGenerator {
|
||||
return new PyNewProjectSettings();
|
||||
}
|
||||
|
||||
public ValidationResult warningValidation() {
|
||||
public ValidationResult warningValidation(@Nullable final Sdk sdk) {
|
||||
return ValidationResult.OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.templateLanguages;
|
||||
|
||||
import com.intellij.facet.ui.ValidationResult;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.jetbrains.python.packaging.PyExternalProcessException;
|
||||
import com.jetbrains.python.packaging.PyPackage;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PyTemplatesUtil {
|
||||
private PyTemplatesUtil(){}
|
||||
|
||||
public static ValidationResult checkInstalled(@Nullable final Sdk sdk, @NotNull final TemplateLanguagePanel templatesPanel,
|
||||
@NotNull final String prefix) {
|
||||
if (sdk == null) return ValidationResult.OK;
|
||||
String templateBinding = null;
|
||||
@NonNls String language = templatesPanel.getTemplateLanguage();
|
||||
if (language != null) {
|
||||
if (language.equals(TemplatesService.JINJA2)) language = "jinja";
|
||||
templateBinding = prefix + language.toLowerCase();
|
||||
}
|
||||
final PyPackageManager packageManager = PyPackageManager.getInstance(sdk);
|
||||
if (templateBinding != null) {
|
||||
if (TemplatesService.ALL_TEMPLATE_BINDINGS.contains(templateBinding)) {
|
||||
try {
|
||||
final PyPackage installedPackage = packageManager.findInstalledPackage(templateBinding);
|
||||
if (installedPackage == null)
|
||||
return new ValidationResult(templateBinding + " will be installed on selected interpreter");
|
||||
}
|
||||
catch (PyExternalProcessException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (language != null) {
|
||||
try {
|
||||
final PyPackage installedPackage = packageManager.findInstalledPackage(language);
|
||||
if (installedPackage == null) {
|
||||
return new ValidationResult(language + " will be installed on selected interpreter");
|
||||
}
|
||||
}
|
||||
catch (PyExternalProcessException ignored) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jetbrains.python.templateLanguages;
|
||||
|
||||
import com.intellij.facet.ui.FacetValidatorsManager;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
@@ -7,6 +8,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
|
||||
public class TemplateLanguagePanel extends JPanel {
|
||||
@@ -58,4 +61,13 @@ public class TemplateLanguagePanel extends JPanel {
|
||||
public Dimension getLabelSize() {
|
||||
return new JBLabel("Template language:").getPreferredSize();
|
||||
}
|
||||
|
||||
public void registerValidators(final FacetValidatorsManager validatorsManager) {
|
||||
myTemplateLanguage.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
validatorsManager.validate();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,9 @@ public abstract class TemplatesService {
|
||||
WEB2PY,
|
||||
CHAMELEON);
|
||||
|
||||
public static List<String> ALL_TEMPLATE_BINDINGS = ContainerUtil.immutableList("django-mako", "django-jinja", "django-chameleon",
|
||||
"flask-mako", "pyramid_jinja2");
|
||||
|
||||
public abstract Language getSelectedTemplateLanguage();
|
||||
|
||||
public static TemplatesService getInstance(Module module) {
|
||||
|
||||
Reference in New Issue
Block a user