How to dynamically change the menu items

cghersi
2014-04-02
2014-04-10
  • cghersi

    cghersi - 2014-04-02

    Hi all,
    I'm trying to develop a plugin in C# where I need to dynamically change the label of menu items (e.g. from "Login" to "Logout") and if possible make some of them grayed or disabled.
    The same for the buttons on the toolbar.
    I have only found the SetCommand() API to set such menu items, but I cannot find any method to remove or update the menu items.
    Can you point me in the right direction please?

    Thank you very much!
    Best
    cghersi

     
  • cchris

    cchris - 2014-04-03

    You need to use Win32 API, unless C# provides helpers::
    Get the handle of the plugin menu sending the NPPM_GETMENUHANDLE message.
    Iterate through the items so as to find the submenu with the name of your plugin
    * Since your menu items were loaded as provided at plugin initialisation, then you know what the position of the desired item in your menu is. So now call GetMenuItemInfo with the proper flags, modify the MENUITEMINFO structure and SetMenuItemInfo(position).

    I won't elaborate over which assembly you need in C# to get them - leaving this bit to anyone familiar with C# development.

    CChris

     
    • cghersi

      cghersi - 2014-04-10

      Hi cchris, thank you very much for the support: it works!
      I mean, it usually works, but sometimes the menu is not updated even if no error arise in the calls to SetMenuItemInfo.
      Do I need to invoke any Npp command to force a refresh of the menu?

      Moreover, I'm only able to change the label of the menu item, but not the shortcut key.

      May you further help me in these problems?

      Thank you very much!

      Best

      cghersi

       

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

Sign up for the SourceForge newsletter:





No, thanks