I have an app that may save some files. When the user closes the app, I would like to ask for saving if the user did not already save the file as it is currenty.
If I am not clear enough, I somehow want to check if the file has been modified from the last saving.
I have considered making a Boolean variable that turns to true if the file is saved and then turns back to false every time the file is modified in any way (writing or deleting elements in the file).
My question is if there is any easier solution to do that. It seems to me a lot of useless work to set the variable to true every time the file changes (work both for me and the machine), and I would not want this, since I have a quite wide and complex app, and changes in file are likely to happen quite often.
Edit after the answers:
Thank you all, it was really helpful. Eventually I realised that I needed a function that was needed in most of the changes I made to the file, so I didn’t need to work so much. The other changes were not so many so I just made the changes to the Boolean.
Thanks again
If changes aren’t likely to happen often then surely the per-change overhead of setting a boolean variable is negligible too.
Ideally you’ll have a point in your code that all changes have to go through (for example where you deal with undo/redo) and you can put your boolean variable updating code there.