tornadofx icon indicating copy to clipboard operation
tornadofx copied to clipboard

MouseClick: Either onLeftClick {} or onRightClick {} prevents the other from working

Open szsoftware opened this issue 4 years ago • 5 comments

`hbox { imageview { image = Image(ivAddContracteeUrl.toString()) fitHeight = 48.0 fitWidth = 48.0 isPickOnBounds = true

                onLeftClick {
                    openInternalWindow(
                            view = ContracteeEditView(),
                            modal = true
                    )
                }

                onRightClick {
                    alert(Alert.AlertType.INFORMATION, "Info", "RightClick")
                }

            }
        }`

Please tell me what I'm doing wrong or need to learn. Thanks in advance!

szsoftware avatar Oct 23 '20 17:10 szsoftware

https://github.com/edvin/tornadofx/blob/7841a92eb491a8ec9e9f97a53d143e2995bc0d92/src/main/java/tornadofx/Nodes.kt#L420 these two different functions actually delegate the same function, which overrides the previous handler. Personally, it confuses me too.

Alternative:

val clickCount: Int = 1
setOnMouseClicked {
    if (it.clickCount == clickCount && it.button === MouseButton.PRIMARY)
         openInternalWindow(view = ContracteeEditView(), modal = true )
    if (it.clickCount == clickCount && it.button === MouseButton.SECONDARY)
         alert(Alert.AlertType.INFORMATION, "Info", "RightClick")
}

SchweinchenFuntik avatar Oct 24 '20 13:10 SchweinchenFuntik

Thank you veeeery much for this working solution!

szsoftware avatar Oct 24 '20 22:10 szsoftware

Shall we consider this as a bug?

Because, as you said It is very confusing. And the type hinting from the IDE should lead to expected results.

szsoftware avatar Oct 24 '20 22:10 szsoftware

I made it a bit more kotlinish: val clicks = 1 setOnMouseClicked { mouseEvent -> mouseEvent.apply { if (clickCount == clicks && button === MouseButton.PRIMARY) openInternalWindow(view = ContracteeEditView(), modal = true )

 if (clickCount == clicks && button === MouseButton.SECONDARY)
     alert(Alert.AlertType.INFORMATION, "Info", "RightClick")
}

}

szsoftware avatar Oct 24 '20 22:10 szsoftware

Shall we consider this as a bug?

No.

but I would fix that. I'll see when there is time

SchweinchenFuntik avatar Oct 28 '20 16:10 SchweinchenFuntik