[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 codeStructure = find<CodeStructureView>()
|
||||
|
||||
private val openTabs = mutableMapOf<Scope, Tab>()
|
||||
|
||||
init {
|
||||
projectContext.projectProperty.addListener { _, _, project ->
|
||||
val projectName = project?.let { " :: ${it.name} (${it.sourceDirectory.absolutePath})" } ?: ""
|
||||
@@ -34,8 +36,38 @@ class MainView : View("BASE Game Editor") {
|
||||
top = mainMenuView.root
|
||||
|
||||
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 {
|
||||
val vm = GameMapVM(item)
|
||||
setInScope(vm, scope)
|
||||
@@ -57,26 +89,4 @@ class MainView : View("BASE Game Editor") {
|
||||
|
||||
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