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 org.jetbrains.kotlin.idea.scratch.ScratchExpression
|
||||
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.Font
|
||||
import java.awt.Graphics
|
||||
@@ -41,7 +41,7 @@ import java.awt.Rectangle
|
||||
|
||||
object InlayScratchOutputHandler : ScratchOutputHandler {
|
||||
override fun onStart(file: ScratchFile) {
|
||||
clearInlays(file.psiFile.project, file.psiFile.virtualFile)
|
||||
clear(file)
|
||||
}
|
||||
|
||||
override fun handle(file: ScratchFile, expression: ScratchExpression, output: ScratchOutput) {
|
||||
@@ -55,8 +55,7 @@ object InlayScratchOutputHandler : ScratchOutputHandler {
|
||||
}
|
||||
|
||||
override fun error(file: ScratchFile, message: String) {
|
||||
// todo multiple errors, clear, close
|
||||
showToolWindow(file.psiFile.project, message, ConsoleViewContentType.ERROR_OUTPUT)
|
||||
ScratchToolWindow.addMessageToToolWindow(file.psiFile.project, message, ConsoleViewContentType.ERROR_OUTPUT)
|
||||
}
|
||||
|
||||
override fun onFinish(file: ScratchFile) {
|
||||
@@ -65,6 +64,7 @@ object InlayScratchOutputHandler : ScratchOutputHandler {
|
||||
|
||||
override fun clear(file: ScratchFile) {
|
||||
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) {
|
||||
|
||||
+46
-21
@@ -65,31 +65,56 @@ class ScratchToolWindowFactory : ToolWindowFactory {
|
||||
}
|
||||
}
|
||||
|
||||
fun showToolWindow(
|
||||
object ScratchToolWindow {
|
||||
|
||||
fun addMessageToToolWindow(
|
||||
project: Project,
|
||||
message: String,
|
||||
type: ConsoleViewContentType
|
||||
) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) return
|
||||
) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) return
|
||||
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
val toolWindowManager = ToolWindowManager.getInstance(project)
|
||||
var window: ToolWindow? = toolWindowManager.getToolWindow(ScratchToolWindowFactory.ID)
|
||||
if (window == null) {
|
||||
toolWindowManager.registerToolWindow(ScratchToolWindowFactory.ID, true, ToolWindowAnchor.BOTTOM)
|
||||
window = toolWindowManager.getToolWindow(ScratchToolWindowFactory.ID)
|
||||
ScratchToolWindowFactory().createToolWindowContent(project, window!!)
|
||||
}
|
||||
|
||||
val contents = window.contentManager.contents
|
||||
for (content in contents) {
|
||||
val component = content.component
|
||||
if (component is ConsoleViewImpl) {
|
||||
component.clear()
|
||||
component.print(message, type)
|
||||
window.setAvailable(true, null)
|
||||
window.show(null)
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
val toolWindow = getToolWindow(project) ?: createToolWindow(project)
|
||||
val contents = toolWindow.contentManager.contents
|
||||
for (content in contents) {
|
||||
val component = content.component
|
||||
if (component is ConsoleViewImpl) {
|
||||
component.print("$message\n", type)
|
||||
}
|
||||
}
|
||||
toolWindow.setAvailable(true, null)
|
||||
toolWindow.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