Modal dialog and long editDocument operation in the same UI event

I can’t do the editDocument operation and show a modal dialog in the same Ui event from a Panel.

Launching the operation and dialog from the same UI event handler results into dialog not being shown. Instead the default “Plugin is working” dialog is shown,

If I launch the editDocument operation from the click handler of a button inside the modal dialog, the operation works.

How can I avoid the default “Plugin is working” dialog and instead show my custom dialog and still do the long editDocument operation?