mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
[html] Use OptPane
GitOrigin-RevId: c17a2ecd7664030b64cd1999834c4725a9ade69b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
760e483321
commit
5936f53ceb
@@ -16,14 +16,18 @@
|
||||
|
||||
package com.intellij.codeInspection.htmlInspections;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.intellij.codeInspection.options.OptPane;
|
||||
import com.intellij.xml.analysis.XmlAnalysisBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import static com.intellij.codeInspection.options.OptPane.*;
|
||||
|
||||
public class HtmlUnknownAttributeInspection extends HtmlUnknownAttributeInspectionBase {
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return HtmlUnknownTagInspection.createOptionsPanel(this);
|
||||
public @NotNull OptPane getOptionsPane() {
|
||||
return pane(
|
||||
checkbox("myCustomValuesEnabled", XmlAnalysisBundle.message("html.inspections.unknown.tag.attribute.checkbox.title"),
|
||||
stringSet("myValues", XmlAnalysisBundle.message("html.inspections.unknown.tag.attribute.title")))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,18 @@
|
||||
|
||||
package com.intellij.codeInspection.htmlInspections;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.intellij.codeInspection.options.OptPane;
|
||||
import com.intellij.xml.analysis.XmlAnalysisBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import static com.intellij.codeInspection.options.OptPane.*;
|
||||
|
||||
public class HtmlUnknownBooleanAttributeInspection extends HtmlUnknownBooleanAttributeInspectionBase {
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return HtmlUnknownTagInspection.createOptionsPanel(this);
|
||||
public @NotNull OptPane getOptionsPane() {
|
||||
return pane(
|
||||
checkbox("myCustomValuesEnabled", XmlAnalysisBundle.message("html.inspections.unknown.tag.boolean.attribute.checkbox.title"),
|
||||
stringSet("myValues", XmlAnalysisBundle.message("html.inspections.unknown.tag.boolean.attribute.title")))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ package com.intellij.codeInspection.htmlInspections;
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.LocalQuickFixOnPsiElement;
|
||||
import com.intellij.codeInspection.options.OptPane;
|
||||
import com.intellij.lang.LangBundle;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -14,21 +14,14 @@ import com.intellij.psi.templateLanguages.ChangeTemplateDataLanguageAction;
|
||||
import com.intellij.psi.templateLanguages.ConfigurableTemplateLanguageFileViewProvider;
|
||||
import com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider;
|
||||
import com.intellij.psi.templateLanguages.TemplateLanguageUtil;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.ui.components.fields.ExpandableTextField;
|
||||
import com.intellij.xml.XmlBundle;
|
||||
import com.intellij.xml.analysis.XmlAnalysisBundle;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Document;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import static com.intellij.codeInspection.options.OptPane.*;
|
||||
|
||||
public class HtmlUnknownTagInspection extends HtmlUnknownTagInspectionBase {
|
||||
|
||||
@@ -41,57 +34,11 @@ public class HtmlUnknownTagInspection extends HtmlUnknownTagInspectionBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JComponent createOptionsPanel() {
|
||||
return createOptionsPanel(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static JComponent createOptionsPanel(@NotNull final HtmlUnknownElementInspection inspection) {
|
||||
final JPanel result = new JPanel(new BorderLayout());
|
||||
|
||||
final JPanel internalPanel = new JPanel(new BorderLayout());
|
||||
result.add(internalPanel, BorderLayout.NORTH);
|
||||
|
||||
final ExpandableTextField additionalAttributesPanel = new ExpandableTextField(s -> reparseProperties(s),
|
||||
strings -> StringUtil.join(strings, ","));
|
||||
additionalAttributesPanel.getDocument().addDocumentListener(new DocumentAdapter() {
|
||||
@Override
|
||||
protected void textChanged(@NotNull DocumentEvent e) {
|
||||
final Document document = e.getDocument();
|
||||
try {
|
||||
final String text = document.getText(0, document.getLength());
|
||||
if (text != null) {
|
||||
inspection.updateAdditionalEntries(text.trim());
|
||||
}
|
||||
}
|
||||
catch (BadLocationException e1) {
|
||||
inspection.getLogger().error(e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
final JCheckBox checkBox = new JCheckBox(inspection.getCheckboxTitle());
|
||||
checkBox.setSelected(inspection.isCustomValuesEnabled());
|
||||
checkBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final boolean b = checkBox.isSelected();
|
||||
if (b != inspection.isCustomValuesEnabled()) {
|
||||
inspection.enableCustomValues(b);
|
||||
additionalAttributesPanel.setEnabled(inspection.isCustomValuesEnabled());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
internalPanel.add(checkBox, BorderLayout.NORTH);
|
||||
internalPanel.add(additionalAttributesPanel, BorderLayout.CENTER);
|
||||
|
||||
additionalAttributesPanel.setPreferredSize(new Dimension(150, additionalAttributesPanel.getPreferredSize().height));
|
||||
additionalAttributesPanel.setEnabled(inspection.isCustomValuesEnabled());
|
||||
additionalAttributesPanel.setText(inspection.getAdditionalEntries());
|
||||
|
||||
return result;
|
||||
public @NotNull OptPane getOptionsPane() {
|
||||
return pane(
|
||||
checkbox("myCustomValuesEnabled", XmlAnalysisBundle.message("html.inspections.unknown.tag.checkbox.title"),
|
||||
stringSet("myValues", XmlAnalysisBundle.message("html.inspections.unknown.tag.title")))
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -55,17 +55,6 @@ public class HtmlUnknownAttributeInspectionBase extends HtmlUnknownElementInspec
|
||||
return ATTRIBUTE_SHORT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCheckboxTitle() {
|
||||
return XmlAnalysisBundle.message("html.inspections.unknown.tag.attribute.checkbox.title");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getPanelTitle() {
|
||||
return XmlAnalysisBundle.message("html.inspections.unknown.tag.attribute.title");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected Logger getLogger() {
|
||||
|
||||
@@ -54,17 +54,6 @@ public class HtmlUnknownBooleanAttributeInspectionBase extends HtmlUnknownElemen
|
||||
return BOOLEAN_ATTRIBUTE_SHORT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCheckboxTitle() {
|
||||
return XmlAnalysisBundle.message("html.inspections.unknown.tag.boolean.attribute.checkbox.title");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getPanelTitle() {
|
||||
return XmlAnalysisBundle.message("html.inspections.unknown.tag.boolean.attribute.title");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected Logger getLogger() {
|
||||
|
||||
@@ -26,10 +26,10 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlChildRole;
|
||||
import java.util.StringTokenizer;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public abstract class HtmlUnknownElementInspection extends HtmlLocalInspectionTool implements XmlEntitiesInspection {
|
||||
public JDOMExternalizableStringList myValues;
|
||||
public boolean myCustomValuesEnabled = true;
|
||||
@@ -89,19 +89,10 @@ public abstract class HtmlUnknownElementInspection extends HtmlLocalInspectionTo
|
||||
return StringUtil.join(myValues, ",");
|
||||
}
|
||||
|
||||
public void enableCustomValues(boolean customValuesEnabled) {
|
||||
myCustomValuesEnabled = customValuesEnabled;
|
||||
}
|
||||
|
||||
public void updateAdditionalEntries(@NotNull final String values) {
|
||||
myValues = reparseProperties(values);
|
||||
}
|
||||
|
||||
protected abstract @Nls String getCheckboxTitle();
|
||||
|
||||
@NotNull
|
||||
protected abstract String getPanelTitle();
|
||||
|
||||
@NotNull
|
||||
protected abstract Logger getLogger();
|
||||
}
|
||||
|
||||
@@ -72,17 +72,6 @@ public class HtmlUnknownTagInspectionBase extends HtmlUnknownElementInspection {
|
||||
return LOG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCheckboxTitle() {
|
||||
return XmlAnalysisBundle.message("html.inspections.unknown.tag.checkbox.title");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String getPanelTitle() {
|
||||
return XmlAnalysisBundle.message("html.inspections.unknown.tag.title");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkTag(@NotNull final XmlTag tag, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
|
||||
if (!(tag instanceof HtmlTag) || !XmlHighlightVisitor.shouldBeValidated(tag)) {
|
||||
|
||||
Reference in New Issue
Block a user