Community
    • Login

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

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    3 Posts 2 Posters 3.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Jeff KellyJ
      Jeff Kelly
      last edited by

      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

      Jeff.

      1 Reply Last reply Reply Quote 0
      • sanastasiouS
        sanastasiou
        last edited by sanastasiou

        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:

        https://github.com/sanastasiou/RTextNpp/blob/master/RTextNpp/DllExport/UnmanagedExports.cs

        Regards

        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.

        1 Reply Last reply Reply Quote 0
        • Jeff KellyJ
          Jeff Kelly
          last edited by

          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.

          Thanks
          Jeff

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors