Show multple errors in scratch toolwindow
This commit is contained in:
+4
-4
@@ -33,7 +33,7 @@ import com.intellij.ui.JBColor
|
|||||||
import com.intellij.util.ui.UIUtil
|
import com.intellij.util.ui.UIUtil
|
||||||
import org.jetbrains.kotlin.idea.scratch.ScratchExpression
|
import org.jetbrains.kotlin.idea.scratch.ScratchExpression
|
||||||
import org.jetbrains.kotlin.idea.scratch.ScratchFile
|
import org.jetbrains.kotlin.idea.scratch.ScratchFile
|
||||||
import org.jetbrains.kotlin.idea.scratch.ui.showToolWindow
|
import org.jetbrains.kotlin.idea.scratch.ui.ScratchToolWindow
|
||||||
import java.awt.Color
|
import java.awt.Color
|
||||||
import java.awt.Font
|
import java.awt.Font
|
||||||
import java.awt.Graphics
|
import java.awt.Graphics
|
||||||
@@ -41,7 +41,7 @@ import java.awt.Rectangle
|
|||||||
|
|
||||||
object InlayScratchOutputHandler : ScratchOutputHandler {
|
object InlayScratchOutputHandler : ScratchOutputHandler {
|
||||||
override fun onStart(file: ScratchFile) {
|
override fun onStart(file: ScratchFile) {
|
||||||
clearInlays(file.psiFile.project, file.psiFile.virtualFile)
|
clear(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handle(file: ScratchFile, expression: ScratchExpression, output: ScratchOutput) {
|
override fun handle(file: ScratchFile, expression: ScratchExpression, output: ScratchOutput) {
|
||||||
@@ -55,8 +55,7 @@ object InlayScratchOutputHandler : ScratchOutputHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun error(file: ScratchFile, message: String) {
|
override fun error(file: ScratchFile, message: String) {
|
||||||
// todo multiple errors, clear, close
|
ScratchToolWindow.addMessageToToolWindow(file.psiFile.project, message, ConsoleViewContentType.ERROR_OUTPUT)
|
||||||
showToolWindow(file.psiFile.project, message, ConsoleViewContentType.ERROR_OUTPUT)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFinish(file: ScratchFile) {
|
override fun onFinish(file: ScratchFile) {
|
||||||
@@ -65,6 +64,7 @@ object InlayScratchOutputHandler : ScratchOutputHandler {
|
|||||||
|
|
||||||
override fun clear(file: ScratchFile) {
|
override fun clear(file: ScratchFile) {
|
||||||
clearInlays(file.psiFile.project, file.psiFile.virtualFile)
|
clearInlays(file.psiFile.project, file.psiFile.virtualFile)
|
||||||
|
ScratchToolWindow.clearToolWindow(file.psiFile.project)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createInlay(project: Project, file: VirtualFile, offset: Int, inlayText: String, outputType: ScratchOutputType) {
|
private fun createInlay(project: Project, file: VirtualFile, offset: Int, inlayText: String, outputType: ScratchOutputType) {
|
||||||
|
|||||||
+46
-21
@@ -65,31 +65,56 @@ class ScratchToolWindowFactory : ToolWindowFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showToolWindow(
|
object ScratchToolWindow {
|
||||||
|
|
||||||
|
fun addMessageToToolWindow(
|
||||||
project: Project,
|
project: Project,
|
||||||
message: String,
|
message: String,
|
||||||
type: ConsoleViewContentType
|
type: ConsoleViewContentType
|
||||||
) {
|
) {
|
||||||
if (ApplicationManager.getApplication().isUnitTestMode) return
|
if (ApplicationManager.getApplication().isUnitTestMode) return
|
||||||
|
|
||||||
ApplicationManager.getApplication().invokeLater {
|
ApplicationManager.getApplication().invokeLater {
|
||||||
val toolWindowManager = ToolWindowManager.getInstance(project)
|
val toolWindow = getToolWindow(project) ?: createToolWindow(project)
|
||||||
var window: ToolWindow? = toolWindowManager.getToolWindow(ScratchToolWindowFactory.ID)
|
val contents = toolWindow.contentManager.contents
|
||||||
if (window == null) {
|
for (content in contents) {
|
||||||
toolWindowManager.registerToolWindow(ScratchToolWindowFactory.ID, true, ToolWindowAnchor.BOTTOM)
|
val component = content.component
|
||||||
window = toolWindowManager.getToolWindow(ScratchToolWindowFactory.ID)
|
if (component is ConsoleViewImpl) {
|
||||||
ScratchToolWindowFactory().createToolWindowContent(project, window!!)
|
component.print("$message\n", type)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
val contents = window.contentManager.contents
|
toolWindow.setAvailable(true, null)
|
||||||
for (content in contents) {
|
toolWindow.show(null)
|
||||||
val component = content.component
|
|
||||||
if (component is ConsoleViewImpl) {
|
|
||||||
component.clear()
|
|
||||||
component.print(message, type)
|
|
||||||
window.setAvailable(true, null)
|
|
||||||
window.show(null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun clearToolWindow(project: Project) {
|
||||||
|
if (ApplicationManager.getApplication().isUnitTestMode) return
|
||||||
|
|
||||||
|
ApplicationManager.getApplication().invokeLater {
|
||||||
|
val toolWindow = getToolWindow(project) ?: return@invokeLater
|
||||||
|
val contents = toolWindow.contentManager.contents
|
||||||
|
for (content in contents) {
|
||||||
|
val component = content.component
|
||||||
|
if (component is ConsoleViewImpl) {
|
||||||
|
component.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toolWindow.setAvailable(false, null)
|
||||||
|
toolWindow.hide(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getToolWindow(project: Project): ToolWindow? {
|
||||||
|
val toolWindowManager = ToolWindowManager.getInstance(project)
|
||||||
|
return toolWindowManager.getToolWindow(ScratchToolWindowFactory.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createToolWindow(project: Project): ToolWindow {
|
||||||
|
val toolWindowManager = ToolWindowManager.getInstance(project)
|
||||||
|
toolWindowManager.registerToolWindow(ScratchToolWindowFactory.ID, true, ToolWindowAnchor.BOTTOM)
|
||||||
|
val window = toolWindowManager.getToolWindow(ScratchToolWindowFactory.ID)
|
||||||
|
ScratchToolWindowFactory().createToolWindowContent(project, window)
|
||||||
|
return window
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user