How do I know if a user has changed to save state if necessary?

My application is a kind of editor in which the user can drag and drop objects over the canvas and change the properties of N objects. How can I find out if the user has made changes to the application to ask him if he wants to save these changes or not? One way is to create the IsDirty property, but that means I will need to add a line of code in many places, maybe another way could be to create a virtual save, and then compare the real saved file with the virtual saved file; Is there another way?

+3
source share
4 answers

The only flag IsDirtythat gets the value truewhen all changes will be the right way to do this. This is the least expensive way to track this condition.

Saving will return it to false.

+1
source

I would prefer the second option of comparing a virtual file with a real saved one, because it is easier than setting the flag IsDirtyin all (all possible event handlers), and you may forget to install it later after some changes.

+1
source

, , , , IsDirty , , , .

0

If the user changes a property and then changes it to its original value, the flag IsDirtyindicates that it needs to be saved, and the "virtual save" method indicates that it does not need to be saved.

Which one you partially choose depends on what kind of semantics you want.

0
source

Source: https://habr.com/ru/post/1795334/


All Articles