How to get "active editor" in Eclipse plugin?

Alan Spark picture Alan Spark · Feb 19, 2012 · Viewed 14.8k times · Source

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:

Debugger buttons

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

Thanks in advance.

Alan

Answer

codejammer picture codejammer · Feb 19, 2012
  1. An editor is active only when it has focus, so what you are getting is the right output by the API. The user of your plugin will not be running it in debug mode, so not a concern for the end user
  2. Alternatively, to get all open editors you can do the following:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences()