Programatically open file as non-default editor

Is there any way to open a file and have it not come up as text, but rather as an alternative editor? For example, suppose one had a plugin that showed an XML file as a structured graph, using the wicked cool new graphing library. Suppose further that the graph included nodes which referred to other XML files. It's easy enough to create a "Goto file" action, which will open up the file corresponding to the selected node, using the FileEditorManager. Unfortunately, that opens up the file using the default editor, showing a bunch of XML text. What I would like to do is be able to open the file corresponding to the selected node while staying in the cool structured graph mode. FileEditorManager doesn't seem to be capable of doing this. Any pointers, or should I file a JIRA?

--Dave Griffith

7 comments

Perhaps I am misunderstanding you, but isn't the "getPolicy()" method in com.intellij.openapi.fileEditor.FileEditorProvider what you need? As far as I understand it making that return com.intellij.openapi.fileEditor.FileEditorPolicy#PLACE_BEFORE_DEFAULT_EDITOR opens your editor in front.

Bas

0

Opps, misunderstandingthe problem :)

0

Maybe I'm misunderstanding, but wouldn't that always make the non-default editor open when files of that type were opened? If so, that would be very, very, bad for my use case, to the point of making IDEA unusable. What I honestly need is a way for an action to programatically open a file in a non-default editor, while normal opening behaviour remains unchanged.

--Dave Griffith

0

Well, the method wouldn't have to return the same value every time. If there isn't a proper way to do what you need, the navigate action could temporarily change the return value and set it back afterward. Kind of a hack, but perhaps it would work.

Bas

0

Yeah, I thought of that, but I'm guessing it wouldn't work with files that were already "open" but not visible. Editor selection seems sticky for those, which means they must be ignoring the editor sorting stuff when they become visible.

Oh well, I'll submit a JIRA. It was a minor-but-nice feature that I can ship without.

--Dave Griffith

0

Please sign in to leave a comment.