如何在基于 Eclipse 的应用程序中将按键重定向到另一个 shell?

发布于 2024-11-10 05:55:21 字数 911 浏览 2 评论 0原文

我正在研究一种方法,使基于 Eclipse 的 RCP 应用程序中的 EditorPart 最大化,使其完全全屏、无修剪、无菜单等。实际上,它是 GEF 编辑器。这有点像黑客,但它确实有效:

GraphicalViewer viewer = (GraphicalViewer)getWorkbenchPart().getAdapter(GraphicalViewer.class);
        Control control = viewer.getControl();
        Composite oldParent = control.getParent();

        Shell shell = new Shell(SWT.APPLICATION_MODAL);
        shell.setFullScreen(true);
        shell.setMaximized(true);

        // Some code here to listen to Esc key to dispose Shell and return...

        shell.setLayout(new FillLayout());
        control.setParent(shell);
        shell.open();

基本上它将 GraphicalViewer 控件的父级设置为新创建的最大化的 Shell。按 escape 会将控件返回到其原始父级(为简洁起见,未显示代码)。

唯一不起作用的是接收全局按键(DelCtrl+ZCtrl+ A)为工作台声明并转发到 EditorPart 的那些。有什么方法可以连接到这些或将它们从 EditorPart 重定向到将它们转发到 GraphicalViewer 吗?

提前致谢

I'm working on a way to maximise an EditorPart in my Eclipse-based RCP app to be absolutely full-screen, no trim, no menu, and so on. Actually, it's a GEF Editor. It's a bit of a hack, but it kind of works:

GraphicalViewer viewer = (GraphicalViewer)getWorkbenchPart().getAdapter(GraphicalViewer.class);
        Control control = viewer.getControl();
        Composite oldParent = control.getParent();

        Shell shell = new Shell(SWT.APPLICATION_MODAL);
        shell.setFullScreen(true);
        shell.setMaximized(true);

        // Some code here to listen to Esc key to dispose Shell and return...

        shell.setLayout(new FillLayout());
        control.setParent(shell);
        shell.open();

Basically it sets the parent of the GraphicalViewer control to the newly created, maximised Shell. Pressing escape will return the control to it's original parent (code not shown for brevity).

The only thing that doesn't work is receiving global key presses (Del, Ctrl+Z, Ctrl+A) the ones that are declared for the Workbench and forwarded to the EditorPart. Is there any way I can hook into these or redirect them from the EditorPart to forward them on to the GraphicalViewer?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

此刻的回忆 2024-11-17 05:55:21

简短的回答是你不能这样做。一旦您将该组合重新设置为工作台窗口之外的父级,它就完全崩溃了。系统无法正确处理该部件,因为事件(如激活、焦点、setBounds(*))未被处理。

唯一受支持的方法是打开一个新的 Workbench 窗口,其中的透视图仅包含编辑器区域,并为该窗口扩展 org.eclipse.ui.application.WorkbenchWindowAdvisor.createWindowContents(Shell) 方法+透视组合,使用 org.eclipse.ui.application.IWorkbenchWindowConfigurer 隐藏所有不需要的修剪。

例如,在 MyWorkbenchWindowAdvisor 中:

public void createWindowContents(Shell shell) {
    if (isCreatingSpecialPerspective()) {
        final IWorkbenchWindowConfigurer config = getWindowConfigurer();
        config.setShowCoolBar(false);
        config.setShowFastViewBars(false);
        config.setShowMenuBar(false);
        config.setShowPerspectiveBar(false);
        config.setShowProgressIndicator(false);
        config.setShowStatusLine(false);
    }
    super.createWindowContents(shell);
}

另请查看 http://code.google.com/p/eclipse- fullscreen/ 其中包含 EPLed 代码,涉及运行具有全屏支持的 RCP 程序。

The short answer is you can't do that. Once you re-parent that composite out of the workbench window, it's totally busted. The system won't correctly deal with the part, as events (like activation, focus, setBounds(*)) aren't being processed.

The only supported way would be to open a new Workbench window with a perspective that only contained the editor area, and extending your org.eclipse.ui.application.WorkbenchWindowAdvisor.createWindowContents(Shell) method for that window+perspective combination to hide all of the trim you don't want, using org.eclipse.ui.application.IWorkbenchWindowConfigurer.

ex, in MyWorkbenchWindowAdvisor:

public void createWindowContents(Shell shell) {
    if (isCreatingSpecialPerspective()) {
        final IWorkbenchWindowConfigurer config = getWindowConfigurer();
        config.setShowCoolBar(false);
        config.setShowFastViewBars(false);
        config.setShowMenuBar(false);
        config.setShowPerspectiveBar(false);
        config.setShowProgressIndicator(false);
        config.setShowStatusLine(false);
    }
    super.createWindowContents(shell);
}

Also check out http://code.google.com/p/eclipse-fullscreen/ which has EPLed code in it concerned with running an RCP program with fullscreen support.

千秋岁 2024-11-17 05:55:21

我的建议是尝试从另一个角度来解决这个问题。不要在代码中侦听击键并对其进行操作,而是定义 您自己的键绑定方案 然后创建命令并使它们使用此方案。这意味着您不再需要监听代码中的击键,而是通过这些击键执行的命令来执行需要完成的任何操作。

My suggestion is to try to approach this problem from another angle. Instead of listening for keystrokes in your code and acting upon them, define your own key binding scheme and then create commands and make them use this scheme. This would mean that you no longer have to listen for the key strokes in your code, but instead do whatever needs to be done through commands executed by these key strokes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文