Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Contributing Popup Menus for CDT Projects
Contributing Popup Menus for CDT Projects [message #1086161] Tue, 13 August 2013 18:36 Go to next message
Eclipse UserFriend
I've been attempting to create a plugin that contributes an item to contextual menus in the project explorer. What I've got is this:

   <extension
         point="org.eclipse.ui.commands">
      <category
            id="org.example.myCategory"
            name="Example Category">
      </category>
      <command
            categoryId="org.exapmle.myCategory"
            defaultHandler="org.example.thingHandler"
            id="org.example.doTheThing"
            name="Do the thing">
      </command>
   </extension>

   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="true"
            locationURI="popup:org.eclipse.ui.popup.any?after=additions">
         <command
               commandId="org.example.doTheThing"
               label="Do the thing"
               style="push">
            <visibleWhen
                  checkEnabled="false">
               <with
                     variable="selection">
                  <count
                        value="1">
                  </count>
                  <iterate>
                     <and>
                        <instanceof
                              value="org.eclipse.core.resources.IResource">
                        </instanceof>
                        <or>
                            <test
                                  property="org.eclipse.core.resources.extension"
                                  value="z">
                            </test>
                            <test
                                  property="org.eclipse.core.resources.extension"
                                  value="cc">
                            </test>                            
                        </or>
                     </and>
                  </iterate>
               </with>
            </visibleWhen>
         </command>
      </menuContribution>
   </extension>


Ideally, the menu should only show up when files with the extension ".z" or ".cc" are selected, and then perform the associated action. However, the menu shows up only when selecting files of the aforementioned extension in Java Projects. The menu is absent in C++ projects when right clicking on a file. I can't seem to find an appropriate place for the locationURI that will get it to show up in C++ projects.

Out of curiosity, I tried the plugin in a separate install of Eclipse which lacked the JDT and the menu was nowhere to be found as well. I also used the plugin wizard for "popup menu" addition, and without making any changes, loaded it up and found that the menu contributed by the sample code only shows up in Java projects as well, and is absent from C++ projects.

I hope I'm just missing something here, possibly a different locationURI Smile Any advice is appreciated.

Edit: One thing I tried out of curiosity was editing the .project file and removing the C nature & CC natures from the project, and replacing them with the Java nature. The project looked a tad funky, but the menu did indeed show up. It doesn't show up if I just added the Java nature and left the C/CC natures in place.

[Updated on: Thu, 15 August 2013 10:46] by Moderator

Re: Contributing Popup Menus for CDT Projects [message #1087587 is a reply to message #1086161] Thu, 15 August 2013 17:52 Go to previous messageGo to next message
Eclipse UserFriend
After a bit more digging I figured it out...

It looks like .cc/.cpp files in the project viewer in C/CC nature projects are actually objects of type ITranslationUnit, not IFile. As such they don't directly inherit from IResource, and the property tester for IResource extension doesn't even want to consider them. I ended up writing my own as there didn't seem to be any property testers for ITranslationUnit (or related files) in any of the cdt source. Everything seems to work for the time being now though.

I did also find out that the other files I had that I wanted it to activate for (.z) did seem to be IFile objects, so it worked on those.
Re: Contributing Popup Menus for CDT Projects [message #1517144 is a reply to message #1087587] Fri, 19 December 2014 04:35 Go to previous messageGo to next message
Eclipse UserFriend
Hello Robert,

Same problem here.
I can only make my popup menu appear in the package explorer.
If I am in the project explorer my popup menu does not appear.

Can you please give some hints to how you solved this problem ?

Cheers,
Radu


Note: here is what I have in the plugin.xml file, if it helps:

<extension
point="org.eclipse.ui.popupMenus">
<objectContribution
objectClass="org.eclipse.core.resources.IFile"
id="PluginBeta.contribution1">
<menu
label="Plugin"
path="additions"
id="PluginBeta.menu1">
<separator
name="group1">
</separator>
</menu>

<action
.....
</action>
Re: Contributing Popup Menus for CDT Projects [message #1549652 is a reply to message #1517144] Tue, 06 January 2015 12:08 Go to previous message
Eclipse UserFriend
Hello,

Managed to "fix" my plug-in Smile [part of plugin.xml design below].

Help can be found:
stackoverflow.com/questions/1342532/how-to-add-items-in-popup-menu
programcreek.com/2013/02/eclipse-rcp-tutorial-add-a-menu-item-to-the-popup-menu-when-right-click-a-file/
wiki.eclipse.org/FAQ_How_do_I_access_the_active_project%3F

[not allowed to add links, so google search the above links]

<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu">
<menu
label="My_Submenu"
id="My_Submenu.menu">
<command
commandId="package.class_Name_id1"
label="Submenu_Entry1"
style="push">
</command>
<command
commandId="package.class_Name_id2"
label="Submenu_Entry1"
style="push">
</command>
<separator
name="group1">
</separator>
</menu>
</menuContribution>
</extension>

<extension
point="org.eclipse.ui.commands">
<command
categoryId="package.class_Name_cid1"
id="package.class_Name_id1">
</command>
<command
categoryId="package.class_Name_cid2"
id="package.class_Name_id2">
</command>

</extension>


<extension point="org.eclipse.ui.handlers">
<handler
class="package.class_Name1"
commandId="package.class_Name_id1">
</handler>
<handler
class="package.class_Name2"
commandId="package.class_Name_id2">
</handler>

</extension>

</plugin>

Previous Topic: Copy file from other project
Next Topic:how can I add popup menu in right-click new->MyNewMenu?
Goto Forum:
  


Current Time: Tue Jul 15 22:52:29 EDT 2025

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

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

Back to the top