two questions on my first plugin



  • Hello,

    i now programing on my first npp plugin (in C#) and i have any little questions ;-)

    a) Is there exist an event or an message when the user change to another document?
    b) Is exist an example or dev-guide for using localization?

    Thats all for the begin.

    regards Mario



  • I’m only able to tell you something about your question a)

    There is a notification called NPPM_BUFFERACTIVATED (see here (slightly outdated) and here (up to date)). It is send to a plugin whenever a document’s text buffer (i.e. its tab) gets activated.

    I’m a plugin author too (see here) thus I know that there are some pitfalls with NPPM_BUFFERACTIVATED. Activating a buffer often happens even in situations where you do not expect it.

    Especially if your plugin does something with a text buffer which has to be done only one times you need to implement some sort of buffer management to remember that a certain buffer already has undergone your manipulations.

    I personally ended up with a dictionary: The keys are buffer IDs and the values are the full paths of the related files. I solved it this way because it can happen that an already closed buffer ID gets reused by another file.



  • Hello dinkumoil,

    thanks for suggestion, it is exactly what i search.

    For all other C#-developers:

    1. In file Main.cs write a new function with header “***internal static void bufferIsActivated()***”
      this function is called by eventmanager on 2.

    2. In file PluginInfrastructure/UnmanagedExports.cs in the function “***static void beNotified(IntPtr notifyCode)***” add follow code above the else statement:

           else if (notification.Header.Code == (uint)NppMsg.NPPN_BUFFERACTIVATED)
           {
               Main.bufferIsActivated();
           }
      

    And now is calling your “bufferIsActivated”-function by change / activate a other tab.

    thanks and regards
    Mario



  • Hello everyone,

    “see the forest for the trees” 8-)

    in file PluginInfrastructure/UnmanagedExports.cs in the function “static void beNotified(IntPtr notifyCode)” in the else statement

            else
            {
                Main.OnNotification(notification);
            }
    

    Main.OnNotification(notification); … oh no
    That is an callback. I am so stup…

    have a nice day
    Mario


Log in to reply