Adding Copy/Paste to Eclipse CNF popup menu

无人久伴 提交于 2019-12-11 15:06:06

问题


We have added a new custom view to our Eclipse Kepler environment. The new view is similar to the Navigator view and the Project Explorer view, except that it filters and reorders the displayed resources according to our special needs. After creating the custom view using the Eclipse Common Navigator Framework (CNF), we find that there are no edit items such as Copy nor Paste in the popup context menu, and they are disabled in the regular dropdown menu. So now we need to add them. Several other posts discuss this issue but none seem to give a complete answer.

What we have so far is (shown only for Copy, others are similar):

In plugin.xml we added menus extension to place items on popup menu:

<extension
      point="org.eclipse.ui.menus">
   <menuContribution
         locationURI="popup:com.company.views.CustomView?before=import">
      <command
            commandId="org.eclipse.ui.edit.copy"
            icon="icons/copy_16x16.png"
            label="Copy"
            style="push">
      </command>
   </menuContribution>
</extension>

Next in plugin.xml we added handlers extension to make menu item functional:

<extension
      point="org.eclipse.ui.handlers">
   <handler
         commandId="org.eclipse.ui.edit.copy"
         class="com.company.views.CustomViewCopyHandler">
      <enabledWhen>
         <not>
            <count value="0"/>
         </not>
      </enabledWhen>
      <activeWhen>
         <with variable="activePartId">
            <equals value="com.company.views.CustomView"/>
         </with>
      </activeWhen>
   </handler>
</extension>

And finally we implemented the handler class:

public class CustomViewCopyHandler
     extends AbstractHandler
  implements IHandler
{
    public Object execute( ExecutionEvent event )
            throws ExecutionException
    {
        return null;
    }
}

It works great as far as it goes. Copy is added to the popup menu and clicking it calls the class execute() function.

But what should execute() do? That is the point of this post. We have found Eclipse classes org.eclipse.ui.internal.navigator.resources.actions.CopyAction and org.eclipse.ui.internal.navigator.resources.actions.EditActionGroup but cannot find a way to use them. Given they are named as 'internal' it is not surprising they are not meant for direct user access.

Has anyone ever successfully done this? Any help or pointers, but especially working code examples, greatly appreciated.

Cheers, Bill :-)

来源:https://stackoverflow.com/questions/21918690/adding-copy-paste-to-eclipse-cnf-popup-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!