如何获得“活动编辑器”在Eclipse插件? [英] How to get "active editor" in Eclipse plugin?

查看:427
本文介绍了如何获得“活动编辑器”在Eclipse插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Eclipse插件中,我需要知道屏幕上可见的编辑器是否发生变化。我正在获得如下主动编辑器:

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:

如果我使用F8快捷方式,则活动编辑器将按预期更新。

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"?

提前感谢

Alan

推荐答案

IWorkbenchPage接口有一个 isPartVisible()`方法,指示指定的部分是否可见。结果不取决于指定的部分当前是否处于活动状态,即是否具有焦点。

The IWorkbenchPage interface has anisPartVisible()` 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插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆