Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Jface accelerator key not working on macOS when focus is on StyledText widget
Jface accelerator key not working on macOS when focus is on StyledText widget [message #1779437] Mon, 08 January 2018 01:17 Go to next message
Nicolas Falliere is currently offline Nicolas FalliereFriend
Messages: 2
Registered: March 2015
Junior Member
Hello,

Within a StyledText or Text widget, a single letter key accelerator is working fine on Windows. However, it is not working on macOS:
- All good on Windows: pressing 'A' when the text view is focused displays the pop-up (and the letter A is not output)
- Fail on macOS: pressing 'A' when the text view is focused does NOT display the pop-up (and the letter A is output)

I'm using the latest version of SWT and Jface packages (provided with Eclipse Oxygen.2). Testing on macOS High Sierra 10.13.

(Note that making the StyledText READ_ONLY at construction does not mitigate the problem; the key still gets processed by the text widget instead of the Jface key binding manager.)

Simple demo snippet below. Any help would be greatly appreciated! Thanks. (I also posted this question on SO: q/48141897/950494).

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Decorations;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;

public class AcceleratorsTest {

    static class ActionTest extends Action {
        ActionTest() {
            super("Sample Action");
            setAccelerator('A');
        }

        @Override
        public void run() {
            MessageDialog.openInformation(null, "hello", "hello");
        }
    }

    public static void main(String[] args) {
        Display display = Display.getDefault();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());

        // menu with one action having the accelerator key 'A'
        MenuManager menuManager = new MenuManager();
        Menu menu = menuManager.createMenuBar((Decorations)shell);
        shell.setMenuBar(menu);
        MenuManager menuFile = new MenuManager("File");
        menuFile.add(new ActionTest());
        menuManager.add(menuFile);
        menuManager.updateAll(true);

        // text widget fills up the main shell
        StyledText text = new StyledText(shell, SWT.BORDER | SWT.READ_ONLY);
        text.setText("Accelerators problem inside StyledText:\r\n"
                + " - okay on Windows: pressing A when the text view is focused displays the pop-up (and the letter A is not output)<br>\r\n"
                + " - fail on macOS: pressing A when the text view is focused does NOT display the pop-up (and the letter A is output)");

        // event loop
        shell.open();
        while(!shell.isDisposed()) {
            if(!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}
Re: Jface accelerator key not working on macOS when focus is on StyledText widget [message #1779641 is a reply to message #1779437] Wed, 10 January 2018 15:34 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 772
Registered: January 2012
Senior Member

Accelerators generally require a modifier, like SWT.CTRL, so I'm not really surprised. If you want to bind actions to specific keys for your StyledText, you'll likely need to use a key-down/-up listener.

Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Jface accelerator key not working on macOS when focus is on StyledText widget [message #1779648 is a reply to message #1779641] Wed, 10 January 2018 17:53 Go to previous message
Nicolas Falliere is currently offline Nicolas FalliereFriend
Messages: 2
Registered: March 2015
Junior Member
Brian,

Those accelerators (single key w/o modifier) work fine with one of my E4 apps though, on all platforms.

As said, the issue/discrepancy in behavior is when using Jface's actions and associated key binding manager, on macOS only.

There's been a bit of discussion with greg-449 on SO here, if you are interested: https://stackoverflow.com/questions/48141897/jface-accelerator-key-not-working-on-macos-when-focus-is-on-styledtext-widget

IMO this deserves a fix: single key accelerators work fine on win32 and GTK; they should work similarly fine on macOS. In the meantime, I have implemented a custom key accelerator manager. It turns out that was the best option since I needed things that Jface's does not support as far as I know (such as multiple accelerators per handler, etc.)

Thanks for your answer! I'm still interested to know if this issue could be worked around, and follow up on any bug ticket that may be filed.

Nicolas
Previous Topic:Scrolling JFace viewers on a white background (Linux/GTK)
Next Topic:Missing minimize, maximize buttons in Dialog on Linux
Goto Forum:
  


Current Time: Sun Sep 23 20:08:40 GMT 2018

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

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

Back to the top