Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » actions in Context Menu
actions in Context Menu [message #449256] Thu, 11 May 2006 09:26 Go to next message
Eclipse UserFriend
Originally posted by: quest_lee.126.com

Why there is no selection being sent to the action?

the problem is as followed:
I have an action Called NewFileAction:
class NewFileAction extends Actioin implements
ISelectionListener,ActionFactory.IWorkbenchAction
{...}
a ViewPart called FileView which has a TreeViewer:
class FileView extends ViewPart
{...}
in this FileView, I created a Context Menu,and add an instance of NewFileAction into this menu,when I right
click on the tree, the context menu popup, then I clicked
on the newFileAction, there should be some action.However,
what I found is that there is no selection sent to NewFileAction.Why this happened?
I also as the newFileAction in file menu bar, which works correctly.
Any help is appreciated!

some of the code are,
public class NewFileView extends ViewPart {

private TreeViewer treeViewer;

public void createPartControl(Composite parent) {

getSite().setSelectionProvider(treeViewer);
...
createContextMenu();
}

private void createContextMenu() {
MenuManager menuMgr = new MenuManager();
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager mgr) {
fillContextMenu(mgr);
}
});
Menu menu = menuMgr.createContextMenu(treeViewer.getControl());
treeViewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, treeViewer);

}

private void fillContextMenu(IMenuManager mgr) {

mgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
IWorkbenchWindow window = getSite().getWorkbenchWindow();
mgr.add(new NewFileAction(window));

}
...

}
Re: actions in Context Menu [message #449263 is a reply to message #449256] Thu, 11 May 2006 09:57 Go to previous messageGo to next message
Eclipse UserFriend
Because when you create your action, in theory there's no selection changed?

I'd augment your NewFileAction so that if it doesn't have a selection,
it goes to the IWorkbenchWindow and gets one.

Then I'd open a bug report on https://bugs.eclipse.org/bugs/ with your
usecase and a simple example that shows it not working.

Later,
PW
Re: actions in Context Menu [message #449405 is a reply to message #449263] Fri, 12 May 2006 02:48 Go to previous message
Eclipse UserFriend
Originally posted by: quest_lee.126.com

Since I registered an instance of NewFileAction
in ApplicationActionBarAdvisor by its ID,
if I could get this action object and send it
to the context menu?
By this by, I don't need to care about the selection
thing.

Thank you.
Previous Topic:how to implement Cut, copy and paste actions
Next Topic:How to hide and Show views????
Goto Forum:
  


Current Time: Sat Aug 30 19:36:43 EDT 2025

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

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

Back to the top