在我的 Eclipse 插件中,我需要知道屏幕上可见的编辑器何时发生更改。我目前正在获取活动编辑器,如下所示:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
这适用于大多数情况,除非按下绿色“继续”按钮:
如果我使用 F8 快捷键,则活动编辑器将按预期更新。
似乎活动编辑器属性在编辑器选项卡获得焦点之前不会更新(按下“继续”按钮时不会发生这种情况)。
我还可以采取其他途径来获得“可见编辑器”吗?
提前致谢。
艾伦
In my Eclipse plugin, I need to know when the editor that is visible on the screen has changed. I am currently getting the active editor as follows:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
This works for most cases except for when the green Continue button is pressed:
If I use the F8 shortcut then the active editor is updated as expected.
It seems that the active editor property is not updated until the editor tab gets focus (which doesn't happen when the Continue button is pressed).
Is there any other route that I can take to get the "visible editor"?
Thanks in advance.
Alan
发布评论
评论(3)
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage( ).getEditorReferences()
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences()
IWorkbenchPage 接口有一个 isPartVisible()` 方法,用于指示指定部分是否可见。结果不取决于指定部分当前是否处于活动状态,即是否具有焦点。
然而,要查找可见但当前不活动的编辑器,仅在活动工作台页面上调用此方法可能还不够。相反,您可能必须迭代所有工作台窗口并检查编辑器在每个窗口页面上的可见性。
The
IWorkbenchPage interface has an
isPartVisible()` method which indicates if the specified part is visible. The result does not depend on whether the specified part is currently active, i.e. has focus, or not.To find a visible but currently not active editor it may however not be sufficient to simply call this method on the active workbench page. Instead you might have to iterate over all workbench windows and check the visibility of your editor on the page of each of them.
该问题与下面链接中发布的问题类似。实现此目的的一种方法是通过创建零件监听器来跟踪先前打开的编辑器。
Eclipse 插件 - 如何获取编辑器的最后一次工作
The question is similar to the question posted in the link below. One way to achieve this is to keep track of which editor was previously opened by creating a Part Listener.
Eclipse Plugin - How to get the last worked on editor