Fixed 1046 and 1051

Also solved issues with the whole Save/Close state system, so files
won't close if you select File->Close, and press cancel at the prompt,
or the Save action fails.