Community
    • Login

    Unable to check a toolbar button on startup

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    2 Posts 2 Posters 275 Views
    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.
    • Brad RobertsonB
      Brad Robertson
      last edited by

      Hello,

      I’ve developing a plugin where I want to save the checked state of a menu item & toolbar button. When Notepad++ loads I want to restore the state that was previously saved.

      I’m running into an issue when on load I can restore the checked state of the menu item, but the checked state of the toolbar button is not restored.

      In my beNotified method I check for NPPN_TBMODIFICATION. This is when I add my icon to the toolbar.

      Immediately after I add my icon to the toolbar I call:

      SendMessage(handle, NPPM_SETMENUITEMCHECK, menuCommand, 1);
      

      After this SendMessage command is run I end up with the menu item checked, but the button on the toolbar is not checked.

      If I call this SendMessage command later on then both the menu item and the toolbar button will be checked.

      Is there a reason why the toolbar button doesn’t get checked at this point in time?

      Is there a notification I should be listening to in order to check my toolbar button?

      rdipardoR 1 Reply Last reply Reply Quote 0
      • rdipardoR
        rdipardo @Brad Robertson
        last edited by

        Every menu item should have a Boolean property similar to the _init2Check member of the FuncItem interface type. Setting this to true makes the checkmark appear.

        Assuming your plugin initializes its menu items in a constructor, the ::setInfo function is where you would assign the restored state to each item’s _init2Check member, or whatever your implementation calls it. One of my own plugins does exactly that by reading values from an *.ini file.

        ::setInfo is called by N++ before ::getFuncsArray, and long before the toolbar gets drawn. Up to now you’ve been calling a window procedure, but your menu items need to be created and configured even before there is any window to receive messages.

        1 Reply Last reply Reply Quote 3
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors