Menu

Being notified when a buffer gets dirty

Franco
2015-04-15
2015-04-17
  • Franco

    Franco - 2015-04-15

    Is there a way to be notified when a buffer becomes dirty or not?

    I found DOCSTAUS_BUFFERDIRTY that gets sent via NPPN_READONLYCHANGED only when the readonly mode is changed.

    Any help or suggestion would be greatly appreciated.

    Thank you,

    Franco

     
  • Anonymous

    Anonymous - 2015-04-15

    Hi,

    I had the exact same problem.. It is quite a wonder that one cannot just ask if file X is dirty..

    There is however a workaround. You need to maintain per file some flag which indicates if something is modified or not. This is done by tracking Scintilla events : SCN_SAVEPOINTLEFT,
    SCN_SAVEPOINTREACHED

    For a more concrete example have a look at FileModificationObserver class

    https://github.com/sanastasiou/RTextNpp/blob/master/RTextNpp/Utilities/FileModificationObserver.cs

    Hope it helps.

     
  • Justin Dailey

    Justin Dailey - 2015-04-15

    Have you tried SCI_GETMODIFY?

     
  • Anonymous

    Anonymous - 2015-04-15

    SCI_GETMODIFY does not work if you close Notepad++ with dirty flag on some file. Same problem with my approach as well. I ended up cleaning the "cached" files of my plugin to prevent this from happening. I have also filed a bug about this problem:

    http://sourceforge.net/p/notepad-plus/bugs/5155/

     
  • Franco

    Franco - 2015-04-16

    How do you get Scintilla notifications in a plugin?

     
    • Justin Dailey

      Justin Dailey - 2015-04-17

      From your first post I'm assuming you already can receive notifications from Notepad++. Scintilla is no different. Its just a different type of message. You can see an example here that handles both Notepad++ notifications and Scintilla notifications. Not sure what language you are using but you can see the general idea.

       

      Last edit: Justin Dailey 2015-04-17
      • Franco

        Franco - 2015-04-17

        Thank you for the clarification