如何让工作台窗口在基于 Eclipse 的项目中打开模式对话框?

为了打开一个模态对话框,你需要传递一个父窗口,并传递必要的标志,使对话框成为模态的.

In order to open a modal dialog, you need to pass a parent window, and pass the necessary flags for the dialog to be modal of course.

根据您在 Eclipse 基础架构中的位置,找到这个父窗口并不总是那么容易.

Depending on where you are in the eclipse infrastructure, finding this parent window is not always easy.

如何访问父窗口?

推荐答案

从视图或编辑器(这部分很简单):

From a view or an editor (this part is easy):

this.getSite().getWorkbenchWindow().getShell()

从其他地方访问视图或编辑器,与上述相同.

From elsewhere, access a view or editor and same as above.

如果您发现自己在一个无法访问视图或编辑器的课程中,您可能不想调用任何 UI 代码,但如果您真的想在脚下开枪:

If you find yourself in a class where you don't have access to a view or editor, you probably don't want to be calling any UI code, but if you really want to shoot yourself in the foot:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()

相关文章