简体   繁体   English

如何在Eclipse RCP中侦听/确定活动/最高级编辑器?

[英]How to listen/determine for active/topmost editor in Eclipse RCP?

Is there a notion of active or topmost editor in Eclipse? Eclipse中有活动的或最顶层的编辑器吗?

I wrote a view and want it to show some data about active editor. 我编写了一个视图,并希望它显示一些有关活动编辑器的数据。

Currently I am using selection service, while editor is providing selection information. 目前,我正在使用选择服务,而编辑器正在提供选择信息。 Unfortunately, this way I can't distinguish if editor was deselected or closed. 不幸的是,这种方式我无法区分是取消选择还是关闭了编辑器。 So I am showing last selected editor information even after it was closed. 因此,即使关闭后,我仍在显示最后选择的编辑器信息。

Use an IPartListener (or IPartListener2 ) to be informed about all the changes to active parts. 使用IPartListener (或IPartListener2 )可通知有关活动零件的所有更改。

IPartService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService();

service.addPartListener(listener);

IPartService also has a getActivePart() method - the active part may be a view as well as an editor. IPartService还具有getActivePart()方法-活动部件可以是视图也可以是编辑器。

The above is assuming an Eclipse 3.x style RCP, Eclipse e4 is different. 上面假设Eclipse 3.x样式的RCP与Eclipse e4不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM