mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:10:43 +07:00
IDEA-312046 remove HtmlPreviewHintProvider
GitOrigin-RevId: 1342c22160eacda6658f81cf724a76fcb01e50ea
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0df134b997
commit
ac5c6b30cd
@@ -22,7 +22,6 @@
|
||||
<refactoring.extractIncludeHandler language="XHTML"
|
||||
implementationClass="com.intellij.htmltools.refactoring.lang.html.ExtractIncludeFromHTMLHandler"/>
|
||||
|
||||
<previewHintProvider implementation="com.intellij.htmltools.codeInsight.preview.HtmlPreviewHintProvider"/>
|
||||
<highlightErrorFilter implementation="com.intellij.htmltools.xml.util.XHtmlErrorFilter"/>
|
||||
|
||||
<externalAnnotator language="HTML"
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.intellij.htmltools.codeInsight.preview;
|
||||
|
||||
import com.intellij.codeInsight.preview.PreviewHintProvider;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.xml.util.HtmlUtil;
|
||||
|
||||
/**
|
||||
* Created by fedorkorotkov.
|
||||
*/
|
||||
public abstract class BaseHtmlPreviewHintProvider implements PreviewHintProvider {
|
||||
@Override
|
||||
public boolean isSupportedFile(PsiFile file) {
|
||||
return HtmlUtil.isHtmlFile(file);
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package com.intellij.htmltools.codeInsight.preview;
|
||||
|
||||
import com.intellij.codeInsight.preview.ColorPreviewComponent;
|
||||
import com.intellij.codeInsight.preview.ImagePreviewComponent;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlAttributeValue;
|
||||
import com.intellij.util.io.URLUtil;
|
||||
import com.intellij.xml.util.ColorMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class HtmlPreviewHintProvider extends BaseHtmlPreviewHintProvider {
|
||||
@Override
|
||||
public JComponent getPreviewComponent(@NotNull PsiElement element) {
|
||||
if (element.getParent() instanceof XmlAttributeValue) {
|
||||
final PsiElement parentParent = element.getParent().getParent();
|
||||
|
||||
if (parentParent instanceof XmlAttribute) {
|
||||
XmlAttribute attribute = ((XmlAttribute)parentParent);
|
||||
final String attrName = attribute.getName();
|
||||
|
||||
if ("alink".equalsIgnoreCase(attrName) ||
|
||||
"link".equalsIgnoreCase(attrName) ||
|
||||
"text".equalsIgnoreCase(attrName) ||
|
||||
"vlink".equalsIgnoreCase(attrName) ||
|
||||
StringUtil.containsIgnoreCase(attrName, "color")) {
|
||||
String s = element.getText(); // TODO: support [#FFF, #FFF]
|
||||
|
||||
if (s.length() > 0) {
|
||||
final String hexColor = (s.charAt(0) == '#') ? s : ColorMap.getHexCodeForColorName(StringUtil.toLowerCase(s));
|
||||
if (hexColor != null) {
|
||||
try {
|
||||
return new ColorPreviewComponent(Color.decode("0x" + hexColor.substring(1)));
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final PsiElement attributeValue = element.getParent();
|
||||
if (attributeValue.getParent() instanceof XmlAttribute) {
|
||||
if ("background".equalsIgnoreCase(attrName) || "src".equalsIgnoreCase(attrName) || "href".equalsIgnoreCase(attrName)) {
|
||||
final String attrValue = attribute.getValue();
|
||||
if (attrValue != null && URLUtil.isDataUri(attrValue)) {
|
||||
return getPreviewFromDataUri(attrValue);
|
||||
}
|
||||
|
||||
PsiElement parent = element;
|
||||
while (parent != null && parent != attribute) {
|
||||
final JComponent c = ImagePreviewComponent.getPreviewComponent(parent);
|
||||
if (c != null) {
|
||||
return c;
|
||||
}
|
||||
|
||||
parent = parent.getParent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JComponent getPreviewFromDataUri(@NotNull String dataUri) {
|
||||
JComponent preview = null;
|
||||
final byte[] imageBytes = URLUtil.getBytesFromDataUri(dataUri);
|
||||
if (imageBytes != null) {
|
||||
try {
|
||||
preview = ImagePreviewComponent.getPreviewComponent(ImagePreviewComponent.readImageFromBytes(imageBytes), imageBytes.length);
|
||||
}
|
||||
catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
return preview;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.intellij.htmltools.codeInsight.preview;
|
||||
|
||||
import com.intellij.codeInsight.preview.PreviewHintComponent;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Created by fedorkorotkov.
|
||||
*/
|
||||
public class ImageDataPreviewHintProviderTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
public void testDataUriImage() {
|
||||
myFixture.configureByText("test.html", """
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<img src="dat<caret>a:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==">
|
||||
</body>
|
||||
</html>""");
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
final HtmlPreviewHintProvider provider = new HtmlPreviewHintProvider();
|
||||
final PsiElement elementAt = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
|
||||
assertNotNull(elementAt);
|
||||
final JComponent previewComponent = provider.getPreviewComponent(elementAt);
|
||||
assertInstanceOf(previewComponent, PreviewHintComponent.class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user