Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [eclipse plugin ] adding a command and control visibility
[eclipse plugin ] adding a command and control visibility [message #549628] Tue, 27 July 2010 12:08 Go to next message
Eclipse User is currently offline Eclipse UserFriend
Messages: 34
Registered: July 2010
Member
hello !

I have added a command in the menu that appears when right clicking with the mouse
in the package explorer view .

I want this command to be visible in the menu only when I click on a file with a particular extention .

I read many articles that explain how to use "visible when " but I didn't manage to figure how to do in my case
here is the part of the plugin.xml that adds the command

<extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
         <command
               commandId="my id"
               label="my label"
               style="push">
         </command>
      </menuContribution>
   </extension>



thanks so much for helping me

[Updated on: Tue, 27 July 2010 12:10]

Report message to a moderator

Re: [eclipse plugin ] adding a command and control visibility [message #549653 is a reply to message #549628] Tue, 27 July 2010 13:28 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Check out http://wiki.eclipse.org/Command_Core_Expressions for examples
of visibleWhen

if you right click, the active variable is activeMenuSelection

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/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: [eclipse plugin ] adding a command and control visibility [message #549659 is a reply to message #549653] Tue, 27 July 2010 13:43 Go to previous messageGo to next message
Eclipse User is currently offline Eclipse UserFriend
Messages: 34
Registered: July 2010
Member
hello !

thanks for your reply !
but it didn't help me

I want the command to appear only when I click on a file with a specific extention

I've added this part
<visibleWhen
                  checkEnabled="false">
               <with
                     variable="activeMenuSelection">
               </with>
</visibleWhen>


How and where I shoud specify the extention of my file

thanks a lot
Re: [eclipse plugin ] adding a command and control visibility [message #549704 is a reply to message #549659] Tue, 27 July 2010 15:38 Go to previous messageGo to next message
Eclipse User is currently offline Eclipse UserFriend
Messages: 34
Registered: July 2010
Member
Hi again !!

I found the answer to my question but I still have a small problem
here is the code XML :


<extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
         <command
               commandId="my Id"
               label="my label
               style="push">
         <visibleWhen>
      <with variable="activeMenuSelection">
         <iterate>
            <adapt type="org.eclipse.core.resources.IFile">
               <test property="org.eclipse.core.resources.name" value="*.extension" />
            </adapt>
         </iterate>
      </with>
   </visibleWhen>
         </command>
      </menuContribution>
   </extension>


the problem is that when there is nothing selected in my package explorer the command still appears and I don't know how to disable this .

apart from this problem the control of the visibility of the extension works very well

can you help with this please Smile
thank you very much
Re: [eclipse plugin ] adding a command and control visibility [message #549719 is a reply to message #549704] Tue, 27 July 2010 16:45 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

It's an attribute on iterate, I believe. An empty iterate evaluates to
true without it. Check out the extension point description for
org.eclipse.ui.menus.

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/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: [eclipse plugin ] adding a command and control visibility [message #549868 is a reply to message #549719] Wed, 28 July 2010 09:35 Go to previous messageGo to next message
Eclipse User is currently offline Eclipse UserFriend
Messages: 34
Registered: July 2010
Member
Okay !!

thanks so much for helping me . I've added this

<iterate  ifEmpty="false">


and now it's perfect Very Happy !!!
Re: [eclipse plugin ] adding a command and control visibility [message #551137 is a reply to message #549628] Thu, 05 August 2010 12:01 Go to previous messageGo to next message
Eclipse User is currently offline Eclipse UserFriend
Messages: 34
Registered: July 2010
Member
Hi !!

I just noticed that the commande is no longer visible in my menu when I change from the java perspective to C / C + + perspective Confused
How can I fix this problem so that it appears in all the available perspectives in eclipse

thank you so much for your help
Re: [eclipse plugin ] adding a command and control visibility [message #551166 is a reply to message #549628] Thu, 05 August 2010 13:35 Go to previous message
Eclipse User is currently offline Eclipse UserFriend
Messages: 34
Registered: July 2010
Member
it's ok I've found the solution
I had to change org.eclipse.jdt.ui.PackageExplorer in the locationURI by this
org.eclipse.ui.popup.any Very Happy

now it's visible in all the available perspectives
Previous Topic:Project set import (Error deleting resources) eclipse 3.4.2, 3.5.2 and 3.6
Next Topic:Creating projects in workspace subfolders
Goto Forum:
  


Current Time: Fri Apr 19 15:33:21 GMT 2024

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

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

Back to the top