OSX: HotKeys not working [message #733881] |
Wed, 05 October 2011 16:48  |
Eclipse User |
|
|
|
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 #734345 is a reply to message #734339] |
Fri, 07 October 2011 10:03   |
Eclipse User |
|
|
|
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);
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.85897 seconds