Callback registered with IPopupChooserBuilder##setCancelCallback is called even when popup item was selected
已回答
Hi,
is it intended that the callback method set by IPopupChooserBuilder##setCancelCallback is called even when an item is selected? I would expect that this method is only called when the popup is left without a selection.
JBPopupFactory.getInstance()
.createPopupChooserBuilder(…)
.setSelectionMode(SINGLE_SELECTION)
.setItemChosenCallback { show("selected", pluginName) }
.setCancelCallback { show("canceled", pluginName) }
.createPopup()
.showInBestPositionFor(editor)
When selecting an item both toasts appear: first “canceled”, then “selected”.
If this is intended, what is the best way to do things only when the popup is left without a selection?
Regards Andreas
请先登录再写评论。
See
com.intellij.ui.popup.AbstractPopup#canClose
.You can just track “no selection” state in your code via (not-invoked)
setItemChosenCallback()
.The cancel-callback is called first regardless if an item is selected or not. So if I understand your answer correctly any tracking in setItemChosenCallback will be too late.
Hi,
I rechecked and the problem remains: The cancel-callback is called before the item-selected-callback. So I can not use Yann Cebron's idea to register some state in the selected-item-callback to change the behavior of the cancel-callback.
Andreas
Sorry for delay, this solution should work via `LightWeightWindowEvent.isOk` property
.createPopup().apply { addListener(object : JBPopupListener { override fun onClosed(event: LightweightWindowEvent) { println(event.isOk) } }) }
Hi Yann, Thank you! That solution works for me.
Andreas