GXT:如何拦截 ctrl-f4
我想拦截 Ctrl+F4 以便关闭 TabPanel 的选项卡,而不是关闭我的应用程序正在其中运行的浏览器选项卡。如果我单击以下代码,则以下代码有效首先在选项卡面板内部:
Viewport v = new Viewport();
v.setLayout(new FitLayout());
v.add(panel);
v.addListener(Events.KeyDown, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent be) {
KeyEvent ce = (KeyEvent)be;
if (ce.isControlKey()) {
if (ce.getKeyCode() == 115) {
System.out.println(ce.getKeyCode() + " Ctrl-f4");
ce.preventDefault();
ce.stopEvent();
}
}
};
});
有趣的是,如果焦点位于 TabPanel 之外的某个位置(显然位于视口内部),则不会触发该事件。
有什么想法吗?
I'd like to intercept Ctrl+F4 in order to close tabs of a TabPanel rather then the browser tab my application is running in. The following code is works if I click inside the tab panel first:
Viewport v = new Viewport();
v.setLayout(new FitLayout());
v.add(panel);
v.addListener(Events.KeyDown, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent be) {
KeyEvent ce = (KeyEvent)be;
if (ce.isControlKey()) {
if (ce.getKeyCode() == 115) {
System.out.println(ce.getKeyCode() + " Ctrl-f4");
ce.preventDefault();
ce.stopEvent();
}
}
};
});
The funny thing is that if the focus is somewhre outside the TabPanel (which is obviously located inside the Viewport) the event isn't fired.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ctrl-f4
是 Windows 特定的,因此您不应该依赖它。相反,要捕获用户关闭窗口/选项卡,请使用 Window.ClosingHandler :
这将显示一个浏览器对话框,其中包含您的消息和确认按钮。
ctrl-f4
is windows specific, so you should not rely on it.Instead to catch user closing window/tab use
Window.ClosingHandler
:This will show a browser dialog with your message and confirm buttons.
您可以使用
ClosingHandler
拦截窗口关闭事件并提示用户确认。但是,您无法完全阻止窗口/选项卡关闭 - 浏览器将不允许这样做。您将必须选择不同的键盘快捷键。选择快捷方式后,请使用
NativePreviewHandler
来检测它:You can use a
ClosingHandler
to intercept the window close event and prompt the user for confirmation. You cannot, however, completely block the window/tab from closing - the browser will not allow it. You're going to have to choose a different keyboard shortcut.Once you choose your shortcut use a
NativePreviewHandler
to detect it: