[Editor] Create JavaClassParameter and SelectJavaClassFragment dialog which enable user to choose Java class via GUI
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.bartlomiejpluta.base.editor.code.view
|
||||
package com.bartlomiejpluta.base.editor.code.view.build
|
||||
|
||||
import com.bartlomiejpluta.base.editor.common.logs.component.LogsPane
|
||||
import com.bartlomiejpluta.base.editor.event.AppendBuildLogsEvent
|
||||
@@ -10,7 +10,6 @@ import org.kordamp.ikonli.javafx.FontIcon
|
||||
import tornadofx.*
|
||||
import java.io.File
|
||||
|
||||
|
||||
class BuildLogsView : View() {
|
||||
private val projectContext: ProjectContext by di()
|
||||
private val mainController: MainController by di()
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bartlomiejpluta.base.editor.code.view
|
||||
package com.bartlomiejpluta.base.editor.code.view.editor
|
||||
|
||||
import tornadofx.Fragment
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bartlomiejpluta.base.editor.code.view
|
||||
package com.bartlomiejpluta.base.editor.code.view.editor
|
||||
|
||||
import com.bartlomiejpluta.base.editor.code.component.CodeEditor
|
||||
import com.bartlomiejpluta.base.editor.code.highlighting.JavaSyntaxHighlighter
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bartlomiejpluta.base.editor.code.view
|
||||
package com.bartlomiejpluta.base.editor.code.view.list
|
||||
|
||||
import com.bartlomiejpluta.base.editor.code.component.ScriptFileTreeCell
|
||||
import com.bartlomiejpluta.base.editor.code.model.FileSystemNode
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.bartlomiejpluta.base.editor.code.view.select
|
||||
|
||||
import com.bartlomiejpluta.base.editor.code.model.FileSystemNode
|
||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||
import javafx.beans.binding.Bindings.createBooleanBinding
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import tornadofx.*
|
||||
import java.io.File
|
||||
|
||||
class SelectJavaClassFragment : Fragment("Select Java Class") {
|
||||
private val projectContext: ProjectContext by di()
|
||||
private val rootNode = projectContext.project!!.codeFSNode
|
||||
private val selection = SimpleObjectProperty<FileSystemNode>()
|
||||
|
||||
private val selectJavaClassView = find<SelectJavaClassView>(
|
||||
SelectJavaClassView::rootNode to rootNode,
|
||||
SelectJavaClassView::selection to selection
|
||||
)
|
||||
|
||||
private val isFile = createBooleanBinding({ selection.value?.isFile ?: false }, selection)
|
||||
|
||||
private var onCompleteConsumer: ((String) -> Unit)? = null
|
||||
|
||||
fun onComplete(onCompleteConsumer: ((String) -> Unit)) {
|
||||
this.onCompleteConsumer = onCompleteConsumer
|
||||
}
|
||||
|
||||
override val root = vbox {
|
||||
this += selectJavaClassView.root
|
||||
buttonbar {
|
||||
button("Ok") {
|
||||
enableWhen(isFile)
|
||||
|
||||
action {
|
||||
selection.value?.let { node ->
|
||||
onCompleteConsumer?.let { consumer ->
|
||||
consumer(formatClassName(node.file))
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
button("Cancel") {
|
||||
action {
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatClassName(file: File) = file
|
||||
.relativeTo(rootNode.file)
|
||||
.toPath()
|
||||
.normalize()
|
||||
.joinToString(".")
|
||||
.substringBeforeLast(".")
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.bartlomiejpluta.base.editor.code.view.select
|
||||
|
||||
import com.bartlomiejpluta.base.editor.code.model.FileSystemNode
|
||||
import javafx.beans.property.Property
|
||||
import javafx.scene.control.TreeItem
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
import tornadofx.*
|
||||
|
||||
class SelectJavaClassView : View() {
|
||||
val rootNode: FileSystemNode by param()
|
||||
val selection: Property<FileSystemNode> by param()
|
||||
|
||||
private val treeView = treeview<FileSystemNode> {
|
||||
root = TreeItem(rootNode)
|
||||
|
||||
populate {
|
||||
it.value?.children
|
||||
}
|
||||
|
||||
cellFormat {
|
||||
text = it.file.nameWithoutExtension
|
||||
graphic = when {
|
||||
it.file.isFile -> FontIcon("fa-cube")
|
||||
else -> FontIcon("fa-folder")
|
||||
}
|
||||
}
|
||||
|
||||
bindSelected(selection)
|
||||
}
|
||||
|
||||
init {
|
||||
treeView.root.expandAll()
|
||||
}
|
||||
|
||||
override val root = treeView
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.bartlomiejpluta.base.editor.common.parameter.model
|
||||
|
||||
import com.bartlomiejpluta.base.editor.code.view.select.SelectJavaClassFragment
|
||||
import javafx.scene.control.Label
|
||||
import javafx.scene.input.MouseButton
|
||||
import javafx.scene.input.MouseEvent
|
||||
import tornadofx.Scope
|
||||
import tornadofx.find
|
||||
import tornadofx.toProperty
|
||||
|
||||
class JavaClassParameter(
|
||||
key: String,
|
||||
initialValue: String,
|
||||
editable: Boolean = true,
|
||||
onCommit: (oldValue: String, newValue: String, submit: () -> Unit) -> Unit = { _, _, submit -> submit() }
|
||||
) : Parameter<String>(key, initialValue, editable, false, onCommit) {
|
||||
override val editorValueProperty = initialValue.toProperty()
|
||||
|
||||
override val editor = Label(initialValue).apply {
|
||||
textProperty().bind(editorValueProperty)
|
||||
|
||||
addEventHandler(MouseEvent.MOUSE_CLICKED) {
|
||||
if (it.button == MouseButton.PRIMARY) {
|
||||
find<SelectJavaClassFragment>(Scope()).apply {
|
||||
onComplete { className ->
|
||||
editorValueProperty.value = className
|
||||
commit()
|
||||
}
|
||||
|
||||
openModal(block = true, resizable = false)
|
||||
}
|
||||
|
||||
it.consume()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@ package com.bartlomiejpluta.base.editor.main.view
|
||||
|
||||
import com.bartlomiejpluta.base.editor.asset.view.list.AssetsListView
|
||||
import com.bartlomiejpluta.base.editor.code.model.Code
|
||||
import com.bartlomiejpluta.base.editor.code.view.BuildLogsView
|
||||
import com.bartlomiejpluta.base.editor.code.view.CodeEditorFragment
|
||||
import com.bartlomiejpluta.base.editor.code.view.ScriptFilesView
|
||||
import com.bartlomiejpluta.base.editor.code.view.build.BuildLogsView
|
||||
import com.bartlomiejpluta.base.editor.code.view.editor.CodeEditorFragment
|
||||
import com.bartlomiejpluta.base.editor.code.view.list.ScriptFilesView
|
||||
import com.bartlomiejpluta.base.editor.code.viewmodel.CodeVM
|
||||
import com.bartlomiejpluta.base.editor.event.AppendBuildLogsEvent
|
||||
import com.bartlomiejpluta.base.editor.event.AppendProcessLogsEvent
|
||||
@@ -120,6 +120,7 @@ class MainView : View("BASE Game Editor") {
|
||||
}
|
||||
|
||||
item("Project Parameters") {
|
||||
enableWhen(projectContext.projectProperty.isNotNull)
|
||||
this += projectPropertiesView
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bartlomiejpluta.base.editor.project.view
|
||||
|
||||
import com.bartlomiejpluta.base.editor.common.parameter.model.JavaClassParameter
|
||||
import com.bartlomiejpluta.base.editor.common.parameter.model.StringParameter
|
||||
import com.bartlomiejpluta.base.editor.common.parameter.view.ParametersTableFragment
|
||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||
@@ -15,7 +16,14 @@ class ProjectParametersView : View() {
|
||||
StringParameter("name", "", onCommit = { _, _, submit ->
|
||||
submit()
|
||||
projectContext.save()
|
||||
}).apply { bindBidirectional(name) }
|
||||
}).apply { bindBidirectional(name) },
|
||||
|
||||
// TODO: It should never be null so it is required Project to have a gameClass set
|
||||
// from its initialization via New project dialog.
|
||||
// In that case, the initialValue will ever be a projectContext.project.gameClass
|
||||
// The "Select class..." placeholder is temporary and it should never be here, because
|
||||
// the game engine would treat the "Select class..." string as a game class name.
|
||||
JavaClassParameter("gameClass", "Select class...")
|
||||
)
|
||||
|
||||
init {
|
||||
|
||||
Reference in New Issue
Block a user