Bug 54779 [RCP] Problem updating menus, menu not appearing
I'm using 3.0 M7. I have an application, implementing workbench advisor, that creates a placeholder Help menu in the top level menu. Since the Help menu has no items other than separators and group items a swt menu is not created. Later on an item, Help Contents, is contributed to the Help menu. When getMenuBarManager().updateAll(false); is called from updateActionBars() in WorkbenchWindow the help menu will not be updated for two reasons: 1) The top level menu is not dirty, so it can't fill the help menu can create the swt menu. 2) The swt menu for the Help menu does not exist, so the swt menu can not be created. I have an sample application to demonstrate the problem as well as a fix to MenuManager.java in jface to solve the problem. The fix is to override markDirty()in MenuManager.java with the following code. /* (non-Javadoc) * @see org.eclipse.jface.action.IContributionManager#markDirty() */ public void markDirty() { super.markDirty(); // if we do not have a menu yet, then we need to mark our parent as dirty so our parent will // have the chance to create our menu when it gets updated. if (!menuExist()) { IContributionManager parent = getParent(); if (parent != null && !parent.isDirty()) { parent.markDirty(); } } }
bundles/org.eclipse.jface/src/org/eclipse/jface/action/MenuManager.java
} else if (data instanceof IContributionItem
                            && ((IContributionItem) data).isDynamic()
                            && ((IContributionItem) data).isDirty()) {
                        mi[i].dispose();
                    }
                }
                
                mi = menu.getItems();
                int srcIx = 0;
                int destIx = 0;
                for (Iterator e = clean.iterator(); e.hasNext();) {
                    IContributionItem src = (IContributionItem) e.next();
                    IContributionItem dest;
                    
                    if (srcIx < mi.length)
                        dest = (IContributionItem) mi[srcIx].getData();
                    else
                        dest = null;
                    if (dest != null && src.equals(dest)) {
                        srcIx++;
                        destIx++;
                    } else if (dest != null && dest.isSeparator()
                            && src.isSeparator()) {
                        mi[srcIx].setData(src);
                        srcIx++;
                        destIx++;
                    } else {
                        int start = menu.getItemCount();
                        src.fill(menu, destIx);
                        int newItems = menu.getItemCount() - start;