Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 151711 - [Commands] [IDE] Make QuickMenuAction API
Summary: [Commands] [IDE] Make QuickMenuAction API
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: IDE (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.5 M6   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 157072
Blocks: 266938
  Show dependency tree
 
Reported: 2006-07-25 11:35 EDT by Markus Keller CLA
Modified: 2009-03-10 10:47 EDT (History)
5 users (show)

See Also:


Attachments
Quick New Menu From Handler (7.06 KB, patch)
2006-12-22 14:36 EST, Paul Webster CLA
no flags Details | Diff
QuickMenuCreator update v01 (4.03 KB, patch)
2009-03-02 14:14 EST, Paul Webster CLA
no flags Details | Diff
QuickMenuCreator update v02 (2.86 KB, patch)
2009-03-03 13:25 EST, 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 Markus Keller CLA 2006-07-25 11:35:26 EDT
There are currently 3 QuickMenuActions in the Eclipse SDK. Since their implementations are already out of sync, I think Platform/UI should provide a reusable API class for this (probably in org.eclipse.ui.actions in the org.eclipse.ui.workbench plug-in).
Comment 1 Dani Megert CLA 2006-09-18 05:04:48 EDT
I think this is fixed (a dup of bug 157072). Please see QuickMenuCreator (in I20060918-0010). Markus, can you check whether this fits our needs?
Comment 2 Markus Keller CLA 2006-09-18 06:41:00 EDT
(In reply to comment #1)
> Markus, can you check whether this fits our needs?

I'll do it thoroughly as soon as we get a clear sign from Platform/UI that the QuickMenuCreator will not be removed again (see class javadoc).

Issues I've already noticed:
- computeMenuLocation(..) methods need to be protected, such that clients can override them (see JDTQuickMenuAction, which places the menu at word boundaries)
- some fixes in JDT/UI's version are missing in the new API:
  - StyledText.getLineHeight(int) not used
  - fix for bug 64855 is not in (leaking menu between invocations)
Comment 3 Paul Webster CLA 2006-09-18 08:14:38 EDT
My concern is that bug 154130 might provide an improved dynamic menu API, and we want to limit use of the legacy API as much as possible.

PW
Comment 4 Paul Webster CLA 2006-12-22 07:58:05 EST
Now that the menu API is taking shape, I think that this can be provided by a handler and a parameterized command.
      <command
            name="%command.newQuickMenu.name"
            description="%command.newQuickMenu.description"
            categoryId="org.eclipse.ui.category.file"
            id="org.eclipse.ui.file.newQuickMenu">
      </command>

would become (we'll come up with a better id):
      <command
            categoryId="org.eclipse.ui.category.file"
            defaultHandler="org.eclipse.ui.internal.handlers.ShowAMenu"
            description="%command.showAMenu.description"
            id="org.eclipse.ui.file.showAMenu"
            name="%command.showAMenu.name">
         <commandParameter
               id="menuLocation"
               name="%command.showAMenu.menuLocation.name"
               optional="false">
         </commandParameter>
      </command>

And then we update the keybinding:
      <key
            commandId="org.eclipse.ui.file.showAMenu"
            contextId="org.eclipse.ui.contexts.window"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence="M2+M3+N">
         <parameter
               id="menuLocation"
               value="menu:new">
         </parameter>
      </key>

The handler uses the IMenuService#populateContributionManager(*) to build the menu.

If we make the ShowAMenu a public handler, you could override the computeMenuLocation(*) and supply your handler for when your parts are active.

PW
Comment 5 Paul Webster CLA 2006-12-22 14:36:10 EST
Created attachment 56104 [details]
Quick New Menu From Handler

This is a parameterized quick menu command ... but it is also a hack that includes making the new menu visible to the IMenuService and it uses the QuickMenuCreator code as a base.

I just didn't want to lose it over the break.

PW
Comment 6 Tod Creasey CLA 2007-06-22 16:14:17 EDT
THis would be best as a command
Comment 7 Paul Webster CLA 2007-07-17 12:42:57 EDT
I'll see if I can slip this in 3.4
PW
Comment 8 Remy Suen CLA 2008-06-29 22:33:06 EDT
I support this, +1.
Comment 9 Paul Webster CLA 2009-03-02 14:14:57 EST
Created attachment 127205 [details]
QuickMenuCreator update v01

(In reply to comment #2)
> (In reply to comment #1)
> I'll do it thoroughly as soon as we get a clear sign from Platform/UI that the
> QuickMenuCreator will not be removed again (see class javadoc).

It'll stay now :-)

> Issues I've already noticed:
> - computeMenuLocation(..) methods need to be protected, such that clients can
> override them (see JDTQuickMenuAction, which places the menu at word
> boundaries)

Make them protected.

> - some fixes in JDT/UI's version are missing in the new API:
>   - StyledText.getLineHeight(int) not used
>   - fix for bug 64855 is not in (leaking menu between invocations)

I've added this 2.

PW
Comment 10 Paul Webster CLA 2009-03-02 14:24:29 EST
(In reply to comment #9)
> Created an attachment (id=127205) [details]
> QuickMenuCreator update v01
>

Released to HEAD.  I won't pursue the command at the moment (although the internal handler is already in the code).

Markus, is the QuickMenuCreator still interesting to you guys?

PW
Comment 11 Markus Keller CLA 2009-03-03 10:24:36 EST
The QuickMenuCreator's Javadoc is wrong: It first tries to open the menu near the current selection. The Javadoc of #createMenu() should tell that it not only creates the context menu, but also opens it.

org.eclipse.jdt.internal.ui.actions.QuickMenuAction doesn't have a dispose() method. You should verify on all platforms (esp. GTK and Carbon) that the dispose strategy in HEAD of QuickMenuCreator works fine, i.e. does not keep a Menu between multiple invocations. If it's good, remove the field 'quickMenu' (make it a local variable), and deprecate the 'dispose()' method.

> Markus, is the QuickMenuCreator still interesting to you guys?

Yes, if you can make the dispose() method obsolete, then we will gladly dump our implementation and use QuickMenuCreator.
Comment 12 Paul Webster CLA 2009-03-03 13:25:04 EST
Created attachment 127356 [details]
QuickMenuCreator update v02

(In reply to comment #11)
> The QuickMenuCreator's Javadoc is wrong: 

Updated javadoc

> 
> org.eclipse.jdt.internal.ui.actions.QuickMenuAction doesn't have a dispose()
> method. You should verify on all platforms (esp. GTK and Carbon) that the
> dispose strategy in HEAD of QuickMenuCreator works fine, i.e. does not keep a
> Menu between multiple invocations. If it's good, remove the field 'quickMenu'
> (make it a local variable), and deprecate the 'dispose()' method.

This is the dispose strategy that works on win32/gtk/carbon in PopupMenuExtender, it's pretty solid.  I've removed the field and tested without it, dispose is called consistently

PW
Comment 13 Paul Webster CLA 2009-03-03 13:26:59 EST
(In reply to comment #12)
> Created an attachment (id=127356) [details]
> QuickMenuCreator update v02

Released to HEAD >20090303
PW
Comment 14 Markus Keller CLA 2009-03-03 16:47:48 EST
> > Created an attachment (id=127356) [details] [details]
> > QuickMenuCreator update v02

Looks good. I need to use my QuickMenuCreator in a handler at 2 places, so I added the following to my subclass of QuickMenuCreator:

	public IHandler createHandler() {
		return new AbstractHandler() {
			public Object execute(ExecutionEvent event) throws ExecutionException {
				createMenu();
				return null;
			}
		};
	}

If you think that's generally useful, you can also pull this up.
Otherwise, I think we're done here. I filed bug 266938 for us to catch up.
Comment 15 Paul Webster CLA 2009-03-04 09:10:46 EST
I think I'll hold off on the handler method for 3.5.

Released to HEAD >20090303
PW
Comment 16 Paul Webster CLA 2009-03-10 10:47:06 EDT
In I20090310-0100
PW