Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » OSX: HotKeys not working
OSX: HotKeys not working [message #733881] Wed, 05 October 2011 20:48 Go to next message
mathew.rowley is currently offline mathew.rowleyFriend
Messages: 7
Registered: April 2010
Junior Member
I am using the following code to try and activate a hotkey for a menuitem, that is shown when right clicking on a StyledText box:
    Shell shell = styledText.getShell();

    // Create the menu
    Menu menu = new Menu(shell, SWT.POP_UP);

    // Create Cut
    MenuItem item = new MenuItem(menu, SWT.NULL);
    item.setText("Select All");
    item.setAccelerator(SWT.MOD1 + 'A');
    item.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            styledText.selectAll();
        }
    });


When the application is run, I can see the COMMAND+A on the menu item, but when pressing it, nothing happens. Has anyone else run into this on OSX before? Thanks.
Re: OSX: HotKeys not working [message #734287 is a reply to message #733881] Fri, 07 October 2011 11:38 Go to previous messageGo to next message
Thomas Singer is currently offline Thomas SingerFriend
Messages: 75
Registered: July 2009
Member
Unfortunately, you've did not provide a fully self-contained example, so it is just guessing:

- What OS X version you are using?
- What happens when you click the menu item directly?
- Is there another menu item with this accelerator?
- Maybe the keyevent is "eaten" by some other control?
Re: OSX: HotKeys not working [message #734290 is a reply to message #734287] Fri, 07 October 2011 11:47 Go to previous messageGo to next message
mathew.rowley is currently offline mathew.rowleyFriend
Messages: 7
Registered: April 2010
Junior Member
I am using the most updated version of lion... I don't think there are any keys that can be overriding this its happening to all accelerators...
Re: OSX: HotKeys not working [message #734339 is a reply to message #734290] Fri, 07 October 2011 13:56 Go to previous messageGo to next message
Thomas Singer is currently offline Thomas SingerFriend
Messages: 75
Registered: July 2009
Member
Could you please provide a fully self-contained sample? At least it is no common OS X 10.7 problem, because for our project it works fine.
Re: OSX: HotKeys not working [message #734345 is a reply to message #734339] Fri, 07 October 2011 14:03 Go to previous messageGo to next message
mathew.rowley is currently offline mathew.rowleyFriend
Messages: 7
Registered: April 2010
Junior Member
Full working example:

package com.wuntee.oter.view;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

public class Test {

	protected Shell shell;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Test window = new Test();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(450, 300);
		shell.setText("SWT Application");
		shell.setLayout(new GridLayout(1, false));
		
		Composite composite = new Composite(shell, SWT.NONE);
		composite.setLayout(new GridLayout(1, false));
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		StyledText styledText = new StyledText(composite, SWT.BORDER);
		styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

		addTextMenu(styledText);
	}
	
	private void addTextMenu(final StyledText styledText) {
		Shell shell = styledText.getShell();
		Menu menu = new Menu(shell, SWT.POP_UP);
		MenuItem item = new MenuItem(menu, SWT.NULL);
		item.setText("Select All");
		item.setAccelerator(SWT.MOD1 + 'A');
		item.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				styledText.selectAll();
			}
		});
		styledText.setMenu(menu);
	}
}
Re: OSX: HotKeys not working [message #734368 is a reply to message #733881] Fri, 07 October 2011 14:46 Go to previous message
Thomas Singer is currently offline Thomas SingerFriend
Messages: 75
Registered: July 2009
Member
Thanks for the sample. IMHO accelerators of menu items in the context menu are ignored. Create a menu item in the shell menu bar and it should work.
Previous Topic:Re: Eclipse on OSX Lion is it safe?
Next Topic:MeasureItem event listener problem on Windows 7
Goto Forum:
  


Current Time: Fri Mar 29 05:28:42 GMT 2024

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

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

Back to the top