DROP_DOWN_MENU not always displaying menu [message #753754] |
Fri, 28 October 2011 11:20  |
Eclipse User |
|
|
|
I've added some actions to my view in the form:
Action someToolAction = new Action("My Action",Action.AS_DROP_DOWN_MENU) {
...
}
MyMenuCreator myCreator = new MyMenuCreator();
someToolAction.setMenuCreator(myCreator);
IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager();
mgr.add(someToolAction);
This works fine as long as I select the drop down button by pressing on the down arrow, but when I press on the body of the button to the left of the arrow, I don't get the menu to display.
I see that I can separately catch this event using the run() or runWithEvent() methods in my Action definition. I can even get the menu to then pop up using something like:
Action someToolAction = new Action("My Action",Action.AS_DROP_DOWN_MENU) {
public void run() {
IMenuCreator imenu = this.getMenuCreator();
Menu menu = imenu.getMenu(parent);
menu.setVisible(true);
}
But that places the menu relative where my mouse was when I selected the button.
My question is this -- is there someway that I am missing to configure the drop down to do the same thing when I select the button body as when I select the button drop down arrow? If not, how do I get the location of the generated button so that I can properly place the popup?
|
|
|
|
|
Re: DROP_DOWN_MENU not always displaying menu [message #872730 is a reply to message #753784] |
Wed, 16 May 2012 13:58  |
Eclipse User |
|
|
|
I know this is an old thread, but the question - how do you get the pop down menu to open when the user clicks on the non latch part of a drop down button - was never answered.
I had the same question. This thread was the only relevant google hit I could find. It got me half way towards the solution. The handleWidgetSelection method in the ActionContributionItem class got me to the full solution.
The eventual method I used is below. I am the farthest thing from an eclipse rcp expert, so please feel free to suggest better alternatives.
@Override
public void runWithEvent(Event e)
{
Widget item = e.widget;
if (item != null)
{
int style = item.getStyle();
if ((style & SWT.DROP_DOWN) != 0) {
IMenuCreator mc = getMenuCreator();
ToolItem toolItem = (ToolItem) item;
if (mc != null) {
Menu m = mc.getMenu(toolItem.getParent());
if (m != null) {
// position the menu below the drop down item
ToolBar toolbar = toolItem.getParent( );
// point is now set to toolbar location.
Point point = toolbar.toDisplay( new Point(e.x, e.y));
// move point over to beneath the button
point.x += toolItem.getBounds( ).x;
point.y += toolItem.getBounds( ).y + toolItem.getBounds( ).height;
m.setLocation(point.x, point.y);
m.setVisible(true);
return;
}
}
}
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.24835 seconds