IntelliJ get open tabs


I was wondering if there's a way to get the open files in a project and collect them by their group.

I'd like to make a snapshot of the open files, and then restore all the open files in the exact same layout it was before. Is there a way to achieve it?


See com.intellij.openapi.fileEditor.FileEditorManager.
Not sure what you want to achieve, given that restoring editors is default IDE feature?


Sorry, English is not my first language, let me give you a bit more context.

I have a plugin that allows to save the session in a JSON file and then restore it from the same file. Basically, I get all the open files by using this piece of code:

FileDocumentManager fdm = FileDocumentManager.getInstance();
Editor[] editors = EditorFactory.getInstance().getAllEditors();
List<String> openFiles =
		.map(e -> fdm.getFile(e.getDocument()))
		.map(s -> PathUtils.normalizeFileName(project, s))
		.filter(s -> !s.isBlank())
// Then the list is serialized (with a bunch of other info) into a JSON file
// Through another dialog, the user can choose one of the previously saved sessions and restore all the files open during that session					

(Note that I get the path of a VirtualFile and then convert it to a String, but that's not relevant here)

This however doesn't allow me to distinguish between files opened in different groups or even different windows. I was asking if there is a way to split the results, said in code what I'd like to achieve is something like this:

Map<K, List<String>> openFiles = ...

Where K is Group/Tab/Window.

Did I explain myself better? Do you understand what I'd like to achieve now?


P.S: yes, I know that the IDE already restores the session on open. But that's not true when moving to other devices. I store my projects on an external NVME drive because I often switch between my desktop PC and laptop. What IntelliJ does is remembering the session on the specific device. In fact, I'd really love to see this as a future improvement, instead of saving the session on the device, it should be saved in the .idea directory


Sorry for delay, researching..


Alessandro sorry for a delay.
It is possible to get information about all splits and separate Editor windows. And then restore the state using this info.
There is an API for that, but it is internal and not intended to be used by the plugin developers, because it is an implementation detail.
You can take a look at the existing implementation of saving and restoring the editors state here: `com.intellij.tasks.context.OpenEditorsContextProvider`


Please sign in to leave a comment.