Reputation: 8292
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:
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
Upvotes: 13
Views: 17864
Reputation: 41
The IWorkbenchPage interface has an
isPartVisible()` method which indicates if the specified part is visible. The result does not depend on whether the specified part is currently active, i.e. has focus, or not.
To find a visible but currently not active editor it may however not be sufficient to simply call this method on the active workbench page. Instead you might have to iterate over all workbench windows and check the visibility of your editor on the page of each of them.
Upvotes: 1
Reputation: 1676
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences()
Upvotes: 2
Reputation: 445
The question is similar to the question posted in the link below. One way to achieve this is to keep track of which editor was previously opened by creating a Part Listener. Eclipse Plugin - How to get the last worked on editor
Upvotes: 0