Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get "active editor" in Eclipse plugin?

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

like image 619
Alan Spark Avatar asked Feb 19 '12 11:02

Alan Spark


People also ask

How do I get active editor in Eclipse?

Show activity on this post. 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).

Why is my Eclipse showing editor does not contain a main type?

If you are using eclipse and you have declared the “main” method in your program and you have written it inside the class then you have to check that you have added the build path or not. If you have not added then:- go to project properties -> Choose java build path -> Click on the source.

How do I change the code editor in Eclipse?

to right click on the HTML file in package explorer > Open With > choose another editor (e.g. text editor). This only associates with current file. If you want to change file association for all HTMLs: goto Preferences (under menu Window) > General > Editor > File Associations and change HTML file association there.


1 Answers

  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()

like image 68
codejammer Avatar answered Sep 21 '22 00:09

codejammer