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 4.3k Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors