Home » Eclipse Projects » Eclipse Platform » How to participate in cut / copy / paste?
| |
Re: How to participate in cut / copy / paste? [message #331257 is a reply to message #331236] |
Thu, 28 August 2008 15:30 |
Eclipse User |
|
|
|
Originally posted by: mario.winterer.gmx.net
Hi!
I think since eclipse 3.4 it should also be possible to use the command
framework and register a command handler for the required retargetable
action.
But I'm wondering what happens if both, an action delegate and a command
handler are registered for a given command/action id. What happens if
the command is executed? Will the handler be used or the action delegate?
Mario
Paul Webster schrieb:
> kaprasanna wrote:
>> Hi,
>>
>> I want the cut / copy / paste buttons on the toolbar (and the Edit
>> menu options) to be enabled when user selects a view of my plugin. And
>> I want to perform some actions when the respective button is pressed.
>> How can I achieve this?
>
> Check out the help listed in my sig and
> http://www.eclipse.org/articles/Article-action-contribution/ Contributing%20Actions%20to%20the%20Eclipse%20Workbench.html
>
>
> PW
>
>
|
|
| |
Re: How to participate in cut / copy / paste? [message #331300 is a reply to message #331276] |
Fri, 29 August 2008 10:29 |
Eclipse User |
|
|
|
Originally posted by: mario.winterer.gmx.net
Ah. Nice. I thought this is only possible using the extension point.
But in my case, a global action handler is already registered for the
copy action. Now I want to additionally register a handler for the same
copy action.
But unfortunately, the global action handler is chosen always, my
handler never gets executed.
Paul Webster schrieb:
> Mario Winterer wrote:
>> Hi!
>>
>> I think since eclipse 3.4 it should also be possible to use the
>> command framework and register a command handler for the required
>> retargetable action.
>> But I'm wondering what happens if both, an action delegate and a
>> command handler are registered for a given command/action id. What
>> happens if the command is executed? Will the handler be used or the
>> action delegate?
>
> In 3.4 you can do it entirely using commands and handlers. For example,
> when your view is created simply get the IHandlerService and register
> handlers:
>
> IHandlerService hs
> = (IHandlerService) getSite().getService(IHandlerService.class);
> hs.activeHandler("org.eclipse.ui.edit.copy", new MyCopyHandler());
> // and so forth for cut and paste
>
> PW
>
|
|
| | |
Re: How to participate in cut / copy / paste? [message #331423 is a reply to message #331412] |
Fri, 05 September 2008 12:15 |
|
kaprasi wrote:
> Hi Paul,
>
> Looks like this is not working for me fully.
>
> This is what I have done :
> I am using Eclipse 3.3.2 (Europa).
> I have used the extension point : org.eclipse.ui.handlers as :
>
> <extension
> point="org.eclipse.ui.handlers">
> <handler
> class="com.example.MyHandler"
> commandId="com.example.handler">
> <activeWhen>
> <instanceof
> value="com.example.helloworld.MyView">
> </instanceof>
> </activeWhen>
> </handler>
> </extension>
^^^ This definition is interesting, but has nothing to do with copy. On
top of that, the activeWhen clause will always be false (since the
default variable is a Collection).
> I have created a class MyHandler which extends
> org.eclipse.core.commands.AbstractHandler.
>
> This is the code in my view's createPartControl method :
> IHandlerService hs =
> (IHandlerService)getSite().getService(IHandlerService.class) ;
> hs.activateHandler("org.eclipse.ui.edit.copy", new MyHandler());
This is fine, and what makes CTRL+C work.
> I run the project and click on my view.
> The copy option on in Edit menu is not enabled.
> But if I press ctrl+c. The above println comes up on the console.
>
> Question : How do I enable the Edit -> copy / cut options when user
> clicks on my view.
In 3.3 Edit>Copy is a RetargetAction. It will only enable if you also
have a
getViewSite().getActionBars().setGlobalActionHandler(ActionF actory.COPY.getId(),
new MyCopyAction());
You can make the handler and the action work off of the same code base
(so they're in sync).
In 3.4, the RetargetAction has been replaced with a
CommandContributionItem (which tracks the same state as CTRL+C)
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/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
|
|
| | | |
Goto Forum:
Current Time: Tue Jan 21 07:02:33 GMT 2025
Powered by FUDForum. Page generated in 0.05115 seconds
|