11package com.emberjs.gts
22
3+ import TemplateLintState
34import com.dmarcotte.handlebars.file.HbFileViewProvider
45import com.emberjs.glint.GlintTypeScriptService
56import com.emberjs.icons.EmberIcons
67import com.intellij.CommonBundle
78import com.intellij.ide.actionsOnSave.ActionOnSaveBackedByOwnConfigurable
89import com.intellij.ide.actionsOnSave.ActionOnSaveContext
10+ import com.intellij.ide.actionsOnSave.ActionsOnSaveConfigurable
911import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterField
1012import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterRef
1113import com.intellij.javascript.nodejs.util.JSLinterPackage
@@ -27,12 +29,17 @@ import com.intellij.psi.PsiFile
2729import com.intellij.reference.SoftReference
2830import com.intellij.ui.components.ActionLink
2931import com.intellij.util.containers.ContainerUtil
32+ import com.intellij.util.ui.FormBuilder
33+ import com.intellij.util.ui.SwingHelper
3034import org.jdom.Element
3135import org.jetbrains.annotations.NonNls
3236import org.jetbrains.annotations.PropertyKey
37+ import java.awt.Component
3338import java.lang.ref.Reference
3439import java.util.*
40+ import javax.swing.BorderFactory
3541import javax.swing.JComponent
42+ import javax.swing.JPanel
3643
3744
3845class GLintBundle {
@@ -88,7 +95,7 @@ data class GlintState(
8895 companion object {
8996 val DEFAULT = GlintState (
9097 NodeJsInterpreterRef .createProjectRef(),
91- NodePackage (" @glint/core " ))
98+ NodePackage (" " ))
9299 }
93100}
94101
@@ -97,8 +104,13 @@ data class GlintState(
97104@State(name = " GlintConfiguration" , storages = [Storage (" emberLinters/glint.xml" )])
98105class GlintConfiguration (project : Project ) : JSLinterConfiguration<GlintState>(project) {
99106 private val myPackage: JSLinterPackage = JSLinterPackage (project, " @glint/core" )
107+
108+ public fun getPackage (): JSLinterPackage {
109+ return myPackage
110+ }
111+
100112 override fun savePrivateSettings (state : GlintState ) {
101- this .myPackage.force(NodePackageRef .create(state.interpreterRef.referenceName ))
113+ this .myPackage.force(NodePackageRef .create(state.templateLintPackage ))
102114 }
103115
104116 override fun loadPrivateSettings (state : GlintState ): GlintState {
@@ -135,6 +147,10 @@ class GlintConfiguration(project: Project) : JSLinterConfiguration<GlintState>(p
135147 return parent
136148 }
137149
150+ companion object {
151+ fun getInstance (project : Project ) = getInstance(project, GlintConfiguration ::class .java)
152+ }
153+
138154}
139155
140156
@@ -152,24 +168,39 @@ class GlintConfigurable(project: Project, fullModeDialog: Boolean = false) :
152168 return ID
153169 }
154170
155- override fun createView (): JSLinterView <GlintState > {
156- return object : JSLinterView <GlintState > {
171+ override fun createView (): JSLinterBaseView <GlintState > {
172+ return object : JSLinterBaseView <GlintState >() {
157173 private val myNodeInterpreterField: NodeJsInterpreterField = NodeJsInterpreterField (project, false )
158174 private val myTemplateLintPackageField: NodePackageField = NodePackageField (myNodeInterpreterField,
159175 " @glint/core"
160176 )
161- var state: ExtendedLinterState <GlintState > = ExtendedLinterState (false , GlintState (
162- myNodeInterpreterField.interpreterRef, myTemplateLintPackageField.selectedRef.constantPackage!! ))
163- override fun getComponent (): JComponent ? {
164- return null
177+
178+ private val panel = FormBuilder .createFormBuilder()
179+ .setHorizontalGap(10 )
180+ .setVerticalGap(4 )
181+ .setFormLeftIndent(10 )
182+ .addLabeledComponent(GLintBundle .message(" g.lint.node.path.label" ), myNodeInterpreterField)
183+ .addLabeledComponent(GLintBundle .message(" g.lint.package.label" ), this .myTemplateLintPackageField)
184+ .panel
185+
186+ private val myCenterPanel: JPanel = SwingHelper .wrapWithHorizontalStretch(panel).apply {
187+ this .border = BorderFactory .createEmptyBorder(5 , 0 , 0 , 0 )
188+ }
189+
190+ override fun createCenterComponent (): Component {
191+ return myCenterPanel
165192 }
166193
167- override fun getExtendedState (): ExtendedLinterState <GlintState > {
168- return state
194+ override fun getState (): GlintState {
195+ return GlintState (
196+ myNodeInterpreterField.interpreterRef,
197+ myTemplateLintPackageField.selected
198+ )
169199 }
170200
171- override fun setExtendedState (p0 : ExtendedLinterState <GlintState >) {
172- state = p0
201+ override fun setState (state : GlintState ) {
202+ myNodeInterpreterField.interpreterRef = state.interpreterRef
203+ myTemplateLintPackageField.selected = state.nodePackageRef.constantPackage ? : GlintState .DEFAULT .nodePackageRef.constantPackage!!
173204 }
174205
175206 }
0 commit comments