API for operation with modal dialogs

This extends on PR #1037 
Should it be commented?