Skip to content

Commit

Permalink
Add document link to plugin page (#108)
Browse files Browse the repository at this point in the history
* update plugin page

* fix html link
  • Loading branch information
koxudaxi committed Apr 22, 2020
1 parent cda090b commit d78089d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
10 changes: 8 additions & 2 deletions resources/META-INF/plugin.xml
Expand Up @@ -7,7 +7,7 @@
<h2>version 0.1.3</h2>
<p>Features</p>
<ul>
<li>Add documents and link to documents [#105, #106, #107] </li>
<li>Add documents and link to documents [#105, #106, #107, #108] </li>
<li>Support acceptable type [#104] </li>
<li>Support parsable type highlight level [#103] </li>
</ul>
Expand Down Expand Up @@ -147,7 +147,10 @@
]]></change-notes>
<description><![CDATA[
<p>This plugin provides autocompletion support for <a href="https://github.com/samuelcolvin/pydantic">pydantic</a></p>
<h2>Help</h2>
<p>See <a href="https://koxudaxi.github.io/pydantic-pycharm-plugin/">documentation</a> for more details.</p>
<h2>Features</h2>
<ul>
<li>pydantic.BaseModel
<ul>
Expand All @@ -156,11 +159,14 @@
<li>Refactor support for renaming fields for subclasses of BaseModel</li>
<li>(If the field name is refactored from the model definition or __init__ call keyword arguments, PyCharm will present a dialog offering the choice to automatically rename the keyword where it occurs in a model initialization call.</li>
<li>Search related-fields by class attributes and keyword arguments of __init__. with Ctrl+B and Cmd+B</li>
<li>Provide an inspection for type-checking which is compatible with pydantic. the inspection supports parsable-type. the detail is at <a href="https://koxudaxi.github.io/pydantic-pycharm-plugin/type-checking/"> Inspection for type-checking section</a></li>
</ul>
</li>
<li>pydantic.dataclasses.dataclass
<ul>
<li>Support same features as pydantic.BaseModel</li>
<li>Support same features as pydantic.BaseModel
<li>(After PyCharm 2020.1 and this plugin version 0.1.0, PyCharm treats pydantic.dataclasses.dataclass as third-party dataclass.</li>
</li>
</ul>
</li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions src/com/koxudaxi/pydantic/PydanticConfigPanel.form
Expand Up @@ -71,11 +71,11 @@
</grid>
</constraints>
<properties>
<contentType value="text/html"/>
<contentType value="text/plain"/>
<editable value="false"/>
<font/>
<opaque value="false"/>
<text value="&lt;html&gt;&#10; &lt;head&gt;&#10;&#10; &lt;/head&gt;&#10; &lt;body&gt;&#10; &lt;p&gt;&#10; &#10; &lt;/p&gt;&#10; &lt;/body&gt;&#10;&lt;/html&gt;&#10;"/>
<text value=""/>
</properties>
</component>
</children>
Expand Down
45 changes: 38 additions & 7 deletions src/com/koxudaxi/pydantic/PydanticConfigPanel.java
@@ -1,10 +1,19 @@
package com.koxudaxi.pydantic;

import com.intellij.ide.BrowserUtil;
import com.intellij.ide.plugins.newui.EmptyCaret;
import com.intellij.openapi.project.Project;
import com.intellij.ui.ColorUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;

import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.text.EditorKit;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;

import static com.intellij.util.ui.JBUI.CurrentTheme.NewClassDialog.panelBackground;

public class PydanticConfigPanel {

Expand All @@ -14,13 +23,7 @@ public class PydanticConfigPanel {
this.initTypedCheckBox.setSelected(pydanticConfigService.getInitTyped());
this.warnUntypedFieldsCheckBox.setSelected(pydanticConfigService.getWarnUntypedFields());

this.textPane1.setText("<p style=\"font-family:Arial, Helvetica, sans-serif;font-size:130%;\">" +
"See <a href=\"https://koxudaxi.github.io/pydantic-pycharm-plugin/\">documentation</a> for more details.</p>");
this.textPane1.addHyperlinkListener(e -> {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
BrowserUtil.browse(e.getURL());
}
});
setHyperlinkHtml(this.textPane1, "See <a href=\"https://koxudaxi.github.io/pydantic-pycharm-plugin/\">documentation</a> for more details.</p>");
}

private JPanel configPanel;
Expand All @@ -41,4 +44,32 @@ public Boolean getWarnUntypedFields() {
public JPanel getConfigPanel() {
return configPanel;
}

private void setHyperlinkHtml(JTextPane jTextPane, String html) {

jTextPane.setContentType("text/html");
jTextPane.setEditable(false);
jTextPane.setEditorKit(UIUtil.getHTMLEditorKit());

EditorKit kit = jTextPane.getEditorKit();
if (kit instanceof HTMLEditorKit) {
StyleSheet css = ((HTMLEditorKit) kit).getStyleSheet();

css.addRule("a, a:link {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkColor()) + ";}");
css.addRule("a:visited {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkVisitedColor()) + ";}");
css.addRule("a:hover {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkHoverColor()) + ";}");
css.addRule("a:active {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkPressedColor()) + ";}");
css.addRule("body {background-color:#" + ColorUtil.toHex(JBUI.CurrentTheme.DefaultTabs.background()) + ";}");
}

jTextPane.setText(html);
jTextPane.setCaret(EmptyCaret.INSTANCE);
jTextPane.setBackground(UIUtil.TRANSPARENT_COLOR);
jTextPane.setOpaque(false);
jTextPane.addHyperlinkListener(e -> {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
BrowserUtil.browse(e.getURL());
}
});
}
}

0 comments on commit d78089d

Please sign in to comment.