Menu on a button of a toolbar? [message #464449] |
Tue, 06 March 2007 16:59 |
Eclipse User |
|
|
|
Originally posted by: diebosto.fi.vupv.es
Hi! is it possible to make a button in a toolbar that shows a menu
(MenuManager)?
It should be something like a popup menu.
How can this be done?
I've seen drop-down buttons, but that's not exactly what I need
Thanks!!
|
|
|
Re: Menu on a button of a toolbar? [message #464463 is a reply to message #464449] |
Wed, 07 March 2007 20:19 |
Eclipse User |
|
|
|
Originally posted by: news4.edv-ernstREMOVE-THIS.de
Diego Bosca <diebosto@fi.vupv.es> wrote:
>Hi! is it possible to make a button in a toolbar that shows a menu
>(MenuManager)?
>It should be something like a popup menu.
>How can this be done?
>I've seen drop-down buttons, but that's not exactly what I need
>Thanks!!
Hi Diego,
may be this is what you want. The whole thing is done in createPartControl of a
ViewPart, but could also be done in the main toolbar. Additionally I set the
button text to the last selected menu item.
private void createToolbar() {
IWorkbenchWindow window =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager();
TextUebersicht tueb = new TextUebersicht();
mgr.add (tueb);
mgr.add(new Separator());
}
public class TextUebersicht extends ControlContribution {
public TextUebersicht (){
super("TextUebersicht");
}
protected Control createControl(Composite parent) {
final Button btnSchriftArt = new Button (parent, SWT.PUSH);
btnSchriftArt.setText("einstellen ...");
try {
btnSchriftArt.setImage(new Image(Display.getCurrent(),
Platform.getBundle(client.Activator.PLUGIN_ID).
getResource("images/font_truetype.gif").openStream()));
}
catch (IOException io) {
io.printStackTrace();
}
final Menu menu = new Menu(getSite().getShell(), SWT.POP_UP);
// final Menu menu = new Menu(topViewForm.getShell(), SWT.DROP_DOWN);
MenuItem miMinischrift = new MenuItem(menu, SWT.PUSH);
miMinischrift.setText("Minischrift");
miMinischrift.setAccelerator(SWT.CTRL | '8');
miMinischrift.addSelectionListener(new SelectionListener () {
public void widgetSelected(SelectionEvent e) {
System.out.println("Minischrift selected.");
btnSchriftArt.setText("Minischrift");
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
MenuItem miMikroschrift = new MenuItem(menu, SWT.PUSH);
miMikroschrift.setText("Mikroschrift");
miMikroschrift.addSelectionListener(new SelectionListener () {
public void widgetSelected(SelectionEvent e) {
System.out.println("Mikroschrift selected.");
btnSchriftArt.setText("Mikroschrift");
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
MenuItem miBreiter = new MenuItem(menu, SWT.PUSH);
miBreiter.setText("breiter");
miBreiter.addSelectionListener(new SelectionListener () {
public void widgetSelected(SelectionEvent e) {
System.out.println("breiter selected.");
btnSchriftArt.setText("breiter");
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
MenuItem miSchmaler = new MenuItem(menu, SWT.PUSH);
miSchmaler.setText("schmaler");
miSchmaler.addSelectionListener(new SelectionListener () {
public void widgetSelected(SelectionEvent e) {
System.out.println("schmaler selected.");
btnSchriftArt.setText("schmaler");
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
MenuItem miEinstellen = new MenuItem(menu, SWT.PUSH);
miEinstellen.setText("einstellen ...");
miEinstellen.addSelectionListener(new SelectionListener () {
public void widgetSelected(SelectionEvent e) {
System.out.println("einstellen ... selected.");
btnSchriftArt.setText("einstellen ...");
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
final Composite par = parent;
btnSchriftArt.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
Rectangle rect = btnSchriftArt.getBounds();
Point pt = new Point(rect.x, rect.y +
rect.height);
pt = par.toDisplay(pt);
menu.setLocation(pt.x, pt.y);
menu.setVisible(true);
}
});
return btnSchriftArt;
}
}
|
|
|
Re: Menu on a button of a toolbar? [message #464563 is a reply to message #464463] |
Fri, 09 March 2007 10:42 |
Eclipse User |
|
|
|
Originally posted by: diebosto.fi.vupv.es
Rudi Ernst <news4@edv-ernstREMOVE-THIS.de> wrote in
news:tf7uu2teg326vmf5m1f3kpd3p5dt39f3dh@4ax.com:
> Diego Bosca <diebosto@fi.vupv.es> wrote:
>
>>Hi! is it possible to make a button in a toolbar that shows a menu
>>(MenuManager)?
>>It should be something like a popup menu.
>>How can this be done?
>>I've seen drop-down buttons, but that's not exactly what I need
>>Thanks!!
>
> Hi Diego,
>
> may be this is what you want. The whole thing is done in
> createPartControl of a ViewPart, but could also be done in the main
> toolbar. Additionally I set the button text to the last selected menu
> item.
>
> private void createToolbar() {
> IWorkbenchWindow window =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow();
> IToolBarManager mgr =
> getViewSite().getActionBars().getToolBarManager();
>
> TextUebersicht tueb = new TextUebersicht();
> mgr.add (tueb);
> mgr.add(new Separator());
> }
>
>
> public class TextUebersicht extends ControlContribution {
> public TextUebersicht (){
> super("TextUebersicht");
> }
>
> protected Control createControl(Composite parent) {
>
> final Button btnSchriftArt = new Button (parent, SWT.PUSH);
> btnSchriftArt.setText("einstellen ...");
> try {
> btnSchriftArt.setImage(new Image(Display.getCurrent(),
> Platform.getBundle(client.Activator.PLUGIN_ID).
> getResource("images/font_truetype.gif").openStream()));
> }
> catch (IOException io) {
> io.printStackTrace();
> }
>
> final Menu menu = new Menu(getSite().getShell(), SWT.POP_UP);
> // final Menu menu = new Menu(topViewForm.getShell(),
> SWT.DROP_DOWN);
> MenuItem miMinischrift = new MenuItem(menu, SWT.PUSH);
> miMinischrift.setText("Minischrift");
> miMinischrift.setAccelerator(SWT.CTRL | '8');
> miMinischrift.addSelectionListener(new SelectionListener () {
> public void widgetSelected(SelectionEvent e) {
> System.out.println("Minischrift selected.");
> btnSchriftArt.setText("Minischrift");
> }
> public void widgetDefaultSelected(SelectionEvent e) {
> }
> });
>
>
> MenuItem miMikroschrift = new MenuItem(menu, SWT.PUSH);
> miMikroschrift.setText("Mikroschrift");
> miMikroschrift.addSelectionListener(new SelectionListener ()
> {
> public void widgetSelected(SelectionEvent e) {
> System.out.println("Mikroschrift selected.");
> btnSchriftArt.setText("Mikroschrift");
> }
> public void widgetDefaultSelected(SelectionEvent e) {
> }
> });
>
> MenuItem miBreiter = new MenuItem(menu, SWT.PUSH);
> miBreiter.setText("breiter");
> miBreiter.addSelectionListener(new SelectionListener () {
> public void widgetSelected(SelectionEvent e) {
> System.out.println("breiter selected.");
> btnSchriftArt.setText("breiter");
> }
> public void widgetDefaultSelected(SelectionEvent e) {
> }
> });
>
> MenuItem miSchmaler = new MenuItem(menu, SWT.PUSH);
> miSchmaler.setText("schmaler");
> miSchmaler.addSelectionListener(new SelectionListener () {
> public void widgetSelected(SelectionEvent e) {
> System.out.println("schmaler selected.");
> btnSchriftArt.setText("schmaler");
> }
> public void widgetDefaultSelected(SelectionEvent e) {
> }
> });
>
>
> MenuItem miEinstellen = new MenuItem(menu, SWT.PUSH);
> miEinstellen.setText("einstellen ...");
> miEinstellen.addSelectionListener(new SelectionListener () {
> public void widgetSelected(SelectionEvent e) {
> System.out.println("einstellen ... selected.");
> btnSchriftArt.setText("einstellen ...");
> }
> public void widgetDefaultSelected(SelectionEvent e) {
> }
> });
>
> final Composite par = parent;
> btnSchriftArt.addListener(SWT.Selection, new Listener() {
> public void handleEvent(Event event) {
> Rectangle rect = btnSchriftArt.getBounds();
> Point pt = new Point(rect.x, rect.y +
> rect.height);
> pt = par.toDisplay(pt);
> menu.setLocation(pt.x, pt.y);
> menu.setVisible(true);
> }
> });
>
> return btnSchriftArt;
> }
> }
>
>
Thanks a lot!
I understand perfectly how to solve it now :)
|
|
|
Powered by
FUDForum. Page generated in 0.03795 seconds