Skip to content

Commit

Permalink
Display links to popular external rulesets, ktlint, and ktlint plugin…
Browse files Browse the repository at this point in the history
… page (#518)

Closes #514
  • Loading branch information
paul-dingemans committed May 8, 2024
1 parent 537d4b7 commit d44c53d
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 17 deletions.
60 changes: 49 additions & 11 deletions plugin/src/main/kotlin/com/nbadal/ktlint/KtlintConfigForm.form
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.nbadal.ktlint.KtlintConfigForm">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="9" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="13" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="757" height="400"/>
Expand All @@ -10,7 +10,7 @@
<children>
<vspacer id="f22cd">
<constraints>
<grid row="7" column="1" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="9" column="1" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="909eb" class="javax.swing.JLabel">
Expand Down Expand Up @@ -82,14 +82,6 @@
<toolTipText resource-bundle="strings" key="disabledModeTooltip"/>
</properties>
</component>
<component id="15acd" class="javax.swing.JButton" binding="githubButton">
<constraints>
<grid row="8" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="strings" key="githubButton"/>
</properties>
</component>
<component id="30741" class="javax.swing.JLabel" binding="formatLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
Expand Down Expand Up @@ -122,7 +114,9 @@
</component>
<component id="eff2f" class="javax.swing.JCheckBox" binding="attachToIntellijFormat">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="289" height="30"/>
</grid>
</constraints>
<properties>
<enabled value="true"/>
Expand All @@ -134,6 +128,50 @@
<visible value="true"/>
</properties>
</component>
<component id="3cbef" class="javax.swing.JLabel" binding="popularExternalRulesetsLabel">
<constraints>
<grid row="7" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="289" height="20"/>
</grid>
</constraints>
<properties>
<text resource-bundle="strings" key="popularExternalRulesetsLabel"/>
</properties>
</component>
<component id="c5efd" class="javax.swing.JLabel" binding="ktlintProjectLabel">
<constraints>
<grid row="11" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="strings" key="ktlintProjectLabel"/>
<toolTipText resource-bundle="strings" key="ktlintProjectTip"/>
</properties>
</component>
<component id="72e8c" class="javax.swing.JLabel">
<constraints>
<grid row="10" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="1" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="strings" key="feedbackLabel"/>
</properties>
</component>
<component id="aa1c5" class="javax.swing.JLabel" binding="ktlintPluginProjectLabel">
<constraints>
<grid row="12" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="strings" key="ktlintPluginProjectLabel"/>
<toolTipText resource-bundle="strings" key="ktlintPluginProjectTip"/>
</properties>
</component>
<component id="8cc62" class="javax.swing.JLabel" binding="jetpackComposeLabel">
<constraints>
<grid row="8" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Jetpack Compose" noi18n="true"/>
</properties>
</component>
<component id="147a1" class="javax.swing.JCheckBox" binding="formatOnSave">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
Expand Down
39 changes: 33 additions & 6 deletions plugin/src/main/kotlin/com/nbadal/ktlint/KtlintConfigForm.kt
Expand Up @@ -13,10 +13,12 @@ import com.nbadal.ktlint.KtlintMode.DISTRACT_FREE
import com.nbadal.ktlint.KtlintMode.MANUAL
import com.nbadal.ktlint.KtlintMode.NOT_INITIALIZED
import com.pinterest.ktlint.ruleset.standard.KtlintRulesetVersion
import java.awt.Cursor
import java.awt.Desktop
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.net.URI
import java.util.Objects
import javax.swing.JButton
import javax.swing.JCheckBox
import javax.swing.JComboBox
import javax.swing.JComponent
Expand All @@ -41,7 +43,10 @@ class KtlintConfigForm(
private lateinit var attachToIntellijFormat: JCheckBox
private lateinit var externalJarPaths: TextFieldWithBrowseButton
private lateinit var baselinePath: TextFieldWithBrowseButton
private lateinit var githubButton: JButton
private lateinit var popularExternalRulesetsLabel: JLabel
private lateinit var jetpackComposeLabel: JLabel
private lateinit var ktlintProjectLabel: JLabel
private lateinit var ktlintPluginProjectLabel: JLabel

fun createUIComponents() {
// Stub.
Expand Down Expand Up @@ -77,16 +82,31 @@ class KtlintConfigForm(

// If we're able to launch the browser, show the GitHub button!
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
githubButton.addActionListener {
Desktop.getDesktop().browse(URI("https://github.com/nbadal/ktlint-intellij-plugin"))
}
jetpackComposeLabel.setLinkLabel(jetpackComposeUri)
ktlintProjectLabel.setLinkLabel(ktlintProjectUri)
ktlintPluginProjectLabel.setLinkLabel(ktlintPluginProjectUri)
} else {
githubButton.isVisible = false
popularExternalRulesetsLabel.isVisible = false
jetpackComposeLabel.isVisible = false
ktlintPluginProjectLabel.isVisible = false
}

return mainPanel
}

private fun JLabel.setLinkLabel(uri: URI) {
setText("<html><a href=\"\">$text</a></html>")
setCursor(Cursor(Cursor.HAND_CURSOR))
addMouseListener(
object : MouseAdapter() {
@Override
override fun mouseClicked(e: MouseEvent?) {
Desktop.getDesktop().browse(uri)
}
},
)
}

fun apply() {
ktlintConfigStorage.ktlintMode = ktlintMode
ktlintConfigStorage.ktlintRulesetVersion = ktlintRulesetVersion
Expand Down Expand Up @@ -161,4 +181,11 @@ class KtlintConfigForm(
formatOnSave.isVisible = distractFreeMode.isSelected
attachToIntellijFormat.isVisible = manualMode.isSelected
}

private companion object {
val jetpackComposeUri =
URI("https://mrmans0n.github.io/compose-rules/ktlint/#using-with-ktlint-cli-or-the-ktlint-unofficial-intellij-plugin")
val ktlintPluginProjectUri = URI("https://github.com/nbadal/ktlint-intellij-plugin/issues")
val ktlintProjectUri = URI("https://github.com/pinterest/ktlint/issues")
}
}
6 changes: 6 additions & 0 deletions plugin/src/main/resources/strings.properties
Expand Up @@ -6,13 +6,19 @@ disabledMode=D&isabled
disabledModeTooltip=Disable ktlint entirely for this project.
distractFreeModeLabel=&Distract free (recommended)
distractFreeModeTooltip=Run ktlint format automatically. Hide ktlint violations that can be autocorrected. Recommended whenever ktlint is configured to your liking, or whenever ktlint format runs in build pipeline.
feedbackLabel=Feedback is welcomed via links below:
formatLabel=Format
formatOnSaveLabel=on &save
formatOnSaveToolTip=Format with KtLint on each save of the file
githubButton=Issues / &Feedback / Source
ktlintPluginProjectLabel=Ktlint Intellij Plugin Project
ktlintPluginProjectTip=The Ktlint Intellij Plugin project provides integration with Ktlint. Report problems regarding the UI and integration with Ktlint in this project.
ktlintProjectLabel=Ktlint Project
ktlintProjectTip=The Ktlint project provides the standard rules and the rule engine for linting and formatting Kotlin code. Report problems regarding linting and formatting here.
manualModeLabel=&Manual
manualModeTooltip=Displays all ktlint violations including violations that can be autocorrected. Ktlint format is never executed automatically. Ktlint format can be run manually.
modeLabel=Mode
popularExternalRulesetsLabel=Popular (external) rulesets:
rulesetLabel=Ruleset JARs:
rulesetToolTip=External ruleset(s). Note that each ruleset needs to be enabled/disabled via the '.editorconfig'.
rulesetVersionLabel=Ruleset version

0 comments on commit d44c53d

Please sign in to comment.