Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to cause right click to both show popup menu and select item clicked on?
How to cause right click to both show popup menu and select item clicked on? [message #441177] |
Tue, 10 August 2004 17:31 |
No real name Messages: 3 Registered: July 2009 |
Junior Member |
|
|
Hi,
I'm having a problem with the builtin Tree and Table classes, in that when
users right click on
something that isn't already selected, it will get selected, but won't show
the popup menu
(well, sometimes it will, sometimes it won't - it's not even consistent).
The Tree seems to have
more problems with this than the Table, which seems to behave properly.
(Aside -- could it
have something to do with the fact that the selection in the Tree updates
the Table display?)
What I'd like is when the user right clicks on something, the thing is
selected AND the popup
menu appears, more or less at the same time.
I've scoured everywhere looking for a clue or a code snippet but haven't
found anything yet.
Does anyone have any ideas on this?
Thanks,
Brian
|
|
|
Re: How to cause right click to both show popup menu and select item clicked on? [message #441191 is a reply to message #441177] |
Wed, 11 August 2004 16:15 |
Steve Northover Messages: 1636 Registered: July 2009 |
Senior Member |
|
|
You'll need to post a stand alone snippet for us to look at. Does this work
for you in the tables and trees in Eclipse?
"Nobody" <vikingofspiking@hotmail.com> wrote in message
news:cfb0ng$qqt$1@eclipse.org...
>
> Hi,
>
> I'm having a problem with the builtin Tree and Table classes, in that when
> users right click on
> something that isn't already selected, it will get selected, but won't
show
> the popup menu
> (well, sometimes it will, sometimes it won't - it's not even consistent).
> The Tree seems to have
> more problems with this than the Table, which seems to behave properly.
> (Aside -- could it
> have something to do with the fact that the selection in the Tree updates
> the Table display?)
>
> What I'd like is when the user right clicks on something, the thing is
> selected AND the popup
> menu appears, more or less at the same time.
>
> I've scoured everywhere looking for a clue or a code snippet but haven't
> found anything yet.
> Does anyone have any ideas on this?
>
> Thanks,
>
>
> Brian
>
>
|
|
|
Re: How to cause right click to both show popup menu and select item clicked on? [message #441197 is a reply to message #441191] |
Wed, 11 August 2004 18:03 |
No real name Messages: 3 Registered: July 2009 |
Junior Member |
|
|
Right now I'm not doing anything special, so I don't have any code to post.
I'm just relying on
the default behavior of the tree and list to do the right thing when the
user right clicks. I don't
have any right click code except the standard:
MenuManager menuMgr = new MenuManager();
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener()
{
public void menuAboutToShow(IMenuManager mgr)
{
fillContextMenu(mgr);
}
});
Menu menu = menuMgr.createContextMenu(control);
control.setMenu(menu);
getSite().registerContextMenu(menuMgr, m_selProvider);
Sorry for the formatting, it didn't survive the copy/paste.
fillContextMenu() just adds in
GroupMarkers for the context menu items.
I noticed that right clicking on an unselected item in Eclipse DOES seem to
work, but even after
wading through the code (there's an awful lot of it) I still haven't found
the magical incantation
that is causing it to do the right thing. By right thing, I mean it selects
the item AND pops up
the context menu.
One thing I tried is handling the mouse button down event, and seeing if
it's button 3. If so,
then select the item the user clicked on (if any). But that didn't work.
Thanks,
Brian
"Steve Northover" <steve_northover@ca.ibm.com> wrote in message
news:cfdgjd$co3$1@eclipse.org...
> You'll need to post a stand alone snippet for us to look at. Does this
work
> for you in the tables and trees in Eclipse?
>
> "Nobody" <vikingofspiking@hotmail.com> wrote in message
> news:cfb0ng$qqt$1@eclipse.org...
> >
> > Hi,
> >
> > I'm having a problem with the builtin Tree and Table classes, in that
when
> > users right click on
> > something that isn't already selected, it will get selected, but won't
> show
> > the popup menu
> > (well, sometimes it will, sometimes it won't - it's not even
consistent).
> > The Tree seems to have
> > more problems with this than the Table, which seems to behave properly.
> > (Aside -- could it
> > have something to do with the fact that the selection in the Tree
updates
> > the Table display?)
> >
> > What I'd like is when the user right clicks on something, the thing is
> > selected AND the popup
> > menu appears, more or less at the same time.
> >
> > I've scoured everywhere looking for a clue or a code snippet but haven't
> > found anything yet.
> > Does anyone have any ideas on this?
> >
> > Thanks,
> >
> >
> > Brian
> >
> >
>
>
|
|
|
Re: How to cause right click to both show popup menu and select item clicked on? [message #441528 is a reply to message #441197] |
Mon, 16 August 2004 20:34 |
Veronika Irvine Messages: 1272 Registered: July 2009 |
Senior Member |
|
|
It appears you are using the JFace and/or Eclipse Platform frameowrk of menu
management. If so, you should ask this question on the eclipse.platform
newsgroup:
news://news.eclipse.org/eclipse.platform
In SWT code, what you are requesting is the default behaviour if you set a
menu on the control:
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
final Table table = new Table(shell, SWT.BORDER);
for (int i = 0; i < 10; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText("item "+i);
}
final Menu menu = new Menu(table);
table.setMenu(menu);
table.addListener(SWT.MenuDetect, new Listener() {
public void handleEvent(Event e) {
MenuItem[] items = menu.getItems();
for (int i = 0; i < items.length; i++) {
items[i].dispose();
}
TableItem[] selection = table.getSelection();
for (int i = 0; i < selection.length; i++) {
MenuItem item = new MenuItem(menu, SWT. PUSH);
item.setText(selection[i].getText());
}
if (selection.length == 0) {
MenuItem item = new MenuItem(menu, SWT. PUSH);
item.setText("No selection");
}
}
});
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
"Brian" <vikingofspiking@hotmail.com> wrote in message
news:cfdn0k$mnl$1@eclipse.org...
> Right now I'm not doing anything special, so I don't have any code to
post.
> I'm just relying on
> the default behavior of the tree and list to do the right thing when the
> user right clicks. I don't
> have any right click code except the standard:
>
> MenuManager menuMgr = new MenuManager();
>
> menuMgr.setRemoveAllWhenShown(true);
>
>
> menuMgr.addMenuListener(new IMenuListener()
>
> {
>
> public void menuAboutToShow(IMenuManager mgr)
>
> {
>
> fillContextMenu(mgr);
>
> }
>
> });
>
>
> Menu menu = menuMgr.createContextMenu(control);
>
> control.setMenu(menu);
>
>
> getSite().registerContextMenu(menuMgr, m_selProvider);
>
>
> Sorry for the formatting, it didn't survive the copy/paste.
> fillContextMenu() just adds in
> GroupMarkers for the context menu items.
>
> I noticed that right clicking on an unselected item in Eclipse DOES seem
to
> work, but even after
> wading through the code (there's an awful lot of it) I still haven't found
> the magical incantation
> that is causing it to do the right thing. By right thing, I mean it
selects
> the item AND pops up
> the context menu.
>
> One thing I tried is handling the mouse button down event, and seeing if
> it's button 3. If so,
> then select the item the user clicked on (if any). But that didn't work.
>
> Thanks,
>
> Brian
>
>
> "Steve Northover" <steve_northover@ca.ibm.com> wrote in message
> news:cfdgjd$co3$1@eclipse.org...
> > You'll need to post a stand alone snippet for us to look at. Does this
> work
> > for you in the tables and trees in Eclipse?
> >
> > "Nobody" <vikingofspiking@hotmail.com> wrote in message
> > news:cfb0ng$qqt$1@eclipse.org...
> > >
> > > Hi,
> > >
> > > I'm having a problem with the builtin Tree and Table classes, in that
> when
> > > users right click on
> > > something that isn't already selected, it will get selected, but won't
> > show
> > > the popup menu
> > > (well, sometimes it will, sometimes it won't - it's not even
> consistent).
> > > The Tree seems to have
> > > more problems with this than the Table, which seems to behave
properly.
> > > (Aside -- could it
> > > have something to do with the fact that the selection in the Tree
> updates
> > > the Table display?)
> > >
> > > What I'd like is when the user right clicks on something, the thing is
> > > selected AND the popup
> > > menu appears, more or less at the same time.
> > >
> > > I've scoured everywhere looking for a clue or a code snippet but
haven't
> > > found anything yet.
> > > Does anyone have any ideas on this?
> > >
> > > Thanks,
> > >
> > >
> > > Brian
> > >
> > >
> >
> >
>
>
|
|
|
Goto Forum:
Current Time: Sat May 04 07:33:03 GMT 2024
Powered by FUDForum. Page generated in 0.03819 seconds
|