How to participate in cut / copy / paste? [message #331100] |
Mon, 25 August 2008 08:28  |
Eclipse User |
|
|
|
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?
Thanks in advance.
|
|
|
|
Re: How to participate in cut / copy / paste? [message #331257 is a reply to message #331236] |
Thu, 28 August 2008 11: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 06: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 #331412 is a reply to message #331236] |
Fri, 05 September 2008 03:01   |
Eclipse User |
|
|
|
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>
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());
I have a println statement in execute method of MyHandler as :
System.out.println("execute called...");
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.
Thanks.
|
|
|
Re: How to participate in cut / copy / paste? [message #331423 is a reply to message #331412] |
Fri, 05 September 2008 08:15   |
Eclipse User |
|
|
|
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
|
|
|
Re: How to participate in cut / copy / paste? [message #331427 is a reply to message #331423] |
Fri, 05 September 2008 09:36   |
Eclipse User |
|
|
|
Hi Paul,
Thanks for the reply.
I got it working. Now both ctrl+x / c / v as well as Edit->options work
fine.
But I still have a slight problem.
Because this code is being called from createPartControl() of the view, I
can't change these behaviors according to the selection.
To elaborate more :
The code in createPartControl() of the view looks like this :
Action copyAction = new Action() {
@Override
public void run() {
System.out.println("copied!!");
super.run();
}
};
IActionBars actionBars = getViewSite().getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.COPY.getId() ,
copyAction);
// similar code for cut and paste
This enables cut / copy / paste options in Edit menu all-time;
irrespective of what is selected.
I want a control over when the edit menu options get enabled.
I have a method which gets called when a particular part of the view gets
selected. Placing the above code in that method doesn't work.
How can I achieve this?
Thanks.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04625 seconds