Update plugin messages in Npp v5

Don HO
2008-06-26
2012-11-14
  • Don HO

    Don HO - 2008-06-26

    As you can notice in Notepad++ v5, the save/open/close document operations behaviour is changed in order to improve performance.

    Such improvement may make your plugins work not as you expect if your are using the following notification :
    NPPN_FILEBEFORECLOSE
    NPPN_FILECLOSED
    NPPN_FILEBEFOREOPEN
    NPPN_FILEOPENED
    NPPN_FILEBEFORESAVE
    NPPN_FILESAVED

    To remedy that, Notepad++ v5 passes the current operated buffer ID to plugins, then plugins can get full file path or view|index in view from buffert ID. It means you may need to modify your plugins to make them work correctly if you use above notifications.

    Here's modified Notification :

        #define NPPN_FILEBEFORECLOSE (NPPN_FIRST + 3) // To notify plugins that the current file is about to be closed
        //scnNotification->nmhdr.code = NPPN_FILEBEFORECLOSE;
        //scnNotification->nmhdr.hwndFrom = hwndNpp;
        //scnNotification->nmhdr.idFrom = BufferID;

        #define NPPN_FILEOPENED (NPPN_FIRST + 4) // To notify plugins that the current file is just opened
        //scnNotification->nmhdr.code = NPPN_FILEOPENED;
        //scnNotification->nmhdr.hwndFrom = hwndNpp;
        //scnNotification->nmhdr.idFrom = BufferID;

        #define NPPN_FILECLOSED (NPPN_FIRST + 5) // To notify plugins that the current file is just closed
        //scnNotification->nmhdr.code = NPPN_FILECLOSED;
        //scnNotification->nmhdr.hwndFrom = hwndNpp;
        //scnNotification->nmhdr.idFrom = BufferID;

        #define NPPN_FILEBEFOREOPEN (NPPN_FIRST + 6) // To notify plugins that the current file is about to be opened
        //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN;
        //scnNotification->nmhdr.hwndFrom = hwndNpp;
        //scnNotification->nmhdr.idFrom = BufferID;
       
        #define NPPN_FILEBEFORESAVE (NPPN_FIRST + 7) // To notify plugins that the current file is about to be saved
        //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN;
        //scnNotification->nmhdr.hwndFrom = hwndNpp;
        //scnNotification->nmhdr.idFrom = BufferID;
       
        #define NPPN_FILESAVED (NPPN_FIRST + 8) // To notify plugins that the current file is just saved
        //scnNotification->nmhdr.code = NPPN_FILECLOSED;
        //scnNotification->nmhdr.hwndFrom = hwndNpp;
        //scnNotification->nmhdr.idFrom = BufferID;

    And 2 new added messages :

        #define NPPM_GETPOSFROMBUFFERID (NPPMSG + 57)
        // INT NPPM_GETPOSFROMBUFFERID(INT bufferID, 0)
        // Return VIEW|INDEX from a buffer ID. -1 if the bufferID non existing
        //
        // VIEW takes 2 highest bits and INDEX (0 based) takes the rest (30 bits)
        // Here's the values for the view :
        //  MAIN_VIEW 0
        //  SUB_VIEW  1

        #define NPPM_GETFULLPATHFROMBUFFERID (NPPMSG + 58)
        // INT NPPM_GETFULLPATHFROMBUFFERID(INT bufferID, CHAR *fullFilePath)
        // Get full path file name from a bufferID.
        // Return -1 if the bufferID non existing, otherwise the number of char copied/to copy
        // User should call it with fullFilePath be NULL to get the number of char (not including the nul character),
        // allocate fullFilePath with the return values + 1, then call it again to get  full path file name

    The last snapshot (code source) is in svn, including Notepad_msgs.h :
    http://notepad-plus.svn.sourceforge.net/viewvc/notepad-plus/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h?revision=258&view=markup

    You can download Notepad++ v5 RC here to test with your plugin :
    http://notepad-plus.sourceforge.net/commun/misc/npp.5.0.RC.bin.zip

    Please let me know if you found any not working message in v5.

    Don

     
    • Don HO

      Don HO - 2008-07-08

      For open/close/save notifications in Notepad++ v5, if you want to get the operated file name,
      you should get the buffer ID from these 6 Notifications :
      NPPN_FILEBEFORECLOSE
      NPPN_FILECLOSED
      NPPN_FILEBEFOREOPEN
      NPPN_FILEOPENED
      NPPN_FILEBEFORESAVE
      NPPN_FILESAVED

      then call NPPM_GETFULLPATHFROMBUFFERID with buffer ID to get the full file name.

      Don

       
      • Thell Fowler

        Thell Fowler - 2009-03-27

        Hi Don,

        Don't mean to dig up an old thread, but it looked appropriate for this question:

        What is the intended purpose of FILEBEFOREOPEN?  I had thought about using it for filtering SCN_MODIFIED messages while a document loading flag was set, but the BEFORE isn't before the SCN_MODIFIED.

        Is the message intended to be after the modified notification?  If so, is there a notification that is already setup to serve as the FIRST notification that a 'not-ready' flag could be set by?

        almostautomated

         
        • Don HO

          Don HO - 2009-03-27

          > What is the intended purpose of FILEBEFOREOPEN?

          NPPN_FILEBEFOREOPEN is a notification sent by Notepad++ to notify plugins a file is about to be opened.

          > I had thought about using it for filtering SCN_MODIFIED messages while a document
          > loading flag was set, but the BEFORE isn't before the SCN_MODIFIED.

          Yes.
          Notepad++ use this mechanism to filter SCN_MODIFIED by setting a flag "isFileOpening" before sending  NPPN_FILEBEFOREOPEN and after sending NPPN_FILEOPENED. That does the trick

          > Is the message intended to be after the modified notification?

          This notification is not related with SCN_MODIFIED, sent by Scintilla.

          Don

           
          • Thell Fowler

            Thell Fowler - 2009-03-27

            "...Notepad++ use this mechanism to filter SCN_MODIFIED by setting a flag "isFileOpening" before sending NPPN_FILEBEFOREOPEN and after sending NPPN_FILEOPENED. That does the trick "

            After looking at the Notepad_plus::doOpen routine it looks like there is a simple fix.

            Currently:

            isFileOpening gets set true.
            file is loaded into Scintilla ( which fires off its own notices )
            A check is done on the validity of the buffer:
              - if good:
                - NPPN_FILEBEFOREOPEN is sent
                - file is loaded into a view
                - isFileOpening flag is reset
                - NPPN_FILEOPENED is sent
              - if invalid:
                - Pop-up message to user about the failure is shown
                - isFileOpening flag is reset.

            Would you be interested in a modification along the following lines?

            Proposed:

            isFileOpening gets set true.
            NPPN_FILEBEFOREOPEN is sent
            file is loaded into Scintilla ( which fires off its own notices )
            A check is done on the validity of the buffer:
              - if good:
                - file is loaded into a view
                - isFileOpening flag is reset
                - NPPN_FILEOPENED is sent
              - if invalid:
                - Pop-up message to user about the failure is shown
                - isFileOpening flag is reset.
                - NPPN_FILEOPENFAILED is sent (<new message>)

            Looks like it would work without problems and would truly make the notification the first for a document.

            almostautomated

             
            • Don HO

              Don HO - 2009-03-27

              I just noticed isFileOpening flag is not consistant.

              Instead of the following code ;
              _isFileOpening = true;
              BufferID buffer = MainFileManager->loadFile(longFileName);
                  if (buffer != BUFFER_INVALID)
                  {
                     
                      Buffer * buf = MainFileManager->getBufferByID(buffer);
              ...

              it will be :
              BufferID buffer = MainFileManager->loadFile(longFileName);
                  if (buffer != BUFFER_INVALID)
                  {
                      _isFileOpening = true;
                      Buffer * buf = MainFileManager->getBufferByID(buffer);
              ...

              OTOH, I don't see the purpose of NPPN_FILEOPENFAILED, since in this case file will not be loaded, therefore SCN_MODIFIED won't be generated.

              Don

               
    • Thell Fowler

      Thell Fowler - 2009-03-27

      Don,

      With the current placement of NPPN_FILEBEFOREOPEN you're right that NPPN_FILEOPENFAILED would have no purpose, yet it also is not the first notification to a plugin about the document.  With the current placement the MainFileManager->loadFile(longFileName) will (if the document loads successfully) cause Scintilla to send out the first notification for a document ( SCN_MODIFIED with SC_MOD_BEFOREINSERT ).

      That's why, IMO, it would be beneficial to have the NPPN_FILEBEFOREOPEN actually fire before the load so that plugins could also utilize a _isFaileOpening flag of their own.  And, if a plugin utilizes such a flag, then it would also have to have a NPPN_FILEOPENFAILED, so that the flag could be reset in the case of a BUFFER_INVALID.

      Perhaps explaining how this came about would better illustrate the point...

      While working on the NppPlugin_ChangeMarker a test was done of opening a file after NPPN_READY was set.  When the file opened all lines where marked as changed.

      This happens because the MainFileManager->loadFile routine calls the FileManager::loadFileData and executes SCI_APPENDTEXT, which in turn executes Scintilla's InsertString function for the document which fires off the notification of SCN_MODIFIED.

      In order to make use of NPPN_FILEBEFOREOPEN it needs be sent prior to the SCN_MODIFIED.  In the mean time a std::set<int> _openDocs is working.

      So, what do you think?  Worthwhile to change?  Or leave it up to the plugin?

      almostautomated

       
      • Don HO

        Don HO - 2009-04-03

        > That's why, IMO, it would be beneficial to have the NPPN_FILEBEFOREOPEN
        > actually fire before the load so that plugins could also utilize a
        > _isFaileOpening flag of their own. And, if a plugin utilizes such a flag,
        > then it would also have to have a NPPN_FILEOPENFAILED,
        > so that the flag could be reset in the case of a BUFFER_INVALID.

        Hmm... you're right about it.
        In the next release, NPPN_FILEBEFOREOPEN will be triggered before MainFileManager->loadFile(longFileName), and NPPN_FILEOPENFAILED will be added.

        Don

         
        • Thell Fowler

          Thell Fowler - 2009-04-03

          Thank you once again Don!  It is a pleasure working with a developer who is open to suggestions like this. :)

          almostautomated

           
    • Jens Lorenz

      Jens Lorenz - 2009-03-31

      Hello,

      please stay the current behaviour of document notification as it is. If you change the sequence it my crash the HexEditor plugin or it doesn't work anymore correctly.

      Jens

       
      • Don HO

        Don HO - 2009-04-03

        > If you change the sequence it my crash the HexEditor plugin or it doesn't work anymore correctly.

        It shouldn't. Or there's a logical problem in your code.

        OTOH, the crash should not happen to the plugins in any case. After observing on the forums, I don't think HexEditor is stable enough to not be excluded in the future release.

        Don

         
      • Thell Fowler

        Thell Fowler - 2009-03-31

        Hi Jens,

        When you say:

        "...If you change the sequence it my crash the HexEditor plugin or it doesn't work anymore correctly. "

        Are you saying you _did_ alter the message order and it caused HexEdit to work incorrectly, or that you don't want it changed because it _may_ cause HexEdit to work incorrectly?

        I took a look at the beNotified for HexEdit v0.9.3 and don't see why there would be any problems.  You're using the FILEOPENED and FILECLOSED, neither of which would be changed...  I'm only recommending a change to the BEFOREOPEN notification.

        Also, while looking at the source I noted the getCurrentHScintilla() routine, you may be interested in the change to that as outlined here:
        https://sourceforge.net/forum/message.php?msg_id=6826720

         

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks