Skip to content

Commit

Permalink
Fix plugin exception
Browse files Browse the repository at this point in the history
fix: #2
  • Loading branch information
YiiGuxing committed Dec 7, 2021
1 parent ba46706 commit db6fb85
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.actionSystem.EditorAction
import com.intellij.util.Producer
import com.intellij.util.ui.TextTransferable
import java.awt.datatransfer.Transferable


class GenerateASCIIArtAction : EditorAction(GenerateASCIIArtHandler()) {
Expand All @@ -27,7 +25,7 @@ class GenerateASCIIArtAction : EditorAction(GenerateASCIIArtHandler()) {
asciiArtText = FIGlet.trimArtText(asciiArtText)
}

execute(editor, dataContext, Producer<Transferable> { TextTransferable(asciiArtText) })
execute(editor, dataContext) { TextTransferable(asciiArtText as CharSequence) }
}
}
}
30 changes: 16 additions & 14 deletions src/main/kotlin/cn/yiiguxing/plugin/figlet/GenerateASCIIArtForm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CustomShortcutSet
import com.intellij.openapi.application.TransactionGuard
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.event.DocumentAdapter
import com.intellij.openapi.editor.event.DocumentEvent
import com.intellij.openapi.editor.event.DocumentListener
import com.intellij.openapi.editor.ex.DocumentEx
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.fileTypes.PlainTextFileType
Expand All @@ -17,7 +18,7 @@ import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.wm.IdeFocusManager
import com.intellij.ui.CollectionComboBoxModel
import com.intellij.ui.EditorTextField
import com.intellij.ui.ListCellRendererWrapper
import com.intellij.ui.SimpleListCellRenderer
import com.intellij.util.Alarm
import com.intellij.util.ui.JBUI
import java.awt.Dimension
Expand Down Expand Up @@ -48,7 +49,7 @@ class GenerateASCIIArtForm(private val project: Project, private val defaultInpu

val component: JComponent get() = contentPanel

val preferredFocusedComponent: JComponent? get() = inputTextField
val preferredFocusedComponent: JComponent get() = inputTextField

init {
val renderer = LayoutRenderer()
Expand Down Expand Up @@ -91,7 +92,7 @@ class GenerateASCIIArtForm(private val project: Project, private val defaultInpu
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), inputTextField)

inputTextField.addDocumentListener(object : DocumentAdapter() {
inputTextField.addDocumentListener(object : DocumentListener {
override fun documentChanged(e: DocumentEvent) = update()
})
fontComboBoxButton.onFontChanged { update() }
Expand All @@ -117,7 +118,6 @@ class GenerateASCIIArtForm(private val project: Project, private val defaultInpu

private fun update() {
callback.onUpdate()
val transactionId = TransactionGuard.getInstance().contextTransaction
updater.cancelAllRequests()
if (!updater.isDisposed) {
updater.addRequest({
Expand All @@ -129,10 +129,10 @@ class GenerateASCIIArtForm(private val project: Project, private val defaultInpu
null
}

TransactionGuard.getInstance().submitTransaction(project, transactionId, Runnable {
ApplicationManager.getApplication().invokeLater({
asciiArtText?.let { setResult(it) }
error?.let { callback.onError(it) }
})
}, ModalityState.stateForComponent(contentPanel))
}, 200)
}
}
Expand Down Expand Up @@ -174,25 +174,27 @@ class GenerateASCIIArtForm(private val project: Project, private val defaultInpu
isOneLineMode = false
}

override fun addNotify() {
super.addNotify()
(editor as? EditorEx)?.setPlaceholder("Write something here.")
override fun createEditor(): EditorEx {
return super.createEditor().apply {
setPlaceholder("Write something here.")
}
}

override fun updateBorder(editor: EditorEx) {
setupBorder(editor)
}
}

private class LayoutRenderer : ListCellRendererWrapper<FIGlet.Layout>() {
private class LayoutRenderer : SimpleListCellRenderer<FIGlet.Layout>() {

override fun customize(
list: JList<*>?,
list: JList<out FIGlet.Layout>,
value: FIGlet.Layout?,
index: Int,
selected: Boolean,
hasFocus: Boolean
) {
setText(value?.displayName)
text = value?.displayName
}
}

Expand Down

0 comments on commit db6fb85

Please sign in to comment.