Handle closing of preview window automatically