Multi-Tab FileEditor, focusing custom tab on editor open

Answered

Hi,

I have written a custom file type extension and registered it in the plugin.xml file. Further, I have written a new FileEditor implementing com.intellij.openapi.fileEditor.FileEditor interface to open my custom file types. 

I have the reference to the PsiFile object which represent one of my custom file type. When I execute 

PsiNavigateUtil.navigate(myPsiFile)

the file is opened in my custom editor window as well. This editor has two tabs (Text and UI). I have specified the my UI panel as the

getPreferredFocusedComponent()

But when the editor is opened, the Text tab is always focused. Is there any way to open the editor where UI tab is focused.

3 comments
Comment actions Permalink

Method `com.intellij.openapi.fileEditor.FileEditor#getPreferredFocusedComponent` returns a component to be focused when a custom editor is selected. Also, `PsiNavigateUtil.navigate(myPsiFile)` simply opens the last opened FileEditor for this file.

Consider implementing com.intellij.openapi.fileEditor.FileEditorProvider#getPolicy

0
Comment actions Permalink

Hi Sergey,

I have solved it in following manner

FileEditorManager.getInstance(project).openFile(result.getVirtualFile(), true);

Above line will open the file in the editor window

FileEditorManager.getInstance(project).setSelectedEditor(result.getVirtualFile(), EDITOR_TYPE_ID)

Above line will focus the custom editor I have provided. In here the "EDITOR_TYPE_ID" is the String returned by 

String getEditorTypeId()

method in my custom FileEditorProvider implementation.

BTW: Thank you for you answer :)

1
Comment actions Permalink

Great, thanks for sharing this solution.

0

Please sign in to leave a comment.