How to open editor tab with code?

Answered

Hi,

Can someone please tell me what to use if I want to open a new editor window for a specific file, within my plugin? I have tried with editor, project and FileEditorManager. It seems like FileEditorManager is the way to go but the methods setSelectedEditor or openFile dont work for me. I've checked that both the project and virtual file are valid.

Thanks.

4 comments
Comment actions Permalink

WDYM with "open a new editor window for a specific file"? Open the given file or open _another_ editor tab for that file?

see com.intellij.ide.util.EditSourceUtil#navigate, com.intellij.ide.util.PsiNavigationSupport#createNavigatable and com.intellij.util.PsiNavigateUtil

0
Comment actions Permalink

Thank you, I meant open an editor tab for that file. Everything is working

0
Comment actions Permalink

Are you looking for the FileEditorManager.openTextEditor? e.g.

FileEditorManager.getInstance(<project>).openTextEditor(new OpenFileDescriptor(<project>, <file>), true);

 

0
Comment actions Permalink

Yes this is what I was looking for and ended up using. It worked as I wanted it to, thank you :)

0

Please sign in to leave a comment.