Bug 170647 - [Contributions] ActionContributionItem should support dynamic dropdown menus
Summary: [Contributions] ActionContributionItem should support dynamic dropdown menus
Status: ASSIGNED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 129973 184856
  Show dependency tree
 
Reported: 2007-01-16 11:36 EST by Markus Keller CLA
Modified: 2019-09-06 16:09 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2007-01-16 11:36:28 EST
I20070110-1600

Currently, there's no way how a drop-down action used in an ActionContributionItem can avoid leaking a Menu widget. The IMenuCreator from IAction#getMenuCreator() is only asked for #getMenu(Control) during the whole lifetime of the ActionContributionItem. IMenuCreator#dispose() is only called when the ActionContributionItem's widget is disposed, which can be as late as shutting down the workbench.

The Javadoc of IMenuCreator suggests to keep a reference to the Menu widget and to dispose it each time a new menu is created, but this still leaks one Menu (including all MenuItems and their associated actions) after the menu has been closed.

An ugly workaround to handle this problem has been implemented for bug 25904. They now reuse the Menu instance and update it manually whenever a change occurs. This is inefficient and overly complex. A dynamic menu would be more appropriate.

I guess the best fix would be a new interface IDynamicMenuCreator that offers getMenu(..) methods like IMenuCreator but where callers will dispose the menu as soon as it is not visible any more.

If IDynamicMenuCreator extends IMenuCreator, then the implementation could simply use the code from https://bugs.eclipse.org/bugs/show_bug.cgi?id=64855#c2 after having called Menu#setVisible(..) in ActionContributionItem.
Comment 1 Markus Keller CLA 2007-06-05 13:23:56 EDT
Another solution would be adding a menuHidden listener and disposing the menu there. We successfully use this in org.eclipse.jdt.internal.ui.viewsupport.HistoryDropDownAction:

	final Display display= parent.getDisplay();
	fMenu.addMenuListener(new MenuAdapter() {
		public void menuHidden(final MenuEvent e) {
			display.asyncExec(new Runnable() {
				public void run() {
					manager.removeAll();
					if (fMenu != null) {
						fMenu.dispose();
						fMenu= null;
					}
				}
			});
		}
	});
Comment 2 Markus Keller CLA 2008-03-20 10:22:18 EDT
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>    Target Milestone|3.4 M6                      |---

Could this be scheduled for 3.5 then? It really is a problem.
Comment 3 Paul Webster CLA 2008-03-20 10:48:20 EDT
The problem is there is not simple solution that doesn't involve a new API path and it is in the action framework ... we don't want to be adding new API to actions.

With menus/commands the dropdown toolitems use a menu contribution to fill in the dropdown.  It's created on every SWT.Show from the IMenuService and can be filled with commands and/or with a dynamic element.  The dynamic element is backed by a CompoundContributionItem (although we opened that up to any ContributionItem in 3.4) and can also return arbitrary ContributionItems.

Dynamic elements can be placed in dropdown toolitems, which would then provide the dynamic menu without having the re-entrant problem that IAction+IMenuCreator has.

PW
Comment 4 Eclipse Webmaster CLA 2019-09-06 16:09:58 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.