[Editor] Create styles for Compilation Logs pane
This commit is contained in:
@@ -0,0 +1,71 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.code.component
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.code.stylesheet.CompilerLogsStylesheet
|
||||||
|
import com.bartlomiejpluta.base.editor.event.UpdateCompilationLogEvent
|
||||||
|
import javafx.scene.Cursor
|
||||||
|
import javafx.scene.layout.StackPane
|
||||||
|
import javafx.scene.paint.Color
|
||||||
|
import javafx.scene.text.Text
|
||||||
|
import org.codehaus.commons.compiler.Location
|
||||||
|
import org.fxmisc.richtext.StyledTextArea
|
||||||
|
import tornadofx.addClass
|
||||||
|
|
||||||
|
class CompilationLogs(private val locationClick: (location: Location) -> Unit) : StackPane() {
|
||||||
|
private val editor = StyledTextArea("compiler-logs",
|
||||||
|
{ text, style -> text.addClass(style) },
|
||||||
|
CompilationLogStyle.NO_STYLE,
|
||||||
|
{ text, style -> style.apply(text) }
|
||||||
|
).apply { isEditable = false }
|
||||||
|
|
||||||
|
init {
|
||||||
|
children += editor
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setEntry(message: String, severity: UpdateCompilationLogEvent.Severity, location: Location?) {
|
||||||
|
editor.clear()
|
||||||
|
|
||||||
|
val locationRef = CompilationLogStyle(location = location, onClick = locationClick)
|
||||||
|
|
||||||
|
editor.insert(editor.length, location?.toString() ?: "", locationRef)
|
||||||
|
editor.insert(editor.length, message, CompilationLogStyle(severity = severity))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clear() = editor.clear()
|
||||||
|
|
||||||
|
override fun getUserAgentStylesheet(): String = CompilerLogsStylesheet().base64URL.toExternalForm()
|
||||||
|
|
||||||
|
class CompilationLogStyle(
|
||||||
|
private val location: Location? = null,
|
||||||
|
private val severity: UpdateCompilationLogEvent.Severity? = null,
|
||||||
|
private val onClick: (Location) -> Unit = {}
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun apply(text: Text) = when {
|
||||||
|
severity != null -> message(text, severity)
|
||||||
|
location != null -> location(text, location)
|
||||||
|
else -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun message(text: Text, severity: UpdateCompilationLogEvent.Severity) {
|
||||||
|
text.fill = when (severity) {
|
||||||
|
UpdateCompilationLogEvent.Severity.WARNING -> Color.ORANGE
|
||||||
|
UpdateCompilationLogEvent.Severity.ERROR -> Color.RED
|
||||||
|
UpdateCompilationLogEvent.Severity.INFO -> text.fill
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun location(text: Text, location: Location) {
|
||||||
|
text.cursor = Cursor.HAND
|
||||||
|
text.fill = Color.BLUE
|
||||||
|
text.isUnderline = true
|
||||||
|
text.setOnMouseClicked {
|
||||||
|
onClick(location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val NO_STYLE = CompilationLogStyle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.code.stylesheet
|
||||||
|
|
||||||
|
import javafx.scene.text.FontWeight
|
||||||
|
import tornadofx.Stylesheet
|
||||||
|
import tornadofx.cssclass
|
||||||
|
|
||||||
|
class CompilerLogsStylesheet : Stylesheet() {
|
||||||
|
companion object {
|
||||||
|
val compilerLogs by cssclass()
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
compilerLogs {
|
||||||
|
fontFamily = "monospace"
|
||||||
|
fontWeight = FontWeight.MEDIUM
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
package com.bartlomiejpluta.base.editor.code.view
|
package com.bartlomiejpluta.base.editor.code.view
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.code.component.CompilationLogs
|
||||||
import com.bartlomiejpluta.base.editor.event.UpdateCompilationLogEvent
|
import com.bartlomiejpluta.base.editor.event.UpdateCompilationLogEvent
|
||||||
import com.bartlomiejpluta.base.editor.main.controller.MainController
|
import com.bartlomiejpluta.base.editor.main.controller.MainController
|
||||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||||
import javafx.scene.Cursor
|
|
||||||
import javafx.scene.paint.Color
|
|
||||||
import javafx.scene.text.Text
|
|
||||||
import org.codehaus.commons.compiler.Location
|
import org.codehaus.commons.compiler.Location
|
||||||
import org.fxmisc.richtext.StyledTextArea
|
|
||||||
import org.kordamp.ikonli.javafx.FontIcon
|
import org.kordamp.ikonli.javafx.FontIcon
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -17,52 +14,27 @@ class CompilerLogsView : View() {
|
|||||||
private val projectContext: ProjectContext by di()
|
private val projectContext: ProjectContext by di()
|
||||||
private val mainController: MainController by di()
|
private val mainController: MainController by di()
|
||||||
|
|
||||||
private val editor = StyledTextArea(
|
private val compilationLogs = CompilationLogs(this::locationClick)
|
||||||
null,
|
|
||||||
{ _, _ -> },
|
|
||||||
LocationRef.NO_LINK,
|
|
||||||
{ text, style -> style.apply(text) }
|
|
||||||
).apply { isEditable = false }
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
subscribe<UpdateCompilationLogEvent> { event ->
|
subscribe<UpdateCompilationLogEvent> { event ->
|
||||||
editor.clear()
|
compilationLogs.setEntry(event.message, event.severity, event.location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val locationRef = LocationRef(event.location) { loc ->
|
private fun locationClick(location: Location) {
|
||||||
projectContext.project?.codeFSNode?.findByFile(File(loc.fileName))?.let {
|
projectContext.project?.codeFSNode?.findByFile(File(location.fileName))?.let {
|
||||||
mainController.openScript(it, loc.lineNumber, 1)
|
mainController.openScript(it, location.lineNumber, 1)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
editor.insert(editor.length, event.location?.toString() ?: "", locationRef)
|
|
||||||
editor.insert(editor.length, event.message, LocationRef.NO_LINK)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val root = borderpane {
|
override val root = borderpane {
|
||||||
left = hbox {
|
left = hbox {
|
||||||
button(graphic = FontIcon("fa-trash")) {
|
button(graphic = FontIcon("fa-trash")) {
|
||||||
action { editor.clear() }
|
action { compilationLogs.clear() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
center = editor
|
center = compilationLogs
|
||||||
}
|
|
||||||
|
|
||||||
class LocationRef(private val location: Location?, private val onClick: (Location) -> Unit = {}) {
|
|
||||||
private constructor() : this(null)
|
|
||||||
|
|
||||||
fun apply(text: Text) = location?.let { loc ->
|
|
||||||
text.cursor = Cursor.HAND
|
|
||||||
text.fill = Color.BLUE
|
|
||||||
text.isUnderline = true
|
|
||||||
text.setOnMouseClicked {
|
|
||||||
onClick(loc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val NO_LINK = LocationRef()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user