How to tell that a file is dirty from plugin ( changed without being saved)

  • Hi
    I am developing a plugin that edits code that is stored in a DB not in files.
    So I have my own opening and saving buttons and want to check and on the state of the document and warn of unsaved changes before they close or re-fetch it from the DB.
    What do I do to check if the current scintilla (buffer) has changed and not been saved since loading?

    I have looked at SCN_MODIFIED notification but did not like having to sort out which file was changing and having to store this in a property for each open file, as well it is firing when loading a document and for each key stroke.

    Is there an existing property that I can get to or something?

    Thanks in advance


  • Hi Jeff,

    unfortunately no. You have to do this with SCN_MODIFIED and keep a list of all open files and their modification stati.

    You can also use other events such as SciMsg.SCN_SAVEPOINTLEFT, SciMsg.SCN_SAVEPOINTREACHED.

    For a complete implementation which you can borrow freely have a look at my upcoming plugin:


    Btw, there is as of today, not a solution for files that have not been saved while NPP was shutdown… In my case, I just delete the backups so that they aren’t saved at all. I explicitly mention this to the users of my plugin because it’s not the default Npp behavior.

  • Hi
    Thanks, I am using a different strategy to achieve how to know when to store the changes back into the DB.
    I save as a file locally when I open the data from the database. (I did this anyway so the Tab Caption would have the correct name and to do comparisons with what is in the DB)
    I save the local file again every time the user saves to the DB
    I listen to the notification NPPN_FILEBEFORESAVE and save the data to the database. (user click the Save icon etc)
    So if the user closes the application or a file that NPP knows needs saving and NPP asks if the user wants to save then the save is also stored into the DB.


Log in to reply