문제

In our RCP application, we need to resort to using a global key event handler (via Display.addFilter()) for more advanced key event handling/routing irrespective of current focus. We need to be able to determine if a dialog box is currently open for some of the routing logic.

Seems like a fairly trivial question but I keep hitting dead ends going off Widget hierarchy, Shells, WindowManagers.

I am looking for a robust solution that would not require any extra work on the part of Dialog implementers or client code that uses standard framework dialogs.

도움이 되었습니까?

해결책

In the example below, shell is a defined Shell in the scope. You could modify the code to compare activeShell with a list of Shells.

shell.getDisplay().addFilter(SWT.KeyDown, new Listener() {
    public void handleEvent(final Event event) {
        if (shell.isDisposed()) {
            return;
        }
        final Shell activeShell = shell.getDisplay().getActiveShell();
        if (activeShell != null && activeShell.equals(shell)) {
            if (event.stateMask == SWT.MOD1 && event.character == 'w') {
                shell.dispose();
            }
        }
    }
});

This example code will close shell when +W is pressed on Mac.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top