Skip to content

Commit a97f102

Browse files
committed
fix(241): update action threads for UI actions
- Ensure all UI actions are run on the correct thread to prevent race conditions and improve performance. - The `AutoDevRateMessageAction` and `AutoDevCopyToClipboardAction` now use the EDT thread for updates, as they involve UI interactions. - The `AutoDevLanguageLabelAction` now uses the BGT thread to avoid blocking the EDT thread while creating custom UI components.
1 parent 2b6a4fe commit a97f102

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/main/kotlin/cc/unitmesh/devti/gui/chat/message/AutoDevRateMessageAction.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cc.unitmesh.devti.gui.chat.message
33
import cc.unitmesh.devti.AutoDevBundle
44
import cc.unitmesh.devti.AutoDevIcons
55
import cc.unitmesh.devti.AutoDevNotifications
6+
import com.intellij.openapi.actionSystem.ActionUpdateThread
67
import com.intellij.temporary.gui.block.CompletableMessage
78
import com.intellij.openapi.actionSystem.AnActionEvent
89
import com.intellij.openapi.project.DumbAwareToggleAction
@@ -16,6 +17,8 @@ enum class ChatMessageRating {
1617
}
1718

1819
abstract class AutoDevRateMessageAction : DumbAwareToggleAction() {
20+
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
21+
1922
abstract fun getReaction(): ChatMessageRating
2023
abstract fun getReactionIcon(): Icon
2124
abstract fun getReactionIconSelected(): Icon

src/main/kotlin/cc/unitmesh/devti/gui/snippet/AutoDevCopyToClipboardAction.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package cc.unitmesh.devti.gui.snippet
22

3+
import com.intellij.openapi.actionSystem.ActionUpdateThread
34
import com.intellij.openapi.actionSystem.AnActionEvent
45
import com.intellij.openapi.project.DumbAwareAction
56
import java.awt.Toolkit
67
import java.awt.datatransfer.StringSelection
78

89
class AutoDevCopyToClipboardAction : DumbAwareAction() {
10+
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
11+
912
override fun actionPerformed(e: AnActionEvent) {
1013
val editor = e.getData(com.intellij.openapi.actionSystem.PlatformDataKeys.EDITOR) ?: return
1114
val document = editor.document

src/main/kotlin/cc/unitmesh/devti/gui/snippet/AutoDevLanguageLabelAction.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cc.unitmesh.devti.gui.snippet
22

3+
import com.intellij.openapi.actionSystem.ActionUpdateThread
34
import com.intellij.openapi.actionSystem.AnActionEvent
45
import com.intellij.openapi.actionSystem.CommonDataKeys
56
import com.intellij.openapi.actionSystem.Presentation
@@ -14,6 +15,8 @@ import com.intellij.util.ui.UIUtil
1415
import javax.swing.JComponent
1516

1617
class AutoDevLanguageLabelAction : DumbAwareAction(), CustomComponentAction {
18+
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
19+
1720
override fun createCustomComponent(presentation: Presentation, place: String): JComponent {
1821
val languageId = snippetLanguageName(presentation)
1922
val jBLabel: JComponent = JBLabel(languageId)

0 commit comments

Comments
 (0)