Toolbar issue

Hi,
I have an issue regarding toolbar…
I have created custom components and added it to the toolbar. I want the toolbar to update the items dynamically. So I add the items to the toolbar whenever i need a toolbar.

I resize the window to its minimum size so that (button or) PopupMenu appears. I have a problem when the PopupMenu is active i.e. I do not bother to select any of the items in the toolbar. The problem is that the items get duplicated in the popupMenu whenever the popUpMenu is active.

Another problem is that when I say _pToolbar->getNumItems(), the number of items returned will not include the items in the PopupMenu. Is there any solution to get the total items in both toolbar & popupMenu so that i can delete all the items using _pToolbar->clear() ??

Waiting for your reply…

Thanks & Regards,
dheeraj

Right, thanks for that. It does need a bit of tweaking to make it work while the menu is open - try the version I’ve checked-in now…

Hi jules,
Thanks for that fix… :slight_smile:

But we did one small change before it got working…
The change is as follows…
~MissingItemsComponent()
{
// deleting the toolbar while its menu it open??
jassert (owner.isValidComponent());

    for (int i = 0; i < getNumChildComponents(); ++i)
    {
        ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));

        if (tc != 0)
        {
            tc->setVisible (false);
            const int index = oldIndexes.remove (i);
            //owner.items.insert (index, tc); [b](CHANGED HERE)[/b]
            owner.addChildComponent (tc, index);
            --i;
        }
    }

    owner.resized();
}

In the destructor we removed owner.items.insert(index, tc)…
The reason is that the items are not removed but inserted again, thus returning improper (sometimes double) values…

I think the change is proper… If not do inform… :slight_smile:

Thanks & Regards,
Dheeraj

Yes - of course that’s right. I’ll check that fix in shortly. Thanks!