当焦点在StyledText小部件上时,Jface加速键不在macOS上工作

时间:2018-01-07 21:54:44

标签: java eclipse swt jface

在StyledText或Text小部件中,单个字母键加速器在Windows上正常工作。但是,它不适用于macOS:

  • Windows上的所有优点:当文本视图聚焦时按“A”会显示弹出窗口(并且不输出字母A)
  • macOS失败:当文本视图聚焦时按“A”不会显示弹出窗口(并且输出字母A)

我正在使用最新版本的SWT和Jface包(随Eclipse Oxygen.2提供)。在macOS High Sierra 10.13上进行测试。

(请注意,在构造时使StyledText READ_ONLY不能解决问题;键仍然由文本小部件而不是Jface键绑定管理器处理。)

下面的简单演示片段。任何帮助将不胜感激!感谢。

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();
    }
}

0 个答案:

没有答案