1+ package org.polyfrost.intelliprocessor.config
2+
3+ import com.intellij.openapi.options.Configurable
4+ import javax.swing.BoxLayout
5+ import javax.swing.JCheckBox
6+ import javax.swing.JComponent
7+ import javax.swing.JLabel
8+ import javax.swing.JPanel
9+ import javax.swing.border.EtchedBorder
10+ import javax.swing.border.TitledBorder
11+
12+ class PluginConfigurable : Configurable {
13+ private lateinit var panel: JPanel
14+ private lateinit var foldInactiveBlocksByDefaultCheckbox: JCheckBox
15+ private lateinit var foldAllBlocksByDefaultCheckbox: JCheckBox
16+ private lateinit var inspectionHighlightNonIndentedNestedIfsCheckbox: JCheckBox
17+ private lateinit var inspectionHighlightCommentsNotMatchingIfIndentsCheckbox: JCheckBox
18+ private lateinit var hideUnmatchedVersionsCheckbox: JCheckBox
19+ private lateinit var addPreprocessorCommentOnEnterCheckbox: JCheckBox
20+
21+
22+ override fun getDisplayName (): String = " IntelliProcessor"
23+
24+ override fun createComponent (): JComponent {
25+
26+ // Setup components
27+
28+ fun <J : JComponent > J.tooltip (str : String ): J = apply { toolTipText = str }
29+
30+ foldInactiveBlocksByDefaultCheckbox = JCheckBox (" Fold inactive preprocessor blocks by default" )
31+ .tooltip(" Automatically folds preprocessor blocks that are conditionally inactive. (E.G. 'MC>=1.20' blocks in a 1.19 file)" )
32+
33+ foldAllBlocksByDefaultCheckbox = JCheckBox (" Fold all preprocessor blocks by default" ).apply {
34+ addChangeListener { event ->
35+ // Disable the "fold inactive blocks" option if "fold all blocks" is enabled
36+ foldInactiveBlocksByDefaultCheckbox.isEnabled = ! (event.source as JCheckBox ).isSelected
37+ }
38+ }
39+
40+ inspectionHighlightNonIndentedNestedIfsCheckbox =
41+ JCheckBox (" Highlight non-indented nested \" if\" preprocessor directives (Code clarity)" )
42+ .tooltip(
43+ " Highlights nested \" if\" preprocessor directives that are not indented more than their enclosing preprocessor block.\n " +
44+ " \n This does not break preprocessing, but can help improve code clarity by visually indicating the nested structure of preprocessor blocks."
45+ )
46+
47+ inspectionHighlightCommentsNotMatchingIfIndentsCheckbox =
48+ JCheckBox (" Highlight preprocessor comments not matching their \" if\" 's indent (Code clarity)" )
49+ .tooltip(
50+ " Highlights preprocessor comments whose indent does not match the indent of the corresponding \" if\" directive.\n " +
51+ " \n This does not break preprocessing, but can help improve code clarity by visually linking preprocessor comments to their corresponding \" if\" directives."
52+ )
53+
54+ hideUnmatchedVersionsCheckbox = JCheckBox (" Hide results that do not meet preprocessor conditions at the caret" )
55+ .tooltip(" Hides version results in the 'Jump To Pre-Processed File' dialog that do not match the current file's preprocessor conditions found at the caret position." )
56+
57+ addPreprocessorCommentOnEnterCheckbox = JCheckBox (" Add preprocessor comment '//$$ ' automatically to new lines in a disabled preprocessor block" )
58+ .tooltip(" When pressing Enter inside a disabled preprocessor block, automatically adds a preprocessor comment '//$$ ' to the new line." )
59+
60+ // Arrange components
61+
62+ fun titledBlock (str : String , block : JPanel .() -> Unit ): JPanel = JPanel ().apply {
63+ border = TitledBorder (EtchedBorder (),str)
64+ layout = BoxLayout (this , BoxLayout .Y_AXIS )
65+ block()
66+ }
67+
68+ panel = JPanel ()
69+
70+ panel.apply {
71+ layout = BoxLayout (this , BoxLayout .Y_AXIS )
72+
73+ add(titledBlock(" Folding" ) {
74+ add(foldAllBlocksByDefaultCheckbox)
75+ add(foldInactiveBlocksByDefaultCheckbox)
76+ })
77+
78+ add(titledBlock(" Formatting" ) {
79+ add(inspectionHighlightNonIndentedNestedIfsCheckbox)
80+ add(inspectionHighlightCommentsNotMatchingIfIndentsCheckbox)
81+ })
82+
83+ add(titledBlock(" Jump To Pre-Processed File Action" ) {
84+ add(hideUnmatchedVersionsCheckbox)
85+ })
86+
87+ add(titledBlock(" Misc" ) {
88+ add(addPreprocessorCommentOnEnterCheckbox)
89+ })
90+
91+ add(titledBlock(" Info" ) {
92+ add(JLabel (" The keybinds can be configured from: Keymap > Plugins > IntelliProcessor" ))
93+ })
94+ }
95+
96+ reset()
97+ return panel
98+ }
99+
100+ override fun isModified (): Boolean =
101+ foldAllBlocksByDefaultCheckbox.isSelected != PluginSettings .instance.foldAllBlocksByDefault
102+ || foldInactiveBlocksByDefaultCheckbox.isSelected != PluginSettings .instance.foldInactiveBlocksByDefault
103+ || inspectionHighlightNonIndentedNestedIfsCheckbox.isSelected != PluginSettings .instance.inspectionHighlightNonIndentedNestedIfs
104+ || inspectionHighlightCommentsNotMatchingIfIndentsCheckbox.isSelected != PluginSettings .instance.inspectionHighlightCommentsNotMatchingIfIndents
105+ || hideUnmatchedVersionsCheckbox.isSelected != PluginSettings .instance.hideUnmatchedVersions
106+ || addPreprocessorCommentOnEnterCheckbox.isSelected != PluginSettings .instance.addPreprocessorCommentOnEnter
107+
108+ override fun apply () {
109+ PluginSettings .instance.foldAllBlocksByDefault = foldAllBlocksByDefaultCheckbox.isSelected
110+ PluginSettings .instance.foldInactiveBlocksByDefault = foldInactiveBlocksByDefaultCheckbox.isSelected
111+ PluginSettings .instance.inspectionHighlightNonIndentedNestedIfs = inspectionHighlightNonIndentedNestedIfsCheckbox.isSelected
112+ PluginSettings .instance.inspectionHighlightCommentsNotMatchingIfIndents = inspectionHighlightCommentsNotMatchingIfIndentsCheckbox.isSelected
113+ PluginSettings .instance.hideUnmatchedVersions = hideUnmatchedVersionsCheckbox.isSelected
114+ PluginSettings .instance.addPreprocessorCommentOnEnter = addPreprocessorCommentOnEnterCheckbox.isSelected
115+ }
116+
117+ override fun reset () {
118+ foldAllBlocksByDefaultCheckbox.isSelected = PluginSettings .instance.foldAllBlocksByDefault
119+ foldInactiveBlocksByDefaultCheckbox.isSelected = PluginSettings .instance.foldInactiveBlocksByDefault
120+ inspectionHighlightNonIndentedNestedIfsCheckbox.isSelected = PluginSettings .instance.inspectionHighlightNonIndentedNestedIfs
121+ inspectionHighlightCommentsNotMatchingIfIndentsCheckbox.isSelected = PluginSettings .instance.inspectionHighlightCommentsNotMatchingIfIndents
122+ hideUnmatchedVersionsCheckbox.isSelected = PluginSettings .instance.hideUnmatchedVersions
123+ addPreprocessorCommentOnEnterCheckbox.isSelected = PluginSettings .instance.addPreprocessorCommentOnEnter
124+ }
125+ }
0 commit comments