[Editor] Improve ProjectSettingsFragment
This commit is contained in:
@@ -23,16 +23,17 @@ class MainController : Controller() {
|
||||
val openMaps = observableMapOf<Scope, GameMap>()
|
||||
|
||||
fun createEmptyProject() {
|
||||
val project = Project()
|
||||
val vm = ProjectVM(project)
|
||||
val vm = ProjectVM(Project())
|
||||
|
||||
setInScope(vm)
|
||||
val modal = find<ProjectSettingsFragment>().apply { openModal(block = true, resizable = false) }
|
||||
find<ProjectSettingsFragment>().apply {
|
||||
onComplete {
|
||||
openMaps.clear()
|
||||
projectContext.project = it
|
||||
projectContext.save()
|
||||
}
|
||||
|
||||
if (modal.result) {
|
||||
openMaps.clear()
|
||||
projectContext.project = project
|
||||
projectContext.save()
|
||||
openModal(block = true, resizable = false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bartlomiejpluta.base.editor.project.view
|
||||
|
||||
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||
import com.bartlomiejpluta.base.editor.project.viewmodel.ProjectVM
|
||||
import javafx.beans.binding.Bindings
|
||||
import javafx.beans.binding.Bindings.createStringBinding
|
||||
@@ -9,19 +10,23 @@ import java.io.File
|
||||
|
||||
class ProjectSettingsFragment : Fragment("Project Settings") {
|
||||
private val projectVM = find<ProjectVM>(FX.defaultScope)
|
||||
|
||||
private val rootDirectory = SimpleStringProperty("")
|
||||
|
||||
private val projectDirectory = SimpleStringProperty("")
|
||||
private val directory = createStringBinding({
|
||||
File(rootDirectory.value, projectDirectory.value).absolutePath
|
||||
}, rootDirectory, projectDirectory)
|
||||
|
||||
private var onCompleteConsumer: ((Project) -> Unit)? = null
|
||||
|
||||
init {
|
||||
directory.addListener { _, _, path -> projectVM.sourceDirectoryProperty.value = File(path) }
|
||||
projectVM.nameProperty.addListener { _, _, name -> projectDirectory.value = name }
|
||||
}
|
||||
|
||||
var result = false
|
||||
private set
|
||||
fun onComplete(consumer: (Project) -> Unit) {
|
||||
this.onCompleteConsumer = consumer
|
||||
}
|
||||
|
||||
override val root = form {
|
||||
fieldset("Project Settings") {
|
||||
@@ -76,7 +81,7 @@ class ProjectSettingsFragment : Fragment("Project Settings") {
|
||||
button("Ok") {
|
||||
action {
|
||||
projectVM.commit {
|
||||
result = true
|
||||
onCompleteConsumer?.let { it(projectVM.item) }
|
||||
close()
|
||||
}
|
||||
}
|
||||
@@ -84,10 +89,6 @@ class ProjectSettingsFragment : Fragment("Project Settings") {
|
||||
shortcut("Enter")
|
||||
}
|
||||
|
||||
button("Reset") {
|
||||
action { projectVM.rollback() }
|
||||
}
|
||||
|
||||
button("Cancel") {
|
||||
action { close() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user