@@ -6,18 +6,22 @@ import com.intellij.openapi.application.ApplicationManager
66import com.intellij.openapi.module.Module
77import com.intellij.openapi.project.Project
88import com.intellij.openapi.ui.ComboBox
9+ import com.intellij.openapi.ui.TextFieldWithBrowseButton
910import com.intellij.openapi.ui.ValidationInfo
1011import com.intellij.openapi.vfs.VirtualFile
1112import com.intellij.platform.ProjectGeneratorPeer
1213import com.intellij.psi.PsiManager
1314import com.intellij.ui.TextAccessor
1415import com.intellij.ui.dsl.builder.Cell
1516import com.intellij.ui.dsl.builder.panel
16- import com.intellij.ui.dsl.builder.whenTextChangedFromUi
1717import il.co.sysbind.intellij.moodledev.moodle.Component
1818import il.co.sysbind.intellij.moodledev.project.MoodleProjectSettings
19+ import java.awt.event.ActionListener
1920import javax.swing.Icon
2021import javax.swing.JComponent
22+ import javax.swing.JTextField
23+ import javax.swing.event.DocumentEvent
24+ import javax.swing.event.DocumentListener
2125
2226class MoodlePluginGenerator : WebProjectTemplate <MoodlePluginGeneratorSettings >() {
2327 override fun getName (): String {
@@ -65,23 +69,48 @@ class MoodlePluginGenerator : WebProjectTemplate<MoodlePluginGeneratorSettings>(
6569 private inner class MoodlePluginGeneratorPeer : ProjectGeneratorPeer <MoodlePluginGeneratorSettings > {
6670 private var myContentRoot: TextAccessor ? = null
6771 private lateinit var myPluginType : Cell <ComboBox <String >>
68- override fun getComponent (): JComponent {
72+ override fun getComponent (
73+ myLocationField : TextFieldWithBrowseButton ,
74+ checkValid : Runnable
75+ ): JComponent {
6976 val moodleTree = Component ()
77+
7078 val myPanel = panel {
71- row(" Plugin Type:" ){
72- myPluginType = comboBox(moodleTree.getPluginTypes().toList())
79+ row(" Plugin Type:" ) {
80+ val pluginTypeComboBox = comboBox(moodleTree.getPluginTypes().toList())
81+ pluginTypeComboBox.component.addActionListener(ActionListener {
82+ // Call checkValid whenever plugin type changes
83+ checkValid.run ()
84+ })
7385 }
7486 row(" Plugin Name:" ) {
75- textField().whenTextChangedFromUi {
76- myContentRoot!! .text = myContentRoot!! .text.substringBeforeLast(' /' ) +
77- " /" + moodleTree.getPluginPath(myPluginType.component.item) + " /" + it
78- }
87+ val pluginNameTextField = JTextField ()
88+ pluginNameTextField.document.addDocumentListener(object : DocumentListener {
89+ override fun insertUpdate (e : DocumentEvent ? ) = updateLocationField(pluginNameTextField, moodleTree)
90+ override fun removeUpdate (e : DocumentEvent ? ) = updateLocationField(pluginNameTextField, moodleTree)
91+ override fun changedUpdate (e : DocumentEvent ? ) = updateLocationField(pluginNameTextField, moodleTree)
92+ })
7993 }
8094 }
8195
96+ myLocationField.textField.document.addDocumentListener(object : DocumentListener {
97+ override fun insertUpdate (e : DocumentEvent ? ) = checkValid.run ()
98+ override fun removeUpdate (e : DocumentEvent ? ) = checkValid.run ()
99+ override fun changedUpdate (e : DocumentEvent ? ) = checkValid.run ()
100+ })
101+
82102 return myPanel
83103 }
84104
105+ private fun updateLocationField (textField : JTextField , moodleTree : Component ) {
106+ if (myContentRoot != null && myPluginType.component.selectedItem != null ) {
107+ val pluginType = myPluginType.component.selectedItem.toString()
108+ val updatedPath = myContentRoot!! .text.substringBeforeLast(' /' ) +
109+ " /" + moodleTree.getPluginPath(pluginType) + " /" + textField.text
110+ myContentRoot!! .text = updatedPath
111+ }
112+ }
113+
85114 override fun buildUI (settingsStep : SettingsStep ) {
86115 val field = settingsStep.moduleNameLocationSettings
87116 if (field != null ) {
0 commit comments