cljfx

2021-12-10T17:44:33.015600Z

Is there a way to get a reference to the top level Stage in an event handler? The :on-action event contains the key :fx/event which is an ActionEvent. With this object I can sometimes get all the way to the top and get the top most Window, but in this case I have a MenuItem and don’t see a way to obtain a reference to the Stage. This is the code this is based on https://github.com/cljfx/cljfx/pull/40#issuecomment-544256262

thom 2021-12-10T20:24:46.016400Z

I've used ext-on-instance-lifecycle in the past to catch a reference to the top level stage and store it in a promise.

2021-12-11T05:39:25.020700Z

I’ll look into that! Might have to do this as a workaround.

thom 2021-12-11T07:34:19.021900Z

Would love to hear back if there's something simpler. Seems likely you could just navigate up the Node tree but that doesn't feel more elegant.

vlaaad 2021-12-10T20:30:54.017200Z

when looking in event, did you check both .getSource and .getTarget if it's possible to reach stage?

2021-12-11T05:38:34.020Z

IIRC both source and target give me a MenuItem. From the MenuItem I don’t see a way back to reach the parent stage. I tried getParent on it and I reach the Menu which is a dead end. On mobile, excuse formatting