Eclipse插件 - 如何获得最后的编辑工作 [英] Eclipse Plugin - How to get the last worked on editor

查看:156
本文介绍了Eclipse插件 - 如何获得最后的编辑工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个eclipse插件,它使用几个按钮向用户显示一个视图。点击任何按钮,我想将某个注释粘贴到用户当前正在工作的编辑器窗口中,并在他指向的光标位置。



用户单击按钮后,编辑器窗口将不再具有焦点,并且以下代码不起作用。

  workbench.getActiveWorkbenchWindow( ).getActivePage()。getActiveEditor()

如何检测用户正在工作的编辑器窗口和用户点击按钮前的光标位置?

解决方案

使用 IPartListener 收听部分激活事件。



在您的视图初始化中设置侦听器:

  getSite()GETPAGE()addPartListener(partListener)。; 

(不要忘了删除视图中的侦听器处理)。



除此之外,这将为您提供部分激活事件:

  public void partActivated(IWorkbenchPart部分)

如果 part 是一个 IEditorPart 那么它是一个被激活的编辑器。所以你只需要跟踪这个激活的编辑器。


I am writing an eclipse plugin which exposes a view to the user with several buttons. On the click of any button, I would like to paste a certain comment into the editor window where the user is currently working and at the cursor location he is pointing to.

Once the user clicks the button, the editor window no longer has focus and the following code does not work.

workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor()

How can I detect the editor window where the user was working and the cursor location before the user clicked the button?

解决方案

Use an IPartListener to listen to part activation events.

Set the listener up in your view initialization:

getSite().getPage().addPartListener(partListener);

(and don't forget to remove the listener in the view dispose).

Among other things this will give you part activation events:

public void partActivated(IWorkbenchPart part)

If part is an instance of IEditorPart then it is an editor being activated. So you just need to keep track of this activated editor.

这篇关于Eclipse插件 - 如何获得最后的编辑工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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