Skip to content

Commit 238aca7

Browse files
committed
.
1 parent 24ee43c commit 238aca7

File tree

4 files changed

+140
-10
lines changed

4 files changed

+140
-10
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
text="Greeting"
5757
description="Greeting menu">
5858
<add-to-group group-id="MainMenu" anchor="last"/>
59-
<action id="Myplugin.Textboxes" class="HelloAction" text="Hello" description="Says hello"/>
59+
<action id="io.plugin.tsnode.action.HelloAction" class="io.plugin.tsnode.action.HelloAction" text="Hello" description="Says hello"/>
6060
</group>
6161
</actions>
6262

src/io/plugin/tsnode/action/HelloAction.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package io.plugin.tsnode.action
2+
13
import com.intellij.openapi.actionSystem.AnAction
24
import com.intellij.openapi.actionSystem.AnActionEvent
35
import com.intellij.openapi.actionSystem.PlatformDataKeys

src/io/plugin/tsnode/execution/TsConfigurationEditor.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,21 @@ class TsConfigurationEditor(runConfig: TsRunConfiguration, project: Project) : _
2727

2828
val nodeJsInterpreterField = TsForm.LazyNodeJsInterpreterField("Node &interpreter:", project)
2929

30+
var interpreterRef
31+
get() = nodeJsInterpreterField.interpreterRef
32+
set(value)
33+
{
34+
nodeJsInterpreterField.interpreterRef = value
35+
}
36+
3037
val nodeOptionsField = TsForm.LazyRawCommandLineEditor("Node &options:")
3138

3239
val tsnodePackageField = TsForm.LazyNodePackageField("&TypeScript Node package:", nodeJsInterpreterField, "ts-node")
3340

34-
private var typescriptOptionsField = createTypeScriptOptionsField()
41+
val typescriptOptionsField = TsForm.LazyRawCommandLineEditor("E&xtra ts-node options:")
42+
43+
//private var typescriptOptionsField = createTypeScriptOptionsField()
44+
3545
private var typescriptConfigFileField = createTypeScriptConfigFileField()
3646

3747
private var typescriptFileField = createTypeScriptFileField()
@@ -51,12 +61,12 @@ class TsConfigurationEditor(runConfig: TsRunConfiguration, project: Project) : _
5161
.addLabeledComponent(nodeJsInterpreterField)
5262
.addLabeledComponent(nodeOptionsField)
5363

54-
.addLabeledComponent("&Working directory:", workingDirectoryField)
64+
.addLabeledComponent(workingDirectoryField)
5565

5666
.addLabeledComponent(tsnodePackageField)
5767

5868
.addLabeledComponent("ts&config file:", typescriptConfigFileField)
59-
.addLabeledComponent("E&xtra ts-node options:", typescriptOptionsField)
69+
.addLabeledComponent(typescriptOptionsField)
6070

6171
.addLabeledComponent("TypeScript &file:", typescriptFileField)
6272
.addLabeledComponent("&Application parameters:", typescriptFileOptionsField)

src/io/plugin/tsnode/lib/TsForm.kt

Lines changed: 124 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton
99
import com.intellij.openapi.util.text.StringUtil
1010
import com.intellij.ui.RawCommandLineEditor
1111
import com.intellij.ui.TextAccessor
12+
import com.intellij.util.ui.ComponentWithEmptyText
1213
import com.intellij.util.ui.FormBuilder
14+
import com.intellij.util.ui.StatusText
1315
import com.intellij.util.ui.SwingHelper
1416
import javax.swing.JComponent
17+
import javax.swing.JTextField
1518

1619
class 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

Comments
 (0)