Using org.eclipse cut / copy / paste in an RCP user application

I am developing an RCP application and I need to cut / copy / paste into this application. Since there are already commands that are delivered by eclipse (org.eclipse.ui.edit.copy, ...), I want to use them (I already added them to the toolbar, for example, in the editor). I played a little, but I don’t understand how I can react to the copy / paste command. For instance. How can I get information in the editor if something has been copied or pasted?

Is there an easy way to use commands like the save command. There I just need to implement ISaveablePart, and then call the doSave () or doSaveAs () methods ... I really like this, but I did not find ICopyablePart, ... interfaces;)

thanks in advance,

t

+4
source share
1 answer

If you require specific behavior to copy (or any command) in your editor or view, you must activate a handler for it. Usually in your createPartControl(Composite) method:

 IHandlerService serv = (IHandlerService) getSite().getService(IHandlerService.class); MyCopyHandler cp = new MyCopyHandler(this); serv.activateHandler(org.eclipse.ui.IWorkbenchCommandConstants.EDIT_COPY, cp); 

Another common way is to provide a handler through your plugin.xml:

 <handler commandId="org.eclipse.ui.edit.copy" handler="com.example.app.MyCopyHandler"> <activeWhen> <with variable="activePartId"> <equals value="com.example.app.MyEditorId"/> </with> </activeWhen> </handler> 

Then in your handler you will receive the active part and name its implementation. eg:

 IWorkbenchPart part = HandlerUtil.getActivePart(event); if (part instanceof MyEditor) { ((MyEditor)part).copy(); } 
+7
source

All Articles