Move the logic for checking whether a dialog is already opened (and raising it to the users attention) and creating a new dialog into a function of its own