Re-open a file after renaming even if the file is open in a custom viewer.

When reopening a renamed file, we can check with language manager again to determine whether to use a different custom viewer or to open it as a text file. So when an image file is renamed with a non-image file extension, then it will be re-opened as text file on Windows, but will trigger an error on Mac since we can't read in any binary file on Mac yet. In order to prevent the same error message repeatedly showing up on Mac, we will explicitly close the image viewer after the user dismisses the error dialog. So this fixes issue #5718.