[Editor] Improve MainView's TabPane binding to the mainController.openItems
This commit is contained in:
@@ -23,6 +23,8 @@ class MainView : View("BASE Game Editor") {
|
|||||||
private val projectStructureView = find<ProjectStructureView>()
|
private val projectStructureView = find<ProjectStructureView>()
|
||||||
private val codeStructure = find<CodeStructureView>()
|
private val codeStructure = find<CodeStructureView>()
|
||||||
|
|
||||||
|
private val openTabs = mutableMapOf<Scope, Tab>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
projectContext.projectProperty.addListener { _, _, project ->
|
projectContext.projectProperty.addListener { _, _, project ->
|
||||||
val projectName = project?.let { " :: ${it.name} (${it.sourceDirectory.absolutePath})" } ?: ""
|
val projectName = project?.let { " :: ${it.name} (${it.sourceDirectory.absolutePath})" } ?: ""
|
||||||
@@ -34,8 +36,38 @@ class MainView : View("BASE Game Editor") {
|
|||||||
top = mainMenuView.root
|
top = mainMenuView.root
|
||||||
|
|
||||||
center = tabpane {
|
center = tabpane {
|
||||||
tabs.bind(mainController.openItems) { scope, item ->
|
|
||||||
when (item) {
|
// FIXME
|
||||||
|
// For some reason the plain object binding does not work between tabs and mainController.openItems.
|
||||||
|
// Because of that, the cache openTabs map has been created and the binding is done by following listener:
|
||||||
|
mainController.openItems.addListener(MapChangeListener {
|
||||||
|
when {
|
||||||
|
it.wasAdded() -> createTab(it.key, it.valueAdded).let { tab ->
|
||||||
|
openTabs[it.key] = tab
|
||||||
|
tabs += tab
|
||||||
|
}
|
||||||
|
|
||||||
|
it.wasRemoved() -> {
|
||||||
|
val tab = openTabs[it.key]
|
||||||
|
tabs -= tab
|
||||||
|
openTabs.remove(it.key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
left = drawer(multiselect = true) {
|
||||||
|
item("Code Structure", expanded = true) {
|
||||||
|
this += codeStructure
|
||||||
|
}
|
||||||
|
|
||||||
|
item("Project Structure", expanded = true) {
|
||||||
|
this += projectStructureView
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createTab(scope: Scope, item: Any) = when (item) {
|
||||||
is GameMap -> Tab().apply {
|
is GameMap -> Tab().apply {
|
||||||
val vm = GameMapVM(item)
|
val vm = GameMapVM(item)
|
||||||
setInScope(vm, scope)
|
setInScope(vm, scope)
|
||||||
@@ -58,25 +90,3 @@ class MainView : View("BASE Game Editor") {
|
|||||||
else -> throw IllegalStateException("Unsupported tab item")
|
else -> throw IllegalStateException("Unsupported tab item")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME
|
|
||||||
// For some reason cleaning mainController.openMaps just takes off the tabs content keeping open themselves.
|
|
||||||
// The workaround is to detect if map is cleaned and the clean the tabs by hand.
|
|
||||||
mainController.openItems.addListener(MapChangeListener {
|
|
||||||
if (it.map.isEmpty()) {
|
|
||||||
tabs.clear()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
left = drawer(multiselect = true) {
|
|
||||||
item("Code Structure", expanded = true) {
|
|
||||||
this += codeStructure
|
|
||||||
}
|
|
||||||
|
|
||||||
item("Project Structure", expanded = true) {
|
|
||||||
this += projectStructureView
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user