Add an action to both main menu & view context menu [message #329152] |
Fri, 13 June 2008 22:59  |
Eclipse User |
|
|
|
Hi,
I need to create an action which will be added to both main menu & a view
context menu. In order to add the action to main menu, the action needs to
extend Action; and in order to add the action to view context menu, the
action needs to extend ActionDelegate. The same action needs to be
implemented twice. For me, it looks tedious. Is there any way such that
just implements the action once?
thanks
hao
|
|
|
|
|
Re: Add an action to both main menu & view context menu [message #329248 is a reply to message #329194] |
Tue, 17 June 2008 08:42  |
Eclipse User |
|
|
|
hao wrote:
> Hi Paul,
>
> I like the command and handler approach. Thanks a lot.
>
> I need a little more explanation on your following comments:
>
>> Other than that, you would have to make the Action from your
> ApplicationActionBarAdvisor (of which there is one per workbench window)
> available to your view createPartControl(*) so you can place it in your
> view context menu (assuming you are an RCP app). Or have the same class
> implement both types of I*ActionDelegate needed for the 2 menus. You'll
> get 2 instances of the object, but in different places.
>
> My question is
>
> 1. If I use command and handler approach, do I need to following the
> about comments too?
No, that's what you have to do if you want to use IAction based
(ApplicationActionBarAdvisor) or I*ActionDelegate based
(org.eclipse.ui.actionSets, etc) contributions. The Command+Handler
based approach simply involves creating the command and handler, and
then using org.eclipse.ui.menus/menuContribution to place the commands
in different menus.
> 2. Do you mean I need to make the reference of
> ApplicationActionBarAdvisor available to my View class? Does getSite()
> method help for getting it in my view class?
There's no support for the first IAction based suggestion ... you would
have to code it yourself, potentially storing the needed actions in your
plugin activator (a manager, maybe) and retrieving them from your view.
--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm
|
|
|
Powered by
FUDForum. Page generated in 0.03417 seconds