Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Add an action to both main menu & view context menu
Add an action to both main menu & view context menu [message #329152] Sat, 14 June 2008 02:59 Go to next message
Hao Missing name is currently offline Hao Missing nameFriend
Messages: 115
Registered: July 2009
Senior Member
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 #329169 is a reply to message #329152] Mon, 16 June 2008 11:55 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Use a command and a handler ... then you can use org.eclipse.ui.menus to
place it in the main menu and view context menu (and most other places
as well).

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.


PW


--
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


Re: Add an action to both main menu & view context menu [message #329194 is a reply to message #329169] Mon, 16 June 2008 16:23 Go to previous messageGo to next message
Hao Missing name is currently offline Hao Missing nameFriend
Messages: 115
Registered: July 2009
Senior Member
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?
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?

thanks
Re: Add an action to both main menu & view context menu [message #329248 is a reply to message #329194] Tue, 17 June 2008 12:42 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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


Previous Topic:How to add a page to existing multi-page editor at runtime
Next Topic:eclipse startup
Goto Forum:
  


Current Time: Tue Jul 16 15:37:39 GMT 2024

Powered by FUDForum. Page generated in 0.03413 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top