Home » Eclipse Projects » Eclipse Platform » customizing conext menu
| | | | | | | | |
Re: customizing conext menu [message #1100850 is a reply to message #1100720] |
Tue, 03 September 2013 17:43 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Phil,
Are you still trying to remove things or to add things? Maybe someone
else can explain how to remove things; I've not tried to do that... If
you look in the plugin.xml for org.eclipse.emf.ecore.editor, you'll see
how it contributes actions that appear in every contact menu, e.g., this
contribution for creating a dynamic instance form an EClass.
<extension point="org.eclipse.ui.popupMenus">
....
<objectContribution
id="org.eclipse.emf.ecore.editor.CreateDynamicInstance"
objectClass="org.eclipse.emf.ecore.EClass">
<action
id="org.eclipse.emf.ecore.editor.CreateDynamicInstanceAction"
label="%_UI_CreateDynamicInstance_menu_item"
menubarPath="additions"
class="org.eclipse.emf.ecore.action.CreateDynamicInstanceAction"
enablesFor="1"/>
</objectContribution>
</extension>
On 03/09/2013 3:51 PM, Phil H wrote:
> What kind of examples do you mean? I was able to figure out how to remove some entries, but there are still entries like "run as", "debug as", "Team" and so on (see attached image).
>
> I thought maybe commeting out "getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer));" in createContextMenuFor(StructuredViewer viewer) would do the trick, but it hasn't changed anything.
> I also checked my plugin dependencies, but couldn't find anything which could contribute this menu entries.
>
> I don't really understand how your Jface approach should work. How can object contribution remove menu entries from ymmeditor?
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | | | | | |
Re: customizing conext menu [message #1102307 is a reply to message #1102293] |
Thu, 05 September 2013 16:11 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Phi,
Comments below.
On 05/09/2013 5:57 PM, Phil H wrote:
> Hmm, that is really odd..So you don't have any menu entries like
> Wizards, Run As, Debus As, Team and son anymore?
No, those are contributed by other things in the platform and that call
registers the context menu to receive those contributions...
>
> I can't remember that I've added additional plugins..At all I give up
> with this..
When you launch, any plugin included in the launch configuration can
register extension in their plugin.xmls that contribute to these menu
items; by default that's all your bundles in the workspace and all the
bundles in your target platform, i.e., the debugger framework, the team
framework, and so on.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: customizing conext menu [message #1103034 is a reply to message #1102307] |
Fri, 06 September 2013 10:08 |
Phil H Messages: 267 Registered: November 2012 |
Senior Member |
|
|
Hi Ed,
you're right, I just found out that there is another class which calling this method. Commeting out this removed all the contributed stuff like "Wizards" etc., but unfortunately also the menuitem which I contributed in the plugin.xml isn't shown anymore.
Just calling getSite().registerContextMenu("myCommandId", contextMenu, new UnwrappingSelectionProvider(viewer)); hasn't worked.
So I thought about filtering out the unwanted contributions with this code:
protected void createContextMenuFor(StructuredViewer viewer) {
MenuManager contextMenu = new MenuManager("#PopUp") {
@Override
public IContributionItem[] getItems() {
IContributionItem[] items = super.getItems();
List<IContributionItem> filteredItems = new ArrayList<IContributionItem>();
for (IContributionItem item : items) {
if (item != null && item.getId() != null && ((item.getId().startsWith("org.itea2"))))
filteredItems.add(item);
}
items = new IContributionItem[filteredItems.size()];
return filteredItems.toArray(items);
}
};
contextMenu.add(new Separator("additions"));
contextMenu.setRemoveAllWhenShown(true);
contextMenu.addMenuListener(this);
Menu menu = contextMenu.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer));
int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() };
viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer));
viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(getEditingDomain(), viewer));
}
This works fine for my menuitem, but it turned out that using this filter (it doesn't matter which string is used in item.getId().startsWith("org.itea2")) results in a context menu without the EMF menu items like "New Child", "undo" etc.
Is there any workaround for this?
[Updated on: Fri, 06 September 2013 10:14] Report message to a moderator
|
|
|
Re: customizing conext menu [message #1103691 is a reply to message #1103034] |
Sat, 07 September 2013 05:40 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Phil,
Comment below.
On 06/09/2013 12:08 PM, Phil H wrote:
> Hi Ed,
>
> you're right, I just found out that there is another class which
> calling this method. Commeting out this removed all the contributed
> stuff like "Wizards" etc., but unfortunately also the menuitem which I
> contributed in the plugin.xml isn't shown anymore.
Yes, that's to ge expected.
>
> Just calling getSite().registerContextMenu("myCommandId", contextMenu,
> new UnwrappingSelectionProvider(viewer)); hasn't worked.
No, the ID you use is important.
>
> So I thought about filtering out the unwanted contributions with this
> code:
>
>
> protected void createContextMenuFor(StructuredViewer viewer) {
> MenuManager contextMenu = new MenuManager("#PopUp") {
> @Override
> public IContributionItem[] getItems() {
>
> IContributionItem[] items = super.getItems();
> List<IContributionItem> filteredItems = new
> ArrayList<IContributionItem>();
> for (IContributionItem item : items) {
> if (item != null && item.getId() != null &&
> ((item.getId().startsWith("org.itea2"))))
> filteredItems.add(item);
> }
> items = new IContributionItem[filteredItems.size()];
> return filteredItems.toArray(items);
> }
> };
> contextMenu.add(new Separator("additions"));
> contextMenu.setRemoveAllWhenShown(true);
> contextMenu.addMenuListener(this);
> Menu menu = contextMenu.createContextMenu(viewer.getControl());
> viewer.getControl().setMenu(menu);
> getSite().registerContextMenu(contextMenu, new
> UnwrappingSelectionProvider(viewer));
>
> int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
> Transfer[] transfers = new Transfer[] {
> LocalTransfer.getInstance() };
> viewer.addDragSupport(dndOperations, transfers, new
> ViewerDragAdapter(viewer));
> viewer.addDropSupport(dndOperations, transfers, new
> EditingDomainViewerDropAdapter(getEditingDomain(), viewer));
> }
>
>
> This works fine for my menuitem, but it turned out that using this
> filter (it doesn't matter which sring is used in
> item.getId().startsWith("org.itea2")) results in a context menu
> without the EMF menu items like "New Child", "undo" etc.
>
> Is there any workaround for this?
It looks like your filter filters out pretty much everything. Are you
actually using a debugger to observe what your filter is doing?
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Goto Forum:
Current Time: Mon Sep 23 11:28:51 GMT 2024
Powered by FUDForum. Page generated in 0.29014 seconds
|