How to get “active editor” in Eclipse plugin?

前端 未结 3 1929
一个人的身影
一个人的身影 2021-01-04 05:40

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:

Platform         


        
相关标签:
3条回答
  • 2021-01-04 06:14

    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

    0 讨论(0)
  • 2021-01-04 06:15

    The IWorkbenchPage interface has anisPartVisible()` 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.

    0 讨论(0)
  • 2021-01-04 06:24
    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()

    0 讨论(0)
提交回复
热议问题