Have a check for unsaved changes on closing the program or opening a file and seeing if there is a need to save current changes.