Eclipse插件 - 如何获得最后的编辑工作 [英] Eclipse Plugin - How to get the last worked on editor
问题描述
用户单击按钮后,编辑器窗口将不再具有焦点,并且以下代码不起作用。
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屋!