Skip to content

Commit cfd5cf4

Browse files
committedDec 19, 2024
refactor(ui): rename ShireInput to ShireInputTextField and update related components #165
- Renamed `ShireInput` class to `ShireInputTextField` - Updated references to `ShireInput` with `ShireInputTextField` - Replaced `AutoDevCoolBorder` with `ShireCoolBorder` - Removed unused imports and cleaned up code - Added `ShireInputSection` to `MarketplaceView`
1 parent 6531f4c commit cfd5cf4

File tree

3 files changed

+54
-40
lines changed

3 files changed

+54
-40
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.phodal.shirecore.ui
2+
3+
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil
4+
import com.intellij.openapi.editor.Editor
5+
import com.intellij.openapi.editor.ex.EditorEx
6+
import com.intellij.openapi.editor.ex.FocusChangeListener
7+
import com.intellij.openapi.ui.ErrorBorderCapable
8+
import com.intellij.util.ui.JBInsets
9+
import com.intellij.util.ui.UIUtil
10+
import java.awt.Component
11+
import java.awt.Graphics
12+
import java.awt.Insets
13+
import java.awt.Rectangle
14+
import javax.swing.JComponent
15+
import javax.swing.border.Border
16+
17+
class ShireCoolBorder(private val editor: EditorEx, parent: JComponent) : Border, ErrorBorderCapable {
18+
init {
19+
editor.addFocusListener(object : FocusChangeListener {
20+
override fun focusGained(editor2: Editor) {
21+
parent.repaint()
22+
}
23+
24+
override fun focusLost(editor2: Editor) {
25+
parent.repaint()
26+
}
27+
})
28+
}
29+
30+
override fun paintBorder(c: Component, g: Graphics, x: Int, y: Int, width: Int, height: Int) {
31+
val r = Rectangle(x, y, width, height)
32+
JBInsets.removeFrom(r, JBInsets.create(1, 1))
33+
34+
DarculaNewUIUtil.fillInsideComponentBorder(g, r, c.background)
35+
val enabled = c.isEnabled
36+
val hasFocus = UIUtil.isFocusAncestor(c)
37+
DarculaNewUIUtil.paintComponentBorder(g, r, DarculaUIUtil.getOutline(c as JComponent), hasFocus, enabled)
38+
}
39+
40+
override fun getBorderInsets(c: Component): Insets = JBInsets.create(Insets(3, 8, 3, 3)).asUIResource()
41+
override fun isBorderOpaque(): Boolean = true
42+
}

‎core/src/main/kotlin/com/phodal/shirecore/ui/ShireInputSection.kt

+7-40
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.phodal.shirecore.ui
22

33
import com.intellij.ide.IdeTooltip
44
import com.intellij.ide.IdeTooltipManager
5-
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil
65
import com.intellij.openapi.Disposable
76
import com.intellij.openapi.actionSystem.*
87
import com.intellij.openapi.actionSystem.ex.AnActionListener
@@ -17,15 +16,12 @@ import com.intellij.openapi.editor.actions.IncrementalFindAction
1716
import com.intellij.openapi.editor.event.DocumentEvent
1817
import com.intellij.openapi.editor.event.DocumentListener
1918
import com.intellij.openapi.editor.ex.EditorEx
20-
import com.intellij.openapi.editor.ex.FocusChangeListener
2119
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
2220
import com.intellij.openapi.fileTypes.FileTypes
2321
import com.intellij.openapi.project.DumbAwareAction
2422
import com.intellij.openapi.project.Project
2523
import com.intellij.openapi.ui.ComponentValidator
26-
import com.intellij.openapi.ui.ErrorBorderCapable
2724
import com.intellij.openapi.ui.popup.Balloon.Position
28-
import com.intellij.openapi.util.NlsContexts
2925
import com.intellij.openapi.wm.IdeFocusManager
3026
import com.intellij.openapi.wm.impl.InternalDecorator
3127
import com.intellij.ui.EditorTextField
@@ -46,7 +42,6 @@ import javax.swing.Box
4642
import javax.swing.JComponent
4743
import javax.swing.JPanel
4844
import javax.swing.KeyStroke
49-
import javax.swing.border.Border
5045
import kotlin.math.max
5146
import kotlin.math.min
5247

@@ -61,7 +56,7 @@ interface ShireInputListener : EventListener {
6156
fun onStop(component: ShireInputSection) {}
6257
}
6358

64-
class ShireInput(
59+
class ShireInputTextField(
6560
project: Project,
6661
private val listeners: List<DocumentListener>,
6762
val disposable: Disposable?,
@@ -84,8 +79,6 @@ class ShireInput(
8479
object : AnAction() {
8580
override fun actionPerformed(actionEvent: AnActionEvent) {
8681
val editor = editor ?: return
87-
88-
// Insert a new line
8982
CommandProcessor.getInstance().executeCommand(project, {
9083
val eol = "\n"
9184
val caretOffset = editor.caretModel.offset
@@ -155,7 +148,7 @@ class ShireInput(
155148
fun recreateDocument() {
156149
val id = UUID.randomUUID()
157150
val language = CodeFenceLanguage.findLanguage("Shire")
158-
val file = LightVirtualFile("AutoDevInput-$id", language, "")
151+
val file = LightVirtualFile("ShireInput-$id", language, "")
159152

160153
val document = file.findDocument() ?: throw IllegalStateException("Can't create in-memory document")
161154

@@ -172,7 +165,7 @@ class ShireInput(
172165
}
173166

174167
class ShireInputSection(private val project: Project, val disposable: Disposable?) : BorderLayoutPanel() {
175-
private val input: ShireInput
168+
private val input: ShireInputTextField
176169
private val documentListener: DocumentListener
177170
private val sendButtonPresentation: Presentation
178171
private val stopButtonPresentation: Presentation
@@ -224,7 +217,7 @@ class ShireInputSection(private val project: Project, val disposable: Disposable
224217
Dimension(20, 20)
225218
)
226219

227-
input = ShireInput(project, listOf(), disposable, this)
220+
input = ShireInputTextField(project, listOf(), disposable, this)
228221

229222
documentListener = object : DocumentListener {
230223
override fun documentChanged(event: DocumentEvent) {
@@ -272,11 +265,11 @@ class ShireInputSection(private val project: Project, val disposable: Disposable
272265
stopButton.isEnabled = true
273266
}
274267

275-
fun showTooltip(text: @NlsContexts.Tooltip String) {
268+
fun showTooltip(text: String) {
276269
showTooltip(input, Position.above, text)
277270
}
278271

279-
fun showTooltip(component: JComponent, position: Position, text: @NlsContexts.Tooltip String) {
272+
fun showTooltip(component: JComponent, position: Position, text: String) {
280273
val point = Point(component.x, component.y)
281274
val tipComponent = IdeTooltipManager.initPane(
282275
text, HintHint(component, point).setAwtTooltip(true).setPreferredPosition(position), null
@@ -292,7 +285,7 @@ class ShireInputSection(private val project: Project, val disposable: Disposable
292285

293286
fun initEditor() {
294287
val editorEx = this.input.editor as? EditorEx ?: return
295-
setBorder(AutoDevCoolBorder(editorEx, this))
288+
setBorder(ShireCoolBorder(editorEx, this))
296289
UIUtil.setOpaqueRecursively(this, false)
297290
this.revalidate()
298291
}
@@ -338,29 +331,3 @@ class ShireInputSection(private val project: Project, val disposable: Disposable
338331
val focusableComponent: JComponent get() = input
339332
}
340333

341-
class AutoDevCoolBorder(private val editor: EditorEx, parent: JComponent) : Border, ErrorBorderCapable {
342-
init {
343-
editor.addFocusListener(object : FocusChangeListener {
344-
override fun focusGained(editor2: Editor) {
345-
parent.repaint()
346-
}
347-
348-
override fun focusLost(editor2: Editor) {
349-
parent.repaint()
350-
}
351-
})
352-
}
353-
354-
override fun paintBorder(c: Component, g: Graphics, x: Int, y: Int, width: Int, height: Int) {
355-
val r = Rectangle(x, y, width, height)
356-
JBInsets.removeFrom(r, JBInsets.create(1, 1))
357-
358-
DarculaNewUIUtil.fillInsideComponentBorder(g, r, c.background)
359-
val enabled = c.isEnabled
360-
val hasFocus = UIUtil.isFocusAncestor(c)
361-
DarculaNewUIUtil.paintComponentBorder(g, r, DarculaUIUtil.getOutline(c as JComponent), hasFocus, enabled)
362-
}
363-
364-
override fun getBorderInsets(c: Component): Insets = JBInsets.create(Insets(3, 8, 3, 3)).asUIResource()
365-
override fun isBorderOpaque(): Boolean = true
366-
}

‎src/main/kotlin/com/phodal/shire/marketplace/ui/MarketplaceView.kt

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.intellij.openapi.wm.ToolWindow
99
import com.intellij.ui.content.ContentFactory
1010
import com.intellij.ui.dsl.builder.Align
1111
import com.intellij.ui.dsl.builder.panel
12+
import com.phodal.shirecore.ui.ShireInputSection
1213
import javax.swing.JPanel
1314

1415
@State(name = "MarketPlaceView", storages = [Storage(StoragePathMacros.PRODUCT_WORKSPACE_FILE)])
@@ -18,10 +19,14 @@ class MarketplaceView(val project: Project) : Disposable {
1819
private val shirePackageTableComponent = ShireMarketplaceTableView(project)
1920

2021
init {
22+
val inputSection = ShireInputSection(project, this)
2123
myToolWindowPanel = panel {
2224
row {
2325
cell(shirePackageTableComponent.mainPanel).align(Align.FILL)
2426
}.resizableRow()
27+
row {
28+
cell(inputSection).align(Align.FILL)
29+
}
2530
}
2631
}
2732

0 commit comments

Comments
 (0)
Please sign in to comment.