delete popup working fine over project explorer view but not working over navigator view - eclipse-plugin

I am trying to hide 'delete' popup-menu for some files. I used following plugin.xml entry.
<extension point="org.eclipse.ui.activities">
<activity id="hidedeletepopupmenuID" name="hidedeletepopupmenu">
<enabledWhen>
<with variable="selection">
<iterate operator="and">
<adapt type="org.eclipse.core.resources.IResource" >
<or>
<test property="org.eclipse.core.resources.name" value="*.java"/>
</or>
</adapt>
</iterate>
</with>
</enabledWhen>
</activity>
<activityPatternBinding activityId="hidedeletepopupmenuID"
isEqualityPattern="false" pattern="org.eclipse.ui.edit.delete">
</activityPatternBinding>
</extension>
This seems to be working fine over project explorer view, but navigator view its not wokring. Can anyone help on this?
Thanks,
darshan

Actions in Navigator view context menu are hard-coded, see ResourceNavigator.fillContextMenu(IMenuManager menu).
Note that the action in popup menu is not the only way to delete a resource (there's also a menu item in Edit menu and key-binding).

Related

How to remove Eclipse Move from context menu and refactor main menu

I want to remove move command for specific resource type. To achieve it, I thought to using org.eclipse.ui.activities
I tried below configuration, but it didn't work.
<extension
point="org.eclipse.ui.activities">
<activity
id="refactormovehiding.id"
name="refactormovehiding">
<enabledWhen>
<not>
<instanceof
value="com.shashwat.resource.PResource">
</instanceof>
</not>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="refactormovehiding.id"
pattern=".*/org.eclipse.jdt.ui.actions.Move">
</activityPatternBinding>
</extension>
I even used different pattern thinking pattern which I am providing is incorrect
<extension
point="org.eclipse.ui.activities">
<activity
id="refactormovehiding.id"
name="refactormovehiding">
<enabledWhen>
<not>
<instanceof
value="com.shashwat.resource.PResource">
</instanceof>
</not>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="refactormovehiding.id"
pattern=".*/org.eclipse.ltk.ui.refactoring.commands.moveResources">
</activityPatternBinding>
</extension>
I even tried without enabledWhen configuration, but no luck.

Project explorer Delete Action not working as expected

Eclipse Default Delete action on the project explorer (context menu, key binding) not working as expected.
In Project explorer I do have 2 different files let's assume ".pc" and ".tc" files.
I want to restrict the user from deleting the ".tc" files from project explorer for that I have written custom handlers to restrict it. Actions are configured as below.
<handler
class="MyTCFileDeleteHandler"
commandId="org.eclipse.ui.edit.delete">
<activeWhen>
<with
variable="selection">
<iterate
ifEmpty="false">
<instanceof
value="org.eclipse.core.resources.IResource">
</instanceof>
<test
property="org.eclipse.core.resources.extension"
value="tc">
</test>
</iterate>
</with>
</activeWhen>
</handler>
<handler
class="MyTCFileDeleteHandler"
commandId="org.eclipse.ltk.ui.refactoring.commands.deleteResource">
<activeWhen>
<with variable="selection">
<iterate
ifEmpty="false">
<instanceof
value="org.eclipse.core.resources.IResource">
</instanceof>
<test
property="org.eclipse.core.resources.extension"
value="tc">
</test>
</iterate>
</with>
</activeWhen>
</handler>
But due to this DeleleParticepent wrote are not getting calls for ".pc" file deletion.
Also, this misbehaves for shortcuts, context menus differently.
What I want to achieve, I should restrict the deleting of some files according to extension and some not, and my participant should call if the file is deleting. And this should work for the context menu, shortcut.

How to limit visibility of a popup menu item only to project which contains a specific file?

I am looking to limit my popup entry to be only displayed when the project has a specific file
at its root directory.
I am currently using this code to only have the popup entry shown when a project is clicked on.
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<adapt
type="org.eclipse.core.resources.IProject">
<test
property="ProjectSharing.test2">
</test>
</adapt>
</iterate>
</visibleWhen>
How can I check for a specific file?

popup plugin development eclipse 3.6.2

I'm trying to develop an eclipse plugin, but, seeing the steps, or using the template Eclipse gives, I can't see the menu item.
Mi Eclipse version is 3.6.2 and mi plugin.xml file has this content:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.popupMenus">
<objectContribution
objectClass="org.eclipse.core.resources.IFile"
id="Test.contribution1">
<menu
label="Test Submenu"
path="additions"
id="Test.menu1">
<separator
name="group1">
</separator>
</menu>
<action
label="Test Action"
class="test.popup.actions.TestNewAction"
menubarPath="Test.menu1/group1"
enablesFor="1"
id="Test.newAction">
</action>
</objectContribution>
</extension>
</plugin>
This is the sample template Eclipse gives, but it doesn't work.
It's supposed that this kind of menu shows the option when you right click on a Java element (like a constant or something like that). Am I wrong?
Indeed, the code you posted should show a menu and a submenu when you make a right click on a file in the Project Explorer/Package Explorer view.
If you don't see any menu or submenu, try to add adaptable="true" and nameFilter="*", like this :
<objectContribution
adaptable="true"
nameFilter="*"
objectClass="org.eclipse.core.resources.IFile"
id="Test.contribution1">
It should work now and you should have this output.

Eclipse Plugin Development : How to add option in Right Click Menu

I have created an eclipse plugin. I am able to add a menu and submenu.
However, I am not able to add an option in the Right Click menu. Does anyone have any idea how to do that?
Here's an example (this code has filled with your preferences and classes and to be added to the plugin.xml):
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
id=""
nameFilter=""
objectClass="org.eclipse.core.resources.IFile">
<action
id="org.eclipse.ui.articles.action.contribution.object.action1"
label=""
icon=""
menubarPath="additions"
class="">
</action>
</objectContribution>
</extension>
The provided solution using org.eclipse.ui.popupMenus is deprecated.
One should use the org.eclipse.ui.menus extension point.
In general you can configure a menuContribution using the plugin GUI, which will generate the plugin.xml for you. As you requested the menu to be available in the "Right Click menu" you can use popup:org.eclipse.ui.popup.any as locationURI. With additional configuration you can control under which circumstances the menu should be visible.
You can also edit the plugin.xml directly in the plugin.xml tab.
The generated plugin.xml will look similar to this:
<extension
id="menuid"
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any">
.
.
.
</menuContribution>
</extension>
See Custom Popup menu in eclipse plugin for a similar problem.