Search code examples
intellij-ideaintellij-plugin

How to enumerate editors and their locations in Intellij Platform SDK?


I have the following example layout on screen

enter image description here

How to enumerate these editors and their locations from within Plugin code?

Any hints please. Can't understand where to dig...


The following code

IdeFrame[] ideFrames = windowManager.getAllProjectFrames();

return only one entry

enter image description here


Solution

  • You can find all active/open editors by using the selectedEditors property of the FileEditorManager, and then ask each editor for their location on screen:

    FileEditorManager.getInstance(project).selectedEditors.associateWith {
        it.component.locationOnScreen
    }
    

    In Java that could be something like

    Editor[] editors = FileEditorManager.getInstance(project).getSelectedEditors()
    Point[] locations = editors.stream()
        .map(editor -> editor.getComponent().getLocationOnScreen())
        .collect(Collectors.toList())
    

    (It probably depends on your context and what you want to do with it how you'd implement this, but you get the idea.)