[Editor] Enable opening code editor on compilation error location click
So far it only opens the tab if it is not already open and do nothing more about it. It would be good if it focused the tab if it is already open and move caret with viewport to the given line and column.
This commit is contained in:
@@ -73,4 +73,6 @@ class FileSystemNode(file: File, val parent: FileSystemNode? = null) {
|
||||
private fun findChild(file: File): FileSystemNode? {
|
||||
return children.firstOrNull { it.file.name == file.name }
|
||||
}
|
||||
|
||||
fun findByFile(file: File) = allChildren.firstOrNull { it.file.equals(file) }
|
||||
}
|
||||
@@ -2,28 +2,34 @@ package com.bartlomiejpluta.base.editor.code.view
|
||||
|
||||
import com.bartlomiejpluta.base.editor.event.UpdateCompilationLogEvent
|
||||
import com.bartlomiejpluta.base.editor.main.controller.MainController
|
||||
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.fxmisc.richtext.StyledTextArea
|
||||
import tornadofx.View
|
||||
import java.io.File
|
||||
|
||||
|
||||
class CompilerLogsView : View() {
|
||||
private val projectContext: ProjectContext by di()
|
||||
private val mainController: MainController by di()
|
||||
|
||||
private val editor = StyledTextArea(null, { _, _ -> }, LocationRef.NO_LINK, { text, style -> style.apply(text) })
|
||||
|
||||
init {
|
||||
subscribe<UpdateCompilationLogEvent> {
|
||||
subscribe<UpdateCompilationLogEvent> { event ->
|
||||
editor.clear()
|
||||
|
||||
val locationRef = LocationRef(it.location) { loc ->
|
||||
// TODO(mainController.openScript(getFileSystemNodeFromSomewhere(loc)))
|
||||
val locationRef = LocationRef(event.location) { loc ->
|
||||
projectContext.project?.codeFSNode?.findByFile(File(loc.fileName))?.let {
|
||||
mainController.openScript(it)
|
||||
}
|
||||
}
|
||||
|
||||
editor.insert(editor.length, it.location.toString(), locationRef)
|
||||
editor.insert(editor.length, it.message, LocationRef.NO_LINK)
|
||||
editor.insert(editor.length, event.location.toString(), locationRef)
|
||||
editor.insert(editor.length, event.message, LocationRef.NO_LINK)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class ScriptFilesView : View() {
|
||||
init {
|
||||
projectContext.projectProperty.addListener { _, _, project ->
|
||||
project?.let {
|
||||
treeView.root = TreeItem(FileSystemNode(it.codeDirectory))
|
||||
treeView.root = TreeItem(it.codeFSNode)
|
||||
treeView.populate { item -> item.value?.children }
|
||||
root.root.expandAll()
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.bartlomiejpluta.base.editor.project.model
|
||||
|
||||
import com.bartlomiejpluta.base.editor.code.model.FileSystemNode
|
||||
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
||||
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||
import com.bartlomiejpluta.base.editor.tileset.asset.TileSetAsset
|
||||
import javafx.beans.binding.Bindings
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import tornadofx.getValue
|
||||
@@ -38,6 +40,8 @@ class Project {
|
||||
val codeDirectoryProperty = SimpleObjectProperty<File>()
|
||||
var codeDirectory by codeDirectoryProperty
|
||||
private set
|
||||
val codeFSNodeProperty = Bindings.createObjectBinding({ FileSystemNode(codeDirectory) }, codeDirectoryProperty)
|
||||
val codeFSNode by codeFSNodeProperty
|
||||
|
||||
init {
|
||||
sourceDirectoryProperty.addListener { _, _, dir ->
|
||||
|
||||
Reference in New Issue
Block a user