Skip to content

Commit 3dda2eb

Browse files
committed
Fix bug #114
Optimize usage experience with `Tab` keyboard to switch from class name input to json content input
1 parent 0fb665e commit 3dda2eb

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/main/kotlin/extensions/wu/seal/PropertyPrefixSupport.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object PropertyPrefixSupport : Extension() {
5757

5858

5959
override fun intercept(kotlinDataClass: KotlinDataClass): KotlinDataClass {
60-
return if (getConfig(prefixKeyEnable).toBoolean()) {
60+
return if (getConfig(prefixKeyEnable).toBoolean() && getConfig(prefixKey).isNotEmpty()) {
6161
val originProperties = kotlinDataClass.properties
6262
val newProperties = originProperties.map {
6363
val prefix = getConfig(prefixKey)

src/main/kotlin/extensions/wu/seal/PropertySuffixSupport.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ object PropertySuffixSupport : Extension() {
2222
addFocusListener(object : FocusListener {
2323
override fun focusGained(e: FocusEvent?) {
2424
}
25+
2526
override fun focusLost(e: FocusEvent?) {
2627
if (getConfig(suffixKeyEnable).toBoolean()) {
2728
setConfig(suffixKey, text)
@@ -46,17 +47,17 @@ object PropertySuffixSupport : Extension() {
4647
suffixJField()
4748
}
4849
}.apply {
49-
border = JBEmptyBorder(6,0,0,0)
50+
border = JBEmptyBorder(6, 0, 0, 0)
5051
}
5152
}
5253

5354

5455
override fun intercept(kotlinDataClass: KotlinDataClass): KotlinDataClass {
55-
return if (getConfig(suffixKeyEnable).toBoolean()) {
56+
return if (getConfig(suffixKeyEnable).toBoolean() && getConfig(suffixKey).isNotEmpty()) {
5657
val originProperties = kotlinDataClass.properties
5758
val newProperties = originProperties.map {
5859
val suffix = getConfig(suffixKey)
59-
val newName = it.name + suffix.first().toUpperCase() +suffix.substring(1)
60+
val newName = it.name + suffix.first().toUpperCase() + suffix.substring(1)
6061
it.copy(name = newName)
6162
}
6263
kotlinDataClass.copy(properties = newProperties)

src/main/kotlin/wu/seal/jsontokotlin/ui/JsonInputDialog.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.intellij.json.JsonFileType
55
import com.intellij.openapi.application.ApplicationManager
66
import com.intellij.openapi.editor.Editor
77
import com.intellij.openapi.editor.EditorFactory
8+
import com.intellij.openapi.editor.impl.EditorImpl
89
import com.intellij.openapi.fileChooser.FileChooser
910
import com.intellij.openapi.fileChooser.FileChooserDescriptor
1011
import com.intellij.openapi.progress.util.DispatchThreadProgressWindow
@@ -22,9 +23,7 @@ import java.awt.BorderLayout
2223
import java.awt.Dimension
2324
import java.awt.Toolkit
2425
import java.awt.datatransfer.DataFlavor
25-
import java.awt.event.ActionEvent
26-
import java.awt.event.KeyAdapter
27-
import java.awt.event.KeyEvent
26+
import java.awt.event.*
2827
import java.net.URL
2928
import javax.swing.*
3029
import javax.swing.text.JTextComponent
@@ -128,7 +127,7 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
128127

129128
private fun createJsonContentEditor(): Editor {
130129
val editorFactory = EditorFactory.getInstance()
131-
val document = editorFactory.createDocument("").apply { }
130+
val document = editorFactory.createDocument("").apply { }
132131
document.setReadOnly(false)
133132
document.addDocumentListener(object : com.intellij.openapi.editor.event.DocumentListener {
134133
override fun documentChanged(event: com.intellij.openapi.editor.event.DocumentEvent?) = revalidate()
@@ -141,8 +140,20 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
141140
component.isEnabled = true
142141
component.preferredSize = Dimension(640, 480)
143142
component.autoscrolls = true
143+
component.addFocusListener(object : FocusListener{
144+
override fun focusLost(e: FocusEvent?) {
144145

145-
editor.contentComponent.componentPopupMenu = JPopupMenu().apply {
146+
}
147+
148+
override fun focusGained(e: FocusEvent?) {
149+
component.isFocusCycleRoot =true
150+
151+
}
152+
})
153+
154+
val contentComponent = editor.contentComponent
155+
contentComponent.isFocusable = true
156+
contentComponent.componentPopupMenu = JPopupMenu().apply {
146157
add(createPasteFromClipboardMenuItem())
147158
add(createRetrieveContentFromHttpURLMenuItem())
148159
add(createLoadFromLocalFileMenu())
@@ -210,7 +221,7 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
210221
override fun getInputString(): String = if (exitCode == 0) jsonContentEditor.document.text.trim() else ""
211222

212223
override fun getPreferredFocusedComponent(): JComponent? {
213-
return if (this.myField.text?.isEmpty() != false) {
224+
return if (this.myField.text.isNullOrEmpty()) {
214225
this.myField
215226
} else {
216227
jsonContentEditor.contentComponent

0 commit comments

Comments
 (0)