Fix a bug when hide is called on an already hidden dialog and focus shifts unexpectedly