Improved file management

Now properly closes files on errors, asks if you want to save files
before closing, and saves/restores the workspace state in an xml file.