@@ -9,12 +9,17 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton
99import com.intellij.openapi.util.text.StringUtil
1010import com.intellij.ui.RawCommandLineEditor
1111import com.intellij.ui.TextAccessor
12+ import com.intellij.util.ui.ComponentWithEmptyText
1213import com.intellij.util.ui.FormBuilder
14+ import com.intellij.util.ui.StatusText
1315import com.intellij.util.ui.SwingHelper
1416import javax.swing.JComponent
17+ import javax.swing.JTextField
1518
1619class TsForm
1720{
21+ val LOG = TsLog (javaClass)
22+
1823 open class TsFormBuilder : com.intellij.util.ui.FormBuilder ()
1924 {
2025 fun append (field : Field <* >) = field.appendTo(this ) as TsFormBuilder
@@ -43,8 +48,14 @@ class TsForm
4348 override abstract fun toString (): String
4449 }
4550
46- open class TextField <Comp : TextAccessor >(override val field : Comp , override val label : String ) : Field<Comp>
51+ open class TextField <Comp : TextAccessor >(override val field : Comp , override val label : String , options : Options ? = null ) : Field<Comp>
4752 {
53+ companion object Options
54+ {
55+ var emptyText: String? = null
56+ var dialogCaption: String? = null
57+ }
58+
4859 var text
4960 get() = this .field.text
5061 set(value)
@@ -57,7 +68,7 @@ class TsForm
5768
5869 open class TextFieldWithBrowseSingleFolderButton <Comp : com.intellij.openapi.ui.TextFieldWithBrowseButton >(
5970 override val field : Comp
60- , override val label : String
71+ , override val label : String , options : Options ? = null
6172 ) : TextField<Comp>(field, label)
6273 {
6374 var defaultFileChooserDescriptor: FileChooserDescriptor ? = null
@@ -70,6 +81,34 @@ class TsForm
7081 {
7182 installFileCompletionAndBrowseDialog(defaultProject, defaultBrowseDialogTitle, defaultFileChooserDescriptor)
7283 }
84+
85+ if (
86+ (field is com.intellij.openapi.ui.TextFieldWithBrowseButton )
87+ || (field is com.intellij.ui.RawCommandLineEditor )
88+ )
89+ {
90+ val textField: JTextField ? = field.textField
91+
92+ if (textField != null && textField is ComponentWithEmptyText )
93+ {
94+ val emptyText = textField.emptyText
95+
96+ /* *
97+ * @FIXME 不知道為什麼要寫成這樣才能成功更新文字
98+ */
99+ if (StringUtil .isEmptyOrSpaces(emptyText?.text))
100+ {
101+ if (! StringUtil .isEmptyOrSpaces(options?.emptyText))
102+ {
103+ emptyText?.text = options?.emptyText as String
104+ }
105+ else if (! StringUtil .isEmptyOrSpaces(label))
106+ {
107+ emptyText?.text = Util .stripTitle(label)
108+ }
109+ }
110+ }
111+ }
73112 }
74113
75114 fun createFileChooserDescriptor (fn : FileChooserDescriptor ? ): FileChooserDescriptor
@@ -94,15 +133,74 @@ class TsForm
94133
95134 return this
96135 }
136+
137+ val textField
138+ get() = field.textField
139+
140+ val emptyText: StatusText ?
141+ get()
142+ {
143+ val field = this .field
144+
145+ if (field.textField != null && field.textField is ComponentWithEmptyText )
146+ {
147+ val emptyText = field.textField as ComponentWithEmptyText
148+
149+ return emptyText?.emptyText
150+ }
151+
152+ return null
153+ }
97154 }
98155
99- open class RawCommandLineEditorField <Comp : RawCommandLineEditor >(override val field : Comp , override val label : String ) : TextField<Comp>(field, label)
156+ open class RawCommandLineEditorField <Comp : RawCommandLineEditor >(override val field : Comp , override val label : String , options : Options ? = null ) : TextField<Comp>(field, label)
100157 {
158+ // val LOG = TsLog(javaClass)
159+
101160 init
102161 {
103- if (StringUtil .isEmptyOrSpaces(field.dialogCaption))
162+ val text = if (StringUtil .isEmptyOrSpaces(field.dialogCaption!! ))
163+ Util .stripTitle(
164+ options?.dialogCaption
165+ ? : label
166+ )
167+ else field.dialogCaption as String
168+
169+ field.dialogCaption = text
170+
171+ /*
172+ if (textField is ExpandableTextField)
104173 {
105- field.dialogCaption = Util .stripTitle(label)
174+ textField?.putClientProperty("monospaced", false)
175+ }
176+ */
177+
178+ if (
179+ (field is com.intellij.openapi.ui.TextFieldWithBrowseButton )
180+ || (field is com.intellij.ui.RawCommandLineEditor )
181+ )
182+ {
183+ val textField: JTextField ? = field.textField
184+
185+ if (textField != null && textField is ComponentWithEmptyText )
186+ {
187+ val emptyText = textField.emptyText
188+
189+ /* *
190+ * @FIXME 不知道為什麼要寫成這樣才能成功更新文字
191+ */
192+ if (StringUtil .isEmptyOrSpaces(emptyText?.text))
193+ {
194+ if (! StringUtil .isEmptyOrSpaces(options?.emptyText))
195+ {
196+ emptyText?.text = options?.emptyText as String
197+ }
198+ else if (! StringUtil .isEmptyOrSpaces(label))
199+ {
200+ emptyText?.text = Util .stripTitle(label)
201+ }
202+ }
203+ }
106204 }
107205 }
108206
@@ -112,6 +210,24 @@ class TsForm
112210 {
113211 this .field.dialogCaption = value
114212 }
213+
214+ val textField
215+ get() = field.textField
216+
217+ val emptyText: StatusText ?
218+ get()
219+ {
220+ val field = this .field
221+
222+ if (field.textField != null && field.textField is ComponentWithEmptyText )
223+ {
224+ val emptyText = field.textField as ComponentWithEmptyText
225+
226+ return emptyText?.emptyText
227+ }
228+
229+ return null
230+ }
115231 }
116232
117233 open class NodePackageField <Comp : com.intellij.javascript.nodejs.util.NodePackageField >(override val field : Comp , override val label : String ) : Field<Comp>
@@ -185,12 +301,14 @@ class TsForm
185301
186302 fun LazyTextFieldWithBrowseSingleFolderButton (label : String , fieldFactory : com.intellij.openapi.ui.TextFieldWithBrowseButton ) = TextField (fieldFactory, label)
187303
188- fun LazyTextFieldWithBrowseSingleFolderButton (label : String , project : Project , browseDialogTitle : String , fieldFactory : com.intellij.openapi.ui.TextFieldWithBrowseButton = Util .createWorkingDirectoryField(project, browseDialogTitle)) = TextFieldWithBrowseSingleFolderButton (fieldFactory, label)
304+ fun LazyTextFieldWithBrowseSingleFolderButton (label : String , project : Project , browseDialogTitle : String , fieldFactory : com.intellij.openapi.ui.TextFieldWithBrowseButton = Util .createWorkingDirectoryField(project, browseDialogTitle)) = TsForm . TextFieldWithBrowseSingleFolderButton (fieldFactory, label)
189305
190306 fun LazyTextFieldWithBrowseSingleFolderButton (label : String , project : Project , fieldFactory : com.intellij.openapi.ui.TextFieldWithBrowseButton = Util .createWorkingDirectoryField(project, label)) = TextFieldWithBrowseSingleFolderButton (fieldFactory, label)
191307
192308 fun LazyRawCommandLineEditor (label : String , fieldFactory : RawCommandLineEditor = com.intellij.ui.RawCommandLineEditor ()) = RawCommandLineEditorField (fieldFactory, label)
193309
310+ fun LazyRawCommandLineEditor (label : String , fieldFactory : RawCommandLineEditor = com.intellij.ui.RawCommandLineEditor (), options : TextField .Options ? = null) = RawCommandLineEditorField (fieldFactory, label, options)
311+
194312 fun LazyNodePackageField (label : String , interpreterField : com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterField , packageName : String , fieldFactory : com.intellij.javascript.nodejs.util.NodePackageField = com.intellij.javascript.nodejs.util.NodePackageField (interpreterField, packageName)) = NodePackageField (fieldFactory, label)
195313
196314 fun LazyNodePackageField (
0 commit comments