edvin / tornadofx2

TornadoFX 2.0
Apache License 2.0
154 stars 40 forks source link

Workspace dynamic components not properly removing under certain condition. #13

Closed SKeeneCode closed 4 years ago

SKeeneCode commented 4 years ago

Run the following minimal example:

image

This only seems to happen when the workspace starts in Stack navigation mode. Starting it in tab mode, or starting it in stack mode and changing to tab mode before docking anything prevents it from happening.

Using some print outs it appears that after the initial component has been docked and the user switching modes to tab navigation. The component is undocked and redocked. However for some reason this re-dock is not ran inDynamicComponent modes so the button is not marked for removal.

This has really stumped me.

I am using the latest 2.0.0 Snapshot.

package org.example

import tornadofx.*
import java.util.*

class MyApp : App(MyWorkspace::class) {
}
class MyWorkspace : Workspace("rere", NavigationMode.Tabs) {
    init {
        primaryStage.width = 1200.0
        primaryStage.height = 800.0
        with(leftDrawer) {
            item(expanded = true) {
                vbox {
                    button("change mode") {
                        action {
                            if (workspace.navigationMode == NavigationMode.Stack) {
                                workspace.navigationMode = NavigationMode.Tabs
                            } else {
                                workspace.navigationMode = NavigationMode.Stack
                            }
                        }
                    }
                    button("add page") {
                        action {
                            workspace.dockInNewScope<Page>()
                        }
                    }
                }
            }
        }
    }
}

class Page : View() {
    val myID = UUID.randomUUID().toString().substring(0..5)

    override fun onDock() {
        println("Docking $myID")
        with(workspace) {
            button(myID)
        }
    }

    override val root = borderpane {
        center = hbox {
            button("docked pages") {
                action {
                     println("docked component is now ${workspace.dockedComponent}")
                }
            }
        }
    }

    init {
        title = myID
    }

    override fun toString(): String {
        return title
    }
}

fun main() {
    launch<MyApp>()
}