Bug 189092 - Can't Replace A Menu
Summary: Can't Replace A Menu
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M3   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 136397
  Show dependency tree
 
Reported: 2007-05-25 03:53 EDT by Dani Megert CLA
Modified: 2007-10-18 10:00 EDT (History)
4 users (show)

See Also:


Attachments
Snippet (1.78 KB, text/plain)
2007-09-13 16:55 EDT, Bogdan Gheorghe CLA
no flags Details
Menu clone v01 (4.66 KB, patch)
2007-09-15 16:00 EDT, Paul Webster CLA
no flags Details | Diff
Menu copy v02 (5.42 KB, patch)
2007-10-04 10:56 EDT, Paul Webster CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2007-05-25 03:53:58 EDT
In order to fix bug 136397 we tried to provide a proxy for the submenu and only load it when the plug-in is available:

final Menu proxyMenu= new Menu(parent);
				
// Listenter to load the menu when needed
final MenuListener[] menuListeners = new MenuListener[1];
menuListeners[0] = new MenuListener() {
	public void menuHidden(MenuEvent e) {
	}

	public void menuShown(MenuEvent e) {
		MenuItem parentItem = proxyMenu.getParentItem();
		if (parentItem != null)
			parentItem.setMenu(loadMenu(proxyMenu));
			proxyMenu.removeMenuListener(menuListeners[0]);
			proxyMenu.dispose();
		}
		
	};
				
proxyMenu.addMenuListener(menuListeners[0]);
return proxyMenu;

While this worked on Windows (with a little flickering) it crashes on Linux GTK (see bug 136397 comment 23).

We'd probably need something like 'aboutToBeShown'.
Comment 1 Steve Northover CLA 2007-05-25 11:16:21 EDT
Not for 3.3.

It shouldn't flicker or crash but Bogdan can fix the crash first, then I will look at the flicker.
Comment 2 Dani Megert CLA 2007-08-29 08:52:32 EDT
For 3.4 we should look with Platform UI whether this is a must have to fix bug 136397 and if so, fix this one.
Comment 3 Paul Webster CLA 2007-08-30 09:05:14 EDT
Based on our attempts in bug 136397 it looks like I have 2 suggestions, either of which could help us:

1) In a SWT.Show event, allow us to swap out the source Menu with another Menu (both children of the same parent menu and same menu item).  That is Dani's original example code with a slight mod:

parentItem.setMenu(loadMenu(proxyMenu)); becomes parentItem.setMenu(loadMenu(parent));

2) in the SWT.Arm event for a cascade menu item, allow us to call menuItem.setMenu(*) and have that be the menu that is cascaded.  That's what I'm attempting in bug 136397 attachement #77368

Option 2 works on linux and the mac, just not reliably on windows.

PW
Comment 4 Bogdan Gheorghe CLA 2007-09-13 16:55:44 EDT
Created attachment 78384 [details]
Snippet

The following snippet worked for me consistently on all platforms (well Linux, Mac and Win32) without flicker. Can you give it a try on your machine?
Comment 5 Dani Megert CLA 2007-09-14 04:40:32 EDT
The snippet doesn't replace the menu on demand but already replaces the menu while selecting the 'Replaceble Menu' item. This is too early as we only want to load the plug-in when the casceded menu is inded shown. With the current snippet if you have:
  Menu1
  Menu2
  Proxy
  Menu3
  Menu4
and scroll down the top menu, it replaces the proxy already while moving down to Menu3 or Menu4. That's why I think something along the lines of 'aboutToBeShown' might be needed.
Comment 6 Paul Webster CLA 2007-09-14 08:48:38 EDT
(In reply to comment #4)
> Created an attachment (id=78384) [details]
> Snippet

This works well on linux and Mac for me but it fails on Tod's boxes (both XP and Vista).

When I use the arrow down to arm the cascade item and the arm listener swaps the menus, something pops up quickly and disappears, and then the cascade item remains armed but moving the mouse causes the first time to be armed as well.

PW
Comment 7 Dani Megert CLA 2007-09-14 09:11:15 EDT
Besides the fact that it doesn't fix the issue the snippet worked on my machine (T43p, WindowsXP Classic Look).
Comment 8 Bogdan Gheorghe CLA 2007-09-14 15:04:48 EDT
The show event is intended to be used as an "about to show" notification. 

Paul's going to try to replace the menu items with proxy menu items and forward events to the real menu items in a show listener.

For Menu, the events are: Hide, Show and Help
For MenuItems, the events are: Selection, Arm and Help.
Comment 9 Paul Webster CLA 2007-09-15 16:00:57 EDT
Created attachment 78505 [details]
Menu clone v01

Trying the ActionContributionItem menu clone idea with more events.

PW
Comment 10 Paul Webster CLA 2007-10-04 10:56:47 EDT
Created attachment 79731 [details]
Menu copy v02

Have the ActionContributionItem proxy any submenus that it can.
PW
Comment 11 Paul Webster CLA 2007-10-04 13:00:33 EDT
(In reply to comment #10)
> Created an attachment (id=79731) [details]
> Menu copy v02

Bogden, could you please give my patch a quick review.  It seems straight forward enough and it looks effective at delaying the request for the real menu until the proxy menu gets an SWT.Show event.

PW

Comment 12 Bogdan Gheorghe CLA 2007-10-10 11:46:36 EDT
Paul - the patch looks good to me!
Comment 13 Paul Webster CLA 2007-10-18 10:00:49 EDT
Released to HEAD >20071018
PW