project_file_name isn't defined if it's just an individual file being opened. That said, I've cleaned this up a bit based on your comments.