Eclipse Plugin - How to get the last worked on editor
Asked Answered
S

1

3

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?

Sterculiaceous answered 30/4, 2014 at 13:28 Comment(0)
I
5

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.

Immotile answered 30/4, 2014 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.