Prompt the code that will issue a message before exiting the program, that changes have been made to the file, with a request to save.
PS Text editor.
Prompt the code that will issue a message before exiting the program, that changes have been made to the file, with a request to save.
PS Text editor.
Algorithm like this.
Start a flag that indicates whether there were any changes in the file. When loading a document, the flag should be cleared (that is, it is false ) - it’s quite logical that you barely opened the document and you haven’t changed anything in it.
Further, it should be remembered that the flag can be cleared or set in case of any changes to the document. There can be four ways to change it (correct it if I am mistaken):
The first three types of changes should set the flag to true - they all assume that the received text will be different from the original one. However, the fourth type of change (undo / redo of previous changes) implies that the document can be returned to its original state. In this case (if of course you have Undo / Redo provided in the editor), you will need to memorize the steps, more precisely, the step that returns the document to its original state. / Upon reaching this step, the flag is also reset to false . For all other steps, the flag will be equal to true.
Well, the last thing to mention is that the flag should be reset when the document is saved. I will not give the code - it will take too much of it to correctly demonstrate the operation of this mechanism. But in general, everything is quite simple.
ZY A very bad idea is a head-on solution - to compare the current contents of a file with the old one at the slightest change. If with small document sizes this can somehow work, in the case of large documents serious brakes can occur.
Source: https://ru.stackoverflow.com/questions/320469/
All Articles